All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[]
@ 2025-02-22 20:33 Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 01/23] net: ravb: Drop empty init callback Marek Vasut
                   ` (23 more replies)
  0 siblings, 24 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

Get rid of global bb_miiphy_buses[] which does not fit well with U-Boot
DM in favor of usual per-ethernet-MAC-driver-instance MDIO bus accessors.

Introduce the ability to allocate struct bb_miiphy_bus {} and make it wrap
struct mii_dev {}, so the struct mii_dev can be passed into MDIO bus access
infrastructure as usual. When the MDIO bus access infrastructure attempts to
access the MDIO bus and invokes any of the bbmiiphy accessors, those accessors
are passed the structu mii_dev {}, but can also access struct bb_miiphy_bus
using plain container_of() .

Clean up the drivers and update them to match.

Marek Vasut (23):
  net: ravb: Drop empty init callback
  net: sh_eth: Drop empty init callback
  net: designware: Drop NULL priv assignment
  net: ravb: Reorder bb_miiphy functions
  net: sh_eth: Reorder bb_miiphy functions
  arm: mvebu: a38x: Reorder bb_miiphy functions
  net: designware: Reorder bb_miiphy functions
  arm: mvebu: a38x: Call bb_miiphy init directly in driver probe
  net: miiphybb: Drop bb_miiphy_init() and .init callback
  net: designware: Drop bus index
  net: designware: Extract bbmiiphy initialization into dedicated
    function
  net: miiphy: Introduce mdio_init()
  net: miiphybb: Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers
  arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill
    in callbacks
  net: ravb: Allocate bb_miiphy using bb_miiphy_alloc() and fill in
    callbacks
  net: sh_eth: Allocate bb_miiphy using bb_miiphy_alloc() and fill in
    callbacks
  net: designware: Allocate bb_miiphy using bb_miiphy_alloc() and fill
    in callbacks
  net: miiphybb: Use container_of() in bb_miiphy_getbus()
  net: miiphybb: Drop name field from struct bb_miiphy_bus
  arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name()
  net: ravb: Drop use of miiphy_get_dev_by_name()
  net: sh_eth: Drop use of miiphy_get_dev_by_name()
  net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num

 board/gdsys/a38x/ihs_phys.c | 237 ++++++++++++++------------------
 common/board_r.c            |   3 -
 common/miiphyutil.c         |  13 +-
 drivers/net/designware.c    | 263 ++++++++++++++++++++----------------
 drivers/net/phy/miiphybb.c  |  36 ++---
 drivers/net/ravb.c          | 159 ++++++++++------------
 drivers/net/sh_eth.c        | 179 ++++++++++++------------
 include/miiphy.h            |  17 +--
 8 files changed, 438 insertions(+), 469 deletions(-)

---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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

-- 
2.47.2


^ permalink raw reply	[flat|nested] 39+ messages in thread

* [PATCH v3 01/23] net: ravb: Drop empty init callback
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 02/23] net: sh_eth: " Marek Vasut
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

The init function does nothing, the bb_miiphy_init() already checks
whether the .init callback is assigned, and if not, skips calling it.
Remove the empty init function. The entire init callback will be
removed in follow up patches.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Drop the = NULL assignment early in here.
V3: Add RB from Paul
---
 drivers/net/ravb.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index 7286ad19598..5df557da7da 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -560,11 +560,6 @@ static int ravb_remove(struct udevice *dev)
 	return 0;
 }
 
-static int ravb_bb_init(struct bb_miiphy_bus *bus)
-{
-	return 0;
-}
-
 static int ravb_bb_mdio_active(struct bb_miiphy_bus *bus)
 {
 	struct ravb_priv *eth = bus->priv;
@@ -626,7 +621,6 @@ static int ravb_bb_delay(struct bb_miiphy_bus *bus)
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
 		.name		= "ravb",
-		.init		= ravb_bb_init,
 		.mdio_active	= ravb_bb_mdio_active,
 		.mdio_tristate	= ravb_bb_mdio_tristate,
 		.set_mdio	= ravb_bb_set_mdio,
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 02/23] net: sh_eth: Drop empty init callback
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 01/23] net: ravb: Drop empty init callback Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 03/23] net: designware: Drop NULL priv assignment Marek Vasut
                   ` (21 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

The init function does nothing, the bb_miiphy_init() already checks
whether the .init callback is assigned, and if not, skips calling it.
Remove the empty init function. The entire init callback will be
removed in follow up patches.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Drop the = NULL assignment early in here.
V3: Add RB from Paul
---
 drivers/net/sh_eth.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index f1ce994cfd5..b607b9a3a43 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -777,11 +777,6 @@ U_BOOT_DRIVER(eth_sh_ether) = {
 };
 
 /******* for bb_miiphy *******/
-static int sh_eth_bb_init(struct bb_miiphy_bus *bus)
-{
-	return 0;
-}
-
 static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
 {
 	struct sh_eth_dev *eth = bus->priv;
@@ -852,7 +847,6 @@ static int sh_eth_bb_delay(struct bb_miiphy_bus *bus)
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
 		.name		= "sh_eth",
-		.init		= sh_eth_bb_init,
 		.mdio_active	= sh_eth_bb_mdio_active,
 		.mdio_tristate	= sh_eth_bb_mdio_tristate,
 		.set_mdio	= sh_eth_bb_set_mdio,
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 03/23] net: designware: Drop NULL priv assignment
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 01/23] net: ravb: Drop empty init callback Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 02/23] net: sh_eth: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 04/23] net: ravb: Reorder bb_miiphy functions Marek Vasut
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

This is unnecessary, the unset structure member is initialized to
NULL by default, drop the assignment.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: New patch
V3: Add RB from Paul
---
 drivers/net/designware.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 2ab03015ffa..c17b4078d5a 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -1041,7 +1041,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 		.get_mdio	= dw_eth_bb_get_mdio,
 		.set_mdc	= dw_eth_bb_set_mdc,
 		.delay		= dw_eth_bb_delay,
-		.priv		= NULL,
 	}
 };
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 04/23] net: ravb: Reorder bb_miiphy functions
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (2 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 03/23] net: designware: Drop NULL priv assignment Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 05/23] net: sh_eth: " Marek Vasut
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

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.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: Add RB from Paul
---
 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 5df557da7da..381cf250ea2 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",
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 05/23] net: sh_eth: Reorder bb_miiphy functions
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (3 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 04/23] net: ravb: Reorder bb_miiphy functions Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:08   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 06/23] arm: mvebu: a38x: " Marek Vasut
                   ` (18 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 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 b607b9a3a43..6bd12ee3f19 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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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 = &eth->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",
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 06/23] arm: mvebu: a38x: Reorder bb_miiphy functions
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (4 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 05/23] net: sh_eth: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:09   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 07/23] net: designware: " Marek Vasut
                   ` (17 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 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",
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 07/23] net: designware: Reorder bb_miiphy functions
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (5 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 06/23] arm: mvebu: a38x: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:10   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe Marek Vasut
                   ` (16 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: New patch
V3: No change
---
 drivers/net/designware.c | 158 +++++++++++++++++++--------------------
 1 file changed, 79 insertions(+), 79 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index c17b4078d5a..95a459cec2a 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -226,6 +226,85 @@ static int dw_dm_mdio_init(const char *name, void *priv)
 }
 #endif
 
+#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO)
+static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
+{
+	struct dw_eth_dev *priv = bus->priv;
+	struct gpio_desc *desc = &priv->mdio_gpio;
+
+	desc->flags = 0;
+	dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+
+	return 0;
+}
+
+static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus)
+{
+	struct dw_eth_dev *priv = bus->priv;
+	struct gpio_desc *desc = &priv->mdio_gpio;
+
+	desc->flags = 0;
+	dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_IN);
+
+	return 0;
+}
+
+static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
+{
+	struct dw_eth_dev *priv = bus->priv;
+
+	if (v)
+		dm_gpio_set_value(&priv->mdio_gpio, 1);
+	else
+		dm_gpio_set_value(&priv->mdio_gpio, 0);
+
+	return 0;
+}
+
+static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
+{
+	struct dw_eth_dev *priv = bus->priv;
+
+	*v = dm_gpio_get_value(&priv->mdio_gpio);
+
+	return 0;
+}
+
+static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
+{
+	struct dw_eth_dev *priv = bus->priv;
+
+	if (v)
+		dm_gpio_set_value(&priv->mdc_gpio, 1);
+	else
+		dm_gpio_set_value(&priv->mdc_gpio, 0);
+
+	return 0;
+}
+
+static int dw_eth_bb_delay(struct bb_miiphy_bus *bus)
+{
+	struct dw_eth_dev *priv = bus->priv;
+
+	udelay(priv->bb_delay);
+	return 0;
+}
+
+struct bb_miiphy_bus bb_miiphy_buses[] = {
+	{
+		.name		= BB_MII_DEVNAME,
+		.mdio_active	= dw_eth_bb_mdio_active,
+		.mdio_tristate	= dw_eth_bb_mdio_tristate,
+		.set_mdio	= dw_eth_bb_set_mdio,
+		.get_mdio	= dw_eth_bb_get_mdio,
+		.set_mdc	= dw_eth_bb_set_mdc,
+		.delay		= dw_eth_bb_delay,
+	}
+};
+
+int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
+#endif
+
 static void tx_descs_init(struct dw_eth_dev *priv)
 {
 	struct eth_dma_regs *dma_p = priv->dma_regs_p;
@@ -967,82 +1046,3 @@ static struct pci_device_id supported[] = {
 };
 
 U_BOOT_PCI_DEVICE(eth_designware, supported);
-
-#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO)
-static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
-{
-	struct dw_eth_dev *priv = bus->priv;
-	struct gpio_desc *desc = &priv->mdio_gpio;
-
-	desc->flags = 0;
-	dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
-
-	return 0;
-}
-
-static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus)
-{
-	struct dw_eth_dev *priv = bus->priv;
-	struct gpio_desc *desc = &priv->mdio_gpio;
-
-	desc->flags = 0;
-	dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_IN);
-
-	return 0;
-}
-
-static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
-{
-	struct dw_eth_dev *priv = bus->priv;
-
-	if (v)
-		dm_gpio_set_value(&priv->mdio_gpio, 1);
-	else
-		dm_gpio_set_value(&priv->mdio_gpio, 0);
-
-	return 0;
-}
-
-static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
-{
-	struct dw_eth_dev *priv = bus->priv;
-
-	*v = dm_gpio_get_value(&priv->mdio_gpio);
-
-	return 0;
-}
-
-static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
-{
-	struct dw_eth_dev *priv = bus->priv;
-
-	if (v)
-		dm_gpio_set_value(&priv->mdc_gpio, 1);
-	else
-		dm_gpio_set_value(&priv->mdc_gpio, 0);
-
-	return 0;
-}
-
-static int dw_eth_bb_delay(struct bb_miiphy_bus *bus)
-{
-	struct dw_eth_dev *priv = bus->priv;
-
-	udelay(priv->bb_delay);
-	return 0;
-}
-
-struct bb_miiphy_bus bb_miiphy_buses[] = {
-	{
-		.name		= BB_MII_DEVNAME,
-		.mdio_active	= dw_eth_bb_mdio_active,
-		.mdio_tristate	= dw_eth_bb_mdio_tristate,
-		.set_mdio	= dw_eth_bb_set_mdio,
-		.get_mdio	= dw_eth_bb_get_mdio,
-		.set_mdc	= dw_eth_bb_set_mdc,
-		.delay		= dw_eth_bb_delay,
-	}
-};
-
-int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
-#endif
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (6 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 07/23] net: designware: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:12   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 09/23] net: miiphybb: Drop bb_miiphy_init() and .init callback Marek Vasut
                   ` (15 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Reorder this earlier in the series
V3: No change
---
 board/gdsys/a38x/ihs_phys.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c
index 3370a4fa1a3..86708ee6715 100644
--- a/board/gdsys/a38x/ihs_phys.c
+++ b/board/gdsys/a38x/ihs_phys.c
@@ -236,7 +236,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus)
 		return retval;
 	*bus = miiphy_get_dev_by_name(name);
 
-	return 0;
+	return mii_mdio_init(&bb_miiphy_buses[k]);
 }
 
 struct porttype *get_porttype(uint octo_phy_mask, uint k)
