OSDN Git Service

mmc: core: Add discard support to sd
authorAvri Altman <avri.altman@wdc.com>
Tue, 26 Feb 2019 15:10:24 +0000 (17:10 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Thu, 28 Feb 2019 08:16:12 +0000 (09:16 +0100)
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>
drivers/mmc/core/core.c
drivers/mmc/core/sd.c
include/linux/mmc/sd.h

index b45aaa9..681b089 100644 (file)
@@ -1847,7 +1847,7 @@ static unsigned int mmc_align_erase_size(struct mmc_card *card,
  * @card: card to erase
  * @from: first sector to erase
  * @nr: number of sectors to erase
- * @arg: erase command argument (SD supports only %SD_ERASE_ARG)
+ * @arg: erase command argument
  *
  * Caller must claim host before calling this function.
  */
@@ -1864,14 +1864,14 @@ int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
        if (!card->erase_size)
                return -EOPNOTSUPP;
 
-       if (mmc_card_sd(card) && arg != SD_ERASE_ARG)
+       if (mmc_card_sd(card) && arg != SD_ERASE_ARG && arg != SD_DISCARD_ARG)
                return -EOPNOTSUPP;
 
-       if ((arg & MMC_SECURE_ARGS) &&
+       if (mmc_card_mmc(card) && (arg & MMC_SECURE_ARGS) &&
            !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_ER_EN))
                return -EOPNOTSUPP;
 
-       if ((arg & MMC_TRIM_ARGS) &&
+       if (mmc_card_mmc(card) && (arg & MMC_TRIM_ARGS) &&
            !(card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN))
                return -EOPNOTSUPP;
 
index c2db94d..2b4fc22 100644 (file)
@@ -231,6 +231,8 @@ static int mmc_read_ssr(struct mmc_card *card)
 {
        unsigned int au, es, et, eo;
        __be32 *raw_ssr;
+       u32 resp[4] = {};
+       u8 discard_support;
        int i;
 
        if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
@@ -276,7 +278,13 @@ static int mmc_read_ssr(struct mmc_card *card)
                }
        }
 
-       card->erase_arg = SD_ERASE_ARG;
+       /*
+        * starting SD5.1 discard is supported if DISCARD_SUPPORT (b313) is set
+        */
+       resp[3] = card->raw_ssr[6];
+       discard_support = UNSTUFF_BITS(resp, 313 - 288, 1);
+       card->erase_arg = (card->scr.sda_specx && discard_support) ?
+                           SD_DISCARD_ARG : SD_ERASE_ARG;
 
        return 0;
 }
index 1a6d10f..ec94a5a 100644 (file)
@@ -95,5 +95,6 @@
  * Erase/discard
  */
 #define SD_ERASE_ARG                   0x00000000
+#define SD_DISCARD_ARG                 0x00000001
 
 #endif /* LINUX_MMC_SD_H */