public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Judith Mendez <jm@ti.com>, Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] mmc: sdhci_am654: Add retry tuning
Date: Wed, 21 Aug 2024 08:37:07 +0300	[thread overview]
Message-ID: <4a563aad-e9b3-43af-8ce5-5d30dace2dd8@intel.com> (raw)
In-Reply-To: <20240815201542.421653-2-jm@ti.com>

On 15/08/24 23:15, Judith Mendez wrote:
> Add retry tuning up to 10 times if we fail to find
> a failing region or no passing itapdly. This is
> necessary since some eMMC's have been observed to never
> find a failing itapdly on the first couple of tuning
> iterations, but eventually do. It been observed that the
> tuning algorithm does not need to loop more than 10 times
> before finding a failing itapdly.
> 
> Signed-off-by: Judith Mendez <jm@ti.com>
> ---
>  drivers/mmc/host/sdhci_am654.c | 30 +++++++++++++++++++++++-------
>  1 file changed, 23 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
> index 64e10f7c9faa3..c3d485bd4d553 100644
> --- a/drivers/mmc/host/sdhci_am654.c
> +++ b/drivers/mmc/host/sdhci_am654.c
> @@ -86,6 +86,7 @@
>  
>  #define CLOCK_TOO_SLOW_HZ	50000000
>  #define SDHCI_AM654_AUTOSUSPEND_DELAY	-1
> +#define RETRY_TUNING_MAX	10
>  
>  /* Command Queue Host Controller Interface Base address */
>  #define SDHCI_AM654_CQE_BASE_ADDR 0x200
> @@ -151,6 +152,7 @@ struct sdhci_am654_data {
>  	u32 flags;
>  	u32 quirks;
>  	bool dll_enable;
> +	u32 tuning_loop;
>  
>  #define SDHCI_AM654_QUIRK_FORCE_CDTEST BIT(0)
>  };
> @@ -453,12 +455,14 @@ static u32 sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
>  	int prev_fail_end = -1;
>  	u8 i;
>  
> -	if (!num_fails)
> -		return ITAPDLY_LAST_INDEX >> 1;
> +	if (!num_fails) {
> +		/* Retry tuning */
> +		return -1;
> +	}
>  
>  	if (fail_window->length == ITAPDLY_LENGTH) {
> -		dev_err(dev, "No passing ITAPDLY, return 0\n");
> -		return 0;
> +		/* Retry tuning */
> +		return -1;
>  	}
>  
>  	first_fail_start = fail_window->start;
> @@ -504,6 +508,7 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
>  	u8 curr_pass, itap;
>  	u8 fail_index = 0;
>  	u8 prev_pass = 1;
> +	int ret;
>  
>  	memset(fail_window, 0, sizeof(fail_window));
>  
> @@ -532,10 +537,20 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
>  	if (fail_window[fail_index].length != 0)
>  		fail_index++;
>  
> -	itap = sdhci_am654_calculate_itap(host, fail_window, fail_index,
> -					  sdhci_am654->dll_enable);
> +	ret = sdhci_am654_calculate_itap(host, fail_window, fail_index,
> +					 sdhci_am654->dll_enable);
>  
> -	sdhci_am654_write_itapdly(sdhci_am654, itap, sdhci_am654->itap_del_ena[timing]);
> +	if (ret >= 0) {
> +		itap = ret;
> +		sdhci_am654_write_itapdly(sdhci_am654, itap, sdhci_am654->itap_del_ena[timing]);
> +	} else {
> +		if (sdhci_am654->tuning_loop < RETRY_TUNING_MAX) {
> +			sdhci_am654->tuning_loop++;
> +			sdhci_am654_platform_execute_tuning(host, opcode);

The kernel uses very small stack size, so recursive function calls
should not be used.  It would be better to put the loop in a separate
function, or add a retry: label and goto retry.

> +		} else {
> +			return -1;
> +		}
> +	}
>  
>  	/* Save ITAPDLY */
>  	sdhci_am654->itap_del_sel[timing] = itap;
> @@ -908,6 +923,7 @@ static int sdhci_am654_probe(struct platform_device *pdev)
>  		goto err_pltfm_free;
>  	}
>  
> +	sdhci_am654->tuning_loop = 0;

So this is 10 retries ever, since sdhci_am654->tuning_loop is never
set back to 0.  Is that the intention?

>  	host->mmc_host_ops.execute_tuning = sdhci_am654_execute_tuning;
>  
>  	pm_runtime_get_noresume(dev);


  parent reply	other threads:[~2024-08-21  5:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-15 20:15 [PATCH 0/2] Add retry tuning sequence Judith Mendez
2024-08-15 20:15 ` [PATCH 1/2] mmc: sdhci_am654: Add retry tuning Judith Mendez
2024-08-20 14:47   ` Judith Mendez
2024-08-21  5:37   ` Adrian Hunter [this message]
2024-08-21 14:14     ` Judith Mendez
2024-08-15 20:15 ` [PATCH 2/2] mmc: sdhci_am654: Add tuning debug prints Judith Mendez
2024-08-20 11:33   ` Ulf Hansson
2024-08-20 14:40     ` Judith Mendez
2024-08-20 15:03       ` Ulf Hansson
2024-08-20 20:17         ` Judith Mendez
2024-08-20 20:18         ` Judith Mendez

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=4a563aad-e9b3-43af-8ce5-5d30dace2dd8@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=jm@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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