@@ -318,7 +318,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,
 		.set_mdio = mii_set_mdio,
@@ -329,7 +328,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 	},
 	{
 		.name = "ihs1",
-		.init = mii_mdio_init,
 		.mdio_active = mii_mdio_active,
 		.mdio_tristate = mii_mdio_tristate,
 		.set_mdio = mii_set_mdio,
@@ -340,7 +338,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 	},
 	{
 		.name = "ihs2",
-		.init = mii_mdio_init,
 		.mdio_active = mii_mdio_active,
 		.mdio_tristate = mii_mdio_tristate,
 		.set_mdio = mii_set_mdio,
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 09/23] net: miiphybb: Drop bb_miiphy_init() and .init callback
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (7 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 10/23] net: designware: Drop bus index Marek Vasut
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

The .init callback is not called by any function, drop it.
There are no more users of the init callback, drop the entire
mechanism.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Reorder this earlier in the series
V3: - Squash net: miiphybb: Drop bb_miiphy_init() and .init callback
      and net: miiphybb: Drop .init callback
    - Add RB from Paul
---
 common/board_r.c           |  3 ---
 drivers/net/phy/miiphybb.c | 11 -----------
 include/miiphy.h           | 10 ----------
 3 files changed, 24 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 9f5f9b12c9f..75d9537b355 100644
--- a/drivers/net/phy/miiphybb.c
+++ b/drivers/net/phy/miiphybb.c
@@ -17,17 +17,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(const char *devname)
 {
 	int i;
diff --git a/include/miiphy.h b/include/miiphy.h
index 1e6c7041fdc..0464f5dc219 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -65,7 +65,6 @@ void mdio_list_devices(void);
 
 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);
 	int (*set_mdio)(struct bb_miiphy_bus *bus, int v);
@@ -78,15 +77,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);
-
 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,
 		    u16 value);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 10/23] net: designware: Drop bus index
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (8 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 09/23] net: miiphybb: Drop bb_miiphy_init() and .init callback Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:15   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function Marek Vasut
                   ` (13 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

There is literally one single bbmiiphy bus in this driver,
remove the bus index handling.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: New patch
V3: No change
---
 drivers/net/designware.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 95a459cec2a..de697060d28 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -905,8 +905,6 @@ int designware_eth_probe(struct udevice *dev)
 
 #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO)
 	if (dev_read_bool(dev, "snps,bitbang-mii")) {
-		int bus_idx;
-
 		debug("\n%s: use bitbang mii..\n", dev->name);
 		ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0,
 					   &priv->mdc_gpio, GPIOD_IS_OUT
@@ -924,16 +922,11 @@ int designware_eth_probe(struct udevice *dev)
 		}
 		priv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1);
 
-		for (bus_idx = 0; bus_idx < bb_miiphy_buses_num; bus_idx++) {
-			if (!bb_miiphy_buses[bus_idx].priv) {
-				bb_miiphy_buses[bus_idx].priv = priv;
-				strlcpy(bb_miiphy_buses[bus_idx].name, priv->bus->name,
-					MDIO_NAME_LEN);
-				priv->bus->read = bb_miiphy_read;
-				priv->bus->write = bb_miiphy_write;
-				break;
-			}
-		}
+		bb_miiphy_buses[0].priv = priv;
+		strlcpy(bb_miiphy_buses[0].name, priv->bus->name,
+			MDIO_NAME_LEN);
+		priv->bus->read = bb_miiphy_read;
+		priv->bus->write = bb_miiphy_write;
 	}
 #endif
 	ret = dw_phy_init(priv, dev);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (9 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 10/23] net: designware: Drop bus index Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:16   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 12/23] net: miiphy: Introduce mdio_init() Marek Vasut
                   ` (12 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

Pull the bbmiiphy initialization code from designware_eth_probe() into
dedicated function, dw_bb_mdio_init(), just like all the other MDIO
initialization functions.

Keep check for "snps,bitbang-mii" in the designware_eth_probe(), so the
driver can initialize this MDIO only in case the property is present,
and initialize regular DW MDIO in case it is not present.

The dw_bb_mdio_init() allocates its own MDIO instance, because thus far
code gated behind "snps,bitbang-mii" did depend on allocation of MDIO bus
by the other two MDIO bus options and then rewrote the newly allocated
MDIO bus callbacks, which is wrong, instead allocate proper MDIO bus with
the correct callbacks outright.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: New patch
V3: No change
---
 drivers/net/designware.c | 95 ++++++++++++++++++++++++++--------------
 1 file changed, 63 insertions(+), 32 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index de697060d28..c88b8df28ed 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -303,6 +303,50 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 };
 
 int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
+
+static int dw_bb_mdio_init(const char *name, struct udevice *dev)
+{
+	struct dw_eth_dev *dwpriv = dev_get_priv(dev);
+	struct mii_dev *bus = mdio_alloc();
+	int ret;
+
+	if (!bus) {
+		printf("Failed to allocate MDIO bus\n");
+		return -ENOMEM;
+	}
+
+	debug("\n%s: use bitbang mii..\n", dev->name);
+	ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0,
+				   &dwpriv->mdc_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret) {
+		debug("no mdc-gpio\n");
+		return ret;
+	}
+	ret = gpio_request_by_name(dev, "snps,mdio-gpio", 0,
+				   &dwpriv->mdio_gpio,
+				   GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
+	if (ret) {
+		debug("no mdio-gpio\n");
+		return ret;
+	}
+	dwpriv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1);
+
+	dwpriv->bus = bus;
+	dwpriv->dev = dev;
+
+	bb_miiphy_buses[0].priv = dwpriv;
+	snprintf(bus->name, sizeof(bus->name), "%s", name);
+	strlcpy(bb_miiphy_buses[0].name, bus->name, MDIO_NAME_LEN);
+	bus->read = bb_miiphy_read;
+	bus->write = bb_miiphy_write;
+#if CONFIG_IS_ENABLED(DM_GPIO)
+	bus->reset = dw_mdio_reset;
+#endif
+	bus->priv = dwpriv;
+
+	return mdio_register(bus);
+}
 #endif
 
 static void tx_descs_init(struct dw_eth_dev *priv)
