Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC
@ 2026-07-25 18:51 Mayur Kumar
  2026-07-27 16:19 ` Ulf Hansson
  0 siblings, 1 reply; 2+ messages in thread
From: Mayur Kumar @ 2026-07-25 18:51 UTC (permalink / raw)
  To: Ulf Hansson; +Cc: linux-mmc, linux-kernel, Mayur Kumar

ESMT eMMC (SM0000) supports normal TRIM discard, but fails when TRIM
is used to offload WRITE_ZEROES operations.

Add a new card quirk, MMC_QUIRK_BROKEN_WRITE_ZEROES, to prevent setting
max_write_zeroes_sectors during queue setup when this quirk is present.
Apply this fixup to ESMT eMMC devices (CID_MANFID_ESM_MMC 0xEC,
CID 'SM0000').

Signed-off-by: Mayur Kumar <kmayur809@gmail.com>
---
 drivers/mmc/core/card.h   | 1 +
 drivers/mmc/core/queue.c  | 3 ++-
 drivers/mmc/core/quirks.h | 6 ++++++
 include/linux/mmc/card.h  | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
index a7c364d0030..144a8f5e7d2 100644
--- a/drivers/mmc/core/card.h
+++ b/drivers/mmc/core/card.h
@@ -94,6 +94,7 @@ struct mmc_fixup {
 #define CID_MANFID_KINGSTON     0x70
 #define CID_MANFID_HYNIX	0x90
 #define CID_MANFID_KINGSTON_SD	0x9F
+#define CID_MANFID_ESMT_MMC	0xEC
 #define CID_MANFID_NUMONYX	0xFE
 
 #define END_FIXUP { NULL }
diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
index 5d187e063da..3ee640056a5 100644
--- a/drivers/mmc/core/queue.c
+++ b/drivers/mmc/core/queue.c
@@ -191,7 +191,8 @@ static void mmc_queue_setup_discard(struct mmc_card *card,
 			lim->max_secure_erase_sectors = max_discard;
 	}
 
-	if (mmc_card_can_trim(card) && card->erased_byte == 0)
+	if (mmc_card_can_trim(card) && card->erased_byte == 0 &&
+	    !(card->quirks & MMC_QUIRK_BROKEN_WRITE_ZEROS))
 		lim->max_write_zeroes_sectors = max_discard;
 
 	/* granularity must not be greater than max. discard */
diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
index ae3ece89d0a..91758fd7fc2 100644
--- a/drivers/mmc/core/quirks.h
+++ b/drivers/mmc/core/quirks.h
@@ -91,6 +91,12 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
 	MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
 		  MMC_QUIRK_BLK_NO_CMD23),
 
+	/* SM0000 supports normal TRIM discard but fails when TRIM is
+	 * used to offload WRITE_ZEROES, so we disable it.
+	 */
+	MMC_FIXUP("SM0000", CID_MANFID_ESMT_MMC, 0x0100, add_quirk_mmc,
+		  MMC_QUIRK_BROKEN_WRITE_ZEROES),
+
 	/*
 	 * Some SD cards lockup while using CMD23 multiblock transfers.
 	 */
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 9dc4750296a..938a4296b55 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -331,6 +331,7 @@ struct mmc_card {
 #define MMC_QUIRK_NO_UHS_DDR50_TUNING	(1<<18) /* Disable DDR50 tuning */
 #define MMC_QUIRK_BROKEN_MDT    (1<<19) /* Wrong manufacturing year */
 #define MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME	(1<<20) /* Secure erase/trim time is fixed regardless of size */
+#define MMC_QUIRK_BROKEN_WRITE_ZEROES	(1<<21)	/* Broken write zeroes via trim */
 
 	bool			written_flag;	/* Indicates eMMC has been written since power on */
 	bool			reenable_cmdq;	/* Re-enable Command Queue */
-- 
2.34.1


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

* Re: [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC
  2026-07-25 18:51 [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC Mayur Kumar
@ 2026-07-27 16:19 ` Ulf Hansson
  0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2026-07-27 16:19 UTC (permalink / raw)
  To: Mayur Kumar; +Cc: Ulf Hansson, linux-mmc, linux-kernel

On Sat, Jul 25, 2026 at 8:51 PM Mayur Kumar <kmayur809@gmail.com> wrote:
>
> ESMT eMMC (SM0000) supports normal TRIM discard, but fails when TRIM
> is used to offload WRITE_ZEROES operations.

