Skip to contentSkip to conversation

mmc: block: use single block write in retry

PATCH Superseded Bin Liu 4 participants 35 messages Mar 10 – Apr 9

Subsystems (2)
lore
Share & tools
lore

Bin Liu

author
#0 lore raw

PATCH 1/1 mmc: block: use single block write in retry

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

[0] https://www.ti.com/lit/pdf/sprz582

---
 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
 	RQF_NAME(ZONE_WRITE_PLUGGING),
 	RQF_NAME(TIMED_OUT),
 	RQF_NAME(RESV),
+	RQF_NAME(XFER_SINGLE_BLK),
 };
 #undef RQF_NAME
 
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 		    rq_data_dir(req) == WRITE &&
 		    (md->flags & MMC_BLK_REL_WR);
 
+	if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+		recovery_mode = 1;
+
 	memset(brq, 0, sizeof(struct mmc_blk_request));
 
 	mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
 		err = 0;
 
 	if (err) {
-		if (mqrq->retries++ < MMC_CQE_RETRIES)
+		if (mqrq->retries++ < MMC_CQE_RETRIES) {
+			if (rq_data_dir(req) == WRITE)
+				req->rq_flags |= RQF_XFER_SINGLE_BLK;
 			blk_mq_requeue_request(req, true);
-		else
+		} else {
 			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
 	} else if (mrq->data) {
 		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
 			blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
 	} else if (!blk_rq_bytes(req)) {
 		__blk_mq_end_request(req, BLK_STS_IOERR);
 	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		if (rq_data_dir(req) == WRITE)
+			req->rq_flags |= RQF_XFER_SINGLE_BLK;
 		blk_mq_requeue_request(req, true);
 	} else {
 		if (mmc_card_removed(mq->card))
include/linux/blk-mq.h +3 -0
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
 	/* ->timeout has been called, don't expire again */
 	__RQF_TIMED_OUT,
 	__RQF_RESV,
+	__RQF_XFER_SINGLE_BLK,
 	__RQF_BITS
 };
 
@@ -85,6 +86,8 @@ enum rqf_flags {
 			((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
 #define RQF_TIMED_OUT		((__force req_flags_t)(1 << __RQF_TIMED_OUT))
 #define RQF_RESV		((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK	\
+			((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
Signature · 1 line
2.34.1
#1 lore raw
Quoted 8 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

[0] https://www.ti.com/lit/pdf/sprz582

It's great that a link like the above can be provided, still it would be nice to explain a bit more about the problem in the commit message too. Can you please do that?

Quoted 24 lines
---
 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
        RQF_NAME(ZONE_WRITE_PLUGGING),
        RQF_NAME(TIMED_OUT),
        RQF_NAME(RESV),
+       RQF_NAME(XFER_SINGLE_BLK),
 };
 #undef RQF_NAME
 
drivers/mmc/core/block.c +0 -0
index 05ee76cb0a08..00016584d70d 100644

drivers/mmc/core/block.c static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq, · line 1406

Quoted 6 lines
drivers/mmc/core/block.c +3 -0
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
                    rq_data_dir(req) == WRITE &&
                    (md->flags & MMC_BLK_REL_WR);
 
+       if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+               recovery_mode = 1;
+

I don't get this, sorry.

Under what circumstances do we need to fall back to using "single block"? Or is this just for debugging?

Quoted 50 lines
drivers/mmc/core/block.c +7 -2
        memset(brq, 0, sizeof(struct mmc_blk_request));
 
        mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
                err = 0;
 
        if (err) {
-               if (mqrq->retries++ < MMC_CQE_RETRIES)
+               if (mqrq->retries++ < MMC_CQE_RETRIES) {
+                       if (rq_data_dir(req) == WRITE)
+                               req->rq_flags |= RQF_XFER_SINGLE_BLK;
                        blk_mq_requeue_request(req, true);
-               else
+               } else {
                        blk_mq_end_request(req, BLK_STS_IOERR);
+               }
        } else if (mrq->data) {
                if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
                        blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
        } else if (!blk_rq_bytes(req)) {
                __blk_mq_end_request(req, BLK_STS_IOERR);
        } else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+               if (rq_data_dir(req) == WRITE)
+                       req->rq_flags |= RQF_XFER_SINGLE_BLK;
                blk_mq_requeue_request(req, true);
        } else {
                if (mmc_card_removed(mq->card))
include/linux/blk-mq.h +3 -1
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
        /* ->timeout has been called, don't expire again */
        __RQF_TIMED_OUT,
        __RQF_RESV,
+       __RQF_XFER_SINGLE_BLK,
        __RQF_BITS
 };
 
@@ -85,6 +86,8 @@ enum rqf_flags {
                        ((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
 #define RQF_TIMED_OUT          ((__force req_flags_t)(1 << __RQF_TIMED_OUT))
 #define RQF_RESV               ((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK    \
+                       ((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
--
Quoted 2 lines

2.34.1

Kind regards
Uffe

author
#2 lore raw

Hi Ulf,

Quoted 8 lines · Ulf Hansson
Quoted 7 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

Quoted 5 lines
Quoted 1 line

[0] https://www.ti.com/lit/pdf/sprz582

It's great that a link like the above can be provided, still it would be nice to explain a bit more about the problem in the commit message too. Can you please do that?

Sure I will add the errata details in the commit message in v2.

Quoted 28 lines
Quoted 28 lines
---
 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
        RQF_NAME(ZONE_WRITE_PLUGGING),
        RQF_NAME(TIMED_OUT),
        RQF_NAME(RESV),
+       RQF_NAME(XFER_SINGLE_BLK),
 };
 #undef RQF_NAME
 
drivers/mmc/core/block.c +0 -0
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
                    rq_data_dir(req) == WRITE &&
                    (md->flags & MMC_BLK_REL_WR);
 
Quoted 5 lines

drivers/mmc/core/block.c static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq, · line 1406

Quoted 3 lines
drivers/mmc/core/block.c +3 -0
+       if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+               recovery_mode = 1;
+

I don't get this, sorry.

No worries, the logic of this solution is not that obvious.

In summary of this patch, in both CQE-enabled and non-CQE cases, in *_complete_rq(), flag RQF_XFER_SINGLE_BLK is set in req->rq_flags when WRITE request fails. This is to mark that single-block write, according to errata i2493, should be used in retrying this WRITE request.

In retrying, mmc_blk_data_prep() is called again with RQF_XFER_SINGLE_BLK set, this makes recovery_mode to be forced to 1,

then a few lines down in mmc_blk_data_prep():

	if (recovery_mode)
		brq->data.blocks = queue_physical_block_size(mq->queue) >> 9;

The req block size is set to 1 to use single block write.

Please let me know if this explains the logic of this patch.

Quoted 3 lines

Under what circumstances do we need to fall back to using "single block"? Or is this just for debugging?

When multiple block write fails, use single block write. This is the software workaround documented in the errata i2493.

This is not for debugging. When multiple block write fails, switching to single block write will sccuseed.

-Bin.

Quoted 56 lines
Quoted 51 lines
drivers/mmc/core/block.c +7 -2
        memset(brq, 0, sizeof(struct mmc_blk_request));
 
        mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
                err = 0;
 
        if (err) {
-               if (mqrq->retries++ < MMC_CQE_RETRIES)
+               if (mqrq->retries++ < MMC_CQE_RETRIES) {
+                       if (rq_data_dir(req) == WRITE)
+                               req->rq_flags |= RQF_XFER_SINGLE_BLK;
                        blk_mq_requeue_request(req, true);
-               else
+               } else {
                        blk_mq_end_request(req, BLK_STS_IOERR);
+               }
        } else if (mrq->data) {
                if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
                        blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
        } else if (!blk_rq_bytes(req)) {
                __blk_mq_end_request(req, BLK_STS_IOERR);
        } else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+               if (rq_data_dir(req) == WRITE)
+                       req->rq_flags |= RQF_XFER_SINGLE_BLK;
                blk_mq_requeue_request(req, true);
        } else {
                if (mmc_card_removed(mq->card))
include/linux/blk-mq.h +3 -1
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
        /* ->timeout has been called, don't expire again */
        __RQF_TIMED_OUT,
        __RQF_RESV,
+       __RQF_XFER_SINGLE_BLK,
        __RQF_BITS
 };
 
@@ -85,6 +86,8 @@ enum rqf_flags {
                        ((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
 #define RQF_TIMED_OUT          ((__force req_flags_t)(1 << __RQF_TIMED_OUT))
 #define RQF_RESV               ((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK    \
+                       ((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
--
Quoted 2 lines

2.34.1

Kind regards
Uffe

#3 lore raw
Quoted 12 lines · Bin Liu

Hi Ulf,

Quoted 8 lines · Ulf Hansson
Quoted 7 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

Quoted 15 lines
Quoted 5 lines
Quoted 1 line

[0] https://www.ti.com/lit/pdf/sprz582

It's great that a link like the above can be provided, still it would be nice to explain a bit more about the problem in the commit message too. Can you please do that?

Sure I will add the errata details in the commit message in v2.

Quoted 7 lines
Quoted 7 lines
---
 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)

Please split this patch into two, one for the blk-mq core and one for mmc core.

Quoted 37 lines
Quoted 21 lines
Quoted 21 lines
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
        RQF_NAME(ZONE_WRITE_PLUGGING),
        RQF_NAME(TIMED_OUT),
        RQF_NAME(RESV),
+       RQF_NAME(XFER_SINGLE_BLK),
 };
 #undef RQF_NAME
 
drivers/mmc/core/block.c +0 -0
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
                    rq_data_dir(req) == WRITE &&
                    (md->flags & MMC_BLK_REL_WR);
 
Quoted 5 lines

drivers/mmc/core/block.c static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq, · line 1406

Quoted 3 lines
drivers/mmc/core/block.c +3 -0
+       if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+               recovery_mode = 1;
+

I don't get this, sorry.

No worries, the logic of this solution is not that obvious.

In summary of this patch, in both CQE-enabled and non-CQE cases, in *_complete_rq(), flag RQF_XFER_SINGLE_BLK is set in req->rq_flags when WRITE request fails. This is to mark that single-block write, according to errata i2493, should be used in retrying this WRITE request.

In retrying, mmc_blk_data_prep() is called again with RQF_XFER_SINGLE_BLK set, this makes recovery_mode to be forced to 1,

Quoted 8 lines

then a few lines down in mmc_blk_data_prep():

        if (recovery_mode)
                brq->data.blocks = queue_physical_block_size(mq->queue) >> 9;

The req block size is set to 1 to use single block write.

Please let me know if this explains the logic of this patch.

Yes, that makes more sense now, thanks for clarifying!

Quoted 10 lines
Quoted 4 lines

Under what circumstances do we need to fall back to using "single block"? Or is this just for debugging?

When multiple block write fails, use single block write. This is the software workaround documented in the errata i2493.

This is not for debugging. When multiple block write fails, switching to single block write will sccuseed.

Okay, again, thanks for clarifying!

[...]

I noticed your conversation with Shawn, where he pointed out, that we already have something similar for READ, which is implemented internally within the mmc block device driver.

I don't have a strong opinion on how to do this, so assuming Jens is okay with the approach in $subject patch, I am happy to proceed.

If we decide to move forward with this, perhaps we should re-work the internal MMC fallback for READ to align with this approach too.

Kind regards
Uffe

#4 lore raw
In reply to Bin Liu
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

More importantly, what is the failure rate of this issue? If it occurs frequently, we should consider this a significant hardware defect. In that case, the host driver could register a multi_io_quirk to apply certain restrictions on the write path. This approach has been used previously on TI OMAP platforms.

Quoted 82 lines

[0] https://www.ti.com/lit/pdf/sprz582

---
  block/blk-mq-debugfs.c   |  1 +
  drivers/mmc/core/block.c | 12 ++++++++++--
  include/linux/blk-mq.h   |  3 +++
  3 files changed, 14 insertions(+), 2 deletions(-)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
  	RQF_NAME(ZONE_WRITE_PLUGGING),
  	RQF_NAME(TIMED_OUT),
  	RQF_NAME(RESV),
+	RQF_NAME(XFER_SINGLE_BLK),
  };
  #undef RQF_NAME
 
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
  		    rq_data_dir(req) == WRITE &&
  		    (md->flags & MMC_BLK_REL_WR);
 
+	if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+		recovery_mode = 1;
+
  	memset(brq, 0, sizeof(struct mmc_blk_request));
 
  	mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
  		err = 0;
 
  	if (err) {
-		if (mqrq->retries++ < MMC_CQE_RETRIES)
+		if (mqrq->retries++ < MMC_CQE_RETRIES) {
+			if (rq_data_dir(req) == WRITE)
+				req->rq_flags |= RQF_XFER_SINGLE_BLK;
  			blk_mq_requeue_request(req, true);
-		else
+		} else {
  			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
  	} else if (mrq->data) {
  		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
  			blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
  	} else if (!blk_rq_bytes(req)) {
  		__blk_mq_end_request(req, BLK_STS_IOERR);
  	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		if (rq_data_dir(req) == WRITE)
+			req->rq_flags |= RQF_XFER_SINGLE_BLK;
  		blk_mq_requeue_request(req, true);
  	} else {
  		if (mmc_card_removed(mq->card))
include/linux/blk-mq.h +3 -0
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
  	/* ->timeout has been called, don't expire again */
  	__RQF_TIMED_OUT,
  	__RQF_RESV,
+	__RQF_XFER_SINGLE_BLK,
  	__RQF_BITS
  };
 
@@ -85,6 +86,8 @@ enum rqf_flags {
  			((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
  #define RQF_TIMED_OUT		((__force req_flags_t)(1 << __RQF_TIMED_OUT))
  #define RQF_RESV		((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK	\
+			((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
 
  /* flags that prevent us from merging requests: */
  #define RQF_NOMERGE_FLAGS \
author
#5 lore raw

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

Quoted 4 lines

frequently, we should consider this a significant hardware defect. In that case, the host driver could register a multi_io_quirk to apply certain restrictions on the write path. This approach has been used previously on TI OMAP platforms.

-Bin.

Quoted 77 lines
Quoted 77 lines

[0] https://www.ti.com/lit/pdf/sprz582

---
  block/blk-mq-debugfs.c   |  1 +
  drivers/mmc/core/block.c | 12 ++++++++++--
  include/linux/blk-mq.h   |  3 +++
  3 files changed, 14 insertions(+), 2 deletions(-)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
  	RQF_NAME(ZONE_WRITE_PLUGGING),
  	RQF_NAME(TIMED_OUT),
  	RQF_NAME(RESV),
+	RQF_NAME(XFER_SINGLE_BLK),
  };
  #undef RQF_NAME
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
  		    rq_data_dir(req) == WRITE &&
  		    (md->flags & MMC_BLK_REL_WR);
+	if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+		recovery_mode = 1;
+
  	memset(brq, 0, sizeof(struct mmc_blk_request));
  	mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
  		err = 0;
  	if (err) {
-		if (mqrq->retries++ < MMC_CQE_RETRIES)
+		if (mqrq->retries++ < MMC_CQE_RETRIES) {
+			if (rq_data_dir(req) == WRITE)
+				req->rq_flags |= RQF_XFER_SINGLE_BLK;
  			blk_mq_requeue_request(req, true);
-		else
+		} else {
  			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
  	} else if (mrq->data) {
  		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
  			blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
  	} else if (!blk_rq_bytes(req)) {
  		__blk_mq_end_request(req, BLK_STS_IOERR);
  	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		if (rq_data_dir(req) == WRITE)
+			req->rq_flags |= RQF_XFER_SINGLE_BLK;
  		blk_mq_requeue_request(req, true);
  	} else {
  		if (mmc_card_removed(mq->card))
include/linux/blk-mq.h +3 -0
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
  	/* ->timeout has been called, don't expire again */
  	__RQF_TIMED_OUT,
  	__RQF_RESV,
+	__RQF_XFER_SINGLE_BLK,
  	__RQF_BITS
  };
@@ -85,6 +86,8 @@ enum rqf_flags {
  			((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
  #define RQF_TIMED_OUT		((__force req_flags_t)(1 << __RQF_TIMED_OUT))
  #define RQF_RESV		((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK	\
+			((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
  /* flags that prevent us from merging requests: */
  #define RQF_NOMERGE_FLAGS \
 
#6 lore raw
Quoted 24 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

Quoted 8 lines

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

drivers/mmc/core/block.c +26 -18
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue *mq, struct request *req)
 	return mmc_blk_cqe_start_req(mq->card->host, mrq);
 }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request *req, int recovery_mode)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
 	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
 	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
 	mmc_pre_req(host, &mqrq->brq.mrq);
 
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
 }
 
 static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req)
 	return err;
 }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_request *mrq = &mqrq->brq.mrq;
 	struct mmc_card *card = mq->card;
 	struct mmc_host *host = card->host;
 	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
 	do {
 		u32 status;
 		int err;
 		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
 			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
 			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
 		else
 			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
 	return;
 
 error_exit:
 	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
 	/* Let it try the remaining request again */
 	if (mqrq->retries > MMC_MAX_RETRIES - 1)
 		mqrq->retries = MMC_MAX_RETRIES - 1;
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req)
 		return;
 	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
 }
 
 static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)
author
#7 lore raw

Hi Shawn,

Quoted 29 lines · Shawn Lin
Quoted 28 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

I feel the solution in this patch is more clever with less code introduced.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

I tested the following patch in CQE mode, it fixes the data corruption problem, however the kernel prints Buffer I/O error messages which is confusing. Please see the test log below.

# hexdump ff00-4096.dat
0000000 00ff 00ff 00ff 00ff 00ff 00ff 00ff 00ff
*
0001000
# dd if=/dev/zero of=/dev/mmcblk0p1 bs=1024
count=4
4+0 records in
4+0 records out
# hexdump -n 4096 /dev/mmcblk0p1
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000
# dd if=ff00-4096.dat of=/dev/mmcblk0p1
8+0 records in
8+0 records out
[  390.990581] mmc0: running CQE recovery
[  390.995129] mmc0: running CQE recovery
[  390.999684] mmc0: running CQE recovery
[  391.004002] I/O error, dev mmcblk0, sector 2048 op 0x1:(WRITE) flags 0x800000 phys_seg 8 prio class 2
[  391.013596] Buffer I/O error on dev mmcblk0p1, logical block 0, lost async page write
[  391.021678] Buffer I/O error on dev mmcblk0p1, logical block 1, lost async page write
[  391.029681] Buffer I/O error on dev mmcblk0p1, logical block 2, lost async page write
[  391.037754] Buffer I/O error on dev mmcblk0p1, logical block 3, lost async page write
[  391.045821] Buffer I/O error on dev mmcblk0p1, logical block 4, lost async page write
[  391.053922] Buffer I/O error on dev mmcblk0p1, logical block 5, lost async page write
[  391.061926] Buffer I/O error on dev mmcblk0p1, logical block 6, lost async page write
[  391.069982] Buffer I/O error on dev mmcblk0p1, logical block 7, lost async page write
# hexdump -n 4096 /dev/mmcblk0p1
0000000 00ff 00ff 00ff 00ff 00ff 00ff 00ff 00ff
*
0001000

-Bin.

Quoted 119 lines
drivers/mmc/core/block.c +2 -2
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue
 *mq, struct request *req)
 	return mmc_blk_cqe_start_req(mq->card->host, mrq);
 }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req, int recovery_mode)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
 	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
drivers/mmc/core/block.c +13 -3
 	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
 	mmc_pre_req(host, &mqrq->brq.mrq);
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue
 *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
 }
 

static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,

drivers/mmc/core/block.c +8 -7
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card,
 struct request *req)
 	return err;
 }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_request *mrq = &mqrq->brq.mrq;
 	struct mmc_card *card = mq->card;
 	struct mmc_host *host = card->host;
 	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
 	do {
 		u32 status;
 		int err;
 		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
 			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
 			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue
 *mq, struct request *req)
 		else
 			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
 	return;
 
 error_exit:
 	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
 	/* Let it try the remaining request again */
 	if (mqrq->retries > MMC_MAX_RETRIES - 1)
drivers/mmc/core/block.c +3 -6
 		mqrq->retries = MMC_MAX_RETRIES - 1;
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue
 *mq, struct request *req)
 		return;
 	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
 }
 

static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)

author
#8 lore raw
Quoted 37 lines · Bin Liu

Hi Shawn,

Quoted 34 lines · Shawn Lin
Quoted 32 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

Quoted 7 lines
Quoted 3 lines

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

I tested the following patch in CQE mode, it fixes the data corruption problem, however the kernel prints Buffer I/O error messages which is confusing. Please see the test log below.

The patch doesn't seem to catch the CQE error path. I added a few pr_err() in the places you patches, but none of them is printed on console. And this time data corruption happens, so the patch doesn't seem to fix the problem. Here is the test log:

# hexdump -n 4096 /dev/mmcblk0p1
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000
# dd if=ff00-4096.dat of=/dev/mmcblk0p1
[   89.208865] mmc0: running CQE recovery
[   89.214757] mmc0: running CQE recovery
[   89.219414] mmc0: running CQE recovery
[   89.223743] I/O error, dev mmcblk0, sector 2048 op 0x1:(WRITE) flags 0x800800 phys_seg 1 prio class 2
[   89.233152] Buffer I/O error on dev mmcblk0p1, logical block 0, lost async page write
8+0 records in
8+0 records out
# hexdump -n 4096 /dev/mmcblk0p1
0000000 00ff 00ff 00ff 00ff 00ff 00ff 00ff 00ff
*
0000600 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000

-Bin.

Quoted 154 lines
# hexdump ff00-4096.dat
0000000 00ff 00ff 00ff 00ff 00ff 00ff 00ff 00ff
*
0001000
# dd if=/dev/zero of=/dev/mmcblk0p1 bs=1024
count=4
4+0 records in
4+0 records out
# hexdump -n 4096 /dev/mmcblk0p1
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0001000
# dd if=ff00-4096.dat of=/dev/mmcblk0p1
8+0 records in
8+0 records out
[  390.990581] mmc0: running CQE recovery
[  390.995129] mmc0: running CQE recovery
[  390.999684] mmc0: running CQE recovery
[  391.004002] I/O error, dev mmcblk0, sector 2048 op 0x1:(WRITE) flags 0x800000 phys_seg 8 prio class 2
[  391.013596] Buffer I/O error on dev mmcblk0p1, logical block 0, lost async page write
[  391.021678] Buffer I/O error on dev mmcblk0p1, logical block 1, lost async page write
[  391.029681] Buffer I/O error on dev mmcblk0p1, logical block 2, lost async page write
[  391.037754] Buffer I/O error on dev mmcblk0p1, logical block 3, lost async page write
[  391.045821] Buffer I/O error on dev mmcblk0p1, logical block 4, lost async page write
[  391.053922] Buffer I/O error on dev mmcblk0p1, logical block 5, lost async page write
[  391.061926] Buffer I/O error on dev mmcblk0p1, logical block 6, lost async page write
[  391.069982] Buffer I/O error on dev mmcblk0p1, logical block 7, lost async page write
# hexdump -n 4096 /dev/mmcblk0p1
0000000 00ff 00ff 00ff 00ff 00ff 00ff 00ff 00ff
*
0001000

-Bin.

Quoted 119 lines
drivers/mmc/core/block.c +2 -2
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue
 *mq, struct request *req)
 	return mmc_blk_cqe_start_req(mq->card->host, mrq);
 }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req, int recovery_mode)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
 	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
