aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@nokia.com>2010-08-11 17:17:46 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-12 11:43:30 -0400
commitdfe86cba7676d58db8de7e623f5e72f1b0d3ca35 (patch)
treeed7e6a267c50e0ba2374dc6895515d7a100961a3 /include
parent81d73a32d775ae9674ea6edf0b5b721fc3bc57d9 (diff)
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>
Diffstat (limited to 'include')
-rw-r--r--include/linux/mmc/card.h20
-rw-r--r--include/linux/mmc/core.h19
-rw-r--r--include/linux/mmc/host.h1
-rw-r--r--include/linux/mmc/mmc.h26
-rw-r--r--include/linux/mmc/sd.h5
5 files changed, 64 insertions, 7 deletions
diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
index 4d893eaf8174..6b7525099e56 100644
--- a/include/linux/mmc/card.h
+++ b/include/linux/mmc/card.h
@@ -31,6 +31,7 @@ struct mmc_csd {
31 unsigned int tacc_ns; 31 unsigned int tacc_ns;
32 unsigned int r2w_factor; 32 unsigned int r2w_factor;
33 unsigned int max_dtr; 33 unsigned int max_dtr;
34 unsigned int erase_size; /* In sectors */
34 unsigned int read_blkbits; 35 unsigned int read_blkbits;
35 unsigned int write_blkbits; 36 unsigned int write_blkbits;
36 unsigned int capacity; 37 unsigned int capacity;
@@ -42,9 +43,16 @@ struct mmc_csd {
42 43
43struct mmc_ext_csd { 44struct mmc_ext_csd {
44 u8 rev; 45 u8 rev;
46 u8 erase_group_def;
47 u8 sec_feature_support;
45 unsigned int sa_timeout; /* Units: 100ns */ 48 unsigned int sa_timeout; /* Units: 100ns */
46 unsigned int hs_max_dtr; 49 unsigned int hs_max_dtr;
47 unsigned int sectors; 50 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 */
48}; 56};
49 57
50struct sd_scr { 58struct sd_scr {
@@ -54,6 +62,12 @@ struct sd_scr {
54#define SD_SCR_BUS_WIDTH_4 (1<<2) 62#define SD_SCR_BUS_WIDTH_4 (1<<2)
55}; 63};
56 64
65struct sd_ssr {
66 unsigned int au; /* In sectors */
67 unsigned int erase_timeout; /* In milliseconds */
68 unsigned int erase_offset; /* In milliseconds */
69};
70
57struct sd_switch_caps { 71struct sd_switch_caps {
58 unsigned int hs_max_dtr; 72 unsigned int hs_max_dtr;
59}; 73};
@@ -106,6 +120,11 @@ struct mmc_card {
106#define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */ 120#define MMC_QUIRK_NONSTD_SDIO (1<<2) /* non-standard SDIO card attached */
107 /* (missing CIA registers) */ 121 /* (missing CIA registers) */
108 122
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
109 u32 raw_cid[4]; /* raw card CID */ 128 u32 raw_cid[4]; /* raw card CID */
110 u32 raw_csd[4]; /* raw card CSD */ 129 u32 raw_csd[4]; /* raw card CSD */
111 u32 raw_scr[2]; /* raw card SCR */ 130 u32 raw_scr[2]; /* raw card SCR */
@@ -113,6 +132,7 @@ struct mmc_card {
113 struct mmc_csd csd; /* card specific */ 132 struct mmc_csd csd; /* card specific */
114 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */ 133 struct mmc_ext_csd ext_csd; /* mmc v4 extended card specific */
115 struct sd_scr scr; /* extra SD information */ 134 struct sd_scr scr; /* extra SD information */
135 struct sd_ssr ssr; /* yet more SD information */
116 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ 136 struct sd_switch_caps sw_caps; /* switch (CMD6) caps */
117 137
118 unsigned int sdio_funcs; /* number of SDIO functions */ 138 unsigned int sdio_funcs; /* number of SDIO functions */
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index e4898e9eeb59..7429033acb66 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -92,6 +92,8 @@ struct mmc_command {
92 * actively failing requests 92 * actively failing requests
93 */ 93 */
94 94
95 unsigned int erase_timeout; /* in milliseconds */
96
95 struct mmc_data *data; /* data segment associated with cmd */ 97 struct mmc_data *data; /* data segment associated with cmd */
96 struct mmc_request *mrq; /* associated request */ 98 struct mmc_request *mrq; /* associated request */
97}; 99};
@@ -134,6 +136,23 @@ extern int mmc_wait_for_cmd(struct mmc_host *, struct mmc_command *, int);
134extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *, 136extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
135 struct mmc_command *, int); 137 struct mmc_command *, int);
136 138
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
148extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
149 unsigned int arg);
150extern int mmc_can_erase(struct mmc_card *card);
151extern int mmc_can_trim(struct mmc_card *card);
152extern int mmc_can_secure_erase_trim(struct mmc_card *card);
153extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
154 unsigned int nr);
155
137extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *); 156extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
138extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int); 157extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
139 158
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 513ff0376b09..1575b52c3bfa 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -156,6 +156,7 @@ struct mmc_host {
156#define MMC_CAP_DISABLE (1 << 7) /* Can the host be disabled */ 156#define MMC_CAP_DISABLE (1 << 7) /* Can the host be disabled */
157#define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */ 157#define MMC_CAP_NONREMOVABLE (1 << 8) /* Nonremovable e.g. eMMC */
158#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */ 158#define MMC_CAP_WAIT_WHILE_BUSY (1 << 9) /* Waits while card is busy */
159#define MMC_CAP_ERASE (1 << 10) /* Allow erase/trim commands */
159 160
160 mmc_pm_flag_t pm_caps; /* supported pm features */ 161 mmc_pm_flag_t pm_caps; /* supported pm features */
161 162
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 52ce98866287..dd11ae51fb68 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -251,13 +251,21 @@ struct _mmc_csd {
251 * EXT_CSD fields 251 * EXT_CSD fields
252 */ 252 */
253 253
254#define EXT_CSD_BUS_WIDTH 183 /* R/W */ 254#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
255#define EXT_CSD_HS_TIMING 185 /* R/W */ 255#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */
256#define EXT_CSD_CARD_TYPE 196 /* RO */ 256#define EXT_CSD_BUS_WIDTH 183 /* R/W */
257#define EXT_CSD_STRUCTURE 194 /* RO */ 257#define EXT_CSD_HS_TIMING 185 /* R/W */
258#define EXT_CSD_REV 192 /* RO */ 258#define EXT_CSD_REV 192 /* RO */
259#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ 259#define EXT_CSD_STRUCTURE 194 /* RO */
260#define EXT_CSD_S_A_TIMEOUT 217 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 */
261 269
262/* 270/*
263 * EXT_CSD field definitions 271 * EXT_CSD field definitions
@@ -275,6 +283,10 @@ struct _mmc_csd {
275#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ 283#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */
276#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ 284#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */
277 285
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
278/* 290/*
279 * MMC_SWITCH access modes 291 * MMC_SWITCH access modes
280 */ 292 */
diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h
index f310062cffb4..3fd85e088cc3 100644
--- a/include/linux/mmc/sd.h
+++ b/include/linux/mmc/sd.h
@@ -21,8 +21,13 @@
21 /* class 10 */ 21 /* class 10 */
22#define SD_SWITCH 6 /* adtc [31:0] See below R1 */ 22#define SD_SWITCH 6 /* adtc [31:0] See below R1 */
23 23
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
24 /* Application commands */ 28 /* Application commands */
25#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ 29#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */
30#define SD_APP_SD_STATUS 13 /* adtc R1 */
26#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ 31#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */
27#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ 32#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */
28#define SD_APP_SEND_SCR 51 /* adtc R1 */ 33#define SD_APP_SEND_SCR 51 /* adtc R1 */