Skip to contentSkip to conversation

spi: cadence-quadspi: fix potential malfunction after ~49 days uptime

PATCH In review Ronald Wahl 3 participants 4 messages Dec 12, 2024 – Jan 22, 2025 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: cadence-quadspi: fix potential malfunction after ~49 days uptime

From: Ronald Wahl <[email protected]>

The get_timer function returns an unsigned long which may be calculated from the ARM system counter. This counter is reset only on a cold reset. U-boot divides this counter down to a 1000 Hz counter that will cross the 32bit barrier after a bit more than 49 days. Assigning the value to an unsigned int will truncate it on 64bit systems.
Passing this truncated value back to the get_timer function will return a very large value that is certainly larger than the timeout and so will go down the error path and besides stopping U-Boot will lead to messages like

"SPI: QSPI is still busy after poll for 5000 ms."

Cc Vignesh R <[email protected]>
Cc Pratyush Yadav <[email protected]>
---
 drivers/spi/cadence_qspi_apb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/cadence_qspi_apb.c +3 -3
index 93ab2b5635..f2f69cf9f1 100644
@@ -151,9 +151,9 @@ static int cadence_qspi_set_protocol(struct cadence_spi_priv *priv,
 /* Return 1 if idle, otherwise return 0 (busy). */
 static unsigned int cadence_qspi_wait_idle(void *reg_base)
 {
-	unsigned int start, count = 0;
+	unsigned long start, count = 0;
 	/* timeout in unit of ms */
-	unsigned int timeout = 5000;
+	unsigned long timeout = 5000;
 
 	start = get_timer(0);
 	for ( ; get_timer(start) < timeout ; ) {
@@ -170,7 +170,7 @@ static unsigned int cadence_qspi_wait_idle(void *reg_base)
 	}
 
 	/* Timeout, still in busy mode. */
-	printf("QSPI: QSPI is still busy after poll for %d ms.\n", timeout);
+	printf("QSPI: QSPI is still busy after poll for %lu ms.\n", timeout);
 	return 0;
 }
 

--
2.47.1

Reviewed-by on v1 1/1
#1 lore raw

+ tom and jagan

Quoted 12 lines · Ronald Wahl

From: Ronald Wahl <[email protected]>

The get_timer function returns an unsigned long which may be calculated from the ARM system counter. This counter is reset only on a cold reset. U-boot divides this counter down to a 1000 Hz counter that will cross the 32bit barrier after a bit more than 49 days. Assigning the value to an unsigned int will truncate it on 64bit systems.
Passing this truncated value back to the get_timer function will return a very large value that is certainly larger than the timeout and so will go down the error path and besides stopping U-Boot will lead to messages like

Quoted 1 line

"SPI: QSPI is still busy after poll for 5000 ms."

Thanks a lot for fixing this!

Quoted 36 lines
Cc Vignesh R <[email protected]>
Cc Pratyush Yadav <[email protected]>
---
 drivers/spi/cadence_qspi_apb.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/cadence_qspi_apb.c +3 -4
index 93ab2b5635..f2f69cf9f1 100644
@@ -151,9 +151,9 @@ static int cadence_qspi_set_protocol(struct cadence_spi_priv *priv,
 /* Return 1 if idle, otherwise return 0 (busy). */
 static unsigned int cadence_qspi_wait_idle(void *reg_base)
 {
-	unsigned int start, count = 0;
+	unsigned long start, count = 0;
 	/* timeout in unit of ms */
-	unsigned int timeout = 5000;
+	unsigned long timeout = 5000;
 
 	start = get_timer(0);
 	for ( ; get_timer(start) < timeout ; ) {
@@ -170,7 +170,7 @@ static unsigned int cadence_qspi_wait_idle(void *reg_base)
 	}
 
 	/* Timeout, still in busy mode. */
-	printf("QSPI: QSPI is still busy after poll for %d ms.\n", timeout);
+	printf("QSPI: QSPI is still busy after poll for %lu ms.\n", timeout);
 	return 0;
 }
 
--

2.47.1

Signature · 3 lines
Regards
Vignesh
https://ti.com/opensource
#2 lore raw
Quoted 1 line · Vignesh Raghavendra

+ tom and jagan

Jagan seems to be missing. Does anyone know something?
There are a number of patches on patchwork waiting for approval or review.

Quoted 57 lines · Ronald Wahl
Quoted 12 lines

From: Ronald Wahl <[email protected]>

The get_timer function returns an unsigned long which may be calculated from the ARM system counter. This counter is reset only on a cold reset. U-boot divides this counter down to a 1000 Hz counter that will cross the 32bit barrier after a bit more than 49 days. Assigning the value to an unsigned int will truncate it on 64bit systems.
Passing this truncated value back to the get_timer function will return a very large value that is certainly larger than the timeout and so will go down the error path and besides stopping U-Boot will lead to messages like

Quoted 1 line

"SPI: QSPI is still busy after poll for 5000 ms."

Thanks a lot for fixing this!

Quoted 36 lines
Cc Vignesh R <[email protected]>
Cc Pratyush Yadav <[email protected]>
---
  drivers/spi/cadence_qspi_apb.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/cadence_qspi_apb.c +3 -4
index 93ab2b5635..f2f69cf9f1 100644
@@ -151,9 +151,9 @@ static int cadence_qspi_set_protocol(struct cadence_spi_priv *priv,
  /* Return 1 if idle, otherwise return 0 (busy). */
  static unsigned int cadence_qspi_wait_idle(void *reg_base)
  {
-	unsigned int start, count = 0;
+	unsigned long start, count = 0;
  	/* timeout in unit of ms */
-	unsigned int timeout = 5000;
+	unsigned long timeout = 5000;
 
  	start = get_timer(0);
  	for ( ; get_timer(start) < timeout ; ) {
@@ -170,7 +170,7 @@ static unsigned int cadence_qspi_wait_idle(void *reg_base)
  	}
 
  	/* Timeout, still in busy mode. */
-	printf("QSPI: QSPI is still busy after poll for %d ms.\n", timeout);
+	printf("QSPI: QSPI is still busy after poll for %lu ms.\n", timeout);
  	return 0;
  }
 
--

2.47.1

#3 lore raw
In reply to Ronald Wahl
Quoted 11 lines · Ronald Wahl

The get_timer function returns an unsigned long which may be calculated from the ARM system counter. This counter is reset only on a cold reset. U-boot divides this counter down to a 1000 Hz counter that will cross the 32bit barrier after a bit more than 49 days. Assigning the value to an unsigned int will truncate it on 64bit systems.
Passing this truncated value back to the get_timer function will return a very large value that is certainly larger than the timeout and so will go down the error path and besides stopping U-Boot will lead to messages like

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom