Skip to contentSkip to conversation

mmc: Update sdhci tune function to return errors

RFC PATCH Superseded Erick Shepherd 3 participants 8 messages Jan 27, 2025 – Feb 6, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 mmc: Update sdhci tune function to return errors

Updates the sdhci_execute_tuning function to return the error code that was returned by the __sdhci_execute_tuning function. Previously this code was only stored in host->tuning_err and not actually returned.

---
 drivers/mmc/host/sdhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index f4a7733a8ad2..b35b8917fa1e 100644
@@ -2967,7 +2967,8 @@ int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 
 	sdhci_start_tuning(host);
 
-	host->tuning_err = __sdhci_execute_tuning(host, opcode);
+	err = __sdhci_execute_tuning(host, opcode);
+	host->tuning_err = err;
 
 	sdhci_end_tuning(host);
 out:
Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 2/2 mmc: Allow tuning to be skipped during card init

Add a new field to the mmc_host struct to track when the card should skip the initial tuning and use it to conditionally stop tuning in the mmc_sd_init_uhs_card function. Currently the new field only gets set when a DDR50 card fails to tune, which indicates the card does not support tuning.

---
 drivers/mmc/core/sd.c    | 4 +++-
 include/linux/mmc/host.h | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +3 -1
index cc757b850e79..353715fd8f53 100644
@@ -663,7 +663,8 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
 	if (!mmc_host_is_spi(card->host) &&
 		(card->host->ios.timing == MMC_TIMING_UHS_SDR50 ||
 		 card->host->ios.timing == MMC_TIMING_UHS_DDR50 ||
-		 card->host->ios.timing == MMC_TIMING_UHS_SDR104)) {
+		 card->host->ios.timing == MMC_TIMING_UHS_SDR104) &&
+		!card->host->skip_init_tune) {
 		err = mmc_execute_tuning(card);
 
 		/*
@@ -676,6 +677,7 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
 		if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) {
 			pr_warn("%s: ddr50 tuning failed\n",
 				mmc_hostname(card->host));
+			card->host->skip_init_tune = 1;
 			err = 0;
 		}
 	}
include/linux/mmc/host.h +1 -0
index 68f09a955a90..91c4db6837c9 100644
@@ -486,6 +486,7 @@ struct mmc_host {
 	unsigned int		use_spi_crc:1;
 	unsigned int		claimed:1;	/* host exclusively claimed */
 	unsigned int		doing_init_tune:1; /* initial tuning in progress */
+	unsigned int		skip_init_tune:1;	/* skip the initial tuning */
 	unsigned int		can_retune:1;	/* re-tuning can be used */
 	unsigned int		doing_retune:1;	/* re-tuning in progress */
 	unsigned int		retune_now:1;	/* do re-tuning at next req */
Signature · 1 line
2.43.0
#2 lore raw

Re: [RFC PATCH 2/2] mmc: Allow tuning to be skipped during card init

Hi Erick,

Quoted 5 lines · Erick Shepherd

Add a new field to the mmc_host struct to track when the card should skip the initial tuning and use it to conditionally stop tuning in the mmc_sd_init_uhs_card function. Currently the new field only gets set when a DDR50 card fails to tune, which indicates the card does not support tuning.

Just out of curiosity, why do we want to stop the initial tuning?

~ Judith

Quoted 41 lines
---
  drivers/mmc/core/sd.c    | 4 +++-
  include/linux/mmc/host.h | 1 +
  2 files changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +3 -1
index cc757b850e79..353715fd8f53 100644
@@ -663,7 +663,8 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
  	if (!mmc_host_is_spi(card->host) &&
  		(card->host->ios.timing == MMC_TIMING_UHS_SDR50 ||
  		 card->host->ios.timing == MMC_TIMING_UHS_DDR50 ||
-		 card->host->ios.timing == MMC_TIMING_UHS_SDR104)) {
+		 card->host->ios.timing == MMC_TIMING_UHS_SDR104) &&
+		!card->host->skip_init_tune) {
  		err = mmc_execute_tuning(card);
 
  		/*
@@ -676,6 +677,7 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
  		if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) {
  			pr_warn("%s: ddr50 tuning failed\n",
  				mmc_hostname(card->host));
+			card->host->skip_init_tune = 1;
  			err = 0;
  		}
  	}
include/linux/mmc/host.h +1 -0
index 68f09a955a90..91c4db6837c9 100644
@@ -486,6 +486,7 @@ struct mmc_host {
  	unsigned int		use_spi_crc:1;
  	unsigned int		claimed:1;	/* host exclusively claimed */
  	unsigned int		doing_init_tune:1; /* initial tuning in progress */
+	unsigned int		skip_init_tune:1;	/* skip the initial tuning */
  	unsigned int		can_retune:1;	/* re-tuning can be used */
  	unsigned int		doing_retune:1;	/* re-tuning in progress */
  	unsigned int		retune_now:1;	/* do re-tuning at next req */
#3 lore raw

RE: [RFC PATCH 2/2] mmc: Allow tuning to be skipped during card init

I have been working with a DDR50 SD card that does not support tuning. The card's first tuning attempt fails, which is expected, but subsequent tuning attempts cause I/O errors due to async page reads. My first patch mostly solves this issue but I was still seeing I/O errors in the case where the card is reset and attempts to do the initial tuning again despite it failing previously. This second patch allows the initial tuning to be skipped if it has already failed for a DDR50 card.

#4 lore raw

Re: [RFC PATCH 2/2] mmc: Allow tuning to be skipped during card init

In reply to Erick Shepherd
Quoted 28 lines · Erick Shepherd

Add a new field to the mmc_host struct to track when the card should skip the initial tuning and use it to conditionally stop tuning in the mmc_sd_init_uhs_card function. Currently the new field only gets set when a DDR50 card fails to tune, which indicates the card does not support tuning.

---
 drivers/mmc/core/sd.c    | 4 +++-
 include/linux/mmc/host.h | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
drivers/mmc/core/sd.c +2 -1
index cc757b850e79..353715fd8f53 100644
@@ -663,7 +663,8 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
        if (!mmc_host_is_spi(card->host) &&
                (card->host->ios.timing == MMC_TIMING_UHS_SDR50 ||
                 card->host->ios.timing == MMC_TIMING_UHS_DDR50 ||
-                card->host->ios.timing == MMC_TIMING_UHS_SDR104)) {
+                card->host->ios.timing == MMC_TIMING_UHS_SDR104) &&
+               !card->host->skip_init_tune) {
                err = mmc_execute_tuning(card);
 
                /*

drivers/mmc/core/sd.c static int mmc_sd_init_uhs_card(struct mmc_card *card) · line 680

Quoted 4 lines
drivers/mmc/core/sd.c +1 -0
@@ -676,6 +677,7 @@ static int mmc_sd_init_uhs_card(struct mmc_card *card)
                if (err && card->host->ios.timing == MMC_TIMING_UHS_DDR50) {
                        pr_warn("%s: ddr50 tuning failed\n",
                                mmc_hostname(card->host));
+                       card->host->skip_init_tune = 1;

Rather than adding a host specific flag to let the core signal to the host driver that it should skip tuning, I think it would be better if we can avoid the core to request a tuning instead.

So we need to get the information from the host, during the first tuning attempt if it fails and then the tuning should be disabled for the *card*, forever.

Quoted 16 lines
drivers/mmc/core/sd.c +0 -0
                        err = 0;
                }
        }
include/linux/mmc/host.h +1 -1
index 68f09a955a90..91c4db6837c9 100644
@@ -486,6 +486,7 @@ struct mmc_host {
        unsigned int            use_spi_crc:1;
        unsigned int            claimed:1;      /* host exclusively claimed */
        unsigned int            doing_init_tune:1; /* initial tuning in progress */
+       unsigned int            skip_init_tune:1;       /* skip the initial tuning */
        unsigned int            can_retune:1;   /* re-tuning can be used */
        unsigned int            doing_retune:1; /* re-tuning in progress */
        unsigned int            retune_now:1;   /* do re-tuning at next req */
--
Quoted 2 lines

2.43.0

Again, please re-submit and loop in Adrian to get his opinion on this.

Kind regards
Uffe

#5 lore raw
In reply to Erick Shepherd
Quoted 16 lines · Erick Shepherd

Updates the sdhci_execute_tuning function to return the error code that was returned by the __sdhci_execute_tuning function. Previously this code was only stored in host->tuning_err and not actually returned.

---
 drivers/mmc/host/sdhci.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +0 -0
index f4a7733a8ad2..b35b8917fa1e 100644

drivers/mmc/host/sdhci.c int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode) · line 2971

