Skip to contentSkip to conversation

ARC: Fix __udelay calculation

PATCH Applied Mischa Jonker 2 participants 2 messages Aug 30, 2013 Synopsys ARC architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARC: Fix __udelay calculation

Cast usecs to u64, to ensure that the (usecs * 4295 * HZ) multiplication is 64 bit.

Initially, the (usecs * 4295 * HZ) part was done as a 32 bit multiplication, with the result casted to 64 bit. This led to some bits falling off, causing a "DMA initialization error" in the stmmac Ethernet driver, due to a premature timeout.

---
 arch/arc/include/asm/delay.h |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arc/include/asm/delay.h +2 -3
index 442ce5d..43de302 100644
@@ -53,11 +53,10 @@ static inline void __udelay(unsigned long usecs)
 {
 	unsigned long loops;
 
-	/* (long long) cast ensures 64 bit MPY - real or emulated
+	/* (u64) cast ensures 64 bit MPY - real or emulated
 	 * HZ * 4295 is pre-evaluated by gcc - hence only 2 mpy ops
 	 */
-	loops = ((long long)(usecs * 4295 * HZ) *
-		 (long long)(loops_per_jiffy)) >> 32;
+	loops = ((u64) usecs * 4295 * HZ * loops_per_jiffy) >> 32;
 
 	__delay(loops);
 }
Signature · 1 line
1.7.9.5
Applied
#1 lore raw
Quoted 10 lines · Mischa Jonker

Cast usecs to u64, to ensure that the (usecs * 4295 * HZ) multiplication is 64 bit.

Initially, the (usecs * 4295 * HZ) part was done as a 32 bit multiplication, with the result casted to 64 bit. This led to some bits falling off, causing a "DMA initialization error" in the stmmac Ethernet driver, due to a premature timeout.

Applied.

Thx,
-Vineet