Re: [PATCH net-next v2 4/4] net: dsa: soce: Add basic support for SoC-e switch IP cores

From: Vasilij Strassheim

Date: Wed Sep 16 2026 - 13:18:02 EST


On Tue, 2026-09-15 at 14:52 +0200, Andrew Lunn wrote:
> > Although mdio-mux-mmioreg might work, I have realized that it is not
> > suitable here.
> >
> > According to the switch documentation, the bus selector occupies bits
> > 26:16 of the MDIO control register, while bit 0 is the transaction
> > start/busy bit. A partial write might trigger an operation before the
> > other fields have been updated.
>
> Maybe. I can see at minimum it is a bit messy. The mux would need to
> write the upper bits, but set the lower start/busy to 0. The MDIO
> driver would then need to read back the register, OR in the bits it
> wants to set, and set the start bit.
>
> This start bit is pretty common, and generally, writes without it set
> are safe. But you need to test it on this particular hardware.
>

Yes, it works.

> > Also accessing this register without checking the controller state
> > could interfere with an active or failed transaction and introduce
> > races (as noted by Netdev-Sashiko).
>
> The mdio mux framework should take care of all the locking for you.
> Take a look a mdio_mux_read(). It takes the lock of the real MDIO bus
> controller, sets the mux, performs the read, and then releases the
> lock.
>
> The only thing you need to be careful of is write must wait around for
> the write to complete before returning. Some MDIO bus implementations
> don't wait, they leave it running, and do a check the bus is idle
> before doing the next operation.
>

I would like to do both. Check at the beginning and wait for the
operation to complete. However, this final wait should not last forever.
If a timeout occurs, something is completely broken and an error is
reported accordingly.

I still had concerns about the following call to set the mux with
mdio_mux_mmioreg_switch_fn() if the previous operation ended in such an
error and released the lock. However, in that case, we are already in a
faulty state and it can not get any worse. The following operation
checks the state and aborts anyway. An alternative switch_fn() with the
overhead of an extra driver is not worth it just to preserve a bitfield
in undefined error state.

So I will implement this as suggested at the beginning using
mdio-mux-mmioreg.

>        Andrew

Thanks,
Vasilij