drivers/mmc/core/block.c +13 -3
 	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
 	mmc_pre_req(host, &mqrq->brq.mrq);
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue
 *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
 }
 

static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,

drivers/mmc/core/block.c +8 -7
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card,
 struct request *req)
 	return err;
 }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_request *mrq = &mqrq->brq.mrq;
 	struct mmc_card *card = mq->card;
 	struct mmc_host *host = card->host;
 	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
 	do {
 		u32 status;
 		int err;
 		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
 			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
 			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue
 *mq, struct request *req)
 		else
 			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
 	return;
 
 error_exit:
 	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
 	/* Let it try the remaining request again */
 	if (mqrq->retries > MMC_MAX_RETRIES - 1)
drivers/mmc/core/block.c +3 -6
 		mqrq->retries = MMC_MAX_RETRIES - 1;
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue
 *mq, struct request *req)
 		return;
 	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
 }
 

static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)

author
#9 lore raw
In reply to Shawn Lin

Hi Shawn,

Quoted 71 lines · Shawn Lin
Quoted 24 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

Quoted 8 lines

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

drivers/mmc/core/block.c +2 -2
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue
 *mq, struct request *req)
 	return mmc_blk_cqe_start_req(mq->card->host, mrq);
 }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req, int recovery_mode)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
 	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
