Skip to contentSkip to conversation

mmc: add erase, secure erase, trim and secure trim operations

PATCH New [email protected] 1 participant 1 message Aug 11, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 15/24 mmc: add erase, secure erase, trim and secure trim operations

From: Adrian Hunter <[email protected]>

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.

Cc Kyungmin Park <[email protected]>
Cc Madhusudhan Chikkature <[email protected]>
Cc Christoph Hellwig <[email protected]>
Cc Ben Gardiner <[email protected]>

---

 Documentation/00-INDEX              |    2 
 Documentation/mmc/00-INDEX          |    4 
 Documentation/mmc/mmc-dev-attrs.txt |   56 ++++
 drivers/mmc/core/core.c             |  346 ++++++++++++++++++++++++++
 drivers/mmc/core/core.h             |    2 
 drivers/mmc/core/mmc.c              |   47 +++
 drivers/mmc/core/sd.c               |   82 ++++++
 drivers/mmc/core/sd_ops.c           |   48 +++
 drivers/mmc/core/sd_ops.h           |    1 
 include/linux/mmc/card.h            |   20 +
 include/linux/mmc/core.h            |   19 +
 include/linux/mmc/host.h            |    1 
 include/linux/mmc/mmc.h             |   26 +
 include/linux/mmc/sd.h              |    5 
 14 files changed, 651 insertions(+), 8 deletions(-)
Documentation/00-INDEX renamed from Documentation/00-INDEX~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +2 -0
diff -puN Documentation/00-INDEX~mmc-add-erase-secure-erase-trim-and-secure-trim-operations Documentation/00-INDEX
@@ -232,6 +232,8 @@ memory.txt
 	- info on typical Linux memory problems.
 mips/
 	- directory with info about Linux on MIPS architecture.
+mmc/
+	- directory with info about the MMC subsystem
 mono.txt
 	- how to execute Mono-based .NET binaries with the help of BINFMT_MISC.
 mutex-design.txt
Documentation/mmc/00-INDEX new file +4 -0
diff -puN /dev/null Documentation/mmc/00-INDEX
@@ -0,0 +1,4 @@
+00-INDEX
+        - this file
+mmc-dev-attrs.txt
+        - info on SD and MMC device attributes
Documentation/mmc/mmc-dev-attrs.txt new file +56 -0

56 lines not on this page · raw message

drivers/mmc/core/core.c renamed from drivers/mmc/core/core.c~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +346 -0

352 lines not on this page · raw message

drivers/mmc/core/core.h renamed from drivers/mmc/core/core.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +2 -0
diff -puN drivers/mmc/core/core.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations drivers/mmc/core/core.h
@@ -29,6 +29,8 @@ struct mmc_bus_ops {
 void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops);
 void mmc_detach_bus(struct mmc_host *host);
 
+void mmc_init_erase(struct mmc_card *card);
+
 void mmc_set_chip_select(struct mmc_host *host, int mode);
 void mmc_set_clock(struct mmc_host *host, unsigned int hz);
 void mmc_set_bus_mode(struct mmc_host *host, unsigned int mode);
drivers/mmc/core/mmc.c renamed from drivers/mmc/core/mmc.c~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +46 -1

91 lines not on this page · raw message

drivers/mmc/core/sd.c renamed from drivers/mmc/core/sd.c~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +82 -0

128 lines not on this page · raw message

drivers/mmc/core/sd_ops.c renamed from drivers/mmc/core/sd_ops.c~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +48 -0

51 lines not on this page · raw message

drivers/mmc/core/sd_ops.h renamed from drivers/mmc/core/sd_ops.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +1 -0
diff -puN drivers/mmc/core/sd_ops.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations drivers/mmc/core/sd_ops.h
@@ -19,6 +19,7 @@ int mmc_send_relative_addr(struct mmc_ho
 int mmc_app_send_scr(struct mmc_card *card, u32 *scr);
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp);
+int mmc_app_sd_status(struct mmc_card *card, void *ssr);
 
 #endif
 
