diff mbox

[U-Boot,1/2] common: miiphyutil: Add helper function for mdio bus name

Message ID 161adaf92b92376e40e8d6cdce964c2470cf68d2.1481265537.git.michal.simek@xilinx.com
State Superseded
Delegated to: Joe Hershberger
Headers show

Commit Message

Michal Simek Dec. 9, 2016, 6:39 a.m. UTC
The most of ethernet drivers are using this mdio registration sequence.
strcpy(priv->bus->name, "emac");
mdio_register(priv->bus);
Where driver can be used only with one MDIO bus because only unique
name should be used.

Other drivers are using unique device name for MDIO registration to
support multiple instances.
snprintf(priv->bus->name, sizeof(bus->name), "%s", name);

With DM dev->seq is used more even in logs
(like random MAC address generation:
printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
       dev->name, dev->seq, pdata->enetaddr);
)
where eth%d prefix is used.

Simplify driver code to register mdio device with dev->seq number
to simplify mdio registration and reduce code duplication across
all drivers. With DM_SEQ_ALIAS enabled dev->seq reflects alias setting.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
---

For example:

Board: Xilinx Zynq
Net:   ZYNQ GEM: e000b000, phyaddr 7, interface rgmii-id

Warning: ethernet@e000b000 (eth0) using random MAC address -
7a:fc:90:53:6a:41
eth0: ethernet@e000b000ZYNQ GEM: e000c000, phyaddr ffffffff, interface
rgmii-id

Warning: ethernet@e000c000 (eth3) using random MAC address -
1a:ff:d7:1a:a1:b2
, eth3: ethernet@e000c000
** Bad device size - mmc 0 **
Checking if uenvcmd is set ...
Hit any key to stop autoboot:  0
Zynq> mdio list
eth0:
17 - Marvell 88E1111S <--> ethernet@e000b000
eth3:
17 - Marvell 88E1111S <--> ethernet@e000c000
Zynq>

---
 common/miiphyutil.c | 12 ++++++++++++
 include/miiphy.h    |  1 +
 2 files changed, 13 insertions(+)

Comments

Joe Hershberger Dec. 9, 2016, 6:40 p.m. UTC | #1
On Fri, Dec 9, 2016 at 12:39 AM, Michal Simek <michal.simek@xilinx.com> wrote:
> The most of ethernet drivers are using this mdio registration sequence.
> strcpy(priv->bus->name, "emac");
> mdio_register(priv->bus);
> Where driver can be used only with one MDIO bus because only unique
> name should be used.
>
> Other drivers are using unique device name for MDIO registration to
> support multiple instances.
> snprintf(priv->bus->name, sizeof(bus->name), "%s", name);
>
> With DM dev->seq is used more even in logs
> (like random MAC address generation:
> printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
>        dev->name, dev->seq, pdata->enetaddr);
> )
> where eth%d prefix is used.
>
> Simplify driver code to register mdio device with dev->seq number
> to simplify mdio registration and reduce code duplication across
> all drivers. With DM_SEQ_ALIAS enabled dev->seq reflects alias setting.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>

Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Simon Glass Dec. 11, 2016, 8:27 p.m. UTC | #2
Hi Michal,

