public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Add retry tuning sequence
@ 2024-09-04 23:25 Judith Mendez
  2024-09-04 23:25 ` [PATCH v4 1/2] mmc: sdhci_am654: Add retry tuning Judith Mendez
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Judith Mendez @ 2024-09-04 23:25 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: Adrian Hunter, linux-mmc, linux-kernel

Due to failures to find failing region issues seen on some
boards, add retry tuning sequence to make the tuning algorithm
more robust. The tuning algorithm will re-execute up to 10
times if there is no failing or passing itapdly.

Due to the same issue above, add prints to the tuning algorithm
to make debugging these corner-cases easier.

Changes since v3:
- Fix compile warnings

link to v1:
https://lore.kernel.org/linux-mmc/20240815201542.421653-1-jm@ti.com
link to v2:
https://lore.kernel.org/linux-mmc/20240821192435.1619271-1-jm@ti.com
link to v3:
https://lore.kernel.org/linux-mmc/20240826210454.3928033-1-jm@ti.com/

Judith Mendez (2):
  mmc: sdhci_am654: Add retry tuning
  mmc: sdhci_am654: Add prints to tuning algorithm

 drivers/mmc/host/sdhci_am654.c | 54 +++++++++++++++++++++++++++-------
 1 file changed, 43 insertions(+), 11 deletions(-)

-- 
2.46.0


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

* [PATCH v4 1/2] mmc: sdhci_am654: Add retry tuning
  2024-09-04 23:25 [PATCH v4 0/2] Add retry tuning sequence Judith Mendez
@ 2024-09-04 23:25 ` Judith Mendez
  2024-09-04 23:25 ` [PATCH v4 2/2] mmc: sdhci_am654: Add prints to tuning algorithm Judith Mendez
  2024-09-05 10:18 ` [PATCH v4 0/2] Add retry tuning sequence Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Judith Mendez @ 2024-09-04 23:25 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: Adrian Hunter, linux-mmc, linux-kernel

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 has been observed to never
find a failing itapdly on the first couple of tuning
iterations, but eventually does. Keep count of current
tuning iteration using tuning_loop. It has 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>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
---
Changes since v3:
- Fix compile warnings
---
 drivers/mmc/host/sdhci_am654.c | 47 +++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
index 64e10f7c9faa3..8eb6ce9f3b173 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)
 };
@@ -443,22 +445,23 @@ static u32 sdhci_am654_cqhci_irq(struct sdhci_host *host, u32 intmask)
 #define ITAPDLY_LENGTH 32
 #define ITAPDLY_LAST_INDEX (ITAPDLY_LENGTH - 1)
 
-static u32 sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
+static int sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
 			  *fail_window, u8 num_fails, bool circular_buffer)
 {
 	u8 itap = 0, start_fail = 0, end_fail = 0, pass_length = 0;
 	u8 first_fail_start = 0, last_fail_end = 0;
-	struct device *dev = mmc_dev(host->mmc);
 	struct window pass_window = {0, 0, 0};
 	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;
@@ -494,8 +497,8 @@ static u32 sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
 	return (itap > ITAPDLY_LAST_INDEX) ? ITAPDLY_LAST_INDEX >> 1 : itap;
 }
 
-static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
-					       u32 opcode)
+static int sdhci_am654_do_tuning(struct sdhci_host *host,
+				 u32 opcode)
 {
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
@@ -532,13 +535,30 @@ 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);
+	return 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]);
+static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
+					       u32 opcode)
+{
+	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
+	struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
+	unsigned char timing = host->mmc->ios.timing;
+	int itapdly;
 
+	do {
+		itapdly = sdhci_am654_do_tuning(host, opcode);
+		if (itapdly >= 0)
+			break;
+	} while (++sdhci_am654->tuning_loop < RETRY_TUNING_MAX);
+
+	if (itapdly < 0)
+		return -1;
+
+	sdhci_am654_write_itapdly(sdhci_am654, itapdly, sdhci_am654->itap_del_ena[timing]);
 	/* Save ITAPDLY */
-	sdhci_am654->itap_del_sel[timing] = itap;
+	sdhci_am654->itap_del_sel[timing] = itapdly;
 
 	return 0;
 }
@@ -742,6 +762,9 @@ static int sdhci_am654_init(struct sdhci_host *host)
 	regmap_update_bits(sdhci_am654->base, CTL_CFG_3, TUNINGFORSDR50_MASK,
 			   TUNINGFORSDR50_MASK);
 
+	/* Use to re-execute tuning */
+	sdhci_am654->tuning_loop = 0;
+
 	ret = sdhci_setup_host(host);
 	if (ret)
 		return ret;
-- 
2.46.0


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

