5856918
From patchwork Mon Nov 19 12:31:53 2018
5856918
Content-Type: text/plain; charset="utf-8"
5856918
MIME-Version: 1.0
5856918
Content-Transfer-Encoding: 7bit
5856918
Subject: [U-Boot,
5856918
 v2] mmc: fsl_esdhc: Avoid infinite loop in esdhc_send_cmd_common()
5856918
X-Patchwork-Submitter: Fabio Estevam <festevam@gmail.com>
5856918
X-Patchwork-Id: 999792
5856918
Message-Id: <1542630713-30355-1-git-send-email-festevam@gmail.com>
5856918
To: jh80.chung@samsung.com
5856918
Cc: baruch@tkos.co.il, u-boot@lists.denx.de
5856918
Date: Mon, 19 Nov 2018 10:31:53 -0200
5856918
From: Fabio Estevam <festevam@gmail.com>
5856918
List-Id: U-Boot discussion <u-boot.lists.denx.de>
5856918
5856918
The following hang is observed on a Hummingboard 2 MicroSOM
5856918
i2eX iMX6D - rev 1.3 with no eMMC populated on board:
5856918
5856918
U-Boot SPL 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)
5856918
Trying to boot from MMC1
5856918
5856918
U-Boot 2018.11+gf6206f8587 (Nov 16 2018 - 00:56:34 +0000)
5856918
5856918
CPU:   Freescale i.MX6D rev1.5 996 MHz (running at 792 MHz)
5856918
CPU:   Extended Commercial temperature grade (-20C to 105C) at 33C
5856918
Reset cause: POR
5856918
Board: MX6 HummingBoard2
5856918
DRAM:  1 GiB
5856918
MMC:   FSL_SDHC: 0, FSL_SDHC: 1
5856918
Loading Environment from MMC... *** Warning - bad CRC, using default environment
5856918
5856918
No panel detected: default to HDMI
5856918
Display: HDMI (1024x768)
5856918
In:    serial
5856918
Out:   serial
5856918
Err:   serial
5856918
---> hangs
5856918
5856918
which is caused by the following infinite loop inside esdhc_send_cmd_common()
5856918
5856918
	while (!(esdhc_read32(&regs->irqstat) & flags))
5856918
		;
5856918
5856918
Instead of looping forever, provide an exit path so that a timeout
5856918
error can be propagated in the case irqstat does not report
5856918
any interrupts, which may happen when no eMMC is populated on
5856918
board.
5856918
5856918
Reported-by: Ricardo Salveti <rsalveti@rsalveti.net>
5856918
Signed-off-by: Fabio Estevam <festevam@gmail.com>
5856918
---
5856918
Changes since v1:
5856918
- Jump to the label out on error path (Baruch).
5856918
5856918
 drivers/mmc/fsl_esdhc.c | 10 ++++++++--
5856918
 1 file changed, 8 insertions(+), 2 deletions(-)
5856918
5856918
diff --git a/drivers/mmc/fsl_esdhc.c b/drivers/mmc/fsl_esdhc.c
5856918
index 3cdfa7f..b8d0b00 100644
5856918
--- a/drivers/mmc/fsl_esdhc.c
5856918
+++ b/drivers/mmc/fsl_esdhc.c
5856918
@@ -396,6 +396,7 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
5856918
 	uint	irqstat;
5856918
 	u32	flags = IRQSTAT_CC | IRQSTAT_CTOE;
5856918
 	struct fsl_esdhc *regs = priv->esdhc_regs;
5856918
+	unsigned long start;
5856918
 
5856918
 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
5856918
 	if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
5856918
@@ -453,8 +454,13 @@ static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
5856918
 		flags = IRQSTAT_BRR;
5856918
 
5856918
 	/* Wait for the command to complete */
5856918
-	while (!(esdhc_read32(&regs->irqstat) & flags))
5856918
-		;
5856918
+	start = get_timer(0);
5856918
+	while (!(esdhc_read32(&regs->irqstat) & flags)) {
5856918
+		if (get_timer(start) > 1000) {
5856918
+			err = -ETIMEDOUT;
5856918
+			goto out;
5856918
+		}
5856918
+	}
5856918
 
5856918
 	irqstat = esdhc_read32(&regs->irqstat);
5856918