@@ -801,6 +845,7 @@ int designware_eth_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_plat(dev);
 	struct dw_eth_dev *priv = dev_get_priv(dev);
+	bool __maybe_unused bbmiiphy = false;
 	phys_addr_t iobase = pdata->iobase;
 	void *ioaddr;
 	int ret, err;
@@ -891,44 +936,30 @@ int designware_eth_probe(struct udevice *dev)
 	priv->interface = pdata->phy_interface;
 	priv->max_speed = pdata->max_speed;
 
-#if IS_ENABLED(CONFIG_DM_MDIO)
-	ret = dw_dm_mdio_init(dev->name, dev);
-#else
-	ret = dw_mdio_init(dev->name, dev);
-#endif
-	if (ret) {
-		err = ret;
-		goto mdio_err;
-	}
-	priv->bus = miiphy_get_dev_by_name(dev->name);
-	priv->dev = dev;
-
 #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO)
-	if (dev_read_bool(dev, "snps,bitbang-mii")) {
-		debug("\n%s: use bitbang mii..\n", dev->name);
-		ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0,
-					   &priv->mdc_gpio, GPIOD_IS_OUT
-					   | GPIOD_IS_OUT_ACTIVE);
+	bbmiiphy = dev_read_bool(dev, "snps,bitbang-mii");
+	if (bbmiiphy) {
+		ret = dw_bb_mdio_init(dev->name, dev);
 		if (ret) {
-			debug("no mdc-gpio\n");
-			return ret;
+			err = ret;
+			goto mdio_err;
 		}
-		ret = gpio_request_by_name(dev, "snps,mdio-gpio", 0,
-					   &priv->mdio_gpio, GPIOD_IS_OUT
-					   | GPIOD_IS_OUT_ACTIVE);
+	} else
+#endif
+	{
+#if IS_ENABLED(CONFIG_DM_MDIO)
+		ret = dw_dm_mdio_init(dev->name, dev);
+#else
+		ret = dw_mdio_init(dev->name, dev);
+#endif
 		if (ret) {
-			debug("no mdio-gpio\n");
-			return ret;
+			err = ret;
+			goto mdio_err;
 		}
-		priv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1);
-
-		bb_miiphy_buses[0].priv = priv;
-		strlcpy(bb_miiphy_buses[0].name, priv->bus->name,
-			MDIO_NAME_LEN);
-		priv->bus->read = bb_miiphy_read;
-		priv->bus->write = bb_miiphy_write;
+		priv->bus = miiphy_get_dev_by_name(dev->name);
+		priv->dev = dev;
 	}
-#endif
+
 	ret = dw_phy_init(priv, dev);
 	debug("%s, ret=%d\n", __func__, ret);
 	if (!ret)
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 12/23] net: miiphy: Introduce mdio_init()
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (10 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 13/23] net: miiphybb: Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers Marek Vasut
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

Introduce mdio_init() split off from mdio_alloc(), which is used
to initialize already allocated struct mii_dev.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: - Add net: subject prefix
    - Add RB from Paul
---
 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 0464f5dc219..40eb14669b8 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);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 13/23] net: miiphybb: Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (11 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 12/23] net: miiphy: Introduce mdio_init() Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks Marek Vasut
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

Introduce bb_miiphy_alloc()/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 .

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Update commit message, fix duplicate _free()
V3: Add RB from Paul
---
 drivers/net/phy/miiphybb.c | 19 +++++++++++++++++++
 include/miiphy.h           |  4 ++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c
index 75d9537b355..66d98d6cc26 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>
 
@@ -30,6 +31,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 40eb14669b8..42300ee5386 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -73,11 +73,15 @@ 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[];
 extern int bb_miiphy_buses_num;
 
+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,
 		    u16 value);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (12 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 13/23] net: miiphybb: Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:18   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 15/23] net: ravb: " Marek Vasut
                   ` (9 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 board/gdsys/a38x/ihs_phys.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c
index 86708ee6715..a121898be52 100644
--- a/board/gdsys/a38x/ihs_phys.c
+++ b/board/gdsys/a38x/ihs_phys.c
@@ -221,22 +221,35 @@ 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->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;
 	*bus = miiphy_get_dev_by_name(name);
 
-	return mii_mdio_init(&bb_miiphy_buses[k]);
+	return mii_mdio_init(bb_miiphy);
 }
 
 struct porttype *get_porttype(uint octo_phy_mask, uint k)
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 15/23] net: ravb: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (13 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-28 13:28   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 16/23] net: sh_eth: " Marek Vasut
                   ` (8 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

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.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: Add RB from Paul
---
 drivers/net/ravb.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index 381cf250ea2..0018b694ec1 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,29 @@ 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->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 +612,7 @@ static int ravb_probe(struct udevice *dev)
 err_mdio_reset:
 	clk_release_bulk(&eth->clks);
 err_mdio_register:
-	mdio_free(mdiodev);
+	bb_miiphy_free(bb_miiphy);
 err_mdio_alloc:
 	unmap_physmem(eth->iobase, MAP_NOCACHE);
 	return ret;
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 16/23] net: sh_eth: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (14 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 15/23] net: ravb: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:19   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 17/23] net: designware: " Marek Vasut
                   ` (7 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 drivers/net/sh_eth.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index 6bd12ee3f19..e78d64d77c3 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,29 @@ 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->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 +784,7 @@ err_phy_config:
 	clk_disable(&priv->clk);
 #endif
 err_mdio_register:
-	mdio_free(mdiodev);
+	bb_miiphy_free(bb_miiphy);
 	return ret;
 }
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 17/23] net: designware: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (15 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 16/23] net: sh_eth: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:19   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 18/23] net: miiphybb: Use container_of() in bb_miiphy_getbus() Marek Vasut
                   ` (6 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: New patch
V3: No change
---
 drivers/net/designware.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index c88b8df28ed..74cf8271e67 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -307,14 +307,17 @@ int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
 static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 {
 	struct dw_eth_dev *dwpriv = dev_get_priv(dev);
-	struct mii_dev *bus = mdio_alloc();
+	struct bb_miiphy_bus *bb_miiphy = bb_miiphy_alloc();
+	struct mii_dev *bus;
 	int ret;
 
-	if (!bus) {
+	if (!bb_miiphy) {
 		printf("Failed to allocate MDIO bus\n");
 		return -ENOMEM;
 	}
 
+	bus = &bb_miiphy->mii;
+
 	debug("\n%s: use bitbang mii..\n", dev->name);
 	ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0,
 				   &dwpriv->mdc_gpio,
@@ -345,6 +348,15 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 #endif
 	bus->priv = dwpriv;
 
+	/* Copy the bus accessors, name and private data */
+	bb_miiphy->mdio_active = dw_eth_bb_mdio_active;
+	bb_miiphy->mdio_tristate = dw_eth_bb_mdio_tristate;
+	bb_miiphy->set_mdio = dw_eth_bb_set_mdio;
+	bb_miiphy->get_mdio = dw_eth_bb_get_mdio;
+	bb_miiphy->set_mdc = dw_eth_bb_set_mdc;
+	bb_miiphy->delay = dw_eth_bb_delay;
+	strlcpy(bb_miiphy->name, bus->name, MDIO_NAME_LEN);
+
 	return mdio_register(bus);
 }
 #endif
@@ -968,7 +980,12 @@ int designware_eth_probe(struct udevice *dev)
 	/* continue here for cleanup if no PHY found */
 	err = ret;
 	mdio_unregister(priv->bus);
-	mdio_free(priv->bus);
+#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO)
+	if (bbmiiphy)
+		bb_miiphy_free(container_of(priv->bus, struct bb_miiphy_bus, mii));
+	else
+#endif
+		mdio_free(priv->bus);
 mdio_err:
 
 #ifdef CONFIG_CLK
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 18/23] net: miiphybb: Use container_of() in bb_miiphy_getbus()
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (16 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 17/23] net: designware: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 19/23] net: miiphybb: Drop name field from struct bb_miiphy_bus Marek Vasut
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

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.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: Add RB from Paul
---
 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 66d98d6cc26..553af2c1032 100644
