diff mbox series

[net-next,2/2] ravb: Add support for an optional MDIO mode

Message ID 20240309155334.1310262-3-niklas.soderlund+renesas@ragnatech.se (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series ravb: Support describing the MDIO bus | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 956 this patch: 956
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 956 this patch: 956
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 29 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-03-10--00-00 (tests: 888)

Commit Message

Niklas Söderlund March 9, 2024, 3:53 p.m. UTC
The driver used the OF node of the device itself when registering the
MDIO bus. While this works it creates a problem, it forces any MDIO bus
properties to also be set on the devices OF node. This mixes the
properties of two distinctly different things and is confusing.

This change adds support for an optional mdio node to be defined as a
child to the device OF node. The child node can then be used to describe
MDIO bus properties that the MDIO core can act on when registering the
bus.

If no mdio child node is found the driver fallback to the old behavior
and register the MDIO bus using the device OF node. This change is
backward compatible with old bindings in use.

Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
---
 drivers/net/ethernet/renesas/ravb_main.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

Comments

Sergey Shtylyov March 9, 2024, 7:28 p.m. UTC | #1
On 3/9/24 6:53 PM, Niklas Söderlund wrote:

> The driver used the OF node of the device itself when registering the

   s/OF/DT/, perhaps?

> MDIO bus. While this works it creates a problem, it forces any MDIO bus

   While this works, it creates a problem: it forces any MDIO bus...

> properties to also be set on the devices OF node. This mixes the

  Again, DT node?

> properties of two distinctly different things and is confusing.
> 
> This change adds support for an optional mdio node to be defined as a
> child to the device OF node. The child node can then be used to describe
> MDIO bus properties that the MDIO core can act on when registering the
> bus.
> 
> If no mdio child node is found the driver fallback to the old behavior
> and register the MDIO bus using the device OF node. This change is
> backward compatible with old bindings in use.
> 
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>

[...]

MBR, Sergey
Niklas Söderlund March 9, 2024, 8:44 p.m. UTC | #2
Hi Sergey,

Thanks for your review.

On 2024-03-09 22:28:47 +0300, Sergey Shtylyov wrote:
> On 3/9/24 6:53 PM, Niklas Söderlund wrote:
> 
> > The driver used the OF node of the device itself when registering the
> 
>    s/OF/DT/, perhaps?

I thought we referred to it as DT node when talking about .dts{i,o} 
files and OF node when it was used inside the kernel? The infrastructure 
around its called of_get_child_by_name() and of_node_put() for example.  
And I believe OF is an abbreviation for Open Firmware (?). IIRC this is 
because ACPI might also be in the mix somewhere and DT != ACPI :-)

I'm happy to change this if I understood it wrong, if not I like to keep 
it as is.

> 
> > MDIO bus. While this works it creates a problem, it forces any MDIO bus
> 
>    While this works, it creates a problem: it forces any MDIO bus...

Thanks will fix.

> 
> > properties to also be set on the devices OF node. This mixes the
> 
>   Again, DT node?
> 
> > properties of two distinctly different things and is confusing.
> > 
> > This change adds support for an optional mdio node to be defined as a
> > child to the device OF node. The child node can then be used to describe
> > MDIO bus properties that the MDIO core can act on when registering the
> > bus.
> > 
> > If no mdio child node is found the driver fallback to the old behavior
> > and register the MDIO bus using the device OF node. This change is
> > backward compatible with old bindings in use.
> > 
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> 
> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
> 
> [...]
> 
> MBR, Sergey
Geert Uytterhoeven March 11, 2024, 9:24 a.m. UTC | #3
Hi Niklas,

