Skip to contentSkip to conversation

mmc: fixes for eMMC v4.5 discard / sanitize operations

PATCH In review Adrian Hunter 4 participants 6 messages Apr 5, 2012 – Apr 9, 2012 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

cover mmc: fixes for eMMC v4.5 discard / sanitize operations

Hi

Here are patches in response to the thread "mmc: card: move variable initialization earlier"

The patches have not been tested on eMMC v4.5 because I do not have one. Consequently, these patches need an ack or tested-by someone who has one that supports discard and sanitize.

Adrian Hunter (2):
mmc: fixes for eMMC v4.5 discard operation
mmc: fixes for eMMC v4.5 sanitize operation

 drivers/mmc/card/block.c |   54 ++++++++++++++++++++++++++++++++-------------
 drivers/mmc/card/queue.c |    2 +-
 drivers/mmc/core/core.c  |    9 +++++--
 3 files changed, 45 insertions(+), 20 deletions(-)

Regards
Adrian

#1 lore raw

PATCH 1/2 mmc: fixes for eMMC v4.5 discard operation

eMMC v4.5 discard operation is significantly different from the existing trim operation because it is not guaranteed to work with the new sanitize operation. Consequently mmc_can_trim() is separated from mmc_can_discard().

Also the new discard operation does not result in the sectors being set to all-zeros, so discard_zeroes_data must not be set.

In addition, the new discard has the same timeout as trim, but from v4.5 trim is defined to use the hc timeout. The timeout calculation is adjusted accordingly.

Fixes apply to linux 3.2 on.

---
 drivers/mmc/card/queue.c |    2 +-
 drivers/mmc/core/core.c  |    7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/mmc/card/queue.c +1 -1
index 2517547..996f8e3 100644
@@ -139,7 +139,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
 
 	queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
 	q->limits.max_discard_sectors = max_discard;
-	if (card->erased_byte == 0)
+	if (card->erased_byte == 0 && !mmc_can_discard(card))
 		q->limits.discard_zeroes_data = 1;
 	q->limits.discard_granularity = card->pref_erase << 9;
 	/* granularity must not be greater than max. discard */