--- a/drivers/net/phy/miiphybb.c
+++ b/drivers/net/phy/miiphybb.c
@@ -18,17 +18,9 @@
 #include <miiphy.h>
 #include <asm/global_data.h>
 
-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)
@@ -141,7 +133,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;
 	}
@@ -209,7 +201,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;
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 19/23] net: miiphybb: Drop name field from struct bb_miiphy_bus
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (17 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 18/23] net: miiphybb: Use container_of() in bb_miiphy_getbus() Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name() Marek Vasut
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

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.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Fold in recently added DWC bbmiiphy too
V3: Add RB from Paul
---
 board/gdsys/a38x/ihs_phys.c | 11 +++--------
 drivers/net/designware.c    |  5 +----
 drivers/net/ravb.c          |  6 +-----
 drivers/net/sh_eth.c        |  6 +-----
 include/miiphy.h            |  1 -
 5 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c
index a121898be52..128b1395243 100644
--- a/board/gdsys/a38x/ihs_phys.c
+++ b/board/gdsys/a38x/ihs_phys.c
@@ -223,31 +223,29 @@ 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->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;
-	*bus = miiphy_get_dev_by_name(name);
+	*bus = miiphy_get_dev_by_name(mdiodev->name);
 
 	return mii_mdio_init(bb_miiphy);
 }
@@ -330,7 +328,6 @@ int init_octo_phys(uint octo_phy_mask)
 
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
-		.name = "ihs0",
 		.mdio_active = mii_mdio_active,
 		.mdio_tristate = mii_mdio_tristate,
 		.set_mdio = mii_set_mdio,
@@ -340,7 +337,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 		.priv = &gpio_mii_set[0],
 	},
 	{
-		.name = "ihs1",
 		.mdio_active = mii_mdio_active,
 		.mdio_tristate = mii_mdio_tristate,
 		.set_mdio = mii_set_mdio,
@@ -350,7 +346,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = {
 		.priv = &gpio_mii_set[1],
 	},
 	{
-		.name = "ihs2",
 		.mdio_active = mii_mdio_active,
 		.mdio_tristate = mii_mdio_tristate,
 		.set_mdio = mii_set_mdio,
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 74cf8271e67..5124982e683 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -292,7 +292,6 @@ static int dw_eth_bb_delay(struct bb_miiphy_bus *bus)
 
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
-		.name		= BB_MII_DEVNAME,
 		.mdio_active	= dw_eth_bb_mdio_active,
 		.mdio_tristate	= dw_eth_bb_mdio_tristate,
 		.set_mdio	= dw_eth_bb_set_mdio,
@@ -340,7 +339,6 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 
 	bb_miiphy_buses[0].priv = dwpriv;
 	snprintf(bus->name, sizeof(bus->name), "%s", name);
-	strlcpy(bb_miiphy_buses[0].name, bus->name, MDIO_NAME_LEN);
 	bus->read = bb_miiphy_read;
 	bus->write = bb_miiphy_write;
 #if CONFIG_IS_ENABLED(DM_GPIO)
@@ -348,14 +346,13 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 #endif
 	bus->priv = dwpriv;
 
-	/* Copy the bus accessors, name and private data */
+	/* Copy the bus accessors and private data */
 	bb_miiphy->mdio_active = dw_eth_bb_mdio_active;
 	bb_miiphy->mdio_tristate = dw_eth_bb_mdio_tristate;
 	bb_miiphy->set_mdio = dw_eth_bb_set_mdio;
 	bb_miiphy->get_mdio = dw_eth_bb_get_mdio;
 	bb_miiphy->set_mdc = dw_eth_bb_set_mdc;
 	bb_miiphy->delay = dw_eth_bb_delay;
-	strlcpy(bb_miiphy->name, bus->name, MDIO_NAME_LEN);
 
 	return mdio_register(bus);
 }
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index 0018b694ec1..86787183488 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -578,14 +578,13 @@ 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->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);
@@ -634,7 +633,6 @@ static int ravb_remove(struct udevice *dev)
 
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
-		.name		= "ravb",
 		.mdio_active	= ravb_bb_mdio_active,
 		.mdio_tristate	= ravb_bb_mdio_tristate,
 		.set_mdio	= ravb_bb_set_mdio,