On Sat, Mar 9, 2024 at 9:44 PM Niklas Söderlund
<niklas.soderlund+renesas@ragnatech.se> wrote:
> On 2024-03-09 22:28:47 +0300, Sergey Shtylyov wrote:
> > On 3/9/24 6:53 PM, Niklas Söderlund wrote:
> >
> > > The driver used the OF node of the device itself when registering the
> >
> >    s/OF/DT/, perhaps?
>
> I thought we referred to it as DT node when talking about .dts{i,o}
> files and OF node when it was used inside the kernel? The infrastructure
> around its called of_get_child_by_name() and of_node_put() for example.
> And I believe OF is an abbreviation for Open Firmware (?). IIRC this is
> because ACPI might also be in the mix somewhere and DT != ACPI :-)

OF is indeed an abbreviation for Open Firmware...
Originally, the of_*() code was written to interact with device trees
provided by Open Firmware.  Later, it was extended to work with
flattened device trees (FDT) provided by something other than Open
Firmware.

> I'm happy to change this if I understood it wrong, if not I like to keep
> it as is.

... but no real Open Firmware is involved on Renesas ARM platforms,
so DT is more appropriate here.

Gr{oetje,eeting}s,

                        Geert
Geert Uytterhoeven March 11, 2024, 9:32 a.m. UTC | #4
Hi Niklas,

On Sat, Mar 9, 2024 at 4:55 PM Niklas Söderlund
<niklas.soderlund+renesas@ragnatech.se> wrote:
> The driver used the OF node of the device itself when registering the
> MDIO bus. While this works it creates a problem, it forces any MDIO bus
> properties to also be set on the devices OF node. This mixes the
> properties of two distinctly different things and is confusing.
>
> This change adds support for an optional mdio node to be defined as a
> child to the device OF node. The child node can then be used to describe
> MDIO bus properties that the MDIO core can act on when registering the
> bus.
>
> If no mdio child node is found the driver fallback to the old behavior
> and register the MDIO bus using the device OF node. This change is
> backward compatible with old bindings in use.
>
> Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>

Thanks for your patch!

> --- a/drivers/net/ethernet/renesas/ravb_main.c
> +++ b/drivers/net/ethernet/renesas/ravb_main.c
> @@ -2582,8 +2583,20 @@ static int ravb_mdio_init(struct ravb_private *priv)
>         snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
>                  pdev->name, pdev->id);
>
> -       /* Register MDIO bus */
> -       error = of_mdiobus_register(priv->mii_bus, dev->of_node);
> +       /* Register MDIO bus
> +        *
> +        * Look for a mdio child node, if it exist use it when registering the
> +        * MDIO bus. If no node is found fallback to old behavior and use the
> +        * device OF node. This is used to be able to describe MDIO bus
> +        * properties that are consumed when registering the MDIO bus.
> +        */
> +       mdio_node = of_get_child_by_name(dev->of_node, "mdio");
> +       if (mdio_node) {
> +               error = of_mdiobus_register(priv->mii_bus, mdio_node);
> +               of_node_put(mdio_node);
> +       } else {
> +               error = of_mdiobus_register(priv->mii_bus, dev->of_node);
> +       }
>         if (error)
>                 goto out_free_bus;
>

Perhaps the code should be streamlined for the modern case?

        mdio_node = of_get_child_by_name(dev->of_node, "mdio");
        if (!mdio_node) {
                /* backwards compatibility for DT lacking mdio subnode */
                mdio_node = of_node_get(dev->of_node);
        }

        error = of_mdiobus_register(priv->mii_bus, mdio_node);
        of_node_put(mdio_node);

When deemed necessary, you can easily replace the backwards
compatibility handling by error handling later.

Gr{oetje,eeting}s,

                        Geert
Niklas Söderlund March 11, 2024, 11:03 a.m. UTC | #5
Hi Geert,

Thanks for your suggestion.