Out of curiosity, how does it fail?

>
> Add a new card quirk, MMC_QUIRK_BROKEN_WRITE_ZEROES, to prevent setting
> max_write_zeroes_sectors during queue setup when this quirk is present.
> Apply this fixup to ESMT eMMC devices (CID_MANFID_ESM_MMC 0xEC,
> CID 'SM0000').
>
> Signed-off-by: Mayur Kumar <kmayur809@gmail.com>
> ---
>  drivers/mmc/core/card.h   | 1 +
>  drivers/mmc/core/queue.c  | 3 ++-
>  drivers/mmc/core/quirks.h | 6 ++++++
>  include/linux/mmc/card.h  | 1 +
>  4 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/card.h b/drivers/mmc/core/card.h
> index a7c364d0030..144a8f5e7d2 100644
> --- a/drivers/mmc/core/card.h
> +++ b/drivers/mmc/core/card.h
> @@ -94,6 +94,7 @@ struct mmc_fixup {
>  #define CID_MANFID_KINGSTON     0x70
>  #define CID_MANFID_HYNIX       0x90
>  #define CID_MANFID_KINGSTON_SD 0x9F
> +#define CID_MANFID_ESMT_MMC    0xEC
>  #define CID_MANFID_NUMONYX     0xFE
>
>  #define END_FIXUP { NULL }
> diff --git a/drivers/mmc/core/queue.c b/drivers/mmc/core/queue.c
> index 5d187e063da..3ee640056a5 100644
> --- a/drivers/mmc/core/queue.c
> +++ b/drivers/mmc/core/queue.c
> @@ -191,7 +191,8 @@ static void mmc_queue_setup_discard(struct mmc_card *card,
>                         lim->max_secure_erase_sectors = max_discard;
>         }
>
> -       if (mmc_card_can_trim(card) && card->erased_byte == 0)
> +       if (mmc_card_can_trim(card) && card->erased_byte == 0 &&
> +           !(card->quirks & MMC_QUIRK_BROKEN_WRITE_ZEROS))

Please add a helper in card.h, similar to the others "mmc_card_broken_*".

>                 lim->max_write_zeroes_sectors = max_discard;
>
>         /* granularity must not be greater than max. discard */
> diff --git a/drivers/mmc/core/quirks.h b/drivers/mmc/core/quirks.h
> index ae3ece89d0a..91758fd7fc2 100644
> --- a/drivers/mmc/core/quirks.h
> +++ b/drivers/mmc/core/quirks.h
> @@ -91,6 +91,12 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
>         MMC_FIXUP("MMC32G", CID_MANFID_TOSHIBA, CID_OEMID_ANY, add_quirk_mmc,
>                   MMC_QUIRK_BLK_NO_CMD23),
>
> +       /* SM0000 supports normal TRIM discard but fails when TRIM is
> +        * used to offload WRITE_ZEROES, so we disable it.
> +        */
> +       MMC_FIXUP("SM0000", CID_MANFID_ESMT_MMC, 0x0100, add_quirk_mmc,
> +                 MMC_QUIRK_BROKEN_WRITE_ZEROES),
> +
>         /*
>          * Some SD cards lockup while using CMD23 multiblock transfers.
>          */
> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
> index 9dc4750296a..938a4296b55 100644
> --- a/include/linux/mmc/card.h
> +++ b/include/linux/mmc/card.h
> @@ -331,6 +331,7 @@ struct mmc_card {
>  #define MMC_QUIRK_NO_UHS_DDR50_TUNING  (1<<18) /* Disable DDR50 tuning */
>  #define MMC_QUIRK_BROKEN_MDT    (1<<19) /* Wrong manufacturing year */
>  #define MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME (1<<20) /* Secure erase/trim time is fixed regardless of size */
> +#define MMC_QUIRK_BROKEN_WRITE_ZEROES  (1<<21) /* Broken write zeroes via trim */
>
>         bool                    written_flag;   /* Indicates eMMC has been written since power on */
>         bool                    reenable_cmdq;  /* Re-enable Command Queue */
> --
> 2.34.1
>

Kind regards
Uffe

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

end of thread, other threads:[~2026-07-27 16:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-25 18:51 [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC Mayur Kumar
2026-07-27 16:19 ` Ulf Hansson

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