drivers/mmc/core/block.c +2 -2
 	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
 	mmc_pre_req(host, &mqrq->brq.mrq);
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue
 *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {

drivers/mmc/core/block.c static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue · line 1678

Quoted 10 lines
drivers/mmc/core/block.c +6 -1
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {

In the CQE case, when the problem happens due to the errata, this function won't return error. The MMC write error is reported in mmc_blk_cqe_complete_rq() if you see my original patch.

-Bin.

Quoted 75 lines
drivers/mmc/core/block.c +5 -0
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
 }
 

static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,

drivers/mmc/core/block.c +8 -7
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card,
 struct request *req)
 	return err;
 }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_request *mrq = &mqrq->brq.mrq;
 	struct mmc_card *card = mq->card;
 	struct mmc_host *host = card->host;
 	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
 	do {
 		u32 status;
 		int err;
 		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
 			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
 			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue
 *mq, struct request *req)
 		else
 			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
 	return;
 
 error_exit:
 	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
 	/* Let it try the remaining request again */
 	if (mqrq->retries > MMC_MAX_RETRIES - 1)
drivers/mmc/core/block.c +3 -6
 		mqrq->retries = MMC_MAX_RETRIES - 1;
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue
 *mq, struct request *req)
 		return;
 	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
 }
 

