[PATCH 01/17] miiphy: Introduce mdio_init()

Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- common/miiphyutil.c | 13 +++++++++---- include/miiphy.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 9b8744e5d8b..2a034d3a77c 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -65,6 +65,14 @@ void miiphy_init(void) current_mii = NULL; }
+void mdio_init(struct mii_dev *bus) +{ + memset(bus, 0, sizeof(*bus)); + + /* initialize mii_dev struct fields */ + INIT_LIST_HEAD(&bus->link); +} + struct mii_dev *mdio_alloc(void) { struct mii_dev *bus; @@ -73,10 +81,7 @@ struct mii_dev *mdio_alloc(void) if (!bus) return bus;
- memset(bus, 0, sizeof(*bus)); - - /* initalize mii_dev struct fields */ - INIT_LIST_HEAD(&bus->link); + mdio_init(bus);
return bus; } diff --git a/include/miiphy.h b/include/miiphy.h index 1e6c7041fdc..f385f3f47e7 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -44,6 +44,7 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname);
void miiphy_listdev(void);
+void mdio_init(struct mii_dev *bus); struct mii_dev *mdio_alloc(void); void mdio_free(struct mii_dev *bus); int mdio_register(struct mii_dev *bus);

Introduce bb_miiphy_free()/bb_miiphy_free() wrappers to allocate and free struct bb_miiphy_bus. Make struct bb_miiphy_bus wrap struct mii_dev, which will become useful later in bb_miiphy_bus accessors, which would be able to access struct bb_miiphy_bus using container_of, even if the PHY stack only passes in the inner struct mii_dev .
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/phy/miiphybb.c | 19 +++++++++++++++++++ include/miiphy.h | 3 +++ 2 files changed, 22 insertions(+)
diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index 5497b838225..9733ebf6f09 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -14,6 +14,7 @@
#include <ioports.h> #include <ppc_asm.tmpl> +#include <malloc.h> #include <miiphy.h> #include <asm/global_data.h>
@@ -41,6 +42,24 @@ static inline struct bb_miiphy_bus *bb_miiphy_getbus(const char *devname) return NULL; }
+struct bb_miiphy_bus *bb_miiphy_alloc(void) +{ + struct bb_miiphy_bus *bus; + + bus = malloc(sizeof(*bus)); + if (!bus) + return bus; + + mdio_init(&bus->mii); + + return bus; +} + +void bb_miiphy_free(struct bb_miiphy_bus *bus) +{ + free(bus); +} + /***************************************************************************** * * Utility to send the preamble, address, and register (common to read diff --git a/include/miiphy.h b/include/miiphy.h index f385f3f47e7..962ace13079 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -74,6 +74,7 @@ struct bb_miiphy_bus { int (*set_mdc)(struct bb_miiphy_bus *bus, int v); int (*delay)(struct bb_miiphy_bus *bus); void *priv; + struct mii_dev mii; };
extern struct bb_miiphy_bus bb_miiphy_buses[]; @@ -87,6 +88,8 @@ extern int bb_miiphy_buses_num; * Return: 0 if OK */ int bb_miiphy_init(void); +struct bb_miiphy_bus *bb_miiphy_alloc(void); +void bb_miiphy_free(struct bb_miiphy_bus *bus);
int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg); int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg,

On 18/01/2025 06:53, Marek Vasut wrote:
Introduce bb_miiphy_free()/bb_miiphy_free() wrappers to allocate and free
This should be bb_miiphy_alloc()/bb_miiphy_free().
Same for the commit title.
Thanks,

