Skip to content

Commit bc47e2f

Browse files
Avri AltmanUlf Hansson
authored andcommitted
mmc: core: Add discard support to sd
SD spec v5.1 adds discard support. The flows and commands are similar to mmc, so just set the discard arg in CMD38. A host which supports DISCARD shall check if the DISCARD_SUPPORT (b313) is set in the SD_STATUS register. If the card does not support discard, the host shall not issue DISCARD command, but ERASE command instead. Post the DISCARD operation, the card may de-allocate the discarded blocks partially or completely. So the host mustn't make any assumptions concerning the content of the discarded region. This is unlike ERASE command, in which the region is guaranteed to contain either '0's or '1's, depends on the content of DATA_STAT_AFTER_ERASE (b55) in the scr register. One more important difference compared to ERASE is the busy timeout which we will address on the next patch. Signed-off-by: Avri Altman <avri.altman@wdc.com> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent 85236d2 commit bc47e2f

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎drivers/mmc/core/core.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
18471847
* @card: card to erase
18481848
* @from: first sector to erase
18491849
* @nr: number of sectors to erase
1850-
* @arg: erase command argument (SD supports only %SD_ERASE_ARG)
1850+
* @arg: erase command argument
18511851
*
18521852
* Caller must claim host before calling this function.
18531853
*/
@@ -1864,14 +1864,14 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
18641864
if (!card->erase_size)
18651865
return -EOPNOTSUPP;
18661866

1867-
if (mmc_card_sd(card) && arg != SD_ERASE_ARG)
1867+
if (mmc_card_sd(card) && arg != SD_ERASE_ARG && arg != SD_DISCARD_ARG)
18681868
return -EOPNOTSUPP;
18691869

1870-
if ((arg & MMC_SECURE_ARGS) &&
1870+
if (mmc_card_mmc(card) && (arg & MMC_SECURE_ARGS) &&
18711871
!(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
18721872
return -EOPNOTSUPP;
18731873

1874-
if ((arg & MMC_TRIM_ARGS) &&
1874+
if (mmc_card_mmc(card) && (arg & MMC_TRIM_ARGS) &&
18751875
!(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
18761876
return -EOPNOTSUPP;
18771877

‎drivers/mmc/core/sd.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ static int mmc_read_ssr(struct mmc_card *card)
231231
{
232232
unsigned int au, es, et, eo;
233233
__be32 *raw_ssr;
234+
u32 resp[4] = {};
235+
u8 discard_support;
234236
int i;
235237

236238
if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
@@ -276,7 +278,13 @@ static int mmc_read_ssr(struct mmc_card *card)
276278
}
277279
}
278280

279-
card->erase_arg = SD_ERASE_ARG;
281+
/*
282+
* starting SD5.1 discard is supported if DISCARD_SUPPORT (b313) is set
283+
*/
284+
resp[3] = card->raw_ssr[6];
285+
discard_support = UNSTUFF_BITS(resp, 313 - 288, 1);
286+
card->erase_arg = (card->scr.sda_specx && discard_support) ?
287+
SD_DISCARD_ARG : SD_ERASE_ARG;
280288

281289
return 0;
282290
}

‎include/linux/mmc/sd.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,6 @@
9595
* Erase/discard
9696
*/
9797
#define SD_ERASE_ARG 0x00000000
98+
#define SD_DISCARD_ARG 0x00000001
9899

99100
#endif /* LINUX_MMC_SD_H */

0 commit comments

Comments
 (0)