static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)

author
#10 lore raw

Hi,

Quoted 81 lines · Bin Liu

Hi Shawn,

Quoted 78 lines · Shawn Lin
Quoted 24 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

Quoted 8 lines

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

drivers/mmc/core/block.c +2 -2
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue
 *mq, struct request *req)
 	return mmc_blk_cqe_start_req(mq->card->host, mrq);
 }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req, int recovery_mode)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
 	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
drivers/mmc/core/block.c +6 -2
 	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
 	mmc_pre_req(host, &mqrq->brq.mrq);
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue
 *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
 	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
Quoted 7 lines

drivers/mmc/core/block.c static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req) · line 1677

Quoted 3 lines
drivers/mmc/core/block.c +2 -1
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {

In the CQE case, when the problem happens due to the errata, this function won't return error. The MMC write error is reported in mmc_blk_cqe_complete_rq() if you see my original patch.

Which route should we go forward, continue to refine this patch or any more comments to my original patch?

Thanks,
-Bin.

Quoted 78 lines

-Bin.

Quoted 75 lines
drivers/mmc/core/block.c +5 -0
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
 }
 

static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,

drivers/mmc/core/block.c +8 -7
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card,
 struct request *req)
 	return err;
 }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
 	struct mmc_request *mrq = &mqrq->brq.mrq;
 	struct mmc_card *card = mq->card;
 	struct mmc_host *host = card->host;
 	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
 	do {
 		u32 status;
 		int err;
 		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
 			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
 			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue
 *mq, struct request *req)
 		else
 			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
 	return;
 
 error_exit:
 	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
 	/* Let it try the remaining request again */
 	if (mqrq->retries > MMC_MAX_RETRIES - 1)
drivers/mmc/core/block.c +3 -6
 		mqrq->retries = MMC_MAX_RETRIES - 1;
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue
 *mq, struct request *req)
 		return;
 	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
 }
 

static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)

#11 lore raw

Hi Bin

Quoted 92 lines · Bin Liu

Hi,

Quoted 81 lines · Bin Liu

Hi Shawn,

Quoted 78 lines · Shawn Lin
Quoted 24 lines · Bin Liu

Hi Shawn,

Quoted 9 lines · Shawn Lin
Quoted 5 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

MMC core natively retries single for multi block read. So I assume what you are trying to do is make it the same for write path. We didn't

Yes I am trying something similar for writ path, but

Quoted 2 lines

resort to upper block layer for help for read case in the past, so I think you could still achieve that within the scope of MMC core.

unlike the read path solution, I didn't solve the issue within the scope of MMC core, becaure it would intruduce more code than this patch does, especially the CQE and non-CQE cases have different failure path. (I didn't try to figure out how the single block read retry covers both failure cases...)

Quoted 8 lines

I feel the solution in this patch is more clever with less code introduced.

Quoted 2 lines

More importantly, what is the failure rate of this issue? If it occurs

Very rare. For example, on the EVM, the issue can only be triggered by writing 3 or more blocks of data pattern 0xFF00.

I manually modified cqhci and sdhci to inject errors for multi-block writes under both CQE and non-CQE modes. The following patch appears to work by testing. Could you please test it?

drivers/mmc/core/block.c +2 -2
index 05ee76cb0a08..ca60991a3305 100644
@@ -1642,13 +1642,13 @@ static int mmc_blk_cqe_issue_flush(struct mmc_queue
 *mq, struct request *req)
  	return mmc_blk_cqe_start_req(mq->card->host, mrq);
  }
 
-static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req)
+static int mmc_blk_hsq_issue_rw_rq(struct mmc_queue *mq, struct request
 *req, int recovery_mode)
  {
  	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
  	struct mmc_host *host = mq->card->host;
  	int err;
 
-	mmc_blk_rw_rq_prep(mqrq, mq->card, 0, mq);
+	mmc_blk_rw_rq_prep(mqrq, mq->card, recovery_mode, mq);
  	mqrq->brq.mrq.done = mmc_blk_hsq_req_done;
  	mmc_pre_req(host, &mqrq->brq.mrq);
drivers/mmc/core/block.c +6 -2
@@ -1663,13 +1663,23 @@ static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue
 *mq, struct request *req)
  {
  	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
  	struct mmc_host *host = mq->card->host;
+	int err;
 
-	if (host->hsq_enabled)
-		return mmc_blk_hsq_issue_rw_rq(mq, req);
+	if (host->hsq_enabled) {
+		err = mmc_blk_hsq_issue_rw_rq(mq, req, 0);
+		if (err)
+			return mmc_blk_hsq_issue_rw_rq(mq, req, 1);
+	}
 
  	mmc_blk_data_prep(mq, mqrq, 0, NULL, NULL);
 
Quoted 7 lines

drivers/mmc/core/block.c static int mmc_blk_cqe_issue_rw_rq(struct mmc_queue *mq, struct request *req) · line 1677

Quoted 3 lines
drivers/mmc/core/block.c +2 -1
-	return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	err = mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	if (err) {

In the CQE case, when the problem happens due to the errata, this function won't return error. The MMC write error is reported in mmc_blk_cqe_complete_rq() if you see my original patch.

Quoted 3 lines

Which route should we go forward, continue to refine this patch or any more comments to my original patch?

Sorry for late reply. I haven't had time to investigate it deeply but I think it would not block your original patch for folks to review it.

Quoted 81 lines

Thanks,
-Bin.

Quoted 78 lines

-Bin.

Quoted 75 lines
drivers/mmc/core/block.c +5 -0
+		mmc_blk_data_prep(mq, mqrq, 1, NULL, NULL);
+		return mmc_blk_cqe_start_req(mq->card->host, &mqrq->brq.mrq);
+	}
+
+	return 0;
  }
 

static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq,

drivers/mmc/core/block.c +8 -7
@@ -1776,24 +1786,26 @@ static int mmc_blk_fix_state(struct mmc_card *card,
 struct request *req)
  	return err;
  }
 
-#define MMC_READ_SINGLE_RETRIES	2
+#define MMC_RW_SINGLE_RETRIES	2
 