include/linux/mmc/card.h renamed from include/linux/mmc/card.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +20 -0
diff -puN include/linux/mmc/card.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations include/linux/mmc/card.h
@@ -31,6 +31,7 @@ struct mmc_csd {
 	unsigned int		tacc_ns;
 	unsigned int		r2w_factor;
 	unsigned int		max_dtr;
+	unsigned int		erase_size;		/* In sectors */
 	unsigned int		read_blkbits;
 	unsigned int		write_blkbits;
 	unsigned int		capacity;
@@ -42,9 +43,16 @@ struct mmc_csd {
 
 struct mmc_ext_csd {
 	u8			rev;
+	u8			erase_group_def;
+	u8			sec_feature_support;
 	unsigned int		sa_timeout;		/* Units: 100ns */
 	unsigned int		hs_max_dtr;
 	unsigned int		sectors;
+	unsigned int		hc_erase_size;		/* In sectors */
+	unsigned int		hc_erase_timeout;	/* In milliseconds */
+	unsigned int		sec_trim_mult;	/* Secure trim multiplier  */
+	unsigned int		sec_erase_mult;	/* Secure erase multiplier */
+	unsigned int		trim_timeout;		/* In milliseconds */
 };
 
 struct sd_scr {
@@ -54,6 +62,12 @@ struct sd_scr {
 #define SD_SCR_BUS_WIDTH_4	(1<<2)
 };
 
+struct sd_ssr {
+	unsigned int		au;			/* In sectors */
+	unsigned int		erase_timeout;		/* In milliseconds */
+	unsigned int		erase_offset;		/* In milliseconds */
+};
+
 struct sd_switch_caps {
 	unsigned int		hs_max_dtr;
 };
@@ -106,6 +120,11 @@ struct mmc_card {
 #define MMC_QUIRK_NONSTD_SDIO	(1<<2)		/* non-standard SDIO card attached */
 						/* (missing CIA registers) */
 
+	unsigned int		erase_size;	/* erase size in sectors */
+ 	unsigned int		erase_shift;	/* if erase unit is power 2 */
+ 	unsigned int		pref_erase;	/* in sectors */
+ 	u8			erased_byte;	/* value of erased bytes */
+
 	u32			raw_cid[4];	/* raw card CID */
 	u32			raw_csd[4];	/* raw card CSD */
 	u32			raw_scr[2];	/* raw card SCR */
@@ -113,6 +132,7 @@ struct mmc_card {
 	struct mmc_csd		csd;		/* card specific */
 	struct mmc_ext_csd	ext_csd;	/* mmc v4 extended card specific */
 	struct sd_scr		scr;		/* extra SD information */
+	struct sd_ssr		ssr;		/* yet more SD information */
 	struct sd_switch_caps	sw_caps;	/* switch (CMD6) caps */
 
 	unsigned int		sdio_funcs;	/* number of SDIO functions */
include/linux/mmc/core.h renamed from include/linux/mmc/core.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +19 -0
diff -puN include/linux/mmc/core.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations include/linux/mmc/core.h
@@ -92,6 +92,8 @@ struct mmc_command {
  *              actively failing requests
  */
 
+	unsigned int		erase_timeout;	/* in milliseconds */
+
 	struct mmc_data		*data;		/* data segment associated with cmd */
 	struct mmc_request	*mrq;		/* associated request */
 };
@@ -134,6 +136,23 @@ extern int mmc_wait_for_cmd(struct mmc_h
 extern int mmc_wait_for_app_cmd(struct mmc_host *, struct mmc_card *,
 	struct mmc_command *, int);
 
+#define MMC_ERASE_ARG		0x00000000
+#define MMC_SECURE_ERASE_ARG	0x80000000
+#define MMC_TRIM_ARG		0x00000001
+#define MMC_SECURE_TRIM1_ARG	0x80000001
+#define MMC_SECURE_TRIM2_ARG	0x80008000
+
+#define MMC_SECURE_ARGS		0x80000000
+#define MMC_TRIM_ARGS		0x00008001
+
+extern int mmc_erase(struct mmc_card *card, unsigned int from, unsigned int nr,
+		     unsigned int arg);
+extern int mmc_can_erase(struct mmc_card *card);
+extern int mmc_can_trim(struct mmc_card *card);
+extern int mmc_can_secure_erase_trim(struct mmc_card *card);
+extern int mmc_erase_group_aligned(struct mmc_card *card, unsigned int from,
+				   unsigned int nr);
+
 extern void mmc_set_data_timeout(struct mmc_data *, const struct mmc_card *);
 extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int);
 
include/linux/mmc/host.h renamed from include/linux/mmc/host.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +1 -0
diff -puN include/linux/mmc/host.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations include/linux/mmc/host.h
@@ -156,6 +156,7 @@ struct mmc_host {
 #define MMC_CAP_DISABLE		(1 << 7)	/* Can the host be disabled */
 #define MMC_CAP_NONREMOVABLE	(1 << 8)	/* Nonremovable e.g. eMMC */
 #define MMC_CAP_WAIT_WHILE_BUSY	(1 << 9)	/* Waits while card is busy */
+#define MMC_CAP_ERASE		(1 << 10)	/* Allow erase/trim commands */
 
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
 
include/linux/mmc/mmc.h renamed from include/linux/mmc/mmc.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +19 -7
diff -puN include/linux/mmc/mmc.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations include/linux/mmc/mmc.h
@@ -251,13 +251,21 @@ struct _mmc_csd {
  * EXT_CSD fields
  */
 
-#define EXT_CSD_BUS_WIDTH	183	/* R/W */
-#define EXT_CSD_HS_TIMING	185	/* R/W */
-#define EXT_CSD_CARD_TYPE	196	/* RO */
-#define EXT_CSD_STRUCTURE	194	/* RO */
-#define EXT_CSD_REV		192	/* RO */
-#define EXT_CSD_SEC_CNT		212	/* RO, 4 bytes */
-#define EXT_CSD_S_A_TIMEOUT	217
+#define EXT_CSD_ERASE_GROUP_DEF		175	/* R/W */
+#define EXT_CSD_ERASED_MEM_CONT		181	/* RO */
+#define EXT_CSD_BUS_WIDTH		183	/* R/W */
+#define EXT_CSD_HS_TIMING		185	/* R/W */
+#define EXT_CSD_REV			192	/* RO */
+#define EXT_CSD_STRUCTURE		194	/* RO */
+#define EXT_CSD_CARD_TYPE		196	/* RO */
+#define EXT_CSD_SEC_CNT			212	/* RO, 4 bytes */
+#define EXT_CSD_S_A_TIMEOUT		217	/* RO */
+#define EXT_CSD_ERASE_TIMEOUT_MULT	223	/* RO */
+#define EXT_CSD_HC_ERASE_GRP_SIZE	224	/* RO */
+#define EXT_CSD_SEC_TRIM_MULT		229	/* RO */
+#define EXT_CSD_SEC_ERASE_MULT		230	/* RO */
+#define EXT_CSD_SEC_FEATURE_SUPPORT	231	/* RO */
+#define EXT_CSD_TRIM_MULT		232	/* RO */
 
 /*
  * EXT_CSD field definitions
@@ -275,6 +283,10 @@ struct _mmc_csd {
 #define EXT_CSD_BUS_WIDTH_4	1	/* Card is in 4 bit mode */
 #define EXT_CSD_BUS_WIDTH_8	2	/* Card is in 8 bit mode */
 
+#define EXT_CSD_SEC_ER_EN	BIT(0)
+#define EXT_CSD_SEC_BD_BLK_EN	BIT(2)
+#define EXT_CSD_SEC_GB_CL_EN	BIT(4)
+
 /*
  * MMC_SWITCH access modes
  */
include/linux/mmc/sd.h renamed from include/linux/mmc/sd.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations +5 -0
diff -puN include/linux/mmc/sd.h~mmc-add-erase-secure-erase-trim-and-secure-trim-operations include/linux/mmc/sd.h
@@ -21,8 +21,13 @@
   /* class 10 */
 #define SD_SWITCH                 6   /* adtc [31:0] See below   R1  */
 
+  /* class 5 */
+#define SD_ERASE_WR_BLK_START    32   /* ac   [31:0] data addr   R1  */
+#define SD_ERASE_WR_BLK_END      33   /* ac   [31:0] data addr   R1  */
+
   /* Application commands */
 #define SD_APP_SET_BUS_WIDTH      6   /* ac   [1:0] bus width    R1  */
+#define SD_APP_SD_STATUS         13   /* adtc                    R1  */
 #define SD_APP_SEND_NUM_WR_BLKS  22   /* adtc                    R1  */
 #define SD_APP_OP_COND           41   /* bcr  [31:0] OCR         R3  */
 #define SD_APP_SEND_SCR          51   /* adtc                    R1  */

_