Move the bb_miiphy functions before MDIO registration. This is a preparatory patch, the functions will be referenced around the MDIO registration in the follow up patches. No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/ravb.c | 117 +++++++++++++++++++++++---------------------- 1 file changed, 59 insertions(+), 58 deletions(-)
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index f9c27f0f370..6e4baff658f 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -490,6 +490,65 @@ static void ravb_stop(struct udevice *dev) ravb_reset(dev); }
+/* Bitbang MDIO access */ +static int ravb_bb_mdio_active(struct bb_miiphy_bus *bus) +{ + struct ravb_priv *eth = bus->priv; + + setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); + + return 0; +} + +static int ravb_bb_mdio_tristate(struct bb_miiphy_bus *bus) +{ + struct ravb_priv *eth = bus->priv; + + clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); + + return 0; +} + +static int ravb_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +{ + struct ravb_priv *eth = bus->priv; + + if (v) + setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); + else + clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); + + return 0; +} + +static int ravb_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +{ + struct ravb_priv *eth = bus->priv; + + *v = (readl(eth->iobase + RAVB_REG_PIR) & PIR_MDI) >> 3; + + return 0; +} + +static int ravb_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +{ + struct ravb_priv *eth = bus->priv; + + if (v) + setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); + else + clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); + + return 0; +} + +static int ravb_bb_delay(struct bb_miiphy_bus *bus) +{ + udelay(10); + + return 0; +} + static int ravb_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); @@ -560,64 +619,6 @@ static int ravb_remove(struct udevice *dev) return 0; }
-static int ravb_bb_mdio_active(struct bb_miiphy_bus *bus) -{ - struct ravb_priv *eth = bus->priv; - - setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); - - return 0; -} - -static int ravb_bb_mdio_tristate(struct bb_miiphy_bus *bus) -{ - struct ravb_priv *eth = bus->priv; - - clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); - - return 0; -} - -static int ravb_bb_set_mdio(struct bb_miiphy_bus *bus, int v) -{ - struct ravb_priv *eth = bus->priv; - - if (v) - setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); - else - clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); - - return 0; -} - -static int ravb_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) -{ - struct ravb_priv *eth = bus->priv; - - *v = (readl(eth->iobase + RAVB_REG_PIR) & PIR_MDI) >> 3; - - return 0; -} - -static int ravb_bb_set_mdc(struct bb_miiphy_bus *bus, int v) -{ - struct ravb_priv *eth = bus->priv; - - if (v) - setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); - else - clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); - - return 0; -} - -static int ravb_bb_delay(struct bb_miiphy_bus *bus) -{ - udelay(10); - - return 0; -} - struct bb_miiphy_bus bb_miiphy_buses[] = { { .name = "ravb",

Move the bb_miiphy functions before MDIO registration. This is a preparatory patch, the functions will be referenced around the MDIO registration in the follow up patches. No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/sh_eth.c | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 8654f1b8085..45dc79c4309 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -643,6 +643,74 @@ static void sh_ether_stop(struct udevice *dev) sh_eth_stop(&priv->shdev); }
+/******* for bb_miiphy *******/ +static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) +{ + struct sh_eth_dev *eth = bus->priv; + struct sh_eth_info *port_info = ð->port_info[eth->port]; + + sh_eth_write(port_info, sh_eth_read(port_info, PIR) | PIR_MMD, PIR); + + return 0; +} + +static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) +{ + struct sh_eth_dev *eth = bus->priv; + struct sh_eth_info *port_info = ð->port_info[eth->port]; + + sh_eth_write(port_info, sh_eth_read(port_info, PIR) & ~PIR_MMD, PIR); + + return 0; +} + +static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +{ + struct sh_eth_dev *eth = bus->priv; + struct sh_eth_info *port_info = ð->port_info[eth->port]; + + if (v) + sh_eth_write(port_info, + sh_eth_read(port_info, PIR) | PIR_MDO, PIR); + else + sh_eth_write(port_info, + sh_eth_read(port_info, PIR) & ~PIR_MDO, PIR); + + return 0; +} + +static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +{ + struct sh_eth_dev *eth = bus->priv; + struct sh_eth_info *port_info = ð->port_info[eth->port]; + + *v = (sh_eth_read(port_info, PIR) & PIR_MDI) >> 3; + + return 0; +} + +static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +{ + struct sh_eth_dev *eth = bus->priv; + struct sh_eth_info *port_info = ð->port_info[eth->port]; + + if (v) + sh_eth_write(port_info, + sh_eth_read(port_info, PIR) | PIR_MDC, PIR); + else + sh_eth_write(port_info, + sh_eth_read(port_info, PIR) & ~PIR_MDC, PIR); + + return 0; +} + +static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) +{ + udelay(10); + + return 0; +} + static int sh_ether_probe(struct udevice *udev) { struct eth_pdata *pdata = dev_get_plat(udev); @@ -776,74 +844,6 @@ U_BOOT_DRIVER(eth_sh_ether) = { .flags = DM_FLAG_ALLOC_PRIV_DMA, };
-/******* for bb_miiphy *******/ -static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) -{ - struct sh_eth_dev *eth = bus->priv; - struct sh_eth_info *port_info = ð->port_info[eth->port]; - - sh_eth_write(port_info, sh_eth_read(port_info, PIR) | PIR_MMD, PIR); - - return 0; -} - -static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) -{ - struct sh_eth_dev *eth = bus->priv; - struct sh_eth_info *port_info = ð->port_info[eth->port]; - - sh_eth_write(port_info, sh_eth_read(port_info, PIR) & ~PIR_MMD, PIR); - - return 0; -} - -static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) -{ - struct sh_eth_dev *eth = bus->priv; - struct sh_eth_info *port_info = ð->port_info[eth->port]; - - if (v) - sh_eth_write(port_info, - sh_eth_read(port_info, PIR) | PIR_MDO, PIR); - else - sh_eth_write(port_info, - sh_eth_read(port_info, PIR) & ~PIR_MDO, PIR); - - return 0; -} - -static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) -{ - struct sh_eth_dev *eth = bus->priv; - struct sh_eth_info *port_info = ð->port_info[eth->port]; - - *v = (sh_eth_read(port_info, PIR) & PIR_MDI) >> 3; - - return 0; -} - -static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) -{ - struct sh_eth_dev *eth = bus->priv; - struct sh_eth_info *port_info = ð->port_info[eth->port]; - - if (v) - sh_eth_write(port_info, - sh_eth_read(port_info, PIR) | PIR_MDC, PIR); - else - sh_eth_write(port_info, - sh_eth_read(port_info, PIR) & ~PIR_MDC, PIR); - - return 0; -} - -static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) -{ - udelay(10); - - return 0; -} - struct bb_miiphy_bus bb_miiphy_buses[] = { { .name = "sh_eth",

Move the bb_miiphy functions before MDIO registration. This is a preparatory patch, the functions will be referenced around the MDIO registration in the follow up patches. No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 192 ++++++++++++++++++------------------ 1 file changed, 96 insertions(+), 96 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 690a29690b9..3370a4fa1a3 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -102,102 +102,6 @@ uint calculate_octo_phy_mask(void) return octo_phy_mask; }
-int register_miiphy_bus(uint k, struct mii_dev **bus) -{ - int retval; - struct mii_dev *mdiodev = mdio_alloc(); - char *name = bb_miiphy_buses[k].name; - - if (!mdiodev) - return -ENOMEM; - strlcpy(mdiodev->name, name, MDIO_NAME_LEN); - mdiodev->read = bb_miiphy_read; - mdiodev->write = bb_miiphy_write; - - retval = mdio_register(mdiodev); - if (retval < 0) - return retval; - *bus = miiphy_get_dev_by_name(name); - - return 0; -} - -struct porttype *get_porttype(uint octo_phy_mask, uint k) -{ - uint octo_index = k * 4; - - if (!k) { - if (octo_phy_mask & 0x01) - return &porttypes[PORTTYPE_MAIN_CAT]; - else if (!(octo_phy_mask & 0x03)) - return &porttypes[PORTTYPE_16C_16F]; - } else { - if (octo_phy_mask & (1 << octo_index)) - return &porttypes[PORTTYPE_TOP_CAT]; - } - - return NULL; -} - -int init_single_phy(struct porttype *porttype, struct mii_dev *bus, - uint bus_idx, uint m, uint phy_idx) -{ - struct phy_device *phydev; - - phydev = phy_find_by_mask(bus, BIT(m * 8 + phy_idx)); - printf(" %u", bus_idx * 32 + m * 8 + phy_idx); - - if (!phydev) - puts("!"); - else - ihs_phy_config(phydev, porttype->phy_invert_in_pol, - porttype->phy_invert_out_pol); - - return 0; -} - -int init_octo_phys(uint octo_phy_mask) -{ - uint bus_idx; - - /* there are up to four octo-phys on each mdio bus */ - for (bus_idx = 0; bus_idx < bb_miiphy_buses_num; ++bus_idx) { - uint m; - uint octo_index = bus_idx * 4; - struct mii_dev *bus = NULL; - struct porttype *porttype = NULL; - int ret; - - porttype = get_porttype(octo_phy_mask, bus_idx); - - if (!porttype) - continue; - - for (m = 0; m < 4; ++m) { - uint phy_idx; - - /** - * Register a bus device if there is at least one phy - * on the current bus - */ - if (!m && octo_phy_mask & (0xf << octo_index)) { - ret = register_miiphy_bus(bus_idx, &bus); - if (ret) - return ret; - } - - if (!(octo_phy_mask & BIT(octo_index + m))) - continue; - - for (phy_idx = 0; phy_idx < 8; ++phy_idx) - init_single_phy(porttype, bus, bus_idx, m, - phy_idx); - } - } - - return 0; -} - /* * MII GPIO bitbang implementation * MDC MDIO bus @@ -315,6 +219,102 @@ static int mii_delay(struct bb_miiphy_bus *bus) return 0; }
+int register_miiphy_bus(uint k, struct mii_dev **bus) +{ + int retval; + struct mii_dev *mdiodev = mdio_alloc(); + char *name = bb_miiphy_buses[k].name; + + if (!mdiodev) + return -ENOMEM; + strlcpy(mdiodev->name, name, MDIO_NAME_LEN); + mdiodev->read = bb_miiphy_read; + mdiodev->write = bb_miiphy_write; + + retval = mdio_register(mdiodev); + if (retval < 0) + return retval; + *bus = miiphy_get_dev_by_name(name); + + return 0; +} + +struct porttype *get_porttype(uint octo_phy_mask, uint k) +{ + uint octo_index = k * 4; + + if (!k) { + if (octo_phy_mask & 0x01) + return &porttypes[PORTTYPE_MAIN_CAT]; + else if (!(octo_phy_mask & 0x03)) + return &porttypes[PORTTYPE_16C_16F]; + } else { + if (octo_phy_mask & (1 << octo_index)) + return &porttypes[PORTTYPE_TOP_CAT]; + } + + return NULL; +} + +int init_single_phy(struct porttype *porttype, struct mii_dev *bus, + uint bus_idx, uint m, uint phy_idx) +{ + struct phy_device *phydev; + + phydev = phy_find_by_mask(bus, BIT(m * 8 + phy_idx)); + printf(" %u", bus_idx * 32 + m * 8 + phy_idx); + + if (!phydev) + puts("!"); + else + ihs_phy_config(phydev, porttype->phy_invert_in_pol, + porttype->phy_invert_out_pol); + + return 0; +} + +int init_octo_phys(uint octo_phy_mask) +{ + uint bus_idx; + + /* there are up to four octo-phys on each mdio bus */ + for (bus_idx = 0; bus_idx < bb_miiphy_buses_num; ++bus_idx) { + uint m; + uint octo_index = bus_idx * 4; + struct mii_dev *bus = NULL; + struct porttype *porttype = NULL; + int ret; + + porttype = get_porttype(octo_phy_mask, bus_idx); + + if (!porttype) + continue; + + for (m = 0; m < 4; ++m) { + uint phy_idx; + + /** + * Register a bus device if there is at least one phy + * on the current bus + */ + if (!m && octo_phy_mask & (0xf << octo_index)) { + ret = register_miiphy_bus(bus_idx, &bus); + if (ret) + return ret; + } + + if (!(octo_phy_mask & BIT(octo_index + m))) + continue; + + for (phy_idx = 0; phy_idx < 8; ++phy_idx) + init_single_phy(porttype, bus, bus_idx, m, + phy_idx); + } + } + + return 0; +} + struct bb_miiphy_bus bb_miiphy_buses[] = { { .name = "ihs0",

Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks currently listed in bb_miiphy_buses[] array. This is a temporary duplication of assignment to avoid breakage, which will be removed in follow up patches. At this point, the bb_miiphy callbacks can reach these accessors by doing container_of() on struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 3370a4fa1a3..aa738016025 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -221,16 +221,30 @@ static int mii_delay(struct bb_miiphy_bus *bus)
int register_miiphy_bus(uint k, struct mii_dev **bus) { - int retval; - struct mii_dev *mdiodev = mdio_alloc(); + struct bb_miiphy_bus *bb_miiphy = bb_miiphy_alloc(); + struct mii_dev *mdiodev; char *name = bb_miiphy_buses[k].name; + int retval;
- if (!mdiodev) + if (!bb_miiphy) return -ENOMEM; + + mdiodev = &bb_miiphy->mii; strlcpy(mdiodev->name, name, MDIO_NAME_LEN); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write;
+ /* Copy the bus accessors, name and private data */ + bb_miiphy->init = mii_mdio_init; + bb_miiphy->mdio_active = mii_mdio_active; + bb_miiphy->mdio_tristate = mii_mdio_tristate; + bb_miiphy->set_mdio = mii_set_mdio; + bb_miiphy->get_mdio = mii_get_mdio; + bb_miiphy->set_mdc = mii_set_mdc; + bb_miiphy->delay = mii_delay; + strlcpy(bb_miiphy->name, name, MDIO_NAME_LEN); + bb_miiphy->priv = &(gpio_mii_set[k]); + retval = mdio_register(mdiodev); if (retval < 0) return retval;

Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks currently listed in bb_miiphy_buses[] array. This is a temporary duplication of assignment to avoid breakage, which will be removed in follow up patches. At this point, the bb_miiphy callbacks can reach these accessors by doing container_of() on struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/ravb.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 6e4baff658f..60454d1a579 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -553,6 +553,7 @@ static int ravb_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct ravb_priv *eth = dev_get_priv(dev); + struct bb_miiphy_bus *bb_miiphy; struct mii_dev *mdiodev; void __iomem *iobase; int ret; @@ -564,17 +565,30 @@ static int ravb_probe(struct udevice *dev) if (ret < 0) goto err_mdio_alloc;
- mdiodev = mdio_alloc(); - if (!mdiodev) { + bb_miiphy = bb_miiphy_alloc(); + if (!bb_miiphy) { ret = -ENOMEM; goto err_mdio_alloc; }
+ mdiodev = &bb_miiphy->mii; + mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name);
+ /* Copy the bus accessors, name and private data */ + bb_miiphy->init = NULL; + bb_miiphy->mdio_active = ravb_bb_mdio_active; + bb_miiphy->mdio_tristate = ravb_bb_mdio_tristate; + bb_miiphy->set_mdio = ravb_bb_set_mdio; + bb_miiphy->get_mdio = ravb_bb_get_mdio; + bb_miiphy->set_mdc = ravb_bb_set_mdc; + bb_miiphy->delay = ravb_bb_delay; + strlcpy(bb_miiphy->name, "ravb", MDIO_NAME_LEN); + bb_miiphy->priv = eth; + ret = mdio_register(mdiodev); if (ret < 0) goto err_mdio_register; @@ -599,7 +613,7 @@ static int ravb_probe(struct udevice *dev) err_mdio_reset: clk_release_bulk(ð->clks); err_mdio_register: - mdio_free(mdiodev); + bb_miiphy_free(bb_miiphy); err_mdio_alloc: unmap_physmem(eth->iobase, MAP_NOCACHE); return ret;

Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks currently listed in bb_miiphy_buses[] array. This is a temporary duplication of assignment to avoid breakage, which will be removed in follow up patches. At this point, the bb_miiphy callbacks can reach these accessors by doing container_of() on struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/sh_eth.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 45dc79c4309..a765c280ff0 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -716,6 +716,7 @@ static int sh_ether_probe(struct udevice *udev) struct eth_pdata *pdata = dev_get_plat(udev); struct sh_ether_priv *priv = dev_get_priv(udev); struct sh_eth_dev *eth = &priv->shdev; + struct bb_miiphy_bus *bb_miiphy; struct mii_dev *mdiodev; int ret;
@@ -726,17 +727,30 @@ static int sh_ether_probe(struct udevice *udev) if (ret < 0) return ret; #endif - mdiodev = mdio_alloc(); - if (!mdiodev) { + bb_miiphy = bb_miiphy_alloc(); + if (!bb_miiphy) { ret = -ENOMEM; return ret; }
+ mdiodev = &bb_miiphy->mii; + mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name);
+ /* Copy the bus accessors, name and private data */ + bb_miiphy->init = NULL; + bb_miiphy->mdio_active = sh_eth_bb_mdio_active; + bb_miiphy->mdio_tristate = sh_eth_bb_mdio_tristate; + bb_miiphy->set_mdio = sh_eth_bb_set_mdio; + bb_miiphy->get_mdio = sh_eth_bb_get_mdio; + bb_miiphy->set_mdc = sh_eth_bb_set_mdc; + bb_miiphy->delay = sh_eth_bb_delay; + strlcpy(bb_miiphy->name, "sh_eth", MDIO_NAME_LEN); + bb_miiphy->priv = eth; + ret = mdio_register(mdiodev); if (ret < 0) goto err_mdio_register; @@ -771,7 +785,7 @@ err_phy_config: clk_disable(&priv->clk); #endif err_mdio_register: - mdio_free(mdiodev); + bb_miiphy_free(bb_miiphy); return ret; }

Replace the name based look up in bb_miiphy_getbus() with trivial container_of() call. This works because the struct bb_miiphy_bus always embeds the matching struct mii_dev . This also makes the code much simpler and more efficient.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/phy/miiphybb.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index 9733ebf6f09..cdb0ee9dc8a 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -29,17 +29,9 @@ int bb_miiphy_init(void) return 0; }
-static inline struct bb_miiphy_bus *bb_miiphy_getbus(const char *devname) +static inline struct bb_miiphy_bus *bb_miiphy_getbus(struct mii_dev *miidev) { - int i; - - /* Search the correct bus */ - for (i = 0; i < bb_miiphy_buses_num; i++) { - if (!strcmp(bb_miiphy_buses[i].name, devname)) { - return &bb_miiphy_buses[i]; - } - } - return NULL; + return container_of(miidev, struct bb_miiphy_bus, mii); }
struct bb_miiphy_bus *bb_miiphy_alloc(void) @@ -152,7 +144,7 @@ int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg) int j; /* counter */ struct bb_miiphy_bus *bus;
- bus = bb_miiphy_getbus(miidev->name); + bus = bb_miiphy_getbus(miidev); if (bus == NULL) { return -1; } @@ -220,7 +212,7 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, struct bb_miiphy_bus *bus; int j; /* counter */
- bus = bb_miiphy_getbus(miidev->name); + bus = bb_miiphy_getbus(miidev); if (bus == NULL) { /* Bus not found! */ return -1;

The struct bb_miiphy_bus embeds struct struct mii_dev, which already contains one copy of name field. Drop the duplicate top level copy of name field.
The a38x code does static assignment of disparate names, use snprintf(...) to fill in matching name in probe to avoid any breakage.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 11 +++-------- drivers/net/ravb.c | 6 +----- drivers/net/sh_eth.c | 6 +----- include/miiphy.h | 1 - 4 files changed, 5 insertions(+), 19 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index aa738016025..2b598abb7f0 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -223,18 +223,17 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) { struct bb_miiphy_bus *bb_miiphy = bb_miiphy_alloc(); struct mii_dev *mdiodev; - char *name = bb_miiphy_buses[k].name; int retval;
if (!bb_miiphy) return -ENOMEM;
mdiodev = &bb_miiphy->mii; - strlcpy(mdiodev->name, name, MDIO_NAME_LEN); + snprintf(mdiodev->name, MDIO_NAME_LEN, "ihs%d", k); mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write;
- /* Copy the bus accessors, name and private data */ + /* Copy the bus accessors and private data */ bb_miiphy->init = mii_mdio_init; bb_miiphy->mdio_active = mii_mdio_active; bb_miiphy->mdio_tristate = mii_mdio_tristate; @@ -242,13 +241,12 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) bb_miiphy->get_mdio = mii_get_mdio; bb_miiphy->set_mdc = mii_set_mdc; bb_miiphy->delay = mii_delay; - strlcpy(bb_miiphy->name, name, MDIO_NAME_LEN); bb_miiphy->priv = &(gpio_mii_set[k]);
retval = mdio_register(mdiodev); if (retval < 0) return retval; - *bus = miiphy_get_dev_by_name(name); + *bus = miiphy_get_dev_by_name(mdiodev->name);
return 0; } @@ -331,7 +329,6 @@ int init_octo_phys(uint octo_phy_mask)
struct bb_miiphy_bus bb_miiphy_buses[] = { { - .name = "ihs0", .init = mii_mdio_init, .mdio_active = mii_mdio_active, .mdio_tristate = mii_mdio_tristate, @@ -342,7 +339,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { .priv = &gpio_mii_set[0], }, { - .name = "ihs1", .init = mii_mdio_init, .mdio_active = mii_mdio_active, .mdio_tristate = mii_mdio_tristate, @@ -353,7 +349,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { .priv = &gpio_mii_set[1], }, { - .name = "ihs2", .init = mii_mdio_init, .mdio_active = mii_mdio_active, .mdio_tristate = mii_mdio_tristate, diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 60454d1a579..efcf176c6ad 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -578,7 +578,7 @@ static int ravb_probe(struct udevice *dev) bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name);
- /* Copy the bus accessors, name and private data */ + /* Copy the bus accessors and private data */ bb_miiphy->init = NULL; bb_miiphy->mdio_active = ravb_bb_mdio_active; bb_miiphy->mdio_tristate = ravb_bb_mdio_tristate; @@ -586,7 +586,6 @@ static int ravb_probe(struct udevice *dev) bb_miiphy->get_mdio = ravb_bb_get_mdio; bb_miiphy->set_mdc = ravb_bb_set_mdc; bb_miiphy->delay = ravb_bb_delay; - strlcpy(bb_miiphy->name, "ravb", MDIO_NAME_LEN); bb_miiphy->priv = eth;
ret = mdio_register(mdiodev); @@ -635,7 +634,6 @@ static int ravb_remove(struct udevice *dev)
struct bb_miiphy_bus bb_miiphy_buses[] = { { - .name = "ravb", .init = NULL, .mdio_active = ravb_bb_mdio_active, .mdio_tristate = ravb_bb_mdio_tristate, @@ -668,8 +666,6 @@ int ravb_of_to_plat(struct udevice *dev)
pdata->max_speed = dev_read_u32_default(dev, "max-speed", 1000);
- sprintf(bb_miiphy_buses[0].name, dev->name); - return 0; }
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index a765c280ff0..ccfb31d40fd 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -740,7 +740,7 @@ static int sh_ether_probe(struct udevice *udev) bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name);
- /* Copy the bus accessors, name and private data */ + /* Copy the bus accessors and private data */ bb_miiphy->init = NULL; bb_miiphy->mdio_active = sh_eth_bb_mdio_active; bb_miiphy->mdio_tristate = sh_eth_bb_mdio_tristate; @@ -748,7 +748,6 @@ static int sh_ether_probe(struct udevice *udev) bb_miiphy->get_mdio = sh_eth_bb_get_mdio; bb_miiphy->set_mdc = sh_eth_bb_set_mdc; bb_miiphy->delay = sh_eth_bb_delay; - strlcpy(bb_miiphy->name, "sh_eth", MDIO_NAME_LEN); bb_miiphy->priv = eth;
ret = mdio_register(mdiodev); @@ -830,8 +829,6 @@ int sh_ether_of_to_plat(struct udevice *dev) if (cell) pdata->max_speed = fdt32_to_cpu(*cell);
- sprintf(bb_miiphy_buses[0].name, dev->name); - return 0; }
@@ -860,7 +857,6 @@ U_BOOT_DRIVER(eth_sh_ether) = {
struct bb_miiphy_bus bb_miiphy_buses[] = { { - .name = "sh_eth", .init = NULL, .mdio_active = sh_eth_bb_mdio_active, .mdio_tristate = sh_eth_bb_mdio_tristate, diff --git a/include/miiphy.h b/include/miiphy.h index 962ace13079..03ae4e0078a 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -65,7 +65,6 @@ void mdio_list_devices(void); #define BB_MII_DEVNAME "bb_miiphy"
struct bb_miiphy_bus { - char name[MDIO_NAME_LEN]; int (*init)(struct bb_miiphy_bus *bus); int (*mdio_active)(struct bb_miiphy_bus *bus); int (*mdio_tristate)(struct bb_miiphy_bus *bus);

All the resources needed by this .init callback should already be available by the time probe function runs, simply call the init callback directly and set the bb_miiphy init callback to NULL. This shouldn't break anything on this hardware, but would be nice if someone could double-check and test that.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 2b598abb7f0..0c2c0a54598 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -234,7 +234,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) mdiodev->write = bb_miiphy_write;
/* Copy the bus accessors and private data */ - bb_miiphy->init = mii_mdio_init; + bb_miiphy->init = NULL; bb_miiphy->mdio_active = mii_mdio_active; bb_miiphy->mdio_tristate = mii_mdio_tristate; bb_miiphy->set_mdio = mii_set_mdio; @@ -248,7 +248,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) return retval; *bus = miiphy_get_dev_by_name(mdiodev->name);
- return 0; + return mii_mdio_init(bb_miiphy); }
struct porttype *get_porttype(uint octo_phy_mask, uint k)

There are no more users of the init callback, drop the entire mechanism.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- common/board_r.c | 3 --- drivers/net/phy/miiphybb.c | 11 ----------- include/miiphy.h | 8 -------- 3 files changed, 22 deletions(-)
diff --git a/common/board_r.c b/common/board_r.c index 179259b00de..db0c5cb8032 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -749,9 +749,6 @@ static init_fnc_t init_sequence_r[] = { #ifdef CONFIG_BOARD_LATE_INIT board_late_init, #endif -#ifdef CONFIG_BITBANGMII - bb_miiphy_init, -#endif #ifdef CONFIG_PCI_ENDPOINT pci_ep_init, #endif diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index cdb0ee9dc8a..27654347725 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -18,17 +18,6 @@ #include <miiphy.h> #include <asm/global_data.h>
-int bb_miiphy_init(void) -{ - int i; - - for (i = 0; i < bb_miiphy_buses_num; i++) - if (bb_miiphy_buses[i].init != NULL) - bb_miiphy_buses[i].init(&bb_miiphy_buses[i]); - - return 0; -} - static inline struct bb_miiphy_bus *bb_miiphy_getbus(struct mii_dev *miidev) { return container_of(miidev, struct bb_miiphy_bus, mii); diff --git a/include/miiphy.h b/include/miiphy.h index 03ae4e0078a..9d9fe58b41c 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -79,14 +79,6 @@ struct bb_miiphy_bus { extern struct bb_miiphy_bus bb_miiphy_buses[]; extern int bb_miiphy_buses_num;
-/** - * bb_miiphy_init() - Initialize bit-banged MII bus driver - * - * It is called during the generic post-relocation init sequence. - * - * Return: 0 if OK - */ -int bb_miiphy_init(void); struct bb_miiphy_bus *bb_miiphy_alloc(void); void bb_miiphy_free(struct bb_miiphy_bus *bus);

Instead of doing another lookup, trivially access the struct mii_dev embedded in struct bb_miiphy_bus . No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 0c2c0a54598..2663724b930 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -246,7 +246,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) retval = mdio_register(mdiodev); if (retval < 0) return retval; - *bus = miiphy_get_dev_by_name(mdiodev->name); + *bus = &bb_miiphy->mii;
return mii_mdio_init(bb_miiphy); }

Instead of doing another lookup, trivially access the struct mii_dev embedded in struct bb_miiphy_bus . No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/ravb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index efcf176c6ad..ac5bb89c905 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -592,7 +592,7 @@ static int ravb_probe(struct udevice *dev) if (ret < 0) goto err_mdio_register;
- eth->bus = miiphy_get_dev_by_name(dev->name); + eth->bus = &bb_miiphy->mii;
/* Bring up PHY */ ret = clk_enable_bulk(ð->clks);

Instead of doing another lookup, trivially access the struct mii_dev embedded in struct bb_miiphy_bus . No functional change.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- drivers/net/sh_eth.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index ccfb31d40fd..824a4a7e004 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -754,7 +754,7 @@ static int sh_ether_probe(struct udevice *udev) if (ret < 0) goto err_mdio_register;
- priv->bus = miiphy_get_dev_by_name(udev->name); + priv->bus = &bb_miiphy->mii;
eth->port = CFG_SH_ETHER_USE_PORT; eth->port_info[eth->port].phy_addr = CFG_SH_ETHER_PHY_ADDR;

Neither bb_miiphy_buses nor bb_miiphy_buses_num are used anymore. Drop both of them.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 37 +------------------------------------ drivers/net/ravb.c | 14 -------------- drivers/net/sh_eth.c | 15 --------------- include/miiphy.h | 3 --- 4 files changed, 1 insertion(+), 68 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 2663724b930..2477a2ea48e 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -290,7 +290,7 @@ int init_octo_phys(uint octo_phy_mask) uint bus_idx;
/* there are up to four octo-phys on each mdio bus */ - for (bus_idx = 0; bus_idx < bb_miiphy_buses_num; ++bus_idx) { + for (bus_idx = 0; bus_idx < ARRAY_SIZE(gpio_mii_set); ++bus_idx) { uint m; uint octo_index = bus_idx * 4; struct mii_dev *bus = NULL; @@ -326,38 +326,3 @@ int init_octo_phys(uint octo_phy_mask)
return 0; } - -struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .init = mii_mdio_init, - .mdio_active = mii_mdio_active, - .mdio_tristate = mii_mdio_tristate, - .set_mdio = mii_set_mdio, - .get_mdio = mii_get_mdio, - .set_mdc = mii_set_mdc, - .delay = mii_delay, - .priv = &gpio_mii_set[0], - }, - { - .init = mii_mdio_init, - .mdio_active = mii_mdio_active, - .mdio_tristate = mii_mdio_tristate, - .set_mdio = mii_set_mdio, - .get_mdio = mii_get_mdio, - .set_mdc = mii_set_mdc, - .delay = mii_delay, - .priv = &gpio_mii_set[1], - }, - { - .init = mii_mdio_init, - .mdio_active = mii_mdio_active, - .mdio_tristate = mii_mdio_tristate, - .set_mdio = mii_set_mdio, - .get_mdio = mii_get_mdio, - .set_mdc = mii_set_mdc, - .delay = mii_delay, - .priv = &gpio_mii_set[2], - }, -}; - -int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index ac5bb89c905..084fe8f9777 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -575,7 +575,6 @@ static int ravb_probe(struct udevice *dev)
mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; - bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name);
/* Copy the bus accessors and private data */ @@ -632,19 +631,6 @@ static int ravb_remove(struct udevice *dev) return 0; }
-struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .init = NULL, - .mdio_active = ravb_bb_mdio_active, - .mdio_tristate = ravb_bb_mdio_tristate, - .set_mdio = ravb_bb_set_mdio, - .get_mdio = ravb_bb_get_mdio, - .set_mdc = ravb_bb_set_mdc, - .delay = ravb_bb_delay, - }, -}; -int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); - static const struct eth_ops ravb_ops = { .start = ravb_start, .send = ravb_send, diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 824a4a7e004..699121a6880 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -737,7 +737,6 @@ static int sh_ether_probe(struct udevice *udev)
mdiodev->read = bb_miiphy_read; mdiodev->write = bb_miiphy_write; - bb_miiphy_buses[0].priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name);
/* Copy the bus accessors and private data */ @@ -854,17 +853,3 @@ U_BOOT_DRIVER(eth_sh_ether) = { .plat_auto = sizeof(struct eth_pdata), .flags = DM_FLAG_ALLOC_PRIV_DMA, }; - -struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .init = NULL, - .mdio_active = sh_eth_bb_mdio_active, - .mdio_tristate = sh_eth_bb_mdio_tristate, - .set_mdio = sh_eth_bb_set_mdio, - .get_mdio = sh_eth_bb_get_mdio, - .set_mdc = sh_eth_bb_set_mdc, - .delay = sh_eth_bb_delay, - } -}; - -int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); diff --git a/include/miiphy.h b/include/miiphy.h index 9d9fe58b41c..6e8e4ee57bc 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -76,9 +76,6 @@ struct bb_miiphy_bus { struct mii_dev mii; };
-extern struct bb_miiphy_bus bb_miiphy_buses[]; -extern int bb_miiphy_buses_num; - struct bb_miiphy_bus *bb_miiphy_alloc(void); void bb_miiphy_free(struct bb_miiphy_bus *bus);

