mmc: add erase, secure erase, trim and secure trim operations
SD/MMC cards tend to support an erase operation. In addition, eMMC v4.4 cards can support secure erase, trim and secure trim operations that are all variants of the basic erase command. SD/MMC device attributes "erase_size" and "preferred_erase_size" have been added. "erase_size" is the minimum size, in bytes, of an erase operation. For MMC, "erase_size" is the erase group size reported by the card. Note that "erase_size" does not apply to trim or secure trim operations where the minimum size is always one 512 byte sector. For SD, "erase_size" is 512 if the card is block-addressed, 0 otherwise. SD/MMC cards can erase an arbitrarily large area up to and including the whole card. When erasing a large area it may be desirable to do it in smaller chunks for three reasons: 1. A single erase command will make all other I/O on the card wait. This is not a problem if the whole card is being erased, but erasing one partition will make I/O for another partition on the same card wait for the duration of the erase - which could be a several minutes. 2. To be able to inform the user of erase progress. 3. The erase timeout becomes too large to be very useful. Because the erase timeout contains a margin which is multiplied by the size of the erase area, the value can end up being several minutes for large areas. "erase_size" is not the most efficient unit to erase (especially for SD where it is just one sector), hence "preferred_erase_size" provides a good chunk size for erasing large areas. For MMC, "preferred_erase_size" is the high-capacity erase size if a card specifies one, otherwise it is based on the capacity of the card. For SD, "preferred_erase_size" is the allocation unit size specified by the card. "preferred_erase_size" is in bytes. Signed-off-by: Adrian Hunter <adrian.hunter@nokia.com> Acked-by: Jens Axboe <axboe@kernel.dk> Cc: Kyungmin Park <kmpark@infradead.org> Cc: Madhusudhan Chikkature <madhu.cr@ti.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Ben Gardiner <bengardiner@nanometrics.ca> Cc: <linux-mmc@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
committed by
Linus Torvalds
parent
81d73a32d7
commit
dfe86cba76
@@ -108,13 +108,23 @@ static int mmc_decode_cid(struct mmc_card *card)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void mmc_set_erase_size(struct mmc_card *card)
|
||||
{
|
||||
if (card->ext_csd.erase_group_def & 1)
|
||||
card->erase_size = card->ext_csd.hc_erase_size;
|
||||
else
|
||||
card->erase_size = card->csd.erase_size;
|
||||
|
||||
mmc_init_erase(card);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a 128-bit response, decode to our card CSD structure.
|
||||
*/
|
||||
static int mmc_decode_csd(struct mmc_card *card)
|
||||
{
|
||||
struct mmc_csd *csd = &card->csd;
|
||||
unsigned int e, m;
|
||||
unsigned int e, m, a, b;
|
||||
u32 *resp = card->raw_csd;
|
||||
|
||||
/*
|
||||
@@ -152,6 +162,13 @@ static int mmc_decode_csd(struct mmc_card *card)
|
||||
csd->write_blkbits = UNSTUFF_BITS(resp, 22, 4);
|
||||
csd->write_partial = UNSTUFF_BITS(resp, 21, 1);
|
||||
|
||||
if (csd->write_blkbits >= 9) {
|
||||
a = UNSTUFF_BITS(resp, 42, 5);
|
||||
b = UNSTUFF_BITS(resp, 37, 5);
|
||||
csd->erase_size = (a + 1) * (b + 1);
|
||||
csd->erase_size <<= csd->write_blkbits - 9;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -261,8 +278,30 @@ static int mmc_read_ext_csd(struct mmc_card *card)
|
||||
if (sa_shift > 0 && sa_shift <= 0x17)
|
||||
card->ext_csd.sa_timeout =
|
||||
1 << ext_csd[EXT_CSD_S_A_TIMEOUT];
|
||||
card->ext_csd.erase_group_def =
|
||||
ext_csd[EXT_CSD_ERASE_GROUP_DEF];
|
||||
card->ext_csd.hc_erase_timeout = 300 *
|
||||
ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT];
|
||||
card->ext_csd.hc_erase_size =
|
||||
ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10;
|
||||
}
|
||||
|
||||
if (card->ext_csd.rev >= 4) {
|
||||
card->ext_csd.sec_trim_mult =
|
||||
ext_csd[EXT_CSD_SEC_TRIM_MULT];
|
||||
card->ext_csd.sec_erase_mult =
|
||||
ext_csd[EXT_CSD_SEC_ERASE_MULT];
|
||||
card->ext_csd.sec_feature_support =
|
||||
ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT];
|
||||
card->ext_csd.trim_timeout = 300 *
|
||||
ext_csd[EXT_CSD_TRIM_MULT];
|
||||
}
|
||||
|
||||
if (ext_csd[EXT_CSD_ERASED_MEM_CONT])
|
||||
card->erased_byte = 0xFF;
|
||||
else
|
||||
card->erased_byte = 0x0;
|
||||
|
||||
out:
|
||||
kfree(ext_csd);
|
||||
|
||||
@@ -274,6 +313,8 @@ MMC_DEV_ATTR(cid, "%08x%08x%08x%08x\n", card->raw_cid[0], card->raw_cid[1],
|
||||
MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
|
||||
card->raw_csd[2], card->raw_csd[3]);
|
||||
MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
|
||||
MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
|
||||
MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
|
||||
MMC_DEV_ATTR(fwrev, "0x%x\n", card->cid.fwrev);
|
||||
MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
|
||||
MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
|
||||
@@ -285,6 +326,8 @@ static struct attribute *mmc_std_attrs[] = {
|
||||
&dev_attr_cid.attr,
|
||||
&dev_attr_csd.attr,
|
||||
&dev_attr_date.attr,
|
||||
&dev_attr_erase_size.attr,
|
||||
&dev_attr_preferred_erase_size.attr,
|
||||
&dev_attr_fwrev.attr,
|
||||
&dev_attr_hwrev.attr,
|
||||
&dev_attr_manfid.attr,
|
||||
@@ -421,6 +464,8 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
|
||||
err = mmc_read_ext_csd(card);
|
||||
if (err)
|
||||
goto free_card;
|
||||
/* Erase size depends on CSD and Extended CSD */
|
||||
mmc_set_erase_size(card);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user