diff mbox series

[net] net: stmmac: Handle disabled MDIO busses from devicetree

Message ID 20231211-b4-stmmac-handle-mdio-enodev-v1-1-73c20c44f8d6@redhat.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net] net: stmmac: Handle disabled MDIO busses from devicetree | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
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 fail Problems with Fixes tag: 1
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch warning WARNING: Please use correct Fixes: style 'Fixes: <12 chars of sha1> ("<title line>")' - ie: 'Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")'
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

Commit Message

Andrew Halaney Dec. 11, 2023, 9:31 p.m. UTC
Many hardware configurations have the MDIO bus disabled, and are instead
using some other MDIO bus to talk to the MAC's phy.

of_mdiobus_register() returns -ENODEV in this case. Let's handle it
gracefully instead of failing to probe the MAC.

Fixes: 47dd7a540b8a (net: add support for STMicroelectronics Ethernet controllers.")
Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)


---
base-commit: bbd220ce4e29ed55ab079007cff0b550895258eb
change-id: 20231211-b4-stmmac-handle-mdio-enodev-82168de68c6a

Best regards,

Comments

Serge Semin Dec. 12, 2023, 10:59 a.m. UTC | #1
On Mon, Dec 11, 2023 at 03:31:17PM -0600, Andrew Halaney wrote:
> Many hardware configurations have the MDIO bus disabled, and are instead
> using some other MDIO bus to talk to the MAC's phy.
> 
> of_mdiobus_register() returns -ENODEV in this case. Let's handle it
> gracefully instead of failing to probe the MAC.
> 
> Fixes: 47dd7a540b8a (net: add support for STMicroelectronics Ethernet controllers.")
> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> ---
>  drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> index fa9e7e7040b9..a39be15d41a8 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> @@ -591,7 +591,13 @@ int stmmac_mdio_register(struct net_device *ndev)
>  	new_bus->parent = priv->device;
>  
>  	err = of_mdiobus_register(new_bus, mdio_node);
> -	if (err != 0) {
> +	if (err) {
> +		if (err == -ENODEV) {
> +			/* The bus is disabled in the devicetree, that's ok */
> +			mdiobus_free(new_bus);
> +			return 0;
> +		}
> +
>  		dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
>  		goto bus_register_fail;
>  	}

This can be implemented a bit simpler, more maintainable and saving
one indentations level:

	err = of_mdiobus_register(new_bus, mdio_node);
	if (err == -ENODEV) {
		err = 0;
		dev_warn(dev, "MDIO bus is disabled\n");
		goto bus_register_fail;
	} else if (err) {
  		dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
  		goto bus_register_fail;
	}

-Serge(y)

> 
> ---
> base-commit: bbd220ce4e29ed55ab079007cff0b550895258eb
> change-id: 20231211-b4-stmmac-handle-mdio-enodev-82168de68c6a
> 
> Best regards,
> -- 
> Andrew Halaney <ahalaney@redhat.com>
>
Andrew Halaney Dec. 12, 2023, 2:28 p.m. UTC | #2
On Tue, Dec 12, 2023 at 01:59:25PM +0300, Serge Semin wrote:
> On Mon, Dec 11, 2023 at 03:31:17PM -0600, Andrew Halaney wrote:
> > Many hardware configurations have the MDIO bus disabled, and are instead
> > using some other MDIO bus to talk to the MAC's phy.
> > 
> > of_mdiobus_register() returns -ENODEV in this case. Let's handle it
> > gracefully instead of failing to probe the MAC.
> > 
> > Fixes: 47dd7a540b8a (net: add support for STMicroelectronics Ethernet controllers.")
> > Signed-off-by: Andrew Halaney <ahalaney@redhat.com>
> > ---
> >  drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c | 8 +++++++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > index fa9e7e7040b9..a39be15d41a8 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
> > @@ -591,7 +591,13 @@ int stmmac_mdio_register(struct net_device *ndev)
> >  	new_bus->parent = priv->device;
> >  
> >  	err = of_mdiobus_register(new_bus, mdio_node);
> > -	if (err != 0) {
> > +	if (err) {
> > +		if (err == -ENODEV) {
> > +			/* The bus is disabled in the devicetree, that's ok */
> > +			mdiobus_free(new_bus);
> > +			return 0;
> > +		}
> > +
> >  		dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
> >  		goto bus_register_fail;
> >  	}
> 
> This can be implemented a bit simpler, more maintainable and saving
> one indentations level:
> 
> 	err = of_mdiobus_register(new_bus, mdio_node);
> 	if (err == -ENODEV) {
> 		err = 0;
> 		dev_warn(dev, "MDIO bus is disabled\n");

Thanks for all your reviews, I agree this is cleaner!

I'm going to opt to use dev_info() here as this isn't something that's
wrong, just worth noting.

> 		goto bus_register_fail;
> 	} else if (err) {
>   		dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
>   		goto bus_register_fail;
> 	}
> 
> -Serge(y)
> 
> > 
> > ---
> > base-commit: bbd220ce4e29ed55ab079007cff0b550895258eb
> > change-id: 20231211-b4-stmmac-handle-mdio-enodev-82168de68c6a
> > 
> > Best regards,
> > -- 
> > Andrew Halaney <ahalaney@redhat.com>
> > 
>
Simon Horman Dec. 12, 2023, 6:48 p.m. UTC | #3
On Mon, Dec 11, 2023 at 03:31:17PM -0600, Andrew Halaney wrote:
> Many hardware configurations have the MDIO bus disabled, and are instead
> using some other MDIO bus to talk to the MAC's phy.
> 
> of_mdiobus_register() returns -ENODEV in this case. Let's handle it
> gracefully instead of failing to probe the MAC.
> 
> Fixes: 47dd7a540b8a (net: add support for STMicroelectronics Ethernet controllers.")

nit: the tag above is malformed, there is a '"' missing before 'net:'.

  Fixes: 47dd7a540b8a ("net: add support for STMicroelectronics Ethernet controllers.")


> Signed-off-by: Andrew Halaney <ahalaney@redhat.com>

...
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
index fa9e7e7040b9..a39be15d41a8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c
@@ -591,7 +591,13 @@  int stmmac_mdio_register(struct net_device *ndev)
 	new_bus->parent = priv->device;
 
 	err = of_mdiobus_register(new_bus, mdio_node);
-	if (err != 0) {
+	if (err) {
+		if (err == -ENODEV) {
+			/* The bus is disabled in the devicetree, that's ok */
+			mdiobus_free(new_bus);
+			return 0;
+		}
+
 		dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
 		goto bus_register_fail;
 	}