The .init callback is not called by any function, drop it.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org --- Cc: Christian Marangi ansuelsmth@gmail.com Cc: Evgeny Bachinin EABachinin@salutedevices.com Cc: Ilias Apalodimas ilias.apalodimas@linaro.org Cc: Jerome Forissier jerome.forissier@linaro.org Cc: Joe Hershberger joe.hershberger@ni.com Cc: Mario Six mario.six@gdsys.cc Cc: Michal Simek michal.simek@amd.com Cc: Nobuhiro Iwamatsu iwamatsu@nigauri.org Cc: Paul Barker paul.barker.ct@bp.renesas.com Cc: Ramon Fried rfried.dev@gmail.com Cc: Simon Glass sjg@chromium.org Cc: Sughosh Ganu sughosh.ganu@linaro.org Cc: Tom Rini trini@konsulko.com Cc: u-boot@lists.denx.de --- board/gdsys/a38x/ihs_phys.c | 1 - drivers/net/ravb.c | 1 - drivers/net/sh_eth.c | 1 - include/miiphy.h | 1 - 4 files changed, 4 deletions(-)
diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 2477a2ea48e..05db266ffd3 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -234,7 +234,6 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) mdiodev->write = bb_miiphy_write;
/* Copy the bus accessors and private data */ - bb_miiphy->init = NULL; bb_miiphy->mdio_active = mii_mdio_active; bb_miiphy->mdio_tristate = mii_mdio_tristate; bb_miiphy->set_mdio = mii_set_mdio; diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 084fe8f9777..cb727ae9bc1 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -578,7 +578,6 @@ static int ravb_probe(struct udevice *dev) snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name);
/* Copy the bus accessors and private data */ - bb_miiphy->init = NULL; bb_miiphy->mdio_active = ravb_bb_mdio_active; bb_miiphy->mdio_tristate = ravb_bb_mdio_tristate; bb_miiphy->set_mdio = ravb_bb_set_mdio; diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 699121a6880..83e48609224 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -740,7 +740,6 @@ static int sh_ether_probe(struct udevice *udev) snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name);
/* Copy the bus accessors and private data */ - bb_miiphy->init = NULL; bb_miiphy->mdio_active = sh_eth_bb_mdio_active; bb_miiphy->mdio_tristate = sh_eth_bb_mdio_tristate; bb_miiphy->set_mdio = sh_eth_bb_set_mdio; diff --git a/include/miiphy.h b/include/miiphy.h index 6e8e4ee57bc..b879fd16ae3 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -65,7 +65,6 @@ void mdio_list_devices(void); #define BB_MII_DEVNAME "bb_miiphy"
struct bb_miiphy_bus { - int (*init)(struct bb_miiphy_bus *bus); int (*mdio_active)(struct bb_miiphy_bus *bus); int (*mdio_tristate)(struct bb_miiphy_bus *bus); int (*set_mdio)(struct bb_miiphy_bus *bus, int v);

On 18/01/2025 06:53, Marek Vasut wrote:
Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Replying here for the whole patch series...
I like where we get to at the end of this series, but I don't like the intermediate state where the bb_miiphy_buses arrays still exist but are unused. I also think we should introduce a new ops struct so we're not duplicating function pointers in each instance of struct bb_miiphy_bus.
I would prefer the following order of changes, let me know if you think this would be cleaner:
1) Introduce mdio_init().
2) Add mii member to struct bb_miiphy_bus.
3) Modify each driver to use the mii member of the appropriate struct bb_miiphy_bus instance, calling mdio_init() instead of mdio_alloc(). At this point we're still using the instances in the statically allocated bb_miiphy_buses array.
4) Use container_of() in bb_miiphy_getbus().
5) Drop global names bb_miiphy_buses and bb_miiphy_buses_num as these should no longer be used. The bb_miiphy_buses arrays can be static in each driver and at this point the miiphy code should not care whether the arrays are statically or dynamically allocated.
6) Drop name member of struct bb_miiphy_bus now that it is unused.
7) arm: mvebu: a38x: Call bb_miiphy init directly in driver probe.
8) Drop bb_miiphy_init() and .init callbacks.
9) Move function pointers to a new ops struct so we're not duplicating them in each instance of struct bb_miiphy_bus:
struct bb_miiphy_ops { int (*mdio_active)(struct bb_miiphy_bus *bus); int (*mdio_tristate)(struct bb_miiphy_bus *bus); int (*set_mdio)(struct bb_miiphy_bus *bus, int v); int (*get_mdio)(struct bb_miiphy_bus *bus, int *v); int (*set_mdc)(struct bb_miiphy_bus *bus, int v); int (*delay)(struct bb_miiphy_bus *bus); };
struct bb_miiphy_bus { struct bb_miiphy_ops *ops; struct mii_dev mii; void *priv; };
10) Introduce bb_miiphy_alloc()/bb_miiphy_free().
11) Convert each driver from a static array of struct bb_miiphy_bus instances to dynamically allocated instances, for each driver removing the static array in the same commit that dynamic allocation is added.
Thanks,

