Messages in this thread | | | From | Alvin Šipraga <> | Subject | Re: [PATCH net-next 0/2] net: dsa: realtek: fix PHY register read corruption | Date | Wed, 16 Feb 2022 19:26:43 +0000 |
| |
Andrew Lunn <andrew@lunn.ch> writes: >> Hmm OK. Actually I'm a bit confused about the mdio_lock: can you explain >> what it's guarding against, for someone unfamiliar with MDIO? > > The more normal use case for MDIO is for PHYs, not switches. There can > be multiple PHYs on one MDIO bus. And these PHYs each have there own > state machine in phylib. At any point in time, that state machine can > request the driver to do something, like poll the PHY status, does it > have link? To prevent two PHY drivers trying to use the MDIO bus at > the same time, there is an MDIO lock. At the beginning of an MDIO > transaction, the lock is taken. And the end of the transaction, > reading or writing one register of a device on the bus, the lock is > released. > > So the MDIO lock simply ensures there is only one user of the MDIO bus > at one time, for a single read or write. > > For PHYs this is sufficient. For switches, sometimes you need > additional protection. The granularity of an access might not be a > single register read or a write. It could be you need to read or write > a few registers in an atomic way. If that is the case, you need a lock > at a higher level.
Thank you Andrew for the clear explanation.
Somewhat unrelated to this series, but are you able to explain to me the difference between:
mutex_lock(&bus->mdio_lock); and mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
While looking at other driver examples I noticed the latter form quite a few times too.
Kind regards, Alvin
| |