-/* Single (native) sector read during recovery */
-static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
+/* Single (native) sector read or write during recovery */
+static void mmc_blk_rw_single(struct mmc_queue *mq, struct request *req)
  {
  	struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req);
  	struct mmc_request *mrq = &mqrq->brq.mrq;
  	struct mmc_card *card = mq->card;
  	struct mmc_host *host = card->host;
  	blk_status_t error = BLK_STS_OK;
-	size_t bytes_per_read = queue_physical_block_size(mq->queue);
+	size_t bytes_per_rw = queue_physical_block_size(mq->queue);
+
 
  	do {
  		u32 status;
  		int err;
  		int retries = 0;
 
-		while (retries++ <= MMC_READ_SINGLE_RETRIES) {
+		while (retries++ <= MMC_RW_SINGLE_RETRIES) {
  			mmc_blk_rw_rq_prep(mqrq, card, 1, mq);
 
  			mmc_wait_for_req(host, mrq);
@@ -1821,13 +1833,13 @@ static void mmc_blk_read_single(struct mmc_queue
 *mq, struct request *req)
  		else
  			error = BLK_STS_OK;
 
-	} while (blk_update_request(req, error, bytes_per_read));
+	} while (blk_update_request(req, error, bytes_per_rw));
 
  	return;
 
  error_exit:
  	mrq->data->bytes_xfered = 0;
-	blk_update_request(req, BLK_STS_IOERR, bytes_per_read);
+	blk_update_request(req, BLK_STS_IOERR, bytes_per_rw);
  	/* Let it try the remaining request again */
  	if (mqrq->retries > MMC_MAX_RETRIES - 1)
  		mqrq->retries = MMC_MAX_RETRIES - 1;
drivers/mmc/core/block.c +3 -6
@@ -1969,12 +1981,9 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue
 *mq, struct request *req)
  		return;
  	}
 
-	if (rq_data_dir(req) == READ && brq->data.blocks >
-			queue_physical_block_size(mq->queue) >> 9) {
-		/* Read one (native) sector at a time */
-		mmc_blk_read_single(mq, req);
-		return;
-	}
+	/* Perform one (native) sector at a time */
+	if (brq->data.blocks > queue_physical_block_size(mq->queue) >> 9)
+		mmc_blk_rw_single(mq, req);
  }
 

static inline bool mmc_blk_rq_error(struct mmc_blk_request *brq)

author
#12 lore raw

v2 cover mmc: block: use single block write in retry

In reply to Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

This patch set reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

link to v1:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#u

[0] https://www.ti.com/lit/pdf/sprz582

Bin Liu (2):
block: define new rqf_flags RQF_XFER_SINGLE_BLK
mmc: block: use single block write in retry

 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
author
#13 lore raw

PATCH v2 1/2 block: define new rqf_flags RQF_XFER_SINGLE_BLK

This new flag will be used to handle multi-block transfer failure, in which case single-block transfer will be used.

---
v2: new patch, separate the new flag definition.

 block/blk-mq-debugfs.c | 1 +
 include/linux/blk-mq.h | 3 +++
 2 files changed, 4 insertions(+)
block/blk-mq-debugfs.c +1 -0
index 28167c9baa55..5f97d07fa3c8 100644
@@ -243,6 +243,7 @@ static const char *const rqf_name[] = {
 	RQF_NAME(ZONE_WRITE_PLUGGING),
 	RQF_NAME(TIMED_OUT),
 	RQF_NAME(RESV),
+	RQF_NAME(XFER_SINGLE_BLK),
 };
 #undef RQF_NAME
 
include/linux/blk-mq.h +3 -0
index 18a2388ba581..06b6e1c4fca3 100644
@@ -64,6 +64,7 @@ enum rqf_flags {
 	/* ->timeout has been called, don't expire again */
 	__RQF_TIMED_OUT,
 	__RQF_RESV,
+	__RQF_XFER_SINGLE_BLK,
 	__RQF_BITS
 };
 
