net: renesas: Fix rgmii-id delays
Subsystems (3)
PATCH 1/1 net: renesas: Fix rgmii-id delays
Invert the configuration of the RGMII delay selected by RGMII_RXID and RGMII_TXID.
The ravb MAC is adding RX delay if RGMII_RXID is selected and TX delay if RGMII_TXID but that behavior is wrong.
Indeed according to the ethernet.txt documentation the ravb configuration should be inverted:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
* "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC should not add an TX delay in this case)
This patch inverts the behavior, i.e adds TX delay when RGMII_RXID is selected and RX delay when RGMII_TXID is selected.
--- drivers/net/ethernet/renesas/ravb_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/renesas/ravb_main.c +2 -2
@@ -2114,13 +2114,13 @@ static void ravb_parse_delay_mode(struct device_node *np, struct net_device *nde/* Fall back to legacy rgmii-*id behavior */ if (priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_RXID ) { - priv->rxcidm =1 ; + priv->txcidm =1 ; priv->rgmii_override =1 ; }if (priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_TXID ) { - priv->txcidm =1 ; + priv->rxcidm =1 ; priv->rgmii_override =1 ; } }
Signature · 1 line
2.25.1
Hi Kory,
Thanks for your patch!
Quoted 6 lines · Kory Maincent
Invert the configuration of the RGMII delay selected by
RGMII_RXIDandRGMII_TXID.The ravb MAC is adding RX delay if
RGMII_RXIDis selected and TX delay ifRGMII_TXIDbut that behavior is wrong.
Indeed according to the ethernet.txt documentation the ravb configuration
Do you mean ethernet-controller.yaml?
Quoted 10 lines
should be inverted:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
* "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC should not add an TX delay in this case)This patch inverts the behavior, i.e adds TX delay when
RGMII_RXIDis selected and RX delay whenRGMII_TXIDis selected.Signed-off-by Kory Maincent <[email protected]>
Does this fix an actual problem for you?
drivers/net/ethernet/renesas/ravb_main.c static void ravb_parse_delay_mode(struct device_node *np, struct net_device *nde · line 2114
Quoted 4 lines
drivers/net/ethernet/renesas/ravb_main.c +0
-0@@ -2114,13 +2114,13 @@ static void ravb_parse_delay_mode(struct device_node *np, struct net_device *nde/* Fall back to legacy rgmii-*id behavior */
Note that in accordance with the comment above, the code section below is only present to support old DTBs. Contemporary DTBs rely on the now mandatory "rx-internal-delay-ps" and "tx-internal-delay-ps" properties instead.
Hence changing this code has no effect on DTS files as supplied with the kernel, but may have ill effects on DTB files in the field, which rely on the current behavior.
Quoted 4 lines
drivers/net/ethernet/renesas/ravb_main.c +1
-1if (priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_RXID ) { - priv->rxcidm =1 ; + priv->txcidm =1 ;
drivers/net/ethernet/renesas/ravb_main.c static void ravb_parse_delay_mode(struct device_node *np, struct net_device *nde · line 2126
Quoted 10 lines
drivers/net/ethernet/renesas/ravb_main.c +1
-1priv->rgmii_override =1 ; }if (priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_ID || priv->phy_interface ==PHY_INTERFACE_MODE_RGMII_TXID ) { - priv->txcidm =1 ; + priv->rxcidm =1 ; priv->rgmii_override =1 ; } }
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert,
Thanks for the review.
Quoted 5 lines · On Tue, 19 Oct 2021 17:13:52 +0200 Geert Uytterhoeven <[email protected]>…
Quoted 3 lines
The ravb MAC is adding RX delay if
RGMII_RXIDis selected and TX delay ifRGMII_TXIDbut that behavior is wrong.
Indeed according to the ethernet.txt documentation the ravb configurationDo you mean
ethernet-controller.yaml?
Doh, yes, I paste the commit log from the older Kernel git and forget to change that.
Quoted 7 lines
Quoted 7 lines
should be inverted:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
* "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC should not add an TX delay in this case)
Quoted 6 lines
Quoted 4 lines
This patch inverts the behavior, i.e adds TX delay when
RGMII_RXIDis selected and RX delay whenRGMII_TXIDis selected.Signed-off-by Kory Maincent <[email protected]>Does this fix an actual problem for you?
In fact, this fix a problem for an older 4.14 Kernel on my current project. I wanted to push my fix in the mainline kernel also, but as you say below, now this code is legacy.
Does it matter to fix legacy code?
Quoted 7 lines
Note that in accordance with the comment above, the code section below is only present to support old DTBs. Contemporary DTBs rely on the now mandatory "rx-internal-delay-ps" and "tx-internal-delay-ps" properties instead.
Hence changing this code has no effect on DTS files as supplied with the kernel, but may have ill effects on DTB files in the field, which rely on the current behavior.
When people update the kernel version don't they update also the devicetree?
Regards,
Köry
Quoted 1 line
When people update the kernel version don't they update also the devicetree?
DT is ABI. Driver writers should not break old blobs running on new kernels. Often the DT blob is updated with the kernel, but it is not required. It could be stored in a hard to reach place, shared with u-boot etc.
Andrew
Quoted 6 lines · On Tue, 19 Oct 2021 17:41:49 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 1 line
When people update the kernel version don't they update also the devicetree?
DT is ABI. Driver writers should not break old blobs running on new kernels. Often the DT blob is updated with the kernel, but it is not required. It could be stored in a hard to reach place, shared with u-boot etc.
Right, but conversely if someone reads the DT bindings that exists today, specifies phy-mode = "rgmii-rxid" or phy-mmode = "rmgii-txid", this person will get incorrect behavior. Sure a behavior that is backward compatible with older DTs, but a terribly wrong one when you write a new DT and read the DT binding documentation. This is exactly the problem that happened to us.
I know that those properties are considered obsolete, but even though they are considered as such, they are still supported, but for this particular MAC driver, with an inverted meaning compared to what the DT binding documentation says.
What wins: DT ABI backward compatibility, or correctness of the DT binding ? :-)
Best regards,
Thomas
Signature · 3 lines
Thomas Petazzoni, co-owner and CEO, Bootlin Embedded Linux and Kernel engineering and training https://bootlin.com
Hi Thomas,
Quoted 11 lines · Thomas Petazzoni
Quoted 6 lines · On Tue, 19 Oct 2021 17:41:49 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 1 line
When people update the kernel version don't they update also the devicetree?
DT is ABI. Driver writers should not break old blobs running on new kernels. Often the DT blob is updated with the kernel, but it is not required. It could be stored in a hard to reach place, shared with u-boot etc.
Right, but conversely if someone reads the DT bindings that exists today, specifies phy-mode = "rgmii-rxid" or phy-mmode = "rmgii-txid",
Today == v5.10-rc1 and later?
Quoted 4 lines
this person will get incorrect behavior. Sure a behavior that is backward compatible with older DTs, but a terribly wrong one when you write a new DT and read the DT binding documentation. This is exactly the problem that happened to us.
If you write a new DT, you read the DT binding documentation, and "make dtbs_check" will inform you politely if you use the legacy/wrong DT (i.e. lacking "[rt]x-internal-delay-ps")?
Quoted 7 lines
I know that those properties are considered obsolete, but even though they are considered as such, they are still supported, but for this particular MAC driver, with an inverted meaning compared to what the DT binding documentation says.
What wins: DT ABI backward compatibility, or correctness of the DT binding ? :-)
Both ;-)
The current driver is backwards-compatible with the legacy/wrong DTB. The current DT bindings (as of v5.10-rc1), using "[rt]x-internal-delay-ps" are correct.
Or am I missing something here?
BTW, it's still not clear to me why the inversion would be needed. Cfr. Andrew's comment:
| So with rgmii-rxid, what is actually passed to the PHY? Is your | problem you get twice the delay in one direction, and no delay in the | other?
We know the ravb driver misbehaved in the past by applying the rgmii-*id values to the MAC, while they are meant for the PHY, thus causing bad interaction with PHY drivers. But that was fixed by commit 9b23203c32ee02cd ("ravb: Mask PHY mode to avoid inserting delays twice") and a6f51f2efa742df0 ("ravb: Add support for explicit internal clock delay configuration").
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Hello Geert, Thomas
Quoted 19 lines · On Tue, 19 Oct 2021 22:05:41 +0200 Geert Uytterhoeven <[email protected]>…
Hi Thomas,
Quoted 5 lines · Thomas Petazzoni
Quoted 3 lines · On Tue, 19 Oct 2021 17:41:49 +0200 Andrew Lunn <[email protected]> wrote:
Quoted 2 lines
When people update the kernel version don't they update also the devicetree?
Quoted 7 lines
Quoted 4 lines
DT is ABI. Driver writers should not break old blobs running on new kernels. Often the DT blob is updated with the kernel, but it is not required. It could be stored in a hard to reach place, shared with u-boot etc.
Right, but conversely if someone reads the DT bindings that exists today, specifies phy-mode = "rgmii-rxid" or phy-mmode = "rmgii-txid",
Today == v5.10-rc1 and later?
Quoted 8 lines
Quoted 4 lines
this person will get incorrect behavior. Sure a behavior that is backward compatible with older DTs, but a terribly wrong one when you write a new DT and read the DT binding documentation. This is exactly the problem that happened to us.
If you write a new DT, you read the DT binding documentation, and "make
dtbs_check" will inform you politely if you use the legacy/wrong DT (i.e. lacking "[rt]x-internal-delay-ps")?
Indeed this command will inform the missing required "[rt]x-internal-delay-ps". I am not use to that command, as it seems to check all the devicetree each time where I want only to check one.
Quoted 5 lines
The current driver is backwards-compatible with the legacy/wrong DTB. The current DT bindings (as of v5.10-rc1), using "[rt]x-internal-delay-ps" are correct.
Or am I missing something here?
You are correct.
Quoted 7 lines
BTW, it's still not clear to me why the inversion would be needed. Cfr. Andrew's comment:
| So with rgmii-rxid, what is actually passed to the PHY? Is your | problem you get twice the delay in one direction, and no delay in the | other?
Yes, it was the problem I got.
The PHY I use have RX delay enabled by default, currently the PHY driver does not support delay configuration, therefore I let the MAC handle TX delay. I have stumbling over that legacy/wrong DTS on the old Kernel.
Regards,
Köry
Hi Köry,
Quoted 8 lines · Köry Maincent
Quoted 4 lines · On Tue, 19 Oct 2021 22:05:41 +0200 Geert Uytterhoeven <[email protected]>…
The current driver is backwards-compatible with the legacy/wrong DTB. The current DT bindings (as of v5.10-rc1), using "[rt]x-internal-delay-ps" are correct.
Or am I missing something here?You are correct.
Thanks for confirming!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 11 lines
Quoted 6 lines
BTW, it's still not clear to me why the inversion would be needed. Cfr. Andrew's comment:
| So with rgmii-rxid, what is actually passed to the PHY? Is your | problem you get twice the delay in one direction, and no delay in the | other?Yes, it was the problem I got.
The PHY I use have RX delay enabled by default, currently the PHY driver does not support delay configuration, therefore I let the MAC handle TX delay. I have stumbling over that legacy/wrong DTS on the old Kernel.
This is where we get into the horrible mess of RGMII delays.
The real solution is to fix the PHY driver. If it is asked to do rgmii, but is actually doing rgmii-id, the PHY driver is broken. It either should do what it is told, or return -EINVAL/-EOPNOTSUPP etc to indicate it does not support what it is asked to do.
But fixing things like this often breaks working systems, because the DT says rgmii, the PHY actually does rgmii-id, the board works, until the PHY is fixed to do what it is told, and all the bugs in the DT suddenly come to light.
Now, you said you are using an old kernel. So it could be we have already fixed this, and had the pain of fixing broken DT. Please look at the current kernel PHY driver, and see if all you need to do is back port some PHY fixes, or better still, throw away your old kernel and use a modern one.
Andrew
Hi Köry,
Quoted 14 lines · Köry Maincent
Quoted 12 lines · On Tue, 19 Oct 2021 17:13:52 +0200 Geert Uytterhoeven <[email protected]>…
Quoted 12 lines
The ravb MAC is adding RX delay if
RGMII_RXIDis selected and TX delay ifRGMII_TXIDbut that behavior is wrong.
Indeed according to the ethernet.txt documentation the ravb configuration should be inverted:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
* "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC should not add an TX delay in this case)This patch inverts the behavior, i.e adds TX delay when
RGMII_RXIDis selected and RX delay whenRGMII_TXIDis selected.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Signed-off-by Kory Maincent <[email protected]>Does this fix an actual problem for you?
In fact, this fix a problem for an older 4.14 Kernel on my current project. I wanted to push my fix in the mainline kernel also, but as you say below, now this code is legacy.
Does it matter to fix legacy code?
I don't think so. If you're stuck on v4.14, you may want to backport commit a6f51f2efa742df0 ("ravb: Add support for explicit internal clock delay configuration"). However, you have to be careful, as it interacts with related changes to PHY drivers, as explained in that commit.
Quoted 9 lines
Quoted 7 lines
Note that in accordance with the comment above, the code section below is only present to support old DTBs. Contemporary DTBs rely on the now mandatory "rx-internal-delay-ps" and "tx-internal-delay-ps" properties instead.
Hence changing this code has no effect on DTS files as supplied with the kernel, but may have ill effects on DTB files in the field, which rely on the current behavior.When people update the kernel version don't they update also the devicetree?
I hope they do ;-)
But we do our best to preserve backwards-compatibility with old DTBS. If you change behavior of v4.14, it may actually introduce backwards-incompatibility we're not aware of, as the behavior you started to rely on never existed in mainline.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 12 lines · Kory Maincent
Invert the configuration of the RGMII delay selected by
RGMII_RXIDandRGMII_TXID.The ravb MAC is adding RX delay if
RGMII_RXIDis selected and TX delay ifRGMII_TXIDbut that behavior is wrong.
Indeed according to the ethernet.txt documentation the ravb configuration should be inverted:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
* "rgmii-txid" (RGMII with internal TX delay provided by the PHY, the MAC should not add an TX delay in this case)
Quoted 2 lines
This patch inverts the behavior, i.e adds TX delay when
RGMII_RXIDis selected and RX delay whenRGMII_TXIDis selected.
This gets messy. As a general rule of thumb, the MAC should not be adding delays, the PHY should. ravb has historically ignored that, and it adds delays. It then needs to be careful with what it passes to the PHY.
So with rgmii-rxid, what is actually passed to the PHY? Is your problem you get twice the delay in one direction, and no delay in the other?
Andrew