* [PATCH v4 2/2] mmc: sdhci_am654: Add prints to tuning algorithm
  2024-09-04 23:25 [PATCH v4 0/2] Add retry tuning sequence Judith Mendez
  2024-09-04 23:25 ` [PATCH v4 1/2] mmc: sdhci_am654: Add retry tuning Judith Mendez
@ 2024-09-04 23:25 ` Judith Mendez
  2024-09-05 10:18 ` [PATCH v4 0/2] Add retry tuning sequence Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Judith Mendez @ 2024-09-04 23:25 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: Adrian Hunter, linux-mmc, linux-kernel

Add debug prints to tuning algorithm for debugging.
Also add error print if we fail tuning.

Signed-off-by: Judith Mendez <jm@ti.com>
---
Changes since v3:
- Fix compile warnings
---
 drivers/mmc/host/sdhci_am654.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/sdhci_am654.c b/drivers/mmc/host/sdhci_am654.c
index 8eb6ce9f3b173..0aa3c40ea6ed8 100644
--- a/drivers/mmc/host/sdhci_am654.c
+++ b/drivers/mmc/host/sdhci_am654.c
@@ -450,17 +450,20 @@ static int sdhci_am654_calculate_itap(struct sdhci_host *host, struct window
 {
 	u8 itap = 0, start_fail = 0, end_fail = 0, pass_length = 0;
 	u8 first_fail_start = 0, last_fail_end = 0;
+	struct device *dev = mmc_dev(host->mmc);
 	struct window pass_window = {0, 0, 0};
 	int prev_fail_end = -1;
 	u8 i;
 
 	if (!num_fails) {
 		/* Retry tuning */
+		dev_dbg(dev, "No failing region found, retry tuning\n");
 		return -1;
 	}
 
 	if (fail_window->length == ITAPDLY_LENGTH) {
 		/* Retry tuning */
+		dev_dbg(dev, "No passing itapdly, retry tuning\n");
 		return -1;
 	}
 
@@ -504,6 +507,7 @@ static int sdhci_am654_do_tuning(struct sdhci_host *host,
 	struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
 	unsigned char timing = host->mmc->ios.timing;
 	struct window fail_window[ITAPDLY_LENGTH];
+	struct device *dev = mmc_dev(host->mmc);
 	u8 curr_pass, itap;
 	u8 fail_index = 0;
 	u8 prev_pass = 1;
@@ -524,6 +528,7 @@ static int sdhci_am654_do_tuning(struct sdhci_host *host,
 		if (!curr_pass) {
 			fail_window[fail_index].end = itap;
 			fail_window[fail_index].length++;
+			dev_dbg(dev, "Failed itapdly=%d\n", itap);
 		}
 
 		if (curr_pass && !prev_pass)
@@ -545,6 +550,7 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
 	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
 	struct sdhci_am654_data *sdhci_am654 = sdhci_pltfm_priv(pltfm_host);
 	unsigned char timing = host->mmc->ios.timing;
+	struct device *dev = mmc_dev(host->mmc);
 	int itapdly;
 
 	do {
@@ -553,9 +559,12 @@ static int sdhci_am654_platform_execute_tuning(struct sdhci_host *host,
 			break;
 	} while (++sdhci_am654->tuning_loop < RETRY_TUNING_MAX);
 
-	if (itapdly < 0)
+	if (itapdly < 0) {
+		dev_err(dev, "Failed to find itapdly, fail tuning\n");
 		return -1;
+	}
 
+	dev_dbg(dev, "Passed tuning, final itapdly=%d\n", itapdly);
 	sdhci_am654_write_itapdly(sdhci_am654, itapdly, sdhci_am654->itap_del_ena[timing]);
 	/* Save ITAPDLY */
 	sdhci_am654->itap_del_sel[timing] = itapdly;
-- 
2.46.0


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

* Re: [PATCH v4 0/2] Add retry tuning sequence
  2024-09-04 23:25 [PATCH v4 0/2] Add retry tuning sequence Judith Mendez
  2024-09-04 23:25 ` [PATCH v4 1/2] mmc: sdhci_am654: Add retry tuning Judith Mendez
  2024-09-04 23:25 ` [PATCH v4 2/2] mmc: sdhci_am654: Add prints to tuning algorithm Judith Mendez
@ 2024-09-05 10:18 ` Ulf Hansson
  2 siblings, 0 replies; 4+ messages in thread
From: Ulf Hansson @ 2024-09-05 10:18 UTC (permalink / raw)
  To: Judith Mendez; +Cc: Adrian Hunter, linux-mmc, linux-kernel

On Thu, 5 Sept 2024 at 01:25, Judith Mendez <jm@ti.com> wrote:
>
> Due to failures to find failing region issues seen on some
> boards, add retry tuning sequence to make the tuning algorithm
> more robust. The tuning algorithm will re-execute up to 10
> times if there is no failing or passing itapdly.
>
> Due to the same issue above, add prints to the tuning algorithm
> to make debugging these corner-cases easier.
>
> Changes since v3:
> - Fix compile warnings
>
> link to v1:
> https://lore.kernel.org/linux-mmc/20240815201542.421653-1-jm@ti.com
> link to v2:
> https://lore.kernel.org/linux-mmc/20240821192435.1619271-1-jm@ti.com
> link to v3:
> https://lore.kernel.org/linux-mmc/20240826210454.3928033-1-jm@ti.com/
>
> Judith Mendez (2):
>   mmc: sdhci_am654: Add retry tuning
>   mmc: sdhci_am654: Add prints to tuning algorithm
>
>  drivers/mmc/host/sdhci_am654.c | 54 +++++++++++++++++++++++++++-------
>  1 file changed, 43 insertions(+), 11 deletions(-)
>

Applied for next, thanks!

Kind regards
Uffe

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

end of thread, other threads:[~2024-09-05 10:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 23:25 [PATCH v4 0/2] Add retry tuning sequence Judith Mendez
2024-09-04 23:25 ` [PATCH v4 1/2] mmc: sdhci_am654: Add retry tuning Judith Mendez
2024-09-04 23:25 ` [PATCH v4 2/2] mmc: sdhci_am654: Add prints to tuning algorithm Judith Mendez
2024-09-05 10:18 ` [PATCH v4 0/2] Add retry tuning sequence Ulf Hansson

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