Skip to content

Commit b58baa1

Browse files
Luke Wanggregkh
authored andcommitted
mmc: core: Optimize time for secure erase/trim for some Kingston eMMCs
[ Upstream commit d6bf2e6 ] 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> [ adapted `lim->max_secure_erase_sectors =` assignment to `blk_queue_max_secure_erase_sectors(q, ...)` setter and used pre-rename `mmc_can_secure_erase_trim`/`mmc_can_trim` helpers ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 058b451 commit b58baa1

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

drivers/mmc/core/card.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,4 +297,9 @@ static inline int mmc_card_no_uhs_ddr50_tuning(const struct mmc_card *c)
297297
return c->quirks & MMC_QUIRK_NO_UHS_DDR50_TUNING;
298298
}
299299

300+
static inline int mmc_card_fixed_secure_erase_trim_time(const struct mmc_card *c)
301+
{
302+
return c->quirks & MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME;
303+
}
304+
300305
#endif

drivers/mmc/core/queue.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,12 @@ static void mmc_queue_setup_discard(struct request_queue *q,
188188
/* granularity must not be greater than max. discard */
189189
if (card->pref_erase > max_discard)
190190
q->limits.discard_granularity = SECTOR_SIZE;
191-
if (mmc_can_secure_erase_trim(card))
192-
blk_queue_max_secure_erase_sectors(q, max_discard);
191+
if (mmc_can_secure_erase_trim(card)) {
192+
if (mmc_card_fixed_secure_erase_trim_time(card))
193+
blk_queue_max_secure_erase_sectors(q, UINT_MAX >> card->erase_shift);
194+
else
195+
blk_queue_max_secure_erase_sectors(q, max_discard);
196+
}
193197
if (mmc_can_trim(card) && card->erased_byte == 0)
194198
blk_queue_max_write_zeroes_sectors(q, max_discard);
195199
}

drivers/mmc/core/quirks.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,15 @@ static const struct mmc_fixup __maybe_unused mmc_blk_fixups[] = {
153153
MMC_FIXUP("M62704", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
154154
MMC_QUIRK_TRIM_BROKEN),
155155

156+
/*
157+
* On Some Kingston eMMCs, secure erase/trim time is independent
158+
* of erase size, fixed at approximately 2 seconds.
159+
*/
160+
MMC_FIXUP("IY2964", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
161+
MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME),
162+
MMC_FIXUP("IB2932", CID_MANFID_KINGSTON, 0x0100, add_quirk_mmc,
163+
MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME),
164+
156165
END_FIXUP
157166
};
158167

include/linux/mmc/card.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ struct mmc_card {
298298
#define MMC_QUIRK_BROKEN_CACHE_FLUSH (1<<16) /* Don't flush cache until the write has occurred */
299299
#define MMC_QUIRK_BROKEN_SD_POWEROFF_NOTIFY (1<<17) /* Disable broken SD poweroff notify support */
300300
#define MMC_QUIRK_NO_UHS_DDR50_TUNING (1<<18) /* Disable DDR50 tuning */
301+
#define MMC_QUIRK_FIXED_SECURE_ERASE_TRIM_TIME (1<<20) /* Secure erase/trim time is fixed regardless of size */
301302

302303
bool written_flag; /* Indicates eMMC has been written since power on */
303304
bool reenable_cmdq; /* Re-enable Command Queue */

0 commit comments

Comments
 (0)