Skip to content

Commit d9ddd62

Browse files
kyungmin-parkcjb
authored andcommitted
mmc: core: mmc sanitize feature support for v4.5
In the v4.5, there's no secure erase & trim support. Instead it supports the sanitize feature. Signed-off-by: Kyungmin Park <[email protected]> Signed-off-by: Jaehoon Chung <[email protected]> Signed-off-by: Chris Ball <[email protected]>
1 parent 4e0a5ad commit d9ddd62

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

drivers/mmc/card/block.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,11 +792,18 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
792792
unsigned int from, nr, arg;
793793
int err = 0, type = MMC_BLK_SECDISCARD;
794794

795-
if (!mmc_can_secure_erase_trim(card)) {
795+
if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
796796
err = -EOPNOTSUPP;
797797
goto out;
798798
}
799799

800+
/* The sanitize operation is supported at v4.5 only */
801+
if (mmc_can_sanitize(card)) {
802+
err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
803+
EXT_CSD_SANITIZE_START, 1, 0);
804+
goto out;
805+
}
806+
800807
from = blk_rq_pos(req);
801808
nr = blk_rq_sectors(req);
802809

drivers/mmc/card/queue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
140140
/* granularity must not be greater than max. discard */
141141
if (card->pref_erase > max_discard)
142142
q->limits.discard_granularity = 0;
143-
if (mmc_can_secure_erase_trim(card))
143+
if (mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))
144144
queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD, q);
145145
}
146146

drivers/mmc/core/core.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,6 +1713,14 @@ int mmc_can_trim(struct mmc_card *card)
17131713
}
17141714
EXPORT_SYMBOL(mmc_can_trim);
17151715

1716+
int mmc_can_sanitize(struct mmc_card *card)
1717+
{
1718+
if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)
1719+
return 1;
1720+
return 0;
1721+
}
1722+
EXPORT_SYMBOL(mmc_can_sanitize);
1723+
17161724
int mmc_can_secure_erase_trim(struct mmc_card *card)
17171725
{
17181726
if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN)

include/linux/mmc/core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
156156
unsigned int arg);
157157
extern int mmc_can_erase(struct mmc_card *card);
158158
extern int mmc_can_trim(struct mmc_card *card);
159+
extern int mmc_can_sanitize(struct mmc_card *card);
159160
extern int mmc_can_secure_erase_trim(struct mmc_card *card);
160161
extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
161162
unsigned int nr);

include/linux/mmc/mmc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ struct _mmc_csd {
275275
#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */
276276
#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */
277277
#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */
278+
#define EXT_CSD_SANITIZE_START 165 /* W */
278279
#define EXT_CSD_WR_REL_PARAM 166 /* RO */
279280
#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
280281
#define EXT_CSD_PART_CONFIG 179 /* R/W */
@@ -343,6 +344,7 @@ struct _mmc_csd {
343344
#define EXT_CSD_SEC_ER_EN BIT(0)
344345
#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
345346
#define EXT_CSD_SEC_GB_CL_EN BIT(4)
347+
#define EXT_CSD_SEC_SANITIZE BIT(6) /* v4.5 only */
346348

347349
#define EXT_CSD_RST_N_EN_MASK 0x3
348350
#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */

0 commit comments

Comments
 (0)