@@ -85,6 +86,8 @@ enum rqf_flags {
 			((__force req_flags_t)(1 << __RQF_ZONE_WRITE_PLUGGING))
 #define RQF_TIMED_OUT		((__force req_flags_t)(1 << __RQF_TIMED_OUT))
 #define RQF_RESV		((__force req_flags_t)(1 << __RQF_RESV))
+#define RQF_XFER_SINGLE_BLK	\
+			((__force req_flags_t)(1 << __RQF_XFER_SINGLE_BLK))
 
 /* flags that prevent us from merging requests: */
 #define RQF_NOMERGE_FLAGS \
Signature · 1 line
2.34.1
maintainer
#14 lore raw

Re: [PATCH v2 1/2] block: define new rqf_flags RQF_XFER_SINGLE_BLK

Quoted 2 lines · Bin Liu

This new flag will be used to handle multi-block transfer failure, in which case single-block transfer will be used.

Maybe I missed this in previous discussions, but why can't this flag go into struct mmc_queue_req?

Signature · 1 line
Jens Axboe
author
#15 lore raw

Re: [PATCH v2 1/2] block: define new rqf_flags RQF_XFER_SINGLE_BLK

Hi Jens,

Quoted 6 lines · Jens Axboe
Quoted 2 lines · Bin Liu

This new flag will be used to handle multi-block transfer failure, in which case single-block transfer will be used.

Maybe I missed this in previous discussions, but why can't this flag go into struct mmc_queue_req?

You didn't miss anything. We didn't discuss about it until now.

I added the flag in struct request because it already has rq_flags to host all the flag bits. But I don't see struct mmc_queue_req has any member for this flag purpose. Do you mean we should add a new flag member into struct mmc_queue_req?

-Bin.

Quoted 3 lines
Signature · 2 lines
-- 
Jens Axboe
maintainer
#16 lore raw

Re: [PATCH v2 1/2] block: define new rqf_flags RQF_XFER_SINGLE_BLK

Quoted 10 lines · Bin Liu

Hi Jens,

Quoted 6 lines · Jens Axboe
Quoted 2 lines · Bin Liu

This new flag will be used to handle multi-block transfer failure, in which case single-block transfer will be used.

Maybe I missed this in previous discussions, but why can't this flag go into struct mmc_queue_req?

Quoted 6 lines

You didn't miss anything. We didn't discuss about it until now.

I added the flag in struct request because it already has rq_flags to host all the flag bits. But I don't see struct mmc_queue_req has any member for this flag purpose. Do you mean we should add a new flag member into struct mmc_queue_req?

It's a bad idea to add driver specific flag to the core flags, particularly when you already have per-rq data associated with the driver. Then it should surely go there. The block layer doesn't care about RQF_XFER_SINGLE_BLK, that's strictly a device property. Hence it should go in the driver, NOT in the block layer.

So yes, add a bool or flags or whatever you need on the driver side.

Signature · 1 line
Jens Axboe
author
#17 lore raw

Re: [PATCH v2 1/2] block: define new rqf_flags RQF_XFER_SINGLE_BLK

Hi Jens,

Quoted 18 lines · Jens Axboe
Quoted 10 lines · Bin Liu

Hi Jens,

Quoted 6 lines · Jens Axboe
Quoted 2 lines · Bin Liu

This new flag will be used to handle multi-block transfer failure, in which case single-block transfer will be used.

Maybe I missed this in previous discussions, but why can't this flag go into struct mmc_queue_req?

Quoted 6 lines

You didn't miss anything. We didn't discuss about it until now.

I added the flag in struct request because it already has rq_flags to host all the flag bits. But I don't see struct mmc_queue_req has any member for this flag purpose. Do you mean we should add a new flag member into struct mmc_queue_req?

Quoted 7 lines

It's a bad idea to add driver specific flag to the core flags, particularly when you already have per-rq data associated with the driver. Then it should surely go there. The block layer doesn't care about RQF_XFER_SINGLE_BLK, that's strictly a device property. Hence it should go in the driver, NOT in the block layer.

So yes, add a bool or flags or whatever you need on the driver side.

Sure I will add a variable in struct mmc_queue_req to carry this flag. Thank you for the comments.

-Bin.

Quoted 3 lines
Signature · 2 lines
-- 
Jens Axboe
author
#18 lore raw

PATCH v2 2/2 mmc: block: use single block write in retry

In reply to Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

[0] https://www.ti.com/lit/pdf/sprz582

---
v2: add errata details in the commit message.

 drivers/mmc/core/block.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..00016584d70d 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 		    rq_data_dir(req) == WRITE &&
 		    (md->flags & MMC_BLK_REL_WR);
 
+	if (req->rq_flags & RQF_XFER_SINGLE_BLK)
+		recovery_mode = 1;
+
 	memset(brq, 0, sizeof(struct mmc_blk_request));
 
 	mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
 		err = 0;
 
 	if (err) {
-		if (mqrq->retries++ < MMC_CQE_RETRIES)
+		if (mqrq->retries++ < MMC_CQE_RETRIES) {
+			if (rq_data_dir(req) == WRITE)
+				req->rq_flags |= RQF_XFER_SINGLE_BLK;
 			blk_mq_requeue_request(req, true);
-		else
+		} else {
 			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
 	} else if (mrq->data) {
 		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
 			blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
 	} else if (!blk_rq_bytes(req)) {
 		__blk_mq_end_request(req, BLK_STS_IOERR);
 	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		if (rq_data_dir(req) == WRITE)
+			req->rq_flags |= RQF_XFER_SINGLE_BLK;
 		blk_mq_requeue_request(req, true);
 	} else {
 		if (mmc_card_removed(mq->card))
Signature · 1 line
2.34.1
Reviewed-by on the v2 series
#19 lore raw
In reply to Bin Liu
Quoted 27 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

This patch set reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

link to v1:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#u

[0] https://www.ti.com/lit/pdf/sprz582

Bin Liu (2):
block: define new rqf_flags RQF_XFER_SINGLE_BLK
mmc: block: use single block write in retry

Quoted 8 lines
 block/blk-mq-debugfs.c   |  1 +
 drivers/mmc/core/block.c | 12 ++++++++++--
 include/linux/blk-mq.h   |  3 +++
 3 files changed, 14 insertions(+), 2 deletions(-)

--
2.34.1

Jens, if you think this approach is okay, feel free to take the series via your tree. Or if you prefer me to handle it, please let me know.

For the series:

Kind regards
Uffe

maintainer
#20 lore raw
Quoted 2 lines · Ulf Hansson

Jens, if you think this approach is okay, feel free to take the series via your tree. Or if you prefer me to handle it, please let me know.

See comments on patch 1, I think that needs a rework. And then you won't have any block related changes either.

Signature · 1 line
Jens Axboe
author
#21 lore raw

PATCH v3 1/1 mmc: block: use single block write in retry

In reply to Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

[0] https://www.ti.com/lit/pdf/sprz582

---
v3: move the flag to struct mmc_queue_req to reduce the scope
cc stable@

v2: add errata details in the commit message.

link to v2:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#mb201075c9c466a78b58dbb0bf1f39139f0928591

link to v1:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#u
 drivers/mmc/core/block.c | 12 ++++++++++--
 drivers/mmc/core/queue.h |  3 +++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..db8c99c73a61 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
 		    rq_data_dir(req) == WRITE &&
 		    (md->flags & MMC_BLK_REL_WR);
 
+	if (mqrq->flags & MQRQ_XFER_SINGLE_BLOCK)
+		recovery_mode = 1;
+
 	memset(brq, 0, sizeof(struct mmc_blk_request));
 
 	mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
 		err = 0;
 
 	if (err) {
-		if (mqrq->retries++ < MMC_CQE_RETRIES)
+		if (mqrq->retries++ < MMC_CQE_RETRIES) {
+			if (rq_data_dir(req) == WRITE)
+				mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
 			blk_mq_requeue_request(req, true);
-		else
+		} else {
 			blk_mq_end_request(req, BLK_STS_IOERR);
+		}
 	} else if (mrq->data) {
 		if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
 			blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
 	} else if (!blk_rq_bytes(req)) {
 		__blk_mq_end_request(req, BLK_STS_IOERR);
 	} else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+		if (rq_data_dir(req) == WRITE)
+			mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
 		blk_mq_requeue_request(req, true);
 	} else {
 		if (mmc_card_removed(mq->card))
drivers/mmc/core/queue.h +3 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
 	MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define	MQRQ_XFER_SINGLE_BLOCK		BIT(0)
+
 struct mmc_queue_req {
 	struct mmc_blk_request	brq;
 	struct scatterlist	*sg;
@@ -69,6 +71,7 @@ struct mmc_queue_req {
 	void			*drv_op_data;
 	unsigned int		ioc_count;
 	int			retries;
+	u32			flags;
 };
 
 struct mmc_queue {
Signature · 1 line
2.34.1
maintainer
#22 lore raw
Quoted 14 lines · Bin Liu
drivers/mmc/core/queue.h +2 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
 	MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define	MQRQ_XFER_SINGLE_BLOCK		BIT(0)
+
 struct mmc_queue_req {
 	struct mmc_blk_request	brq;
 	struct scatterlist	*sg;

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 7 lines
drivers/mmc/core/queue.h +1 -0
@@ -69,6 +71,7 @@ struct mmc_queue_req {
 	void			*drv_op_data;
 	unsigned int		ioc_count;
 	int			retries;
+	u32			flags;
 };
 
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

	u16 retries;
	u16 flags;

and not grow the size of it by 8 bytes with that addition.

Not a huge deal, obviously, but always good to consider things like that to avoid wasting memory for nothing.

Signature · 1 line
Jens Axboe
author
#23 lore raw
Quoted 21 lines · Jens Axboe
Quoted 20 lines · Bin Liu
drivers/mmc/core/queue.h +3 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
 	MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define	MQRQ_XFER_SINGLE_BLOCK		BIT(0)
+
 struct mmc_queue_req {
 	struct mmc_blk_request	brq;
 	struct scatterlist	*sg;
@@ -69,6 +71,7 @@ struct mmc_queue_req {
 	void			*drv_op_data;
 	unsigned int		ioc_count;
 	int			retries;
+	u32			flags;
 };
 
Quoted 7 lines

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 1 line
drivers/mmc/core/queue.h +0 -0
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

	u16 retries;
	u16 flags;

I quickly went throught block.c, it appears retries would be only a single digit number. I will update the patch to use u16.

Thanks,
-Bin.

Quoted 8 lines

and not grow the size of it by 8 bytes with that addition.

Not a huge deal, obviously, but always good to consider things like that to avoid wasting memory for nothing.

Signature · 1 line
Jens Axboe
maintainer
#24 lore raw
Quoted 27 lines · Bin Liu
Quoted 26 lines · Jens Axboe
Quoted 14 lines · Bin Liu
drivers/mmc/core/queue.h +2 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
 	MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define	MQRQ_XFER_SINGLE_BLOCK		BIT(0)
+
 struct mmc_queue_req {
 	struct mmc_blk_request	brq;
 	struct scatterlist	*sg;

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 7 lines
drivers/mmc/core/queue.h +1 -0
@@ -69,6 +71,7 @@ struct mmc_queue_req {
 	void			*drv_op_data;
 	unsigned int		ioc_count;
 	int			retries;
+	u32			flags;
 };
 
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

Quoted 5 lines
Quoted 2 lines
	u16 retries;
	u16 flags;

I quickly went throught block.c, it appears retries would be only a single digit number. I will update the patch to use u16.

Note that this is just my suggestion, it's down to Ulf. But what I would do is a prep patch that makes retries u16 and ensures that's sane, then do your flags patch on top of that. I think that's better than making that unrelated size change for retries in your patch that isn't related to that at all. It just sets you up to not grow the struct after your change.

Signature · 1 line
Jens Axboe
author
#25 lore raw
Quoted 34 lines · Jens Axboe
Quoted 27 lines · Bin Liu
Quoted 26 lines · Jens Axboe
Quoted 14 lines · Bin Liu
drivers/mmc/core/queue.h +2 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
 	MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define	MQRQ_XFER_SINGLE_BLOCK		BIT(0)
+
 struct mmc_queue_req {
 	struct mmc_blk_request	brq;
 	struct scatterlist	*sg;

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 7 lines
drivers/mmc/core/queue.h +1 -0
@@ -69,6 +71,7 @@ struct mmc_queue_req {
 	void			*drv_op_data;
 	unsigned int		ioc_count;
 	int			retries;
+	u32			flags;
 };
 
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

Quoted 5 lines
Quoted 2 lines
	u16 retries;
	u16 flags;

I quickly went throught block.c, it appears retries would be only a single digit number. I will update the patch to use u16.

Quoted 6 lines

Note that this is just my suggestion, it's down to Ulf. But what I would do is a prep patch that makes retries u16 and ensures that's sane, then do your flags patch on top of that. I think that's better than making that unrelated size change for retries in your patch that isn't related to that at all. It just sets you up to not grow the struct after your change.

Okay I will wait for Ulf's decision to make the u16 change or not.

-Bin.

Quoted 3 lines
Signature · 2 lines
-- 
Jens Axboe
#26 lore raw
Quoted 36 lines · Bin Liu
Quoted 34 lines · Jens Axboe
Quoted 32 lines · Bin Liu
Quoted 21 lines · Jens Axboe
Quoted 20 lines · Bin Liu
drivers/mmc/core/queue.h +3 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
  MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define  MQRQ_XFER_SINGLE_BLOCK          BIT(0)
+
 struct mmc_queue_req {
  struct mmc_blk_request  brq;
  struct scatterlist      *sg;
@@ -69,6 +71,7 @@ struct mmc_queue_req {
  void                    *drv_op_data;
  unsigned int            ioc_count;
  int                     retries;
+ u32                     flags;
 };
 
Quoted 7 lines

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 1 line
drivers/mmc/core/queue.h +0 -0
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

   u16 retries;
   u16 flags;

I quickly went throught block.c, it appears retries would be only a single digit number. I will update the patch to use u16.

Quoted 8 lines
Quoted 6 lines

Note that this is just my suggestion, it's down to Ulf. But what I would do is a prep patch that makes retries u16 and ensures that's sane, then do your flags patch on top of that. I think that's better than making that unrelated size change for retries in your patch that isn't related to that at all. It just sets you up to not grow the struct after your change.

Okay I will wait for Ulf's decision to make the u16 change or not.

I have no strong opinion, before or after works for me, while I certainly thinks it makes sense to do the optimization.

Even ioc_count can be changed. From a brief analyze it looks like this (needs to be double checked).
ioc_count <= 255
retries <= max 5

So maybe u8 is good enough :-)

Kind regards
Uffe

author
#27 lore raw
Quoted 44 lines · Ulf Hansson
Quoted 43 lines · Bin Liu
Quoted 40 lines · Jens Axboe
Quoted 27 lines · Bin Liu
Quoted 26 lines · Jens Axboe
Quoted 14 lines · Bin Liu
drivers/mmc/core/queue.h +2 -0
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
  MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define  MQRQ_XFER_SINGLE_BLOCK          BIT(0)
+
 struct mmc_queue_req {
  struct mmc_blk_request  brq;
  struct scatterlist      *sg;

drivers/mmc/core/queue.h struct mmc_queue_req { · line 77

Quoted 7 lines
drivers/mmc/core/queue.h +1 -0
@@ -69,6 +71,7 @@ struct mmc_queue_req {
  void                    *drv_op_data;
  unsigned int            ioc_count;
  int                     retries;
+ u32                     flags;
 };
 
 struct mmc_queue {

I'm assuming retries is a pretty small number (didn't check), so if you care about layout/space in mmc_queue_req, you could make this:

Quoted 5 lines
Quoted 2 lines
   u16 retries;
   u16 flags;

I quickly went throught block.c, it appears retries would be only a single digit number. I will update the patch to use u16.

Note that this is just my suggestion, it's down to Ulf. But what I would do is a prep patch that makes retries u16 and ensures that's sane, then do your flags patch on top of that. I think that's better than making that unrelated size change for retries in your patch that isn't related to that at all. It just sets you up to not grow the struct after your change.

Quoted 3 lines
Quoted 1 line

Okay I will wait for Ulf's decision to make the u16 change or not.

I have no strong opinion, before or after works for me, while I

Okay, can you please just take this v3 then? I think we typically don't mix fix and optimization in a single patch set. I am talking about other subsystems thought...

-Bin.

Quoted 11 lines

certainly thinks it makes sense to do the optimization.

Even ioc_count can be changed. From a brief analyze it looks like this (needs to be double checked).
ioc_count <= 255
retries <= max 5

So maybe u8 is good enough :-)

Kind regards
Uffe

#28 lore raw
In reply to Bin Liu
Quoted 13 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

Quoted 7 lines

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

[0] https://www.ti.com/lit/pdf/sprz582

Applied for next and by adding a suggested-by tag from Jens, thanks!

Please consider sending a patch on top, that decreases the data size of struct mmc_queue_req.

Kind regards
Uffe

Quoted 79 lines

---
v3: move the flag to struct mmc_queue_req to reduce the scope
cc stable@

v2: add errata details in the commit message.

link to v2:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#mb201075c9c466a78b58dbb0bf1f39139f0928591

link to v1:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#u
 drivers/mmc/core/block.c | 12 ++++++++++--
 drivers/mmc/core/queue.h |  3 +++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..db8c99c73a61 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
                    rq_data_dir(req) == WRITE &&
                    (md->flags & MMC_BLK_REL_WR);
 
+       if (mqrq->flags & MQRQ_XFER_SINGLE_BLOCK)
+               recovery_mode = 1;
+
        memset(brq, 0, sizeof(struct mmc_blk_request));
 
        mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
                err = 0;
 
        if (err) {
-               if (mqrq->retries++ < MMC_CQE_RETRIES)
+               if (mqrq->retries++ < MMC_CQE_RETRIES) {
+                       if (rq_data_dir(req) == WRITE)
+                               mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
                        blk_mq_requeue_request(req, true);
-               else
+               } else {
                        blk_mq_end_request(req, BLK_STS_IOERR);
+               }
        } else if (mrq->data) {
                if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
                        blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
        } else if (!blk_rq_bytes(req)) {
                __blk_mq_end_request(req, BLK_STS_IOERR);
        } else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+               if (rq_data_dir(req) == WRITE)
+                       mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
                blk_mq_requeue_request(req, true);
        } else {
                if (mmc_card_removed(mq->card))
drivers/mmc/core/queue.h +3 -1
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
        MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define        MQRQ_XFER_SINGLE_BLOCK          BIT(0)
+
 struct mmc_queue_req {
        struct mmc_blk_request  brq;
        struct scatterlist      *sg;
@@ -69,6 +71,7 @@ struct mmc_queue_req {
        void                    *drv_op_data;
        unsigned int            ioc_count;
        int                     retries;
+       u32                     flags;
 };
 
 struct mmc_queue {
--

2.34.1

author
#29 lore raw

Hi Ulf,

Quoted 18 lines · Ulf Hansson
Quoted 17 lines · Bin Liu

Due to errata i2493[0], multi-block write would still fail in retries.

With i2493, the MMC interface has the potential of write failures when issuing multi-block writes operating in HS200 mode with excessive IO supply noise.

While the errata provides guidance in hardware design and layout to minimize the IO supply noise, in theory the write failure cannot be resolved in hardware. The software solution to ensure the data integrity is to add minimum 5us delay between block writes. Single-block write is the practical way to introduce the delay.

This patch reuses recovery_mode flag, and switches to single-block write in retry when multi-block write fails. It covers both CQE and non-CQE cases.

Quoted 5 lines
Quoted 3 lines

[0] https://www.ti.com/lit/pdf/sprz582

Applied for next and by adding a suggested-by tag from Jens, thanks!

Thanks.

Quoted 3 lines

Please consider sending a patch on top, that decreases the data size of struct mmc_queue_req.

Will do, in a few days or next week.

-Bin.

Quoted 85 lines

Kind regards
Uffe

Quoted 79 lines

---
v3: move the flag to struct mmc_queue_req to reduce the scope
cc stable@

v2: add errata details in the commit message.

link to v2:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#mb201075c9c466a78b58dbb0bf1f39139f0928591

link to v1:

    https://lore.kernel.org/linux-mmc/[email protected]/T/#u
 drivers/mmc/core/block.c | 12 ++++++++++--
 drivers/mmc/core/queue.h |  3 +++
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/mmc/core/block.c +10 -2
index 05ee76cb0a08..db8c99c73a61 100644
@@ -1401,6 +1401,9 @@ static void mmc_blk_data_prep(struct mmc_queue *mq, struct mmc_queue_req *mqrq,
                    rq_data_dir(req) == WRITE &&
                    (md->flags & MMC_BLK_REL_WR);
 
+       if (mqrq->flags & MQRQ_XFER_SINGLE_BLOCK)
+               recovery_mode = 1;
+
        memset(brq, 0, sizeof(struct mmc_blk_request));
 
        mmc_crypto_prepare_req(mqrq);
@@ -1540,10 +1543,13 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req)
                err = 0;
 
        if (err) {
-               if (mqrq->retries++ < MMC_CQE_RETRIES)
+               if (mqrq->retries++ < MMC_CQE_RETRIES) {
+                       if (rq_data_dir(req) == WRITE)
+                               mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
                        blk_mq_requeue_request(req, true);
-               else
+               } else {
                        blk_mq_end_request(req, BLK_STS_IOERR);
+               }
        } else if (mrq->data) {
                if (blk_update_request(req, BLK_STS_OK, mrq->data->bytes_xfered))
                        blk_mq_requeue_request(req, true);
@@ -2085,6 +2091,8 @@ static void mmc_blk_mq_complete_rq(struct mmc_queue *mq, struct request *req)
        } else if (!blk_rq_bytes(req)) {
                __blk_mq_end_request(req, BLK_STS_IOERR);
        } else if (mqrq->retries++ < MMC_MAX_RETRIES) {
+               if (rq_data_dir(req) == WRITE)
+                       mqrq->flags |= MQRQ_XFER_SINGLE_BLOCK;
                blk_mq_requeue_request(req, true);
        } else {
                if (mmc_card_removed(mq->card))
drivers/mmc/core/queue.h +3 -1
index 1498840a4ea0..c254e6580afd 100644
@@ -61,6 +61,8 @@ enum mmc_drv_op {
        MMC_DRV_OP_GET_EXT_CSD,
 };
 
+#define        MQRQ_XFER_SINGLE_BLOCK          BIT(0)
+
 struct mmc_queue_req {
        struct mmc_blk_request  brq;
        struct scatterlist      *sg;
@@ -69,6 +71,7 @@ struct mmc_queue_req {
        void                    *drv_op_data;
        unsigned int            ioc_count;
        int                     retries;
+       u32                     flags;
 };
 
 struct mmc_queue {
--

2.34.1

author
#30 lore raw

PATCH 1/1 mmc: block: optimize size of struct mmc_queue_req

In reply to Ulf Hansson

ioc_count won't be more than MMC_IOC_MAX_CMDS (255), retries won't be more than MMC_NO_RETRIES (6),

so change both to u8 type.

---
 drivers/mmc/core/queue.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/core/queue.h +2 -2
index 7bf20e3db5b6..71c82153dce0 100644
@@ -69,8 +69,8 @@ struct mmc_queue_req {
 	enum mmc_drv_op		drv_op;
 	int			drv_op_result;
 	void			*drv_op_data;
-	unsigned int		ioc_count;
-	u16			retries;
+	u8			ioc_count;
+	u8			retries;
 	u16			flags;
 };
 
Signature · 1 line
2.34.1
#31 lore raw

Re: [PATCH] mmc: block: optimize size of struct mmc_queue_req

Quoted 16 lines · Bin Liu

ioc_count won't be more than MMC_IOC_MAX_CMDS (255), retries won't be more than MMC_NO_RETRIES (6),

so change both to u8 type.

---
 drivers/mmc/core/queue.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/core/queue.h +0 -0
index 7bf20e3db5b6..71c82153dce0 100644

drivers/mmc/core/queue.h struct mmc_queue_req { · line 74

Quoted 8 lines
drivers/mmc/core/queue.h +2 -2
@@ -69,8 +69,8 @@ struct mmc_queue_req {
        enum mmc_drv_op         drv_op;
        int                     drv_op_result;
        void                    *drv_op_data;
-       unsigned int            ioc_count;
-       u16                     retries;
+       u8                      ioc_count;
+       u8                      retries;
        u16                     flags;

The previous patch I applied added *u32* flags, so this doesn't apply on my next branch. Did I apply the wrong patch?

Moreover, flags can be u8 too, so please convert this too.

Quoted 5 lines
drivers/mmc/core/queue.h +0 -1
 };
 
--

2.34.1

Kind regards
Uffe

author
#32 lore raw

Re: [PATCH] mmc: block: optimize size of struct mmc_queue_req

Hi Ulf,

Quoted 12 lines · Ulf Hansson
Quoted 11 lines · Bin Liu

ioc_count won't be more than MMC_IOC_MAX_CMDS (255), retries won't be more than MMC_NO_RETRIES (6),

so change both to u8 type.

---
 drivers/mmc/core/queue.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 16 lines

drivers/mmc/core/queue.h struct mmc_queue_req { · line 74

Quoted 13 lines
drivers/mmc/core/queue.h +2 -2
index 7bf20e3db5b6..71c82153dce0 100644
@@ -69,8 +69,8 @@ struct mmc_queue_req {
        enum mmc_drv_op         drv_op;
        int                     drv_op_result;
        void                    *drv_op_data;
-       unsigned int            ioc_count;
-       u16                     retries;
+       u8                      ioc_count;
+       u8                      retries;
        u16                     flags;

The previous patch I applied added *u32* flags, so this doesn't apply on my next branch. Did I apply the wrong patch?

My apologies. I forgot I have already amened my local tree to the following for the v4 of the previous patch.

-       int                     retries;
+       u16                     retries;
+       u16                     flags;

Sorry. I will correct this.

Quoted 2 lines

Moreover, flags can be u8 too, so please convert this too.

I did u8, u8. u16 here only because the total of the 3 variables are 4 bytes (instead of 3). But I can use u8 for all 3 of them.

Will send v2 today.

-Bin.

Quoted 9 lines
Quoted 6 lines
drivers/mmc/core/queue.h +0 -1
 };
 
--

2.34.1

Kind regards
Uffe

author
#33 lore raw

PATCH 1/1 mmc: block: optimize size of struct mmc_queue_req

In reply to Bin Liu

ioc_count won't be more than MMC_IOC_MAX_CMDS (255), retries won't be more than MMC_NO_RETRIES (6), flags is newly introduced and uses only 1 bit now.

so change all 3 of them to u8 type.

---
v2: rebase to upstream tree
change flags to u8 too

 drivers/mmc/core/queue.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/core/queue.h +3 -3
index c254e6580afd..dd7211e3a6d5 100644
@@ -69,9 +69,9 @@ struct mmc_queue_req {
 	enum mmc_drv_op		drv_op;
 	int			drv_op_result;
 	void			*drv_op_data;
-	unsigned int		ioc_count;
-	int			retries;
-	u32			flags;
+	u8			ioc_count;
+	u8			retries;
+	u8			flags;
 };
 
 struct mmc_queue {
Signature · 1 line
2.34.1
#34 lore raw

Re: [PATCH c2] mmc: block: optimize size of struct mmc_queue_req

Quoted 8 lines · Bin Liu

ioc_count won't be more than MMC_IOC_MAX_CMDS (255), retries won't be more than MMC_NO_RETRIES (6), flags is newly introduced and uses only 1 bit now.

so change all 3 of them to u8 type.

Applied for next, thanks!

Kind regards
Uffe

Quoted 27 lines

---
v2: rebase to upstream tree
change flags to u8 too

 drivers/mmc/core/queue.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mmc/core/queue.h +3 -4
index c254e6580afd..dd7211e3a6d5 100644
@@ -69,9 +69,9 @@ struct mmc_queue_req {
        enum mmc_drv_op         drv_op;
        int                     drv_op_result;
        void                    *drv_op_data;
-       unsigned int            ioc_count;
-       int                     retries;
-       u32                     flags;
+       u8                      ioc_count;
+       u8                      retries;
+       u8                      flags;
 };
 
 struct mmc_queue {
--

2.34.1