On 9 December 2016 at 01:39, Michal Simek <michal.simek@xilinx.com> wrote:
> The most of ethernet drivers are using this mdio registration sequence.
> strcpy(priv->bus->name, "emac");
> mdio_register(priv->bus);
> Where driver can be used only with one MDIO bus because only unique
> name should be used.
>
> Other drivers are using unique device name for MDIO registration to
> support multiple instances.
> snprintf(priv->bus->name, sizeof(bus->name), "%s", name);
>
> With DM dev->seq is used more even in logs
> (like random MAC address generation:
> printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
>        dev->name, dev->seq, pdata->enetaddr);
> )
> where eth%d prefix is used.
>
> Simplify driver code to register mdio device with dev->seq number
> to simplify mdio registration and reduce code duplication across
> all drivers. With DM_SEQ_ALIAS enabled dev->seq reflects alias setting.
>
> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
> ---
>
> For example:
>
> Board: Xilinx Zynq
> Net:   ZYNQ GEM: e000b000, phyaddr 7, interface rgmii-id
>
> Warning: ethernet@e000b000 (eth0) using random MAC address -
> 7a:fc:90:53:6a:41
> eth0: ethernet@e000b000ZYNQ GEM: e000c000, phyaddr ffffffff, interface
> rgmii-id
>
> Warning: ethernet@e000c000 (eth3) using random MAC address -
> 1a:ff:d7:1a:a1:b2
> , eth3: ethernet@e000c000
> ** Bad device size - mmc 0 **
> Checking if uenvcmd is set ...
> Hit any key to stop autoboot:  0
> Zynq> mdio list
> eth0:
> 17 - Marvell 88E1111S <--> ethernet@e000b000
> eth3:
> 17 - Marvell 88E1111S <--> ethernet@e000c000
> Zynq>
>
> ---
>  common/miiphyutil.c | 12 ++++++++++++
>  include/miiphy.h    |  1 +
>  2 files changed, 13 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>

But please see below.

>
> diff --git a/common/miiphyutil.c b/common/miiphyutil.c
> index aca18db52a00..8eb0f761bb01 100644
> --- a/common/miiphyutil.c
> +++ b/common/miiphyutil.c
> @@ -107,6 +107,18 @@ int mdio_register(struct mii_dev *bus)
>         return 0;
>  }
>
> +int mdio_register_seq(struct mii_dev *bus, int seq)
> +{
> +       int ret;
> +
> +       /* Setup a unique name for each mdio bus */
> +       ret = snprintf(bus->name, MDIO_NAME_LEN, "eth%d", seq);
> +       if (ret < 0)
> +               return ret;
> +
> +       return mdio_register(bus);
> +}
> +
>  int mdio_unregister(struct mii_dev *bus)
>  {
>         if (!bus)
> diff --git a/include/miiphy.h b/include/miiphy.h
> index 83141b4a6ae1..df371425441d 100644
> --- a/include/miiphy.h
> +++ b/include/miiphy.h
> @@ -48,6 +48,7 @@ void miiphy_listdev(void);
>  struct mii_dev *mdio_alloc(void);
>  void mdio_free(struct mii_dev *bus);
>  int mdio_register(struct mii_dev *bus);
> +int mdio_register_seq(struct mii_dev *bus, int seq);

Please can you add a comment for this function?

>  int mdio_unregister(struct mii_dev *bus);
>  void mdio_list_devices(void);
>
> --
> 1.9.1
>

Regards,
Simon
diff mbox

Patch

diff --git a/common/miiphyutil.c b/common/miiphyutil.c
index aca18db52a00..8eb0f761bb01 100644
--- a/common/miiphyutil.c
+++ b/common/miiphyutil.c
@@ -107,6 +107,18 @@  int mdio_register(struct mii_dev *bus)
 	return 0;
 }
 
+int mdio_register_seq(struct mii_dev *bus, int seq)
+{
+	int ret;
+
+	/* Setup a unique name for each mdio bus */
+	ret = snprintf(bus->name, MDIO_NAME_LEN, "eth%d", seq);
+	if (ret < 0)
+		return ret;
+
+	return mdio_register(bus);
+}
+
 int mdio_unregister(struct mii_dev *bus)
 {
 	if (!bus)
diff --git a/include/miiphy.h b/include/miiphy.h
index 83141b4a6ae1..df371425441d 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -48,6 +48,7 @@  void miiphy_listdev(void);
 struct mii_dev *mdio_alloc(void);
 void mdio_free(struct mii_dev *bus);
 int mdio_register(struct mii_dev *bus);
+int mdio_register_seq(struct mii_dev *bus, int seq);
 int mdio_unregister(struct mii_dev *bus);
 void mdio_list_devices(void);