]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
mmc: core: Optimize time for secure erase/trim for some Kingston eMMCs
authorLuke Wang <ziniu.wang_1@nxp.com>
Tue, 5 May 2026 10:02:50 +0000 (06:02 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 May 2026 13:31:19 +0000 (15:31 +0200)
[ Upstream commit d6bf2e64dec87322f2b11565ddb59c0e967f96e3 ]

Kingston eMMC IY2964 and IB2932 takes a fixed ~2 seconds for each secure
erase/trim operation regardless of size - that is, a single secure
erase/trim operation of 1MB takes the same time as 1GB. With default
calculated 3.5MB max discard size, secure erase 1GB requires ~300 separate
operations taking ~10 minutes total.

Add a card quirk, MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME, to set maximum
secure erase size for those devices. This allows 1GB secure erase to
complete in a single operation, reducing time from 10 minutes to just 2
seconds.

Signed-off-by: Luke Wang <ziniu.wang_1@nxp.com>
Cc: stable@vger.kernel.org
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/mmc/core/card.h
drivers/mmc/core/queue.c
drivers/mmc/core/quirks.h
include/linux/mmc/card.h

index a9619dd45270840143533e710a0a8f555a8d67be..a7c364d0030ad5737f73def62e668a3fe41fc54e 100644 (file)
@@ -311,4 +311,9 @@ static inline int mmc_card_broken_mdt(const struct mmc_card *c)
        return c->quirks & MMC_QUIRK_BROKEN_MDT;
 }
 
+static inline int mmc_card_fixed_secure_erase_trim_time(const struct mmc_card *c)
+{
+       return c->quirks & MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME;
+}
+
 #endif
index 13000fc57e2e12cf0bdcba7d8fe5233acf0df7fd..39fcb662c43fc05f916ef3f2a7fef8011e43505f 100644 (file)
@@ -184,8 +184,13 @@ static void mmc_queue_setup_discard(struct mmc_card *card,
                return;
 
        lim->max_hw_discard_sectors = max_discard;
-       if (mmc_card_can_secure_erase_trim(card))
-               lim->max_secure_erase_sectors = max_discard;
+       if (mmc_card_can_secure_erase_trim(card)) {
+               if (mmc_card_fixed_secure_erase_trim_time(card))
+                       lim->max_secure_erase_sectors = UINT_MAX >> card->erase_shift;
+               else
+                       lim->max_secure_erase_sectors = max_discard;
+       }
+
        if (mmc_card_can_trim(card) && card->erased_byte == 0)
                lim->max_write_zeroes_sectors = max_discard;
 
index f5e8a0f6d11b936d465b51f22614f2c30c2752fb..6f727b4a60a527f42ccbd386f3e5819b1069e386 100644 (file)
@@ -153,6 +153,15 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
        MMC_FIXUP("M62704", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
                  MMC_QUIRK_TRIM_BROKEN),
 
+       /*
+        * On Some Kingston eMMCs, secure erase/trim time is independent
+        * of erase size, fixed at approximately 2 seconds.
+        */
+       MMC_FIXUP("IY2964", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
+                 MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME),
+       MMC_FIXUP("IB2932", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
+                 MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME),
+
        END_FIXUP
 };
 
index 4722dd7e46ce10d9fff65d3f819bae3d8ff91945..9dc4750296af99844623c5970c3194590911454c 100644 (file)
@@ -330,6 +330,7 @@ struct mmc_card {
 #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 */
 #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 */
 
        bool                    written_flag;   /* Indicates eMMC has been written since power on */
        bool                    reenable_cmdq;  /* Re-enable Command Queue */