Skip to contentSkip to conversation

net: stmmac: fixed new system time seconds value calculation

PATCH In review Voon Weifeng 2 participants 2 messages Jun 19, 2019 – Jun 22, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: stmmac: fixed new system time seconds value calculation

From: Roland Hii <[email protected]>

When ADDSUB bit is set, the system time seconds field is calculated as the complement of the seconds part of the update value.

For example, if 3.000000001 seconds need to be subtracted from the system time, this field is calculated as
2^32 - 3 = 4294967296 - 3 = 0x100000000 - 3 = 0xFFFFFFFD

Previously, the 0x100000000 is mistakenly written as 100000000.

This is further simplified from
sec = (0x100000000ULL - sec);
to
sec = -sec;

Fixes ba1ffd74df74 ("stmmac: fix PTP support for GMAC4")
drivers/net/ethernet/stmicro/stmmac/stmmac_hwtstamp.c +1 -1
index 2dcdf761d525..020159622559 100644
@@ -112,7 +112,7 @@ static int adjust_systime(void __iomem *ioaddr, u32 sec, u32 nsec,
 		 * programmed with (2^32 – <new_sec_value>)
 		 */
 		if (gmac4)
-			sec = (100000000ULL - sec);
+			sec = -sec;
 
 		value = readl(ioaddr + PTP_TCR);
 		if (value & PTP_TCR_TSCTRLSSR)
Signature · 1 line
1.9.1
maintainer
#1 lore raw

From: Voon Weifeng <[email protected]>
Date: Wed, 19 Jun 2019 22:13:48 +0800

Quoted 16 lines

From: Roland Hii <[email protected]>

When ADDSUB bit is set, the system time seconds field is calculated as the complement of the seconds part of the update value.

For example, if 3.000000001 seconds need to be subtracted from the system time, this field is calculated as
2^32 - 3 = 4294967296 - 3 = 0x100000000 - 3 = 0xFFFFFFFD

Previously, the 0x100000000 is mistakenly written as 100000000.

This is further simplified from
sec = (0x100000000ULL - sec);
to
sec = -sec;

Quoted 4 lines
Fixes ba1ffd74df74 ("stmmac: fix PTP support for GMAC4")

Applied and queued up for -stable.