Quoted 6 lines
drivers/mmc/host/sdhci.c +2 -1
@@ -2967,7 +2967,8 @@ int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 
        sdhci_start_tuning(host);
 
-       host->tuning_err = __sdhci_execute_tuning(host, opcode);
+       err = __sdhci_execute_tuning(host, opcode);
+       host->tuning_err = err;

Hmm, this code was deliberately not returning an error in this path, so I am pretty sure things will break with this change.

Anyway, please re-submit and add Adrian (the sdhci maintainer) and possibly a couple other contributors that have been working with tunings for host drivers. We need their feedback on this.

Quoted 6 lines
drivers/mmc/host/sdhci.c +0 -1
        sdhci_end_tuning(host);
 out:
--

2.43.0

Kind regards
Uffe

#6 lore raw

Thank you for taking the time to review this. I'll resubmit the patch, pull in Adrian, and move the new field to the mmc_card struct.

Regards
Erick

Reviewed-by on v1 1/2
#7 lore raw
In reply to Erick Shepherd

Hi Erick,

Quoted 6 lines · Erick Shepherd

Updates the sdhci_execute_tuning function to return the error code that was returned by the __sdhci_execute_tuning function. Previously this code was only stored in host->tuning_err and not actually returned.

Quoted 18 lines
---
  drivers/mmc/host/sdhci.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci.c +2 -1
index f4a7733a8ad2..b35b8917fa1e 100644
@@ -2967,7 +2967,8 @@ int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode)
 
  	sdhci_start_tuning(host);
 
-	host->tuning_err = __sdhci_execute_tuning(host, opcode);
+	err = __sdhci_execute_tuning(host, opcode);
+	host->tuning_err = err;
 
  	sdhci_end_tuning(host);
  out: