* [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000
@ 2025-04-23 7:12 Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset Alexis Lothore
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alexis Lothore @ 2025-04-23 7:12 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran,
Daniel Machon, Maxime Chevallier
Cc: Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, Russell King (Oracle), Alexis Lothoré
Hello,
this is the v2 of a small series containing two small fixes for the
timestamp snapshot feature on stmmac, especially on dwmac1000 version.
Those issues have been detected on a socfpga (Cyclone V) platform. They
kind of follow the big rework sent by Maxime at the end of last year to
properly split this feature support between different versions of the
DWMAC IP.
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
Changes in v2:
- drop additional parenthesis
- fix wrong hashes in Fixes tags
- add Maxime's RB on first patch
- Link to v1: https://lore.kernel.org/r/20250422-stmmac_ts-v1-0-b59c9f406041@bootlin.com
---
Alexis Lothore (1):
net: stmmac: fix dwmac1000 ptp timestamp status offset
Alexis Lothoré (1):
net: stmmac: fix multiplication overflow when reading timestamp
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h | 4 ++--
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
---
base-commit: c03a49f3093a4903c8a93c8b5c9a297b5343b169
change-id: 20250422-stmmac_ts-c226a53099e2
Best regards,
--
Alexis Lothoré, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net v2 1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset
2025-04-23 7:12 [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 Alexis Lothore
@ 2025-04-23 7:12 ` Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp Alexis Lothoré
2025-04-24 10:00 ` [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: Alexis Lothore @ 2025-04-23 7:12 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran,
Daniel Machon, Maxime Chevallier
Cc: Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, Russell King (Oracle), Alexis Lothoré
When a PTP interrupt occurs, the driver accesses the wrong offset to
learn about the number of available snapshots in the FIFO for dwmac1000:
it should be accessing bits 29..25, while it is currently reading bits
19..16 (those are bits about the auxiliary triggers which have generated
the timestamps). As a consequence, it does not compute correctly the
number of available snapshots, and so possibly do not generate the
corresponding clock events if the bogus value ends up being 0.
Fix clock events generation by reading the correct bits in the timestamp
register for dwmac1000.
Fixes: 477c3e1f6363 ("net: stmmac: Introduce dwmac1000 timestamping operations")
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac1000.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
index 967a16212faf008bc7b5e43031e2d85800c5c467..0c011a47d5a3e98280a98d25b8ef3614684ae78c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000.h
@@ -320,8 +320,8 @@ enum rtc_control {
/* PTP and timestamping registers */
-#define GMAC3_X_ATSNS GENMASK(19, 16)
-#define GMAC3_X_ATSNS_SHIFT 16
+#define GMAC3_X_ATSNS GENMASK(29, 25)
+#define GMAC3_X_ATSNS_SHIFT 25
#define GMAC_PTP_TCR_ATSFC BIT(24)
#define GMAC_PTP_TCR_ATSEN0 BIT(25)
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp
2025-04-23 7:12 [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset Alexis Lothore
@ 2025-04-23 7:12 ` Alexis Lothoré
2025-04-23 13:02 ` Maxime Chevallier
2025-04-24 10:00 ` [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 patchwork-bot+netdevbpf
2 siblings, 1 reply; 5+ messages in thread
From: Alexis Lothoré @ 2025-04-23 7:12 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran,
Daniel Machon, Maxime Chevallier
Cc: Thomas Petazzoni, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, Russell King (Oracle), Alexis Lothoré
The current way of reading a timestamp snapshot in stmmac can lead to
integer overflow, as the computation is done on 32 bits. The issue has
been observed on a dwmac-socfpga platform returning chaotic timestamp
values due to this overflow. The corresponding multiplication is done
with a MUL instruction, which returns 32 bit values. Explicitly casting
the value to 64 bits replaced the MUL with a UMLAL, which computes and
returns the result on 64 bits, and so returns correctly the timestamps.
Prevent this overflow by explicitly casting the intermediate value to
u64 to make sure that the whole computation is made on u64. While at it,
apply the same cast on the other dwmac variant (GMAC4) method for
snapshot retrieval.
Fixes: 477c3e1f6363 ("net: stmmac: Introduce dwmac1000 timestamping operations")
Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
---
drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c | 2 +-
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
index a8b901cdf5cbb395a0f6b4800ad6f06c6e870077..56b76aaa58f04a6f01eb56c7ad6aa135a7f76c96 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -553,7 +553,7 @@ void dwmac1000_get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
u64 ns;
ns = readl(ptpaddr + GMAC_PTP_ATNR);
- ns += readl(ptpaddr + GMAC_PTP_ATSR) * NSEC_PER_SEC;
+ ns += (u64)readl(ptpaddr + GMAC_PTP_ATSR) * NSEC_PER_SEC;
*ptp_time = ns;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
index 0f59aa98260404bece530f505500f13d35884d0c..e2840fa241f29121c4f074872c4986906201cb57 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c
@@ -222,7 +222,7 @@ static void get_ptptime(void __iomem *ptpaddr, u64 *ptp_time)
u64 ns;
ns = readl(ptpaddr + PTP_ATNR);
- ns += readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC;
+ ns += (u64)readl(ptpaddr + PTP_ATSR) * NSEC_PER_SEC;
*ptp_time = ns;
}
--
2.49.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp
2025-04-23 7:12 ` [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp Alexis Lothoré
@ 2025-04-23 13:02 ` Maxime Chevallier
0 siblings, 0 replies; 5+ messages in thread
From: Maxime Chevallier @ 2025-04-23 13:02 UTC (permalink / raw)
To: Alexis Lothoré
Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Richard Cochran,
Daniel Machon, Thomas Petazzoni, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, Russell King (Oracle)
On Wed, 23 Apr 2025 09:12:10 +0200
Alexis Lothoré <alexis.lothore@bootlin.com> wrote:
> The current way of reading a timestamp snapshot in stmmac can lead to
> integer overflow, as the computation is done on 32 bits. The issue has
> been observed on a dwmac-socfpga platform returning chaotic timestamp
> values due to this overflow. The corresponding multiplication is done
> with a MUL instruction, which returns 32 bit values. Explicitly casting
> the value to 64 bits replaced the MUL with a UMLAL, which computes and
> returns the result on 64 bits, and so returns correctly the timestamps.
>
> Prevent this overflow by explicitly casting the intermediate value to
> u64 to make sure that the whole computation is made on u64. While at it,
> apply the same cast on the other dwmac variant (GMAC4) method for
> snapshot retrieval.
>
> Fixes: 477c3e1f6363 ("net: stmmac: Introduce dwmac1000 timestamping operations")
> Signed-off-by: Alexis Lothoré <alexis.lothore@bootlin.com>
Reviewed-by: Maxime Chevallier <maxime.chevallier@bootlin.com>
Thanks,
Maxime
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000
2025-04-23 7:12 [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp Alexis Lothoré
@ 2025-04-24 10:00 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2025-04-24 10:00 UTC (permalink / raw)
To: =?utf-8?q?Alexis_Lothor=C3=A9_=3Calexis=2Elothore=40bootlin=2Ecom=3E?=
Cc: andrew+netdev, davem, edumazet, kuba, pabeni, mcoquelin.stm32,
alexandre.torgue, richardcochran, daniel.machon,
maxime.chevallier, thomas.petazzoni, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, linux
Hello:
This series was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:
On Wed, 23 Apr 2025 09:12:08 +0200 you wrote:
> Hello,
>
> this is the v2 of a small series containing two small fixes for the
> timestamp snapshot feature on stmmac, especially on dwmac1000 version.
> Those issues have been detected on a socfpga (Cyclone V) platform. They
> kind of follow the big rework sent by Maxime at the end of last year to
> properly split this feature support between different versions of the
> DWMAC IP.
>
> [...]
Here is the summary with links:
- [net,v2,1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset
https://git.kernel.org/netdev/net/c/73fa4597bdc0
- [net,v2,2/2] net: stmmac: fix multiplication overflow when reading timestamp
https://git.kernel.org/netdev/net/c/7b7491372f8e
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-24 10:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 7:12 [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 1/2] net: stmmac: fix dwmac1000 ptp timestamp status offset Alexis Lothore
2025-04-23 7:12 ` [PATCH net v2 2/2] net: stmmac: fix multiplication overflow when reading timestamp Alexis Lothoré
2025-04-23 13:02 ` Maxime Chevallier
2025-04-24 10:00 ` [PATCH net v2 0/2] net: stmmac: fix timestamp snapshots on dwmac1000 patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).