Subject: Re: [PATCH] net: phy: at803x: disable delay only for RGMII mode

From: Niklas Cassel <[email-masked]>
Date: Wed, 13 Feb 2019 21:07:38 +0100

On Wed, Feb 13, 2019 at 09:59:43AM -0800, Florian Fainelli wrote:
> On 2/13/19 9:40 AM, Niklas Cassel wrote:
> > On Wed, Feb 13, 2019 at 02:40:18PM +0100, Marc Gonzalez wrote:
> >> On 13/02/2019 14:29, Andrew Lunn wrote:
> >>
> >>>> So we have these modes:
> >>>>
> >>>> PHY_INTERFACE_MODE_RGMII: TX and RX delays disabled
> >>>> PHY_INTERFACE_MODE_RGMII_ID: TX and RX delays enabled
> >>>> PHY_INTERFACE_MODE_RGMII_RXID: RX delay enabled, TX delay disabled
> >>>> PHY_INTERFACE_MODE_RGMII_TXID: TX delay enabled, RX delay disabled
> >>>>
> >>>> What I don't like with this patch, is that if we specify phy-mode
> >>>> PHY_INTERFACE_MODE_RGMII_TXID, this patch will enable TX delay,
> >>>> but RX delay will not be explicitly set.
> >>>
> >>> That is not the behaviour we want. It is best to assume the device is
> >>> in a random state, and correctly enable/disable all delays as
> >>> requested. Only leave the hardware alone if PHY_INTERFACE_MODE_NA is
> >>> used.
> >>
> >> That's what my patch did:
> >> https://www.spinics.net/lists/netdev/msg445053.html
> >>
> >> But see Florian's remarks:
> >> https://www.spinics.net/lists/netdev/msg445133.html
> > 
> > Hello Marc,
> > 
> > I saw that comment from Florian. However that was way back in 2017.
> > Maybe the phy-modes were not as well defined back then?
> 
> The definition of the 'phy-mode' was clarified to be understood from the
> perspective of the PHY device (hence the name) after we had several
> fruitful exchanges with Marc (at least from my perspective), but since
> the definition was not clear before, there is a high chance of finding
> DTS/DTBs out there with the 'phy-mode' property understood from the
> MAC's perspective, which would now be wrong.

Hello Florian,

We have a specification:
Documentation/devicetree/bindings/net/ethernet.txt

And several implementations: the PHY drivers.

Either we decide that all PHY drivers have to follow
the specification for "phy-mode" in
Documentation/devicetree/bindings/net/ethernet.txt
or we decide that they don't.

If we decide that all PHY drivers have to follow the specification,
then we can fix the PHY drivers that currently do not follow the
specification.

If we decide that all PHY drivers do not have to follow the spec,
then the "phy-mode" property is basically useless, and then we should
introduce a new device tree property, e.g. "phy-mode2", that is
guaranteed to respect the definitons in
Documentation/devicetree/bindings/net/ethernet.txt

> 
> 
> > 
> > Andrew recently suggested to fix the driver so that it conforms with the
> > phy-modes, and fix any SoC that specified an incorrect phy-mode in DT
> > and thus relied upon the broken behavior of the PHY driver:
> > https://www.spinics.net/lists/netdev/msg445133.html
> > 
> > 
> > So, I've rebased your old patch, see attachment.
> > I suggest that Peter test it on am335x-evm.
> > 
> > am335x-evm appears to rely on the current broken behavior of the PHY
> > driver, so we will probably need to fix the am335x-evm according to this:
> > https://www.spinics.net/lists/netdev/msg445117.html
> > and merge that as well.
> > 
> > 
> > Andrew, Florian, do you both agree?
> 
> In my reply to Marc, there was a concern that while am335x-evm was
> identified and reported to be broken after fixing the PHY driver, there
> could be platforms out there that we have little to no visibility that
> would most likely be equally broken. That concern still exists, and I
> don't think there is anything we can do to even assess the size of the
> problem unless we attempt to fix it, so maybe we should attempt to fix that.
> 
> There was a suggestion to Marc that one way to possibly "ignore" an
> incorrectly broken 'phy-mode' property would be to allow specifying
> rx/tx delay properties such that if the driver obtained its
> phy_interface_t, yet still parsed rx/tx delays, the rx/tx delays would
> take precedence, and we could possibly derive some sort of a "more
> correct" phy_interface_t that we could assign back to phydev->interface
> and issue a warning about that.

You mean to add new device tree properties to
Documentation/devicetree/bindings/net/ethernet.txt

- phy-id-tx: "true" if PHY should add internal delay on TX lines;
             "false" or not specified if PHY should not add internal
	     delay on TX lines. This property overrides any delay
	     requested by "phy-mode".
- phy-id-rx: "true" if PHY should add internal delay on RX lines;
             "false" or not specified if PHY should not add internal
	     delay on RX lines. This property overrides any delay
	     requested by "phy-mode".

Perhaps something like that?

Personally, I prefer making "phy-mode" strict,
but whatever you guys decide:
- making "phy-mode" strict
- introducing a "phy-mode2"
- introducing "phy-id-tx/phy-id-rx"
- introducing "mac-mode"
- some other solution

It is probably wise to introduce helper functions in phy.h
 phy_wants_id_rx()
 phy_wants_id_tx()
so that PHY drivers can simply use e.g.:

if (phy_wants_id_rx(phydev))
	at803x_enable_rx_delay(phydev);
else
	at803x_disable_rx_delay(phydev);

if (phy_wants_id_tx(phydev))
	at803x_enable_tx_delay(phydev);
else
	at803x_disable_tx_delay(phydev);

> 
> Another possible way to resolve that could be to introduce a 'mac-mode'
> property, which must be strictly compatible with specifying a 'phy-mode'
> property. For instance:
> 
> - MAC specifies mac-mode = 'rgmii-id', then the PHY must have phy-mode =
> 'rmgii' since the MAC is taking of inserting both RX and TX delays,
> reverse also applies
> 
> - MAC specifies mac-mode = 'rgmii-txid', then the PHY must have phy-mode
> = 'rgmii-rxid' because the MAC adds the TX delay, but the PHY should
> insert the delay on the RX lines, reverse also applies
> 
> Because there is usually (not always, DSA is an exception) a 1:1 mapping
> between MAC and PHY devices we could look up the 'mac-mode' property in
> the MAC in the PHY library code and make sure that we have a compatible
> matrix and if we do not, maybe pass something like PHY_INTERFACE_MODE_NA
> such that the driver retains its settings.

Is there any advantage of creating a "mac-mode" over creating a
"phy-mode2" ?

Kind regards,
Niklas

> 
> Maybe another way to approach this is if we assume that the PHY comes up
> configured correctly by the boot loader, or upon power on reset, we add
> some PHY driver methods that allow us to determine the RGMII mode in
> which a PHY is and that tells us whether we are compatible with the
> MAC's phy_interface_t upon connection. We check both at connect() time
> and if something does not look right, we flip the meaning of
> phy_interface_t.
> 
> None of those solutions are entirely fool proof, but at least we might
> be able to detect incorrect combinations, yet still make them work by
> reversing the meaning of the 'phy-mode' property given information at hand.
> 
> Let me know if none of that makes sense and this just looks like yet
> another brain dump.
> 
> Wonderful RGMII...
> -- 
> Florian