@@ -666,8 +664,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 e78d64d77c3..49065ebe717 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -740,14 +740,13 @@ 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->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);
@@ -829,8 +828,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;
 }
 
@@ -859,7 +856,6 @@ U_BOOT_DRIVER(eth_sh_ether) = {
 
 struct bb_miiphy_bus bb_miiphy_buses[] = {
 	{
-		.name		= "sh_eth",
 		.mdio_active	= sh_eth_bb_mdio_active,
 		.mdio_tristate	= sh_eth_bb_mdio_tristate,
 		.set_mdio	= sh_eth_bb_set_mdio,
diff --git a/include/miiphy.h b/include/miiphy.h
index 42300ee5386..efeff8ae70b 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 (*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);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name()
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (18 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 19/23] net: miiphybb: Drop name field from struct bb_miiphy_bus Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:20   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 21/23] net: ravb: " Marek Vasut
                   ` (3 subsequent siblings)
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 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 128b1395243..71c9398c77a 100644
--- a/board/gdsys/a38x/ihs_phys.c
+++ b/board/gdsys/a38x/ihs_phys.c
@@ -245,7 +245,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);
 }
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 21/23] net: ravb: Drop use of miiphy_get_dev_by_name()
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (19 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name() Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-22 20:33 ` [PATCH v3 22/23] net: sh_eth: " Marek Vasut
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

Instead of doing another lookup, trivially access the struct mii_dev
embedded in struct bb_miiphy_bus . No functional change.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: Add RB from Paul
---
 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 86787183488..b790de98b48 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -591,7 +591,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(&eth->clks);
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 22/23] net: sh_eth: Drop use of miiphy_get_dev_by_name()
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (20 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 21/23] net: ravb: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26 17:20   ` Paul Barker
  2025-02-22 20:33 ` [PATCH v3 23/23] net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num Marek Vasut
  2025-02-26  8:51 ` [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Paul Barker
  23 siblings, 1 reply; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Paul Barker, Ramon Fried,
	Simon Glass, Sughosh Ganu, Tom Rini

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: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: No change
V3: No change
---
 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 49065ebe717..b1e35aaf291 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -753,7 +753,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;
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* [PATCH v3 23/23] net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (21 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 22/23] net: sh_eth: " Marek Vasut
@ 2025-02-22 20:33 ` Marek Vasut
  2025-02-26  8:51 ` [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Paul Barker
  23 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-22 20:33 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Paul Barker, Christian Marangi, Ilias Apalodimas,
	Jerome Forissier, Jim Liu, Joe Hershberger, Mario Six,
	Michal Simek, Nobuhiro Iwamatsu, Ramon Fried, Simon Glass,
	Sughosh Ganu, Tom Rini

Neither bb_miiphy_buses nor bb_miiphy_buses_num are used anymore.
Drop both of them.

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Christian Marangi <ansuelsmth@gmail.com>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Jerome Forissier <jerome.forissier@linaro.org>
Cc: Jim Liu <JJLIU0@nuvoton.com>
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
---
V2: Fold in recently added DWC bbmiiphy too
V3: Add RB from Paul
---
 board/gdsys/a38x/ihs_phys.c | 34 +---------------------------------
 drivers/net/designware.c    | 14 --------------
 drivers/net/ravb.c          | 13 -------------
 drivers/net/sh_eth.c        | 14 --------------
 include/miiphy.h            |  3 ---
 5 files changed, 1 insertion(+), 77 deletions(-)

diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c
index 71c9398c77a..0c68087912a 100644
--- a/board/gdsys/a38x/ihs_phys.c
+++ b/board/gdsys/a38x/ihs_phys.c
@@ -289,7 +289,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;
@@ -325,35 +325,3 @@ int init_octo_phys(uint octo_phy_mask)
 
 	return 0;
 }
-
-struct bb_miiphy_bus bb_miiphy_buses[] = {
-	{
-		.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],
-	},
-	{
-		.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],
-	},
-	{
-		.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/designware.c b/drivers/net/designware.c
index 5124982e683..5a6e89c0575 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -290,19 +290,6 @@ static int dw_eth_bb_delay(struct bb_miiphy_bus *bus)
 	return 0;
 }
 
-struct bb_miiphy_bus bb_miiphy_buses[] = {
-	{
-		.mdio_active	= dw_eth_bb_mdio_active,
-		.mdio_tristate	= dw_eth_bb_mdio_tristate,
-		.set_mdio	= dw_eth_bb_set_mdio,
-		.get_mdio	= dw_eth_bb_get_mdio,
-		.set_mdc	= dw_eth_bb_set_mdc,
-		.delay		= dw_eth_bb_delay,
-	}
-};
-
-int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
-
 static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 {
 	struct dw_eth_dev *dwpriv = dev_get_priv(dev);
@@ -337,7 +324,6 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev)
 	dwpriv->bus = bus;
 	dwpriv->dev = dev;
 
-	bb_miiphy_buses[0].priv = dwpriv;
 	snprintf(bus->name, sizeof(bus->name), "%s", name);
 	bus->read = bb_miiphy_read;
 	bus->write = bb_miiphy_write;
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index b790de98b48..cb727ae9bc1 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 */
@@ -631,18 +630,6 @@ static int ravb_remove(struct udevice *dev)
 	return 0;
 }
 
-struct bb_miiphy_bus bb_miiphy_buses[] = {
-	{
-		.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 b1e35aaf291..83e48609224 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 */
@@ -853,16 +852,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[] = {
-	{
-		.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 efeff8ae70b..b879fd16ae3 100644
--- a/include/miiphy.h
+++ b/include/miiphy.h
@@ -75,9 +75,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);
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[]
  2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
                   ` (22 preceding siblings ...)
  2025-02-22 20:33 ` [PATCH v3 23/23] net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num Marek Vasut
@ 2025-02-26  8:51 ` Paul Barker
  2025-02-26 12:43   ` Marek Vasut
  23 siblings, 1 reply; 39+ messages in thread
From: Paul Barker @ 2025-02-26  8:51 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 818 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> Get rid of global bb_miiphy_buses[] which does not fit well with U-Boot
> DM in favor of usual per-ethernet-MAC-driver-instance MDIO bus accessors.
> 
> Introduce the ability to allocate struct bb_miiphy_bus {} and make it wrap
> struct mii_dev {}, so the struct mii_dev can be passed into MDIO bus access
> infrastructure as usual. When the MDIO bus access infrastructure attempts to
> access the MDIO bus and invokes any of the bbmiiphy accessors, those accessors
> are passed the structu mii_dev {}, but can also access struct bb_miiphy_bus
> using plain container_of() .
> 
> Clean up the drivers and update them to match.

I think this series looks ready to merge so I'll start rebasing my
RZ/G2L Ethernet patches on it.

Thanks Marek!

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[]
  2025-02-26  8:51 ` [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Paul Barker
@ 2025-02-26 12:43   ` Marek Vasut
  0 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-02-26 12:43 UTC (permalink / raw)
  To: Paul Barker, Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini

On 2/26/25 9:51 AM, Paul Barker wrote:
> On 22/02/2025 20:33, Marek Vasut wrote:
>> Get rid of global bb_miiphy_buses[] which does not fit well with U-Boot
>> DM in favor of usual per-ethernet-MAC-driver-instance MDIO bus accessors.
>>
>> Introduce the ability to allocate struct bb_miiphy_bus {} and make it wrap
>> struct mii_dev {}, so the struct mii_dev can be passed into MDIO bus access
>> infrastructure as usual. When the MDIO bus access infrastructure attempts to
>> access the MDIO bus and invokes any of the bbmiiphy accessors, those accessors
>> are passed the structu mii_dev {}, but can also access struct bb_miiphy_bus
>> using plain container_of() .
>>
>> Clean up the drivers and update them to match.
> 
> I think this series looks ready to merge so I'll start rebasing my
> RZ/G2L Ethernet patches on it.
> 
> Thanks Marek!
Can you please fill in the RBs to patches which are still missing them, 
so I am not applying my own stuff without RBs ?

(and yes, there will be a follow up series which deduplicates the ops, 
that is not forgotten)

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 05/23] net: sh_eth: Reorder bb_miiphy functions
  2025-02-22 20:33 ` [PATCH v3 05/23] net: sh_eth: " Marek Vasut
@ 2025-02-26 17:08   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:08 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 390 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 06/23] arm: mvebu: a38x: Reorder bb_miiphy functions
  2025-02-22 20:33 ` [PATCH v3 06/23] arm: mvebu: a38x: " Marek Vasut
@ 2025-02-26 17:09   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:09 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 390 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 07/23] net: designware: Reorder bb_miiphy functions
  2025-02-22 20:33 ` [PATCH v3 07/23] net: designware: " Marek Vasut
@ 2025-02-26 17:10   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:10 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 390 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe
  2025-02-22 20:33 ` [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe Marek Vasut
@ 2025-02-26 17:12   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:12 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 506 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 10/23] net: designware: Drop bus index
  2025-02-22 20:33 ` [PATCH v3 10/23] net: designware: Drop bus index Marek Vasut
@ 2025-02-26 17:15   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:15 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 283 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> There is literally one single bbmiiphy bus in this driver,
> remove the bus index handling.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function
  2025-02-22 20:33 ` [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function Marek Vasut
@ 2025-02-26 17:16   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:16 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 916 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> Pull the bbmiiphy initialization code from designware_eth_probe() into
> dedicated function, dw_bb_mdio_init(), just like all the other MDIO
> initialization functions.
> 
> Keep check for "snps,bitbang-mii" in the designware_eth_probe(), so the
> driver can initialize this MDIO only in case the property is present,
> and initialize regular DW MDIO in case it is not present.
> 
> The dw_bb_mdio_init() allocates its own MDIO instance, because thus far
> code gated behind "snps,bitbang-mii" did depend on allocation of MDIO bus
> by the other two MDIO bus options and then rewrote the newly allocated
> MDIO bus callbacks, which is wrong, instead allocate proper MDIO bus with
> the correct callbacks outright.
> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 ` [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks Marek Vasut
@ 2025-02-26 17:18   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:18 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 529 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 16/23] net: sh_eth: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 ` [PATCH v3 16/23] net: sh_eth: " Marek Vasut
@ 2025-02-26 17:19   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:19 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 531 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 17/23] net: designware: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 ` [PATCH v3 17/23] net: designware: " Marek Vasut
@ 2025-02-26 17:19   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:19 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 531 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name()
  2025-02-22 20:33 ` [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name() Marek Vasut
@ 2025-02-26 17:20   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:20 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 321 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 22/23] net: sh_eth: Drop use of miiphy_get_dev_by_name()
  2025-02-22 20:33 ` [PATCH v3 22/23] net: sh_eth: " Marek Vasut
@ 2025-02-26 17:20   ` Paul Barker
  0 siblings, 0 replies; 39+ messages in thread
From: Paul Barker @ 2025-02-26 17:20 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 321 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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>

Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 15/23] net: ravb: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-22 20:33 ` [PATCH v3 15/23] net: ravb: " Marek Vasut
@ 2025-02-28 13:28   ` Paul Barker
  2025-03-03 23:13     ` Marek Vasut
  0 siblings, 1 reply; 39+ messages in thread
From: Paul Barker @ 2025-02-28 13:28 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini


[-- Attachment #1.1.1: Type: text/plain, Size: 3564 bytes --]

On 22/02/2025 20:33, Marek Vasut wrote:
> 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.
> 
> Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---
> Cc: Christian Marangi <ansuelsmth@gmail.com>
> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
> Cc: Jerome Forissier <jerome.forissier@linaro.org>
> Cc: Jim Liu <JJLIU0@nuvoton.com>
> 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
> ---
> V2: No change
> V3: Add RB from Paul
> ---
>  drivers/net/ravb.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
> index 381cf250ea2..0018b694ec1 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,29 @@ 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->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 +612,7 @@ static int ravb_probe(struct udevice *dev)
>  err_mdio_reset:
>  	clk_release_bulk(&eth->clks);
>  err_mdio_register:
> -	mdio_free(mdiodev);
> +	bb_miiphy_free(bb_miiphy);
>  err_mdio_alloc:
>  	unmap_physmem(eth->iobase, MAP_NOCACHE);
>  	return ret;

Marek,

I've rebased my RZ/G2L Ethernet patches on top of this series and as
part of tidying things up I spotted an issue that I'd missed -
ravb_remove() still calls mdio_free(eth->bus). The error paths in the
probe functions have been converted but the remove functions were
missed. It should instead use something like:

    struct bb_miiphy_bus *bus = container_of(eth->bus, struct bb_miiphy_bus, mii);
    bb_miiphy_free(bus);

The same applies to the following two patches (sh_eth.c & designware.c). 

Thanks,

-- 
Paul Barker

[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 3577 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 39+ messages in thread

* Re: [PATCH v3 15/23] net: ravb: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks
  2025-02-28 13:28   ` Paul Barker
@ 2025-03-03 23:13     ` Marek Vasut
  0 siblings, 0 replies; 39+ messages in thread
From: Marek Vasut @ 2025-03-03 23:13 UTC (permalink / raw)
  To: Paul Barker, Marek Vasut, u-boot
  Cc: Christian Marangi, Ilias Apalodimas, Jerome Forissier, Jim Liu,
	Joe Hershberger, Mario Six, Michal Simek, Nobuhiro Iwamatsu,
	Ramon Fried, Simon Glass, Sughosh Ganu, Tom Rini

On 2/28/25 2:28 PM, Paul Barker wrote:
> On 22/02/2025 20:33, Marek Vasut wrote:
>> 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.
>>
>> Reviewed-by: Paul Barker <paul.barker.ct@bp.renesas.com>
>> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
>> ---
>> Cc: Christian Marangi <ansuelsmth@gmail.com>
>> Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>
>> Cc: Jerome Forissier <jerome.forissier@linaro.org>
>> Cc: Jim Liu <JJLIU0@nuvoton.com>
>> 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
>> ---
>> V2: No change
>> V3: Add RB from Paul
>> ---
>>   drivers/net/ravb.c | 19 ++++++++++++++++---
>>   1 file changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
>> index 381cf250ea2..0018b694ec1 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,29 @@ 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->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 +612,7 @@ static int ravb_probe(struct udevice *dev)
>>   err_mdio_reset:
>>   	clk_release_bulk(&eth->clks);
>>   err_mdio_register:
>> -	mdio_free(mdiodev);
>> +	bb_miiphy_free(bb_miiphy);
>>   err_mdio_alloc:
>>   	unmap_physmem(eth->iobase, MAP_NOCACHE);
>>   	return ret;
> 
> Marek,
> 
> I've rebased my RZ/G2L Ethernet patches on top of this series and as
> part of tidying things up I spotted an issue that I'd missed -
> ravb_remove() still calls mdio_free(eth->bus). The error paths in the
> probe functions have been converted but the remove functions were
> missed. It should instead use something like:
> 
>      struct bb_miiphy_bus *bus = container_of(eth->bus, struct bb_miiphy_bus, mii);
>      bb_miiphy_free(bus);
> 
> The same applies to the following two patches (sh_eth.c & designware.c).
This should be fixed in

[PATCH 01/11] net: miiphybb: Split off struct bb_miiphy_bus_ops

^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2025-03-03 23:13 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-22 20:33 [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Marek Vasut
2025-02-22 20:33 ` [PATCH v3 01/23] net: ravb: Drop empty init callback Marek Vasut
2025-02-22 20:33 ` [PATCH v3 02/23] net: sh_eth: " Marek Vasut
2025-02-22 20:33 ` [PATCH v3 03/23] net: designware: Drop NULL priv assignment Marek Vasut
2025-02-22 20:33 ` [PATCH v3 04/23] net: ravb: Reorder bb_miiphy functions Marek Vasut
2025-02-22 20:33 ` [PATCH v3 05/23] net: sh_eth: " Marek Vasut
2025-02-26 17:08   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 06/23] arm: mvebu: a38x: " Marek Vasut
2025-02-26 17:09   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 07/23] net: designware: " Marek Vasut
2025-02-26 17:10   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 08/23] arm: mvebu: a38x: Call bb_miiphy init directly in driver probe Marek Vasut
2025-02-26 17:12   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 09/23] net: miiphybb: Drop bb_miiphy_init() and .init callback Marek Vasut
2025-02-22 20:33 ` [PATCH v3 10/23] net: designware: Drop bus index Marek Vasut
2025-02-26 17:15   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 11/23] net: designware: Extract bbmiiphy initialization into dedicated function Marek Vasut
2025-02-26 17:16   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 12/23] net: miiphy: Introduce mdio_init() Marek Vasut
2025-02-22 20:33 ` [PATCH v3 13/23] net: miiphybb: Introduce bb_miiphy_alloc()/bb_miiphy_free() wrappers Marek Vasut
2025-02-22 20:33 ` [PATCH v3 14/23] arm: mvebu: a38x: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks Marek Vasut
2025-02-26 17:18   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 15/23] net: ravb: " Marek Vasut
2025-02-28 13:28   ` Paul Barker
2025-03-03 23:13     ` Marek Vasut
2025-02-22 20:33 ` [PATCH v3 16/23] net: sh_eth: " Marek Vasut
2025-02-26 17:19   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 17/23] net: designware: " Marek Vasut
2025-02-26 17:19   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 18/23] net: miiphybb: Use container_of() in bb_miiphy_getbus() Marek Vasut
2025-02-22 20:33 ` [PATCH v3 19/23] net: miiphybb: Drop name field from struct bb_miiphy_bus Marek Vasut
2025-02-22 20:33 ` [PATCH v3 20/23] arm: mvebu: a38x: Drop use of miiphy_get_dev_by_name() Marek Vasut
2025-02-26 17:20   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 21/23] net: ravb: " Marek Vasut
2025-02-22 20:33 ` [PATCH v3 22/23] net: sh_eth: " Marek Vasut
2025-02-26 17:20   ` Paul Barker
2025-02-22 20:33 ` [PATCH v3 23/23] net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num Marek Vasut
2025-02-26  8:51 ` [PATCH v3 00/23] net: miiphybb: Get rid of global bb_miiphy_buses[] Paul Barker
2025-02-26 12:43   ` Marek Vasut

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.