drivers/mmc/core/core.c +4 -3
index 14f262e..8a9f286 100644
@@ -1405,7 +1405,10 @@ static unsigned int mmc_mmc_erase_timeout(struct mmc_card *card,
 {
 	unsigned int erase_timeout;
 
-	if (card->ext_csd.erase_group_def & 1) {
+	if (arg == MMC_DISCARD_ARG ||
+	    (arg == MMC_TRIM_ARG && card->ext_csd.rev >= 6)) {
+		erase_timeout = card->ext_csd.trim_timeout;
+	} else if (card->ext_csd.erase_group_def & 1) {
 		/* High Capacity Erase Group Size uses HC timeouts */
 		if (arg == MMC_TRIM_ARG)
 			erase_timeout = card->ext_csd.trim_timeout;
@@ -1677,8 +1680,6 @@ int mmc_can_trim(struct mmc_card *card)
 {
 	if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_GB_CL_EN)
 		return 1;
-	if (mmc_can_discard(card))
-		return 1;
 	return 0;
 }
 EXPORT_SYMBOL(mmc_can_trim);
Signature · 1 line
1.7.6.5
#2 lore raw

PATCH 2/2 mmc: fixes for eMMC v4.5 sanitize operation

In reply to Adrian Hunter

eMMC v4.5 sanitize operation erases all copies of unmapped data. However trim or erase operations must be used first to unmap the required sectors. That was not being done.

Fixes apply to linux 3.2 on.

---
 drivers/mmc/card/block.c |   54 ++++++++++++++++++++++++++++++++-------------
 drivers/mmc/core/core.c  |    2 +
 2 files changed, 40 insertions(+), 16 deletions(-)
drivers/mmc/card/block.c +38 -16
index b180965..4232bc4 100644
@@ -873,7 +873,7 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
 {
 	struct mmc_blk_data *md = mq->data;
 	struct mmc_card *card = md->queue.card;
-	unsigned int from, nr, arg;
+	unsigned int from, nr, arg, trim_arg, erase_arg;
 	int err = 0, type = MMC_BLK_SECDISCARD;
 
 	if (!(mmc_can_secure_erase_trim(card) || mmc_can_sanitize(card))) {
@@ -881,20 +881,26 @@ static int mmc_blk_issue_secdiscard_rq(struct mmc_queue *mq,
 		goto out;
 	}
 
+	from = blk_rq_pos(req);
+	nr = blk_rq_sectors(req);
+
 	/* The sanitize operation is supported at v4.5 only */
 	if (mmc_can_sanitize(card)) {
-		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-				EXT_CSD_SANITIZE_START, 1, 0);
-		goto out;
+		erase_arg = MMC_ERASE_ARG;
+		trim_arg = MMC_TRIM_ARG;
+	} else {
+		erase_arg = MMC_SECURE_ERASE_ARG;
+		trim_arg = MMC_SECURE_TRIM1_ARG;
 	}
 
-	from = blk_rq_pos(req);
-	nr = blk_rq_sectors(req);
-
-	if (mmc_can_trim(card) && !mmc_erase_group_aligned(card, from, nr))
-		arg = MMC_SECURE_TRIM1_ARG;
-	else
-		arg = MMC_SECURE_ERASE_ARG;
+	if (mmc_erase_group_aligned(card, from, nr))
+		arg = erase_arg;
+	else if (mmc_can_trim(card))
+		arg = trim_arg;
+	else {
+		err = -EINVAL;
+		goto out;
+	}
 retry:
 	if (card->quirks & MMC_QUIRK_INAND_CMD38) {
 		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
@@ -904,25 +910,41 @@ retry:
 				 INAND_CMD38_ARG_SECERASE,
 				 0);
 		if (err)
-			goto out;
+			goto out_retry;
 	}
+
 	err = mmc_erase(card, from, nr, arg);
-	if (!err && arg == MMC_SECURE_TRIM1_ARG) {
+	if (err == -EIO)
+		goto out_retry;
+	if (err)
+		goto out;
+
+	if (arg == MMC_SECURE_TRIM1_ARG) {
 		if (card->quirks & MMC_QUIRK_INAND_CMD38) {
 			err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
 					 INAND_CMD38_ARG_EXT_CSD,
 					 INAND_CMD38_ARG_SECTRIM2,
 					 0);
 			if (err)
-				goto out;
+				goto out_retry;
 		}
+
 		err = mmc_erase(card, from, nr, MMC_SECURE_TRIM2_ARG);
+		if (err == -EIO)
+			goto out_retry;
+		if (err)
+			goto out;
 	}
-out:
-	if (err == -EIO && !mmc_blk_reset(md, card->host, type))
+
+	if (mmc_can_sanitize(card))
+		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
+				 EXT_CSD_SANITIZE_START, 1, 0);
+out_retry:
+	if (err && !mmc_blk_reset(md, card->host, type))
 		goto retry;
 	if (!err)
 		mmc_blk_reset_success(md, type);
+out:
 	spin_lock_irq(&md->lock);
 	__blk_end_request(req, err, blk_rq_bytes(req));
 	spin_unlock_irq(&md->lock);
drivers/mmc/core/core.c +2 -0
index 8a9f286..50eb323 100644
@@ -1698,6 +1698,8 @@ EXPORT_SYMBOL(mmc_can_discard);
 
 int mmc_can_sanitize(struct mmc_card *card)
 {
+	if (!mmc_can_trim(card) && !mmc_can_erase(card))
+		return 0;
 	if (card->ext_csd.sec_feature_support & EXT_CSD_SEC_SANITIZE)
 		return 1;
 	return 0;
Signature · 1 line
1.7.6.5
Acked-by on the v1 series
#3 lore raw
In reply to Adrian Hunter

Hi Adrian.

This patch is make sense.
It looks fine to me.
I tested with eMMC4.5 and triggered the secdiscard/discard with ioctl. (But i didn't have the iNAND.)

Best Regards,
Jaehoon Chung

Quoted 28 lines · Adrian Hunter

Hi

Here are patches in response to the thread
"mmc: card: move variable initialization earlier"

The patches have not been tested on eMMC v4.5
because I do not have one. Consequently, these
patches need an ack or tested-by someone who has
one that supports discard and sanitize.

Adrian Hunter (2):
mmc: fixes for eMMC v4.5 discard operation
mmc: fixes for eMMC v4.5 sanitize operation

 drivers/mmc/card/block.c |   54 ++++++++++++++++++++++++++++++++-------------
 drivers/mmc/card/queue.c |    2 +-
 drivers/mmc/core/core.c  |    9 +++++--
 3 files changed, 45 insertions(+), 20 deletions(-)

Regards
Adrian
--
To unsubscribe from this list: send the line "unsubscribe linux-mmc" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#5 lore raw
In reply to Adrian Hunter

Hi,

Quoted 9 lines · Adrian Hunter

Here are patches in response to the thread "mmc: card: move variable initialization earlier"

The patches have not been tested on eMMC v4.5 because I do not have one. Consequently, these patches need an ack or tested-by someone who has one that supports discard and sanitize.

Quoted 8 lines

Adrian Hunter (2):
mmc: fixes for eMMC v4.5 discard operation
mmc: fixes for eMMC v4.5 sanitize operation

 drivers/mmc/card/block.c |   54 ++++++++++++++++++++++++++++++++-------------
 drivers/mmc/card/queue.c |    2 +-
 drivers/mmc/core/core.c  |    9 +++++--
 3 files changed, 45 insertions(+), 20 deletions(-)

Thanks very much, Adrian, pushed to mmc-next with ACKs from Jaehoon and Linus W.

I'm not sure whether to merge these for 3.4, or let them soak until the 3.5 window opens given how scarce the 4.5 devices are. Opinions welcome; I'm thinking about waiting until 3.5 if no-one feels strongly.

- Chris.

Signature · 2 lines
Chris Ball   <[email protected]>   <http://printf.net/>
One Laptop Per Child