Skip to content

Commit b3bf915

Browse files
kyungmin-parkcjb
authored andcommitted
mmc: core: new discard feature support at eMMC v4.5
MMC v4.5 supports the DISCARD feature (CMD38). It's different from trim and there's no check bit. Currently it's only supported at v4.5. Signed-off-by: Kyungmin Park <[email protected]> Signed-off-by: Jaehoon Chung <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent d9ddd62 commit b3bf915

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

drivers/mmc/card/block.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,9 @@ static int mmc_blk_issue_discard_rq(struct mmc_queue *mq, struct request *req)
756756
from = blk_rq_pos(req);
757757
nr = blk_rq_sectors(req);
758758

759-
if (mmc_can_trim(card))
759+
if (mmc_can_discard(card))
760+
arg = MMC_DISCARD_ARG;
761+
else if (mmc_can_trim(card))
760762
arg = MMC_TRIM_ARG;
761763
else
762764
arg = MMC_ERASE_ARG;

drivers/mmc/core/core.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,10 +1709,24 @@ int mmc_can_trim(struct mmc_card *card)
17091709
{
17101710
if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
17111711
return 1;
1712+
if (mmc_can_discard(card))
1713+
return 1;
17121714
return 0;
17131715
}
17141716
EXPORT_SYMBOL(mmc_can_trim);
17151717

1718+
int mmc_can_discard(struct mmc_card *card)
1719+
{
1720+
/*
1721+
* As there's no way to detect the discard support bit at v4.5
1722+
* use the s/w feature support filed.
1723+
*/
1724+
if (card->ext_csd.feature_support & MMC_DISCARD_FEATURE)
1725+
return 1;
1726+
return 0;
1727+
}
1728+
EXPORT_SYMBOL(mmc_can_discard);
1729+
17161730
int mmc_can_sanitize(struct mmc_card *card)
17171731
{
17181732
if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)

drivers/mmc/core/mmc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
452452
card->ext_csd.rst_n_function = ext_csd[EXT_CSD_RST_N_FUNCTION];
453453
}
454454

455+
/* eMMC v4.5 or later */
456+
if (card->ext_csd.rev >= 6)
457+
card->ext_csd.feature_support |= MMC_DISCARD_FEATURE;
458+
455459
card->ext_csd.raw_erased_mem_count = ext_csd[EXT_CSD_ERASED_MEM_CONT];
456460
if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
457461
card->erased_byte = 0xFF;

include/linux/mmc/card.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ struct mmc_ext_csd {
8080
u8 raw_sec_feature_support;/* 231 */
8181
u8 raw_trim_mult; /* 232 */
8282
u8 raw_sectors[4]; /* 212 - 4 bytes */
83+
84+
unsigned int feature_support;
85+
#define MMC_DISCARD_FEATURE BIT(0) /* CMD38 feature */
8386
};
8487

8588
struct sd_scr {

include/linux/mmc/core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ extern int mmc_switch(struct mmc_card *, u8, u8, u8, unsigned int);
146146
#define MMC_ERASE_ARG 0x00000000
147147
#define MMC_SECURE_ERASE_ARG 0x80000000
148148
#define MMC_TRIM_ARG 0x00000001
149+
#define MMC_DISCARD_ARG 0x00000003
149150
#define MMC_SECURE_TRIM1_ARG 0x80000001
150151
#define MMC_SECURE_TRIM2_ARG 0x80008000
151152

@@ -156,6 +157,7 @@ extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
156157
unsigned int arg);
157158
extern int mmc_can_erase(struct mmc_card *card);
158159
extern int mmc_can_trim(struct mmc_card *card);
160+
extern int mmc_can_discard(struct mmc_card *card);
159161
extern int mmc_can_sanitize(struct mmc_card *card);
160162
extern int mmc_can_secure_erase_trim(struct mmc_card *card);
161163
extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,

0 commit comments

Comments
 (0)