RE: [PATCH net] net: phy: add device link between MAC device and MDIO device

From: Wei Fang

Date: Fri Jan 30 2026 - 05:10:10 EST


> On 30/01/2026 04:41, Wei Fang wrote:
> [...]
> >
> > diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> > index 81984d4ebb7c..c48335bfc7b6 100644
> > --- a/drivers/net/phy/phy_device.c
> > +++ b/drivers/net/phy/phy_device.c
> > @@ -1771,9 +1771,17 @@ int phy_attach_direct(struct net_device *dev,
> struct phy_device *phydev,
> > * another mac interface, so we should create a device link
> between
> > * phy dev and mac dev.
> > */
> > - if (dev && phydev->mdio.bus->parent && dev->dev.parent !=
> phydev->mdio.bus->parent)
> > - phydev->devlink = device_link_add(dev->dev.parent,
> &phydev->mdio.dev,
> > -
> DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> > + if (dev && bus->parent && dev->dev.parent != bus->parent) {
> > + if (phydev->sfp_bus_attached)
> ^ assuming we replace with phy_on_sfp()
> > + phydev->devlink =
> device_link_add(dev->dev.parent,
> > +
> bus->parent,
> > +
> DL_FLAG_PM_RUNTIME |
> > +
> DL_FLAG_STATELESS);
> > + else
> > + device_link_add(dev->dev.parent, bus->parent,
> > + DL_FLAG_PM_RUNTIME |
> > +
> DL_FLAG_AUTOREMOVE_SUPPLIER);
> > + }
>
> I think we should let the phy_on_sfp() case alone for now. The lifetime
> of the SFP phydev and the MAC are completely independent here, the PHY
> can be probed/removed without the MAC being there, and vice versa.
>
> The MDIO bus that controls that SFP PHY's lifetime is the same as the
> PHY itself, the mdio bus in that case exists solely to drive that single
> PHY, and in can't be shared between multiple PHYs even if we have
> multiple SFP ports in the entire system.
>
> The logical thing to do IMO is not to tie the MAC and the MDIO Bus
> itself, but rather the MAC and the PHY as was done before. As you state,

Okay, I agree. I will only change the devlink flag to
DL_FLAG_AUTOREMOVE_SUPPLIER. And thanks for you prompt feedback. :)


> we couldn't set DL_FLAG_AUTOREMOVE_SUPPLIER because of SFP PHYs, but
> if we add the check on "phy_on_sfp()", it should now be fine.
>