History

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.

Adrian Hunter committed 16 years ago

Commit dfe86cb1 parent 81d73a314 files · +651 −8Browse files

Showing the changes to include/linux (5 of 14 files). Show all

Unified · Split

5 files
  1. include/linux/mmc/card.h +20 −0
  2. include/linux/mmc/core.h +19 −0
  3. include/linux/mmc/host.h +1 −0
  4. include/linux/mmc/mmc.h +19 −7
  5. include/linux/mmc/sd.h +5 −0
include/linux/mmc/card.h+20−0
@@ -31,6 +31,7 @@ struct mmc_csd { · 30 unmodified lines
3131 unsigned int tacc_ns;
3232 unsigned int r2w_factor;
3333 unsigned int max_dtr;
34+ unsigned int erase_size; /* In sectors */
3435 unsigned int read_blkbits;
3536 unsigned int write_blkbits;
3637 unsigned int capacity;
@@ -42,9 +43,16 @@ struct mmc_csd { · 5 unmodified lines
4243
4344 struct mmc_ext_csd {
4445 u8 rev;
46+ u8 erase_group_def;
47+ u8 sec_feature_support;
4548 unsigned int sa_timeout; /* Units: 100ns */
4649 unsigned int hs_max_dtr;
4750 unsigned int sectors;
51+ unsigned int hc_erase_size; /* In sectors */
52+ unsigned int hc_erase_timeout; /* In milliseconds */
53+ unsigned int sec_trim_mult; /* Secure trim multiplier */
54+ unsigned int sec_erase_mult; /* Secure erase multiplier */
55+ unsigned int trim_timeout; /* In milliseconds */
4856 };
4957
5058 struct sd_scr {
@@ -54,6 +62,12 @@ struct sd_scr { · 3 unmodified lines
5462 #define SD_SCR_BUS_WIDTH_4 (1<<2)
5563 };
5664
65+struct sd_ssr {
66+ unsigned int au; /* In sectors */
67+ unsigned int erase_timeout; /* In milliseconds */
68+ unsigned int erase_offset; /* In milliseconds */
69+};
70+
5771 struct sd_switch_caps {
5872 unsigned int hs_max_dtr;
5973 };
@@ -106,6 +120,11 @@ struct mmc_card { · 46 unmodified lines
106120 #define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
107121 /* (missing CIA registers) */
108122
123+ unsigned int erase_size; /* erase size in sectors */
124+ unsigned int erase_shift; /* if erase unit is power 2 */
125+ unsigned int pref_erase; /* in sectors */
126+ u8 erased_byte; /* value of erased bytes */
127+
109128 u32 raw_cid[4]; /* raw card CID */
110129 u32 raw_csd[4]; /* raw card CSD */
111130 u32 raw_scr[2]; /* raw card SCR */
@@ -113,6 +132,7 @@ struct mmc_card { · 1 unmodified line
113132 struct mmc_csd csd; /* card specific */
114133 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
115134 struct sd_scr scr; /* extra SD information */
135+ struct sd_ssr ssr; /* yet more SD information */
116136 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
117137
118138 unsigned int sdio_funcs; /* number of SDIO functions */
include/linux/mmc/core.h+19−0
@@ -92,6 +92,8 @@ struct mmc_command { · 91 unmodified lines
9292 * actively failing requests
9393 */
9494
95+ unsigned int erase_timeout; /* in milliseconds */
96+
9597 struct mmc_data *data; /* data segment associated with cmd */
9698 struct mmc_request *mrq; /* associated request */
9799 };
@@ -134,6 +136,23 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int); · 36 unmodified lines
134136 extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
135137 struct mmc_command *, int);
136138
139+#define MMC_ERASE_ARG 0x00000000
140+#define MMC_SECURE_ERASE_ARG 0x80000000
141+#define MMC_TRIM_ARG 0x00000001
142+#define MMC_SECURE_TRIM1_ARG 0x80000001
143+#define MMC_SECURE_TRIM2_ARG 0x80008000
144+
145+#define MMC_SECURE_ARGS 0x80000000
146+#define MMC_TRIM_ARGS 0x00008001
147+
148+extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
149+ unsigned int arg);
150+extern int mmc_can_erase(struct mmc_card *card);
151+extern int mmc_can_trim(struct mmc_card *card);
152+extern int mmc_can_secure_erase_trim(struct mmc_card *card);
153+extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
154+ unsigned int nr);
155+
137156 extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
138157 extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
139158
include/linux/mmc/host.h+1−0
@@ -156,6 +156,7 @@ struct mmc_host { · 155 unmodified lines
156156 #define MMC_CAP_DISABLE (1 << 7) /* Can the host be disabled */
157157 #define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */
158158 #define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */
159+#define MMC_CAP_ERASE (1 << 10) /* Allow erase/trim commands */
159160
160161 mmc_pm_flag_t pm_caps; /* supported pm features */
161162
include/linux/mmc/mmc.h+19−7
@@ -251,13 +251,21 @@ struct _mmc_csd { · 250 unmodified lines
251251 * EXT_CSD fields
252252 */
253253
254−#define EXT_CSD_BUS_WIDTH 183 /* R/W */
255−#define EXT_CSD_HS_TIMING 185 /* R/W */
256−#define EXT_CSD_CARD_TYPE 196 /* RO */
257−#define EXT_CSD_STRUCTURE 194 /* RO */
258−#define EXT_CSD_REV 192 /* RO */
259−#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
260−#define EXT_CSD_S_A_TIMEOUT 217
254+#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
255+#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
256+#define EXT_CSD_BUS_WIDTH 183 /* R/W */
257+#define EXT_CSD_HS_TIMING 185 /* R/W */
258+#define EXT_CSD_REV 192 /* RO */
259+#define EXT_CSD_STRUCTURE 194 /* RO */
260+#define EXT_CSD_CARD_TYPE 196 /* RO */
261+#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */
262+#define EXT_CSD_S_A_TIMEOUT 217 /* RO */
263+#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */
264+#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */
265+#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */
266+#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */
267+#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */
268+#define EXT_CSD_TRIM_MULT 232 /* RO */
261269
262270 /*
263271 * EXT_CSD field definitions
@@ -275,6 +283,10 @@ struct _mmc_csd { · 11 unmodified lines
275283 #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
276284 #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
277285
286+#define EXT_CSD_SEC_ER_EN BIT(0)
287+#define EXT_CSD_SEC_BD_BLK_EN BIT(2)
288+#define EXT_CSD_SEC_GB_CL_EN BIT(4)
289+
278290 /*
279291 * MMC_SWITCH access modes
280292 */
include/linux/mmc/sd.h+5−0
@@ -21,8 +21,13 @@ · 20 unmodified lines
2121 /* class 10 */
2222 #define SD_SWITCH 6 /* adtc [31:0] See below R1 */
2323
24+ /* class 5 */
25+#define SD_ERASE_WR_BLK_START 32 /* ac [31:0] data addr R1 */
26+#define SD_ERASE_WR_BLK_END 33 /* ac [31:0] data addr R1 */
27+
2428 /* Application commands */
2529 #define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
30+#define SD_APP_SD_STATUS 13 /* adtc R1 */
2631 #define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */
2732 #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */
2833 #define SD_APP_SEND_SCR 51 /* adtc R1 */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t