diff mbox series

[RFC,V2,2/2] mmc: allow card to disable tuning

Message ID 20250206210835.2980500-2-erick.shepherd@ni.com (mailing list archive)
State New
Headers show
Series [RFC,V2,1/2] mmc: Update sdhci tune function to return errors | expand

Commit Message

Erick Shepherd Feb. 6, 2025, 9:08 p.m. UTC
Add a new field to the mmc_card struct to disable tuning for the card.
Currently the new field only gets set when a DDR50 card fails to tune,
which indicates the card does not support tuning.

Signed-off-by: Erick Shepherd <erick.shepherd@ni.com>
---
 drivers/mmc/core/core.c  | 3 +++
 drivers/mmc/core/sd.c    | 1 +
 include/linux/mmc/card.h | 1 +
 3 files changed, 5 insertions(+)

Comments

Adrian Hunter Feb. 15, 2025, 1:08 a.m. UTC | #1
On 6/02/25 23:08, Erick Shepherd wrote:
> Add a new field to the mmc_card struct to disable tuning for the card.
> Currently the new field only gets set when a DDR50 card fails to tune,
> which indicates the card does not support tuning.

You need to explain why this is needed.  Presumably it speeds up
runtime-resume in some cases?

> 
> Signed-off-by: Erick Shepherd <erick.shepherd@ni.com>
> ---
>  drivers/mmc/core/core.c  | 3 +++
>  drivers/mmc/core/sd.c    | 1 +
>  include/linux/mmc/card.h | 1 +
>  3 files changed, 5 insertions(+)
> 
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 5241528f8b90..ee91d53c45d5 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -934,6 +934,9 @@ int mmc_execute_tuning(struct mmc_card *card)
>  	u32 opcode;
>  	int err;
>  
> +	if (card->disable_tuning)
> +		return 0;
> +
>  	if (!host->ops->execute_tuning)
>  		return 0;
>  
> diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
> index cc757b850e79..dd65485c61d8 100644
> --- a/drivers/mmc/core/sd.c
> +++ b/drivers/mmc/core/sd.c
> @@ -676,6 +676,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->disable_tuning = true;
>  			err = 0;
>  		}
>  	}
> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
> index 526fce581657..f9733c7ce430 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -332,6 +332,7 @@ struct mmc_card {
>  
>  	bool			written_flag;	/* Indicates eMMC has been written since power on */
>  	bool			reenable_cmdq;	/* Re-enable Command Queue */
> +	bool			disable_tuning;	/* Disables tuning for the card */
>  
>  	unsigned int		erase_size;	/* erase size in sectors */
>   	unsigned int		erase_shift;	/* if erase unit is power 2 */
Erick Shepherd Feb. 18, 2025, 6:41 p.m. UTC | #2
Sorry about that, the context for this change is that I have been
working with a DDR50 swissbit SD card that does not support tuning.
The case I'm seeing is that the first tuning times out and any
further tuning attempts cause an async page read I/O error. I used
this change to prevent the card from attempting to tune again if it
is ever reset in the case where we know tuning isn't supported.

Regards
Erick
Adrian Hunter March 6, 2025, 2:01 p.m. UTC | #3
On 18/02/25 20:41, Erick Shepherd wrote:
> Sorry about that, the context for this change is that I have been
> working with a DDR50 swissbit SD card that does not support tuning.
> The case I'm seeing is that the first tuning times out and any
> further tuning attempts cause an async page read I/O error. I used
> this change to prevent the card from attempting to tune again if it
> is ever reset in the case where we know tuning isn't supported.

Sorry for the slow reply.

I would expect if there was a general problem with DDR50 SD cards,
it would have come to light before now.

Does the card work with any other host controllers with linux?

If it is specific to a particular kind of card, a card quirk
could be added, say MMC_QUIRK_BROKEN_DDR50_TUNING
Erick Shepherd March 7, 2025, 5:45 p.m. UTC | #4
> Sorry for the slow reply.

> I would expect if there was a general problem with DDR50 SD cards,
> it would have come to light before now.

> Does the card work with any other host controllers with linux?

> If it is specific to a particular kind of card, a card quirk
> could be added, say MMC_QUIRK_BROKEN_DDR50_TUNING

No worries. I have not tested this with other host controllers but
can try to get something set up. This issue has only appeared on
one particular SD card model for us so I would not be surprised if
the I/O errors we see on subsequent tune requests are specific to this
card. I can put together a solution using the card quirk you suggested
if you think that is the best way forward.

My fix is currently spread across two commits, one to return the error
code thrown by the tune request timing out, which prevents the card from
retuning, and this one that prevents the initial card tuning if it has
already failed. Should both parts be controlled by the new card quirk?

Regards,
Erick
Adrian Hunter March 7, 2025, 6:44 p.m. UTC | #5
On 7/03/25 19:45, Erick Shepherd wrote:
>> Sorry for the slow reply.
> 
>> I would expect if there was a general problem with DDR50 SD cards,
>> it would have come to light before now.
> 
>> Does the card work with any other host controllers with linux?
> 
>> If it is specific to a particular kind of card, a card quirk
>> could be added, say MMC_QUIRK_BROKEN_DDR50_TUNING
> 
> No worries. I have not tested this with other host controllers but
> can try to get something set up. This issue has only appeared on
> one particular SD card model for us so I would not be surprised if
> the I/O errors we see on subsequent tune requests are specific to this
> card. I can put together a solution using the card quirk you suggested
> if you think that is the best way forward.
> 
> My fix is currently spread across two commits, one to return the error
> code thrown by the tune request timing out, which prevents the card from
> retuning, and this one that prevents the initial card tuning if it has
> already failed. Should both parts be controlled by the new card quirk?

Does it tuning at all?  Maybe MMC_QUIRK_NO_UHS_DDR50_TUNING is a better
name, then at the top of mmc_execute_tuning()

	if ((card->quirks & MMC_QUIRK_NO_UHS_DDR50_TUNING) &&
	    host->ios->timing == MMC_TIMING_UHS_DDR50)
		return 0;
Erick Shepherd March 7, 2025, 9:17 p.m. UTC | #6
> Does it tuning at all?  Maybe MMC_QUIRK_NO_UHS_DDR50_TUNING is a better
> name, then at the top of mmc_execute_tuning()

> 	if ((card->quirks & MMC_QUIRK_NO_UHS_DDR50_TUNING) &&
> 	    host->ios->timing == MMC_TIMING_UHS_DDR50)
> 		return 0;

The card doesn't need to tune at all so I think this would work for us.
I'm not very familiar with using card quirks. What would be the best
way to set MMC_QUIRK_NO_UHS_DDR50_TUNING? Would it be set based on the
model of the card or should it be set after the initial tuning times
out?

Regards,
Erick
Adrian Hunter March 11, 2025, 3:20 p.m. UTC | #7
On 7/03/25 23:17, Erick Shepherd wrote:
>> Does it tuning at all?  Maybe MMC_QUIRK_NO_UHS_DDR50_TUNING is a better
>> name, then at the top of mmc_execute_tuning()
> 
>> 	if ((card->quirks & MMC_QUIRK_NO_UHS_DDR50_TUNING) &&
>> 	    host->ios->timing == MMC_TIMING_UHS_DDR50)
>> 		return 0;
> 
> The card doesn't need to tune at all so I think this would work for us.
> I'm not very familiar with using card quirks. What would be the best
> way to set MMC_QUIRK_NO_UHS_DDR50_TUNING? Would it be set based on the
> model of the card or should it be set after the initial tuning times
> out?

Based on the model of the card i.e. add a new entry to mmc_sd_fixups[]
Erick Shepherd March 13, 2025, 4:32 p.m. UTC | #8
How does this look? I confirmed the changes stop the card from tuning
and prevent the I/O errors. I can submit a new patch since these
changes are substantially different than my initial ones.

diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index 3205feb1e8ff..756f80024635 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -89,6 +89,7 @@ struct mmc_fixup {
 #define CID_MANFID_MICRON       0x13
 #define CID_MANFID_SAMSUNG      0x15
 #define CID_MANFID_APACER       0x27
+#define CID_MANFID_SWISSBIT     0x5D
 #define CID_MANFID_KINGSTON     0x70
 #define CID_MANFID_HYNIX	0x90
 #define CID_MANFID_KINGSTON_SD	0x9F


diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5241528f8b90..8962992f05aa 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -937,6 +937,10 @@ int mmc_execute_tuning(struct mmc_card *card)
 	if (!host->ops->execute_tuning)
 		return 0;
 
+	if ((card->quirks & MMC_QUIRK_NO_UHS_DDR50_TUNING) &&
+	    host->ios.timing == MMC_TIMING_UHS_DDR50)
+		return 0;
+
 	if (host->cqe_on)
 		host->cqe_ops->cqe_off(host);

 
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index 89b512905be1..7f893bafaa60 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -34,6 +34,16 @@ static const struct mmc_fixup __maybe_unused mmc_sd_fixups[] = {
 		   MMC_QUIRK_BROKEN_SD_CACHE | MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY,
 		   EXT_CSD_REV_ANY),
 
+	/*
+	 * Swissbit series S46-u cards throw I/O errors during tuning requests
+	 * after the initial tuning request expectedly times out. This has
+	 * only been observed on cards manufactured on 01/2019 that are using
+	 * Bay Trail host controllers.
+	 */
+	_FIXUP_EXT("0016G", CID_MANFID_SWISSBIT, 0x5342, 2019, 1,
+		   0, -1ull, SDIO_ANY_ID, SDIO_ANY_ID, add_quirk_sd,
+		   MMC_QUIRK_NO_UHS_DDR50_TUNING, EXT_CSD_REV_ANY),
+
 	END_FIXUP
 };

 
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 526fce581657..ddcdf23d731c 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -329,6 +329,7 @@ struct mmc_card {
 #define MMC_QUIRK_BROKEN_SD_CACHE	(1<<15)	/* Disable broken SD cache support */
 #define MMC_QUIRK_BROKEN_CACHE_FLUSH	(1<<16)	/* Don't flush cache until the write has occurred */
 #define MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY	(1<<17) /* Disable broken SD poweroff notify support */
+#define MMC_QUIRK_NO_UHS_DDR50_TUNING	(1<<18) /* Disable DDR50 tuning */
 
 	bool			written_flag;	/* Indicates eMMC has been written since power on */
 	bool			reenable_cmdq;	/* Re-enable Command Queue */
diff mbox series

Patch

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 5241528f8b90..ee91d53c45d5 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -934,6 +934,9 @@  int mmc_execute_tuning(struct mmc_card *card)
 	u32 opcode;
 	int err;
 
+	if (card->disable_tuning)
+		return 0;
+
 	if (!host->ops->execute_tuning)
 		return 0;
 
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index cc757b850e79..dd65485c61d8 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -676,6 +676,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->disable_tuning = true;
 			err = 0;
 		}
 	}
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 526fce581657..f9733c7ce430 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -332,6 +332,7 @@  struct mmc_card {
 
 	bool			written_flag;	/* Indicates eMMC has been written since power on */
 	bool			reenable_cmdq;	/* Re-enable Command Queue */
+	bool			disable_tuning;	/* Disables tuning for the card */
 
 	unsigned int		erase_size;	/* erase size in sectors */
  	unsigned int		erase_shift;	/* if erase unit is power 2 */