On 1/21/25 3:38 PM, Paul Barker wrote:
On 18/01/2025 06:53, Marek Vasut wrote:
Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Replying here for the whole patch series...
I like where we get to at the end of this series, but I don't like the intermediate state where the bb_miiphy_buses arrays still exist but are unused. I also think we should introduce a new ops struct so we're not duplicating function pointers in each instance of struct bb_miiphy_bus.
I would prefer the following order of changes, let me know if you think this would be cleaner:
Introduce mdio_init().
Add mii member to struct bb_miiphy_bus.
Modify each driver to use the mii member of the appropriate struct bb_miiphy_bus instance, calling mdio_init() instead of mdio_alloc(). At this point we're still using the instances in the statically allocated bb_miiphy_buses array.
Those instances might be rodata , so using them as read-write storage does not necessarily work , does it ?

Hi Marek,
On 25/01/2025 12:56, Marek Vasut wrote:
On 1/21/25 3:38 PM, Paul Barker wrote:
On 18/01/2025 06:53, Marek Vasut wrote:
Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Replying here for the whole patch series...
I like where we get to at the end of this series, but I don't like the intermediate state where the bb_miiphy_buses arrays still exist but are unused. I also think we should introduce a new ops struct so we're not duplicating function pointers in each instance of struct bb_miiphy_bus.
I would prefer the following order of changes, let me know if you think this would be cleaner:
Introduce mdio_init().
Add mii member to struct bb_miiphy_bus.
Modify each driver to use the mii member of the appropriate struct bb_miiphy_bus instance, calling mdio_init() instead of mdio_alloc(). At this point we're still using the instances in the statically allocated bb_miiphy_buses array.
Those instances might be rodata , so using them as read-write storage does not necessarily work , does it ?
None of the instances in the current U-Boot code are marked as const, and the name field is already modified at runtime by each driver. So I don't think we need to worry about them being rodata.
Thanks,

On 1/27/25 11:32 AM, Paul Barker wrote:
Hi Marek,
On 25/01/2025 12:56, Marek Vasut wrote:
On 1/21/25 3:38 PM, Paul Barker wrote:
On 18/01/2025 06:53, Marek Vasut wrote:
Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Replying here for the whole patch series...
I like where we get to at the end of this series, but I don't like the intermediate state where the bb_miiphy_buses arrays still exist but are unused. I also think we should introduce a new ops struct so we're not duplicating function pointers in each instance of struct bb_miiphy_bus.
I would prefer the following order of changes, let me know if you think this would be cleaner:
Introduce mdio_init().
Add mii member to struct bb_miiphy_bus.
Modify each driver to use the mii member of the appropriate struct bb_miiphy_bus instance, calling mdio_init() instead of mdio_alloc(). At this point we're still using the instances in the statically allocated bb_miiphy_buses array.
Those instances might be rodata , so using them as read-write storage does not necessarily work , does it ?
None of the instances in the current U-Boot code are marked as const, and the name field is already modified at runtime by each driver. So I don't think we need to worry about them being rodata.
Can the compiler not decide to place the structure into rodata if it is never written ?

On 27/01/2025 11:30, Marek Vasut wrote:
On 1/27/25 11:32 AM, Paul Barker wrote:
Hi Marek,
On 25/01/2025 12:56, Marek Vasut wrote:
On 1/21/25 3:38 PM, Paul Barker wrote:
On 18/01/2025 06:53, Marek Vasut wrote:
Introduce mdio_init() split off from mdio_alloc(), which is used to initialize already allocated struct mii_dev.
Signed-off-by: Marek Vasut marek.vasut+renesas@mailbox.org
Replying here for the whole patch series...
I like where we get to at the end of this series, but I don't like the intermediate state where the bb_miiphy_buses arrays still exist but are unused. I also think we should introduce a new ops struct so we're not duplicating function pointers in each instance of struct bb_miiphy_bus.
I would prefer the following order of changes, let me know if you think this would be cleaner:
Introduce mdio_init().
Add mii member to struct bb_miiphy_bus.
Modify each driver to use the mii member of the appropriate struct bb_miiphy_bus instance, calling mdio_init() instead of mdio_alloc(). At this point we're still using the instances in the statically allocated bb_miiphy_buses array.
Those instances might be rodata , so using them as read-write storage does not necessarily work , does it ?
None of the instances in the current U-Boot code are marked as const, and the name field is already modified at runtime by each driver. So I don't think we need to worry about them being rodata.
Can the compiler not decide to place the structure into rodata if it is never written ?
To my understanding the compiler cannot place anything in a different section such as rodata unless this is explicitly requested with an attribute (i.e. `__attribute__(( section(".rodata") ))` or a macro call which resolves to this).
Thanks,
participants (3)
-
Marek Vasut
-
Marek Vasut
-
Paul Barker