Subject: Re: [RFC PATCH] net: phy/mdio: enable mmd indirect access through phy_mii_ioctl()

From: Andrew Lunn <[email-masked]>
Date: Tue, 2 Nov 2021 18:13:53 +0100

On Tue, Nov 02, 2021 at 12:39:52PM +0000, Russell King (Oracle) wrote:
> On Tue, Nov 02, 2021 at 01:49:42AM +0100, Andrew Lunn wrote:
> > > The use of the indirect registers is specific to PHYs, and we already
> > > know that various PHYs don't support indirect access, and some emulate
> > > access to the EEE registers - both of which are handled at the PHY
> > > driver level.
> > 
> > That is actually an interesting point. Should the ioctl call actually
> > use the PHY driver read_mmd and write_mmd? Or should it go direct to
> > the bus? realtek uses MII_MMD_DATA for something to do with suspend,
> > and hence it uses genphy_write_mmd_unsupported(), or it has its own
> > function emulating MMD operations.
> > 
> > So maybe the ioctl handler actually needs to use __phy_read_mmd() if
> > there is a phy at the address, rather than go direct to the bus?
> > 
> > Or maybe we should just say no, you should do this all from userspace,
> > by implementing C45 over C22 in userspace, the ioctl allows that, the
> > kernel does not need to be involved.
> 
> Yes and no. There's a problem accessing anything that involves some kind
> of indirect or paged access with the current API - you can only do one
> access under the bus lock at a time, which makes the whole thing
> unreliable. We've accepted that unreliability on the grounds that this
> interface is for debugging only, so if it does go wrong, you get to keep
> all the pieces!

Agreed.

> That said, the MII ioctls are designed to be a bus level thing - you can
> address anything on the MII bus with them. Pushing the ioctl up to the
> PHY layer means we need to find the right phy device to operate on. What
> if we attempt a C45 access at an address that there isn't a phy device?

Yes, i think we need to keep with, this API is for MDIO bus access. If
you want to do C45 over C22, you need to do it in user space, since
that builds on top of basic MDIO bus accesses.

> Personally, my feeling would be that if we want to solve this, we need
> to solve this properly - we need to revise the interface so it's
> possible to request the kernel to perform a group of MII operations, so
> that userspace can safely access any paged/indirect register. With that
> solved, there will be no issue with requiring userspace to know what
> it's doing with indirect C45 accesses.

I'm against that. It opens up an API to allow user space drivers,
which i have always pushed back against. The current API is good
enough you can use it for debug, but at the same time it is
sufficiently broken that anybody trying to do user space drivers over
it is asking for trouble. That seems like a good balance to me.

   Andrew