Re: [RFC net-next 0/2] Introduce MDIO probe order C45 over C22

From: Wong Vee Khee
Date: Wed Jun 02 2021 - 10:21:10 EST


On Wed, Jun 02, 2021 at 04:19:43AM +0200, Andrew Lunn wrote:
> > Yeah, you're right. Thanks for pointing that out. It should be:
> >
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 1539ea021ac0..73bfde770f2d 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -862,11 +862,22 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
> > c45_ids.mmds_present = 0;
> > memset(c45_ids.device_ids, 0xff, sizeof(c45_ids.device_ids));
> >
> > - if (is_c45)
> > + if (is_c45) {
> > r = get_phy_c45_ids(bus, addr, &c45_ids);
> > - else
> > + } else {
> > r = get_phy_c22_id(bus, addr, &phy_id);
> >
> > + if (phy_id == 0) {
> > + r = get_phy_c45_ids(bus, addr, &c45_ids);
> > + if (r == -ENOTSUPP || r == -ENODEV)
> > + return phy_device_create(bus, addr, phy_id,
> > + false, &c45_ids);
> > + else
> > + return phy_device_create(bus, addr, phy_id,
> > + true, &c45_ids);
>
> Still not correct. Think about when get_phy_c22_id() returns an
> error. Walk through all the different code paths and check they do the
> right thing. It is actually a lot more complex than what is shown
> here. Think about all the different types of PHYs and all the
> different types of MDIO bus drivers.
>

I took a look at how most ethernet drivers implement their "bus->read"
function. Most of them either return -EIO or -ENODEV.

I think it safe to drop the return error type when we try with C45 access:


diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 1539ea021ac0..282d16fdf6e1 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -870,6 +870,18 @@ struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45)
if (r)
return ERR_PTR(r);

+ /* PHY device such as the Marvell Alaska 88E2110 will return a PHY ID
+ * of 0 when probed using get_phy_c22_id() with no error. Proceed to
+ * probe with C45 to see if we're able to get a valid PHY ID in the C45
+ * space, if successful, create the C45 PHY device.
+ */
+ if ((!is_c45) && (phy_id == 0)) {
+ r = get_phy_c45_ids(bus, addr, &c45_ids);
+ if (!r)
+ return phy_device_create(bus, addr, phy_id,
+ true, &c45_ids);
+ }
+
return phy_device_create(bus, addr, phy_id, is_c45, &c45_ids);
}
EXPORT_SYMBOL(get_phy_device);

With this implementation, it should have handled all four scenarios listed
in the table below:

*------------------*------------*------------*
| get_phy_c22_id() | phy_id==0 | Handled |
| return error | | |
*------------------*------------*------------*
| false | false | true |
*------------------*------------*------------*
| false | true | true |
*------------------*------------*------------*
| true | false | true |
*------------------*------------*------------*
| true | true | true |
*------------------*------------*------------*


VK