From: sashiko-bot@kernel.org
To: "Louis-Alexis Eyraud" <louisalexis.eyraud@collabora.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH net-next v3 4/9] net: stmmac: mediatek: simplify TX/RX delay handling in mt2712_set_delay
Date: Sat, 17 Oct 2026 10:32:15 +0000 [thread overview]
Message-ID: <sashiko-outbox-175458@kernel.org> (raw)
In-Reply-To: <20261016-dwmac-mediatek-mt8189-v3-4-25daf2bbcf35@collabora.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] stmmac: mediatek: swapped RGMII and RMII/MII delay stage divisors
--
commit 83d585b88ab8ffcfd715b793f8dc33929760603d
Author: Louis-Alexis Eyraud <louisalexis.eyraud@collabora.com>
net: stmmac: mediatek: simplify TX/RX delay handling in mt2712_set_delay
This commit simplifies TX/RX delay handling for MT2712 by calculating
delay stage values locally instead of modifying the driver data. It
also introduces macro definitions for the stage divisors and maximums.
> diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> index f7eb85110df08..596411d4a5b2b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-mediatek.c
> @@ -36,6 +36,14 @@
> #define ETH_FINE_DLY_GTXC BIT(1)
> #define ETH_FINE_DLY_RXC BIT(0)
>
> +#define MT2712_RMII_DLY_RXC_STAGE_DIV 170 /* 170ps per stage */
> +#define MT2712_RMII_DLY_TXC_STAGE_DIV 170 /* 170ps per stage */
> +
> +#define MT2712_RGMII_DLY_RXC_STAGE_DIV 550 /* 550ps per stage */
> +#define MT2712_RGMII_DLY_RXC_MAX 17600 /* 32 x 550ps */
> +#define MT2712_RGMII_DLY_TXC_STAGE_DIV 550 /* 550ps per stage */
> +#define MT2712_RGMII_DLY_TXC_MAX 17600 /* 32 x 550ps */
> +
[Severity: High]
Are these stage divisors swapped compared to the original code?
In the original code, the divisors were:
/* 550ps per stage for MII/RMII */
mac_delay->tx_delay /= 550;
...
/* 170ps per stage for RGMII */
mac_delay->tx_delay /= 170;
With the new definitions, RMII gets divided by 170 and RGMII by 550, which
reverses the intended delay values for both interfaces.
[ ... ]
> @@ -129,71 +137,36 @@ static int mt2712_set_interface(struct mediatek_dwmac_plat_data *plat,
> static int mt2712_set_delay(struct mediatek_dwmac_plat_data *plat)
> {
> struct mac_delay_struct *mac_delay = &plat->mac_delay;
> - u32 delay_val = 0, fine_val = 0;
> + u32 rx_delay_stage_val, tx_delay_stage_val;
> + u16 rx_delay_stage_div, tx_delay_stage_div;
> + u32 delay_val = 0;
> + u32 fine_val = 0;
>
> - mt2712_delay_ps2stage(plat);
> + if (phy_interface_mode_is_rgmii(plat->phy_mode)) {
> + rx_delay_stage_div = MT2712_RGMII_DLY_RXC_STAGE_DIV;
> + tx_delay_stage_div = MT2712_RGMII_DLY_TXC_STAGE_DIV;
> + } else {
> + rx_delay_stage_div = MT2712_RMII_DLY_RXC_STAGE_DIV;
> + tx_delay_stage_div = MT2712_RMII_DLY_TXC_STAGE_DIV;
> + }
> + rx_delay_stage_val = mac_delay->rx_delay / rx_delay_stage_div;
> + tx_delay_stage_val = mac_delay->tx_delay / tx_delay_stage_div;
>
> switch (plat->phy_mode) {
> case PHY_INTERFACE_MODE_MII:
> - delay_val |= FIELD_PREP(ETH_DLY_TXC_ENABLE, !!mac_delay->tx_delay);
> - delay_val |= FIELD_PREP(ETH_DLY_TXC_STAGES, mac_delay->tx_delay);
> + delay_val |= FIELD_PREP(ETH_DLY_TXC_ENABLE,
> + !!tx_delay_stage_val);
> + delay_val |= FIELD_PREP(ETH_DLY_TXC_STAGES,
> + tx_delay_stage_val);
[Severity: High]
Because the divisors are swapped above, could the resulting stage value
exceed the bitfield boundaries?
Since RMII is now incorrectly divided by 170 instead of 550, valid device
tree delay values might produce a stage count that exceeds the 5-bit width
of the ETH_DLY_TXC_STAGES hardware field. When this happens, FIELD_PREP()
would silently truncate the stages value, leading to misconfigured hardware
timings.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261016-dwmac-mediatek-mt8189-v3-0-25daf2bbcf35@collabora.com?part=4
next prev parent reply other threads:[~2026-10-17 10:32 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 10:31 [PATCH net-next v3 0/9] net/stmmac: Add Mediatek MT8189 support Louis-Alexis Eyraud
2026-10-16 10:31 ` [PATCH net-next v3 1/9] dt-bindings: net: mediatek-dwmac: fix unit in rx/tx delay property description Louis-Alexis Eyraud
2026-10-16 15:33 ` Andrew Lunn
2026-10-16 10:31 ` [PATCH net-next v3 2/9] dt-bindings: net: mediatek-dwmac: add support for MT8189 SoC Louis-Alexis Eyraud
2026-10-16 15:40 ` Andrew Lunn
2026-10-16 10:31 ` [PATCH net-next v3 3/9] net: stmmac: mediatek: simplify TX/RX delay handling in mt8195_set_delay Louis-Alexis Eyraud
2026-10-16 10:31 ` [PATCH net-next v3 4/9] net: stmmac: mediatek: simplify TX/RX delay handling in mt2712_set_delay Louis-Alexis Eyraud
2026-10-17 10:32 ` sashiko-bot [this message]
2026-10-16 10:31 ` [PATCH net-next v3 5/9] net: stmmac: mediatek: add RX/TX delay stage divider in platform data Louis-Alexis Eyraud
2026-10-16 11:37 ` Maxime Chevallier
2026-10-17 10:32 ` sashiko-bot
2026-10-16 10:31 ` [PATCH net-next v3 6/9] net: stmmac: mediatek: add PERI_ETH_CTRLx register offset " Louis-Alexis Eyraud
2026-10-16 10:31 ` [PATCH net-next v3 7/9] net: stmmac: mediatek: use TX clock phase shift in RGMII mode with 1Gbps speed Louis-Alexis Eyraud
2026-10-16 11:41 ` Maxime Chevallier
2026-10-16 15:48 ` Andrew Lunn
2026-10-17 10:32 ` sashiko-bot
2026-10-16 10:31 ` [PATCH net-next v3 8/9] net: stmmac: mediatek: add support for TX clock output enable feature Louis-Alexis Eyraud
2026-10-16 10:31 ` [PATCH net-next v3 9/9] net: stmmac: mediatek: add support for MT8189 SoC Louis-Alexis Eyraud
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=sashiko-outbox-175458@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=louisalexis.eyraud@collabora.com \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox