All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mayur Kumar <kmayur809@gmail.com>
To: Ulf Hansson <ulfh@kernel.org>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Mayur Kumar <kmayur809@gmail.com>
Subject: [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC
Date: Sun, 26 Jul 2026 00:21:29 +0530	[thread overview]
Message-ID: <20260725185129.43397-1-kmayur809@gmail.com> (raw)

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


             reply	other threads:[~2026-07-25 18:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 18:51 Mayur Kumar [this message]
2026-07-27 16:19 ` [PATCH] mmc: core: add MMC_QUIRK_BROKEN_WRITE_ZEROES for ESMT eMMC Ulf Hansson
2026-08-07 21:47 ` kernel test robot
2026-08-08 10:56 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260725185129.43397-1-kmayur809@gmail.com \
    --to=kmayur809@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulfh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.