On 2024-03-11 10:32:35 +0100, Geert Uytterhoeven wrote:
> Hi Niklas,
> 
> On Sat, Mar 9, 2024 at 4:55 PM Niklas Söderlund
> <niklas.soderlund+renesas@ragnatech.se> wrote:
> > The driver used the OF node of the device itself when registering the
> > MDIO bus. While this works it creates a problem, it forces any MDIO bus
> > properties to also be set on the devices OF node. This mixes the
> > properties of two distinctly different things and is confusing.
> >
> > This change adds support for an optional mdio node to be defined as a
> > child to the device OF node. The child node can then be used to describe
> > MDIO bus properties that the MDIO core can act on when registering the
> > bus.
> >
> > If no mdio child node is found the driver fallback to the old behavior
> > and register the MDIO bus using the device OF node. This change is
> > backward compatible with old bindings in use.
> >
> > Signed-off-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
> 
> Thanks for your patch!
> 
> > --- a/drivers/net/ethernet/renesas/ravb_main.c
> > +++ b/drivers/net/ethernet/renesas/ravb_main.c
> > @@ -2582,8 +2583,20 @@ static int ravb_mdio_init(struct ravb_private *priv)
> >         snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
> >                  pdev->name, pdev->id);
> >
> > -       /* Register MDIO bus */
> > -       error = of_mdiobus_register(priv->mii_bus, dev->of_node);
> > +       /* Register MDIO bus
> > +        *
> > +        * Look for a mdio child node, if it exist use it when registering the
> > +        * MDIO bus. If no node is found fallback to old behavior and use the
> > +        * device OF node. This is used to be able to describe MDIO bus
> > +        * properties that are consumed when registering the MDIO bus.
> > +        */
> > +       mdio_node = of_get_child_by_name(dev->of_node, "mdio");
> > +       if (mdio_node) {
> > +               error = of_mdiobus_register(priv->mii_bus, mdio_node);
> > +               of_node_put(mdio_node);
> > +       } else {
> > +               error = of_mdiobus_register(priv->mii_bus, dev->of_node);
> > +       }
> >         if (error)
> >                 goto out_free_bus;
> >
> 
> Perhaps the code should be streamlined for the modern case?
> 
>         mdio_node = of_get_child_by_name(dev->of_node, "mdio");
>         if (!mdio_node) {
>                 /* backwards compatibility for DT lacking mdio subnode */
>                 mdio_node = of_node_get(dev->of_node);
>         }
> 
>         error = of_mdiobus_register(priv->mii_bus, mdio_node);
>         of_node_put(mdio_node);
> 
> When deemed necessary, you can easily replace the backwards
> compatibility handling by error handling later.

This looks much better, will do so as well as s/OF/DT/ in the commit 
message for next version.

> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> -- 
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
diff mbox series

Patch

diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c
index fa48ff4aba2d..b62f765ce066 100644
--- a/drivers/net/ethernet/renesas/ravb_main.c
+++ b/drivers/net/ethernet/renesas/ravb_main.c
@@ -2564,6 +2564,7 @@  static int ravb_mdio_init(struct ravb_private *priv)
 {
 	struct platform_device *pdev = priv->pdev;
 	struct device *dev = &pdev->dev;
+	struct device_node *mdio_node;
 	struct phy_device *phydev;
 	struct device_node *pn;
 	int error;
@@ -2582,8 +2583,20 @@  static int ravb_mdio_init(struct ravb_private *priv)
 	snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
 		 pdev->name, pdev->id);
 
-	/* Register MDIO bus */
-	error = of_mdiobus_register(priv->mii_bus, dev->of_node);
+	/* Register MDIO bus
+	 *
+	 * Look for a mdio child node, if it exist use it when registering the
+	 * MDIO bus. If no node is found fallback to old behavior and use the
+	 * device OF node. This is used to be able to describe MDIO bus
+	 * properties that are consumed when registering the MDIO bus.
+	 */
+	mdio_node = of_get_child_by_name(dev->of_node, "mdio");
+	if (mdio_node) {
+		error = of_mdiobus_register(priv->mii_bus, mdio_node);
+		of_node_put(mdio_node);
+	} else {
+		error = of_mdiobus_register(priv->mii_bus, dev->of_node);
+	}
 	if (error)
 		goto out_free_bus;