[PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC

From: Mayur Kumar

Date: Sat Jul 25 2026 - 14:51:52 EST


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@xxxxxxxxx>
---
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