mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] mci: sdhci: don't hang indefinitely waiting for DMA completion
@ 2023-08-24 13:59 Ahmad Fatoum
  2023-08-25  7:34 ` Marco Felsch
  2023-08-28  8:02 ` Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-08-24 13:59 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

barebox was observed to hang on an i.MX8MP while reading ext_csd from
a broken eMMC that even bootROM refused to boot from. For PIO, we
already have a maximum wait time of 10s. Do the same for DMA.

It's unlikely that in that state any further communication with the card
will work, but at least, the system isn't stuck and the shell can be
reached. The reset is done on the off-chance that the DMA would've completed
after the 10s and corrupted memory if not disabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/sdhci.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index b0b83bfaa9a7..9829a78cb6c5 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -252,6 +252,7 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 			    dma_addr_t dma)
 {
 	struct device *dev = sdhci->mci->hw_dev;
+	u64 start;
 	int nbytes;
 	u32 irqstat;
 	int ret;
@@ -261,6 +262,8 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 
 	nbytes = data->blocks * data->blocksize;
 
+	start = get_time_ns();
+
 	do {
 		irqstat = sdhci_read32(sdhci, SDHCI_INT_STATUS);
 
@@ -304,6 +307,13 @@ int sdhci_transfer_data_dma(struct sdhci *sdhci, struct mci_data *data,
 
 		if (irqstat & SDHCI_INT_XFER_COMPLETE)
 			break;
+
+		if (is_timeout(start, 10 * SECOND)) {
+			dev_alert(dev, "DMA wait timed out. Resetting, but recovery unlikely\n");
+			sdhci_reset(sdhci, SDHCI_RESET_ALL);
+			ret = -ETIMEDOUT;
+			goto out;
+		}
 	} while (1);
 
 	ret = 0;
-- 
2.39.2




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

end of thread, other threads:[~2023-08-28  8:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-24 13:59 [PATCH] mci: sdhci: don't hang indefinitely waiting for DMA completion Ahmad Fatoum
2023-08-25  7:34 ` Marco Felsch
2023-08-28  8:02 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox