All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaehoon Chung <jh80.chung@samsung.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mmc: sdhci: Avoid commands errors by simple timeout adaptation.
Date: Fri, 04 Oct 2013 13:39:55 +0900	[thread overview]
Message-ID: <524E469B.3080303@samsung.com> (raw)
In-Reply-To: <1380629761-16502-1-git-send-email-p.marczak@samsung.com>

Hi Przemyslaw,

On 10/01/2013 09:16 PM, Przemyslaw Marczak wrote:
> Old command timeout value was too small and it caused I/O errors which
> led to uncompleted read/write/erase operations and filesystem errors.
> Timeout adaptation fixes this issue.
> 
> Changes in sdhci_send_command() function:
> - change timeout variable to static
> - increase default command timeout to 100 ms
> - add definition of max command timeout value,
>   which can be redefined in each board config file
> - wait for card ready state for max defined time
>   if it doesn't exceed defined maximum or return COMM_ERR
> 
> Once successfully increased timeout value will be used in next function
> call. This fix was tested on Goni, Trats, Trats2 boards by testing UMS
> on MMC storage.
> 
> Signed-off-by: Przemyslaw Marczak <p.marczak@samsung.com>
> ---
>  drivers/mmc/sdhci.c |   34 +++++++++++++++++++++++++++-------
>  1 file changed, 27 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
> index 4261991..af11fc5 100644
> --- a/drivers/mmc/sdhci.c
> +++ b/drivers/mmc/sdhci.c
> @@ -110,6 +110,22 @@ static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data,
>  	return 0;
>  }
>  
> +/*
> + * No command will be sent by driver if card is busy, so driver must wait
> + * for card ready state.
> + * Every time when card is busy after timeout then (last) timeout value will be
> + * increased twice but only if it doesn't exceed global defined maximum.
> + * Each function call will use last timeout value. Max timeout can be redefined
> + * in board config file.
> + */
> +#ifndef CONFIG_SDHCI_CMD_MAX_TIMEOUT
> +#define CONFIG_SDHCI_CMD_MAX_TIMEOUT		3200
How do you get "3200"? Is it too long time?

> +#endif
> +#define CONFIG_SDHCI_CMD_DEFAULT_TIMEOUT	100
> +
> +/* Timeout unit - ms */
> +static unsigned int cmd_timeout = CONFIG_SDHCI_CMD_DEFAULT_TIMEOUT;
Global variable?

Best Regards,
Jaehoon Chung
> +
>  int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
>  		       struct mmc_data *data)
>  {
> @@ -118,12 +134,9 @@ int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
>  	int ret = 0;
>  	int trans_bytes = 0, is_aligned = 1;
>  	u32 mask, flags, mode;
> -	unsigned int timeout, start_addr = 0;
> +	unsigned int time = 0, start_addr = 0;
>  	unsigned int retry = 10000;
>  
> -	/* Wait max 10 ms */
> -	timeout = 10;
> -
>  	sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
>  	mask = SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT;
>  
> @@ -133,11 +146,18 @@ int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
>  		mask &= ~SDHCI_DATA_INHIBIT;
>  
>  	while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
> -		if (timeout == 0) {
> +		if (time == cmd_timeout) {
>  			printf("Controller never released inhibit bit(s).\n");
> -			return COMM_ERR;
> +			if (2 * cmd_timeout <= CONFIG_SDHCI_CMD_MAX_TIMEOUT) {
> +				cmd_timeout += cmd_timeout;
> +				debug("Increasing command timeout to: %u ms.\n",
> +				      cmd_timeout);
> +			} else {
> +				error("Command timeout is set to max.\n");
> +				return COMM_ERR;
> +			}
>  		}
> -		timeout--;
> +		time++;
>  		udelay(1000);
>  	}
>  
> 

  parent reply	other threads:[~2013-10-04  4:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01 12:16 [U-Boot] [PATCH] mmc: sdhci: Avoid commands errors by simple timeout adaptation Przemyslaw Marczak
2013-10-01 15:50 ` Pantelis Antoniou
2013-10-01 16:59   ` Przemyslaw Marczak
2013-10-02  9:40     ` Pantelis Antoniou
2013-10-04  4:39 ` Jaehoon Chung [this message]
2013-10-04 13:17   ` Przemyslaw Marczak
2013-10-08 16:12 ` [U-Boot] [PATCH v2] " Przemyslaw Marczak
2013-10-15 20:18   ` Przemyslaw Marczak
2013-10-29 13:02     ` Przemyslaw Marczak
2013-10-29 13:08       ` Pantelis Antoniou
2013-10-29 13:24         ` Przemyslaw Marczak
2013-10-29 13:28           ` Pantelis Antoniou
2013-10-29 13:39             ` Mateusz Zalega
2013-10-31  7:49 ` [U-Boot] [PATCH] " Pantelis Antoniou

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=524E469B.3080303@samsung.com \
    --to=jh80.chung@samsung.com \
    --cc=u-boot@lists.denx.de \
    /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 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.