]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
amd-xgbe: fix PTP addend overflow causing frozen clock
authorGregory Fuchedgi <gfuchedgi@gmail.com>
Wed, 29 Apr 2026 21:54:14 +0000 (14:54 -0700)
committerJakub Kicinski <kuba@kernel.org>
Sat, 2 May 2026 17:16:27 +0000 (10:16 -0700)
XGBE_PTP_ACT_CLK_FREQ and XGBE_V2_PTP_ACT_CLK_FREQ were 10x too
large (500MHz/1GHz instead of 50MHz/100MHz), causing the computed
addend to overflow the 32-bit tstamp_addend. In the general case
this would result in the clock advancing at the wrong rate. For v2
(PCI), ptpclk_rate is hardcoded to 125MHz, so the addend formula
(ACT_CLK_FREQ << 32) / ptpclk_rate yields exactly 8 * 2^32, and
when stored to the 32-bit tstamp_addend the value is zero. With
addend = 0 the hardware accumulator never overflows and the PTP
clock is fully stopped. For v1 (platform), ptpclk_rate is read from
ACPI/DT so the exact overflow behavior depends on the
firmware-reported frequency.

Define the constants as NSEC_PER_SEC / SSINC so the relationship is
explicit and cannot drift out of sync.

Fixes: fbd47be098b5 ("amd-xgbe: add hardware PTP timestamping support")
Tested-by: Gregory Fuchedgi <gfuchedgi@gmail.com>
Signed-off-by: Gregory Fuchedgi <gfuchedgi@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20260429-fix-xgbe-ptp-addend-v1-1-fca5b0ca5e62@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/amd/xgbe/xgbe.h

index 60b7e53206d1e18f541c96f335613ccc1d4197a4..3d3b09010d48fb1e8fff4d8224a61d20b9fa7dae 100644 (file)
  */
 #define XGBE_TSTAMP_SSINC      20
 #define XGBE_TSTAMP_SNSINC     0
-#define XGBE_PTP_ACT_CLK_FREQ  500000000
+#define XGBE_PTP_ACT_CLK_FREQ  (NSEC_PER_SEC / XGBE_TSTAMP_SSINC)
 
 #define XGBE_V2_TSTAMP_SSINC   0xA
 #define XGBE_V2_TSTAMP_SNSINC  0
-#define XGBE_V2_PTP_ACT_CLK_FREQ       1000000000
+#define XGBE_V2_PTP_ACT_CLK_FREQ       (NSEC_PER_SEC / XGBE_V2_TSTAMP_SSINC)
 
 /* Define maximum supported values */
 #define XGBE_MAX_PPS_OUT       4