All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common()
@ 2018-11-19 11:15 Fabio Estevam
  2018-11-19 11:43 ` Baruch Siach
  0 siblings, 1 reply; 3+ messages in thread
From: Fabio Estevam @ 2018-11-19 11:15 UTC (permalink / raw)
  To: u-boot

The following hang is observed on a Hummingboard 2 MicroSOM
i2eX iMX6D - rev 1.3 with no eMMC populated on board:

U-Boot SPL 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)
Trying to boot from MMC1

U-Boot 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)

CPU:   Freescale i.MX6D rev1.5 996 MHz (running at 792 MHz)
CPU:   Extended Commercial temperature grade (-20C to 105C) at 33C
Reset cause: POR
Board: MX6 HummingBoard2
DRAM:  1 GiB
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
Loading Environment from MMC... *** Warning - bad CRC, using default environment

No panel detected: default to HDMI
Display: HDMI (1024x768)
In:    serial
Out:   serial
Err:   serial
---> hangs

which is caused by the following infinite loop inside esdhc_send_cmd_common()

	while (!(esdhc_read32(&regs->irqstat) & flags))
		;

Instead of looping forever, provide an exit path so that a timeout
error can be propagated in the case irqstat does not report
any interrupts, which may happen when no eMMC is populated on
board.

Reported-by: Ricardo Salveti <rsalveti@rsalveti.net>
Signed-off-by: Fabio Estevam <festevam@gmail.com>
---
 drivers/mmc/fsl_esdhc.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
index 3cdfa7f..7c17b79 100644
--- a/drivers/mmc/fsl_esdhc.c
+++ b/drivers/mmc/fsl_esdhc.c
@@ -396,6 +396,7 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
 	uint	irqstat;
 	u32	flags = IRQSTAT_CC | IRQSTAT_CTOE;
 	struct fsl_esdhc *regs = priv->esdhc_regs;
+	unsigned long start;
 
 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
 	if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
@@ -453,8 +454,11 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
 		flags = IRQSTAT_BRR;
 
 	/* Wait for the command to complete */
-	while (!(esdhc_read32(&regs->irqstat) & flags))
-		;
+	start = get_timer(0);
+	while (!(esdhc_read32(&regs->irqstat) & flags)) {
+		if (get_timer(start) > 1000)
+			return -ETIMEDOUT;
+	}
 
 	irqstat = esdhc_read32(&regs->irqstat);
 
-- 
2.7.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common()
  2018-11-19 11:15 [U-Boot] [PATCH] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common() Fabio Estevam
@ 2018-11-19 11:43 ` Baruch Siach
  2018-11-19 12:35   ` Fabio Estevam
  0 siblings, 1 reply; 3+ messages in thread
From: Baruch Siach @ 2018-11-19 11:43 UTC (permalink / raw)
  To: u-boot

Hi Fabio,

On Mon, Nov 19, 2018 at 09:15:24AM -0200, Fabio Estevam wrote:
> The following hang is observed on a Hummingboard 2 MicroSOM
> i2eX iMX6D - rev 1.3 with no eMMC populated on board:
> 
> U-Boot SPL 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)
> Trying to boot from MMC1
> 
> U-Boot 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)
> 
> CPU:   Freescale i.MX6D rev1.5 996 MHz (running at 792 MHz)
> CPU:   Extended Commercial temperature grade (-20C to 105C) at 33C
> Reset cause: POR
> Board: MX6 HummingBoard2
> DRAM:  1 GiB
> MMC:   FSL_SDHC: 0, FSL_SDHC: 1
> Loading Environment from MMC... *** Warning - bad CRC, using default environment
> 
> No panel detected: default to HDMI
> Display: HDMI (1024x768)
> In:    serial
> Out:   serial
> Err:   serial
> ---> hangs
> 
> which is caused by the following infinite loop inside esdhc_send_cmd_common()
> 
> 	while (!(esdhc_read32(&regs->irqstat) & flags))
> 		;
> 
> Instead of looping forever, provide an exit path so that a timeout
> error can be propagated in the case irqstat does not report
> any interrupts, which may happen when no eMMC is populated on
> board.
> 
> Reported-by: Ricardo Salveti <rsalveti@rsalveti.net>
> Signed-off-by: Fabio Estevam <festevam@gmail.com>
> ---
>  drivers/mmc/fsl_esdhc.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
> index 3cdfa7f..7c17b79 100644
> --- a/drivers/mmc/fsl_esdhc.c
> +++ b/drivers/mmc/fsl_esdhc.c
> @@ -396,6 +396,7 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
>  	uint	irqstat;
>  	u32	flags = IRQSTAT_CC | IRQSTAT_CTOE;
>  	struct fsl_esdhc *regs = priv->esdhc_regs;
> +	unsigned long start;
>  
>  #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
>  	if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
> @@ -453,8 +454,11 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
>  		flags = IRQSTAT_BRR;
>  
>  	/* Wait for the command to complete */
> -	while (!(esdhc_read32(&regs->irqstat) & flags))
> -		;
> +	start = get_timer(0);
> +	while (!(esdhc_read32(&regs->irqstat) & flags)) {
> +		if (get_timer(start) > 1000)
> +			return -ETIMEDOUT;

Most other error paths in this routine do 'goto out' instead. The code under 
the 'out' label resets the module.

baruch

> +	}
>  
>  	irqstat = esdhc_read32(&regs->irqstat);

-- 
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [U-Boot] [PATCH] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common()
  2018-11-19 11:43 ` Baruch Siach
@ 2018-11-19 12:35   ` Fabio Estevam
  0 siblings, 0 replies; 3+ messages in thread
From: Fabio Estevam @ 2018-11-19 12:35 UTC (permalink / raw)
  To: u-boot

Hi Baruch,

On Mon, Nov 19, 2018 at 10:19 AM Baruch Siach <baruch@tkos.co.il> wrote:

> Most other error paths in this routine do 'goto out' instead. The code under
> the 'out' label resets the module.

Thanks for the suggestion. I have sent a v2 that jumps to the 'out' label.

Hopefully it will not hang there as there are more inifinite loops in
this path :-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-11-19 12:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-19 11:15 [U-Boot] [PATCH] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common() Fabio Estevam
2018-11-19 11:43 ` Baruch Siach
2018-11-19 12:35   ` Fabio Estevam

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.