mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <sha@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] mci: sdhci: don't hang indefinitely waiting for DMA completion
Date: Mon, 28 Aug 2023 10:02:12 +0200	[thread overview]
Message-ID: <20230828080212.GK16522@pengutronix.de> (raw)
In-Reply-To: <20230824135939.1614716-1-a.fatoum@pengutronix.de>

On Thu, Aug 24, 2023 at 03:59:39PM +0200, Ahmad Fatoum wrote:
> 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(+)

Applied, thanks

Sascha

> 
> 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
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



      parent reply	other threads:[~2023-08-28  8:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-24 13:59 Ahmad Fatoum
2023-08-25  7:34 ` Marco Felsch
2023-08-28  8:02 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230828080212.GK16522@pengutronix.de \
    --to=sha@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox