All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment
@ 2023-06-14 13:42 Marek Vasut
  2023-06-14 13:42 ` [PATCH v2 2/3] mmc: Introduce mmc_send_stop_transmission() Marek Vasut
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marek Vasut @ 2023-06-14 13:42 UTC (permalink / raw)
  To: u-boot
  Cc: Marek Vasut, Ying-Chun Liu (PaulLiu),
	Hai Pham, Jaehoon Chung, Loic Poulain, Peng Fan, Simon Glass,
	Takeshi Kihara

The MMC_CMD_STOP_TRANSMISSION response is R1 for read transfers
per JEDEC Standard No. 84-B51 Page 126 . Correct the response
type and add a comment about it.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
V2: New patch
---
Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Cc: Hai Pham <hai.pham.ud@renesas.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Takeshi Kihara <takeshi.kihara.df@renesas.com>
---
 drivers/mmc/mmc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 965bc8f0dba..f9b2f940389 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -427,7 +427,12 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
 	if (blkcnt > 1) {
 		cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
 		cmd.cmdarg = 0;
-		cmd.resp_type = MMC_RSP_R1b;
+		/*
+		 * JEDEC Standard No. 84-B51 Page 126
+		 * CMD12 STOP_TRANSMISSION R1/R1b[3]
+		 * NOTE 3 R1 for read cases and R1b for write cases.
+		 */
+		cmd.resp_type = MMC_RSP_R1;
 		if (mmc_send_cmd(mmc, &cmd, NULL)) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
 			pr_err("mmc fail to send stop cmd\n");
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/3] mmc: Introduce mmc_send_stop_transmission()
  2023-06-14 13:42 [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Marek Vasut
@ 2023-06-14 13:42 ` Marek Vasut
  2023-06-14 13:42 ` [PATCH v2 3/3] mmc: renesas-sdhi: Send stop when MMC tuning command fails Marek Vasut
  2023-06-15  4:08 ` [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Peng Fan
  2 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2023-06-14 13:42 UTC (permalink / raw)
  To: u-boot
  Cc: Hai Pham, Takeshi Kihara, Marek Vasut, Ying-Chun Liu (PaulLiu),
	Jaehoon Chung, Loic Poulain, Peng Fan, Simon Glass

From: Hai Pham <hai.pham.ud@renesas.com>

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
  The data transfer will terminate and the Device will return to the Transfer State.
  The read commands are: ... send tuning block (CMD21) ....
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Update commit message, quote relevant part of the specification.
        Rename to mmc_send_stop_transmission().
	Remove tuning opcode check, this is controller driver specific.
	Deduplicate part of mmc_read_blocks() using this function.]
---
V2: Support both read and write transmission stop
---
Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Cc: Hai Pham <hai.pham.ud@renesas.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Takeshi Kihara <takeshi.kihara.df@renesas.com>
---
 drivers/mmc/mmc.c | 26 +++++++++++++++++---------
 include/mmc.h     |  2 ++
 2 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index f9b2f940389..d5922d842e8 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -398,6 +398,22 @@ int mmc_send_tuning(struct mmc *mmc, u32 opcode, int *cmd_error)
 }
 #endif
 
+int mmc_send_stop_transmission(struct mmc *mmc, bool read)
+{
+	struct mmc_cmd cmd;
+
+	cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
+	cmd.cmdarg = 0;
+	/*
+	 * JEDEC Standard No. 84-B51 Page 126
+	 * CMD12 STOP_TRANSMISSION R1/R1b[3]
+	 * NOTE 3 R1 for read cases and R1b for write cases.
+	 */
+	cmd.resp_type = read ? MMC_RSP_R1 : MMC_RSP_R1b;
+
+	return mmc_send_cmd(mmc, &cmd, NULL);
+}
+
 static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
 			   lbaint_t blkcnt)
 {
@@ -425,15 +441,7 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
 		return 0;
 
 	if (blkcnt > 1) {
-		cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
-		cmd.cmdarg = 0;
-		/*
-		 * JEDEC Standard No. 84-B51 Page 126
-		 * CMD12 STOP_TRANSMISSION R1/R1b[3]
-		 * NOTE 3 R1 for read cases and R1b for write cases.
-		 */
-		cmd.resp_type = MMC_RSP_R1;
-		if (mmc_send_cmd(mmc, &cmd, NULL)) {
+		if (mmc_send_stop_transmission(mmc, true)) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
 			pr_err("mmc fail to send stop cmd\n");
 #endif
diff --git a/include/mmc.h b/include/mmc.h
index b8fbff150de..b47d2e1a895 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -558,6 +558,8 @@ int mmc_deferred_probe(struct mmc *mmc);
 int mmc_reinit(struct mmc *mmc);
 int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt);
 int mmc_hs400_prepare_ddr(struct mmc *mmc);
+int mmc_send_stop_transmission(struct mmc *mmc, bool read);
+
 #else
 struct mmc_ops {
 	int (*send_cmd)(struct mmc *mmc,
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 3/3] mmc: renesas-sdhi: Send stop when MMC tuning command fails
  2023-06-14 13:42 [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Marek Vasut
  2023-06-14 13:42 ` [PATCH v2 2/3] mmc: Introduce mmc_send_stop_transmission() Marek Vasut
@ 2023-06-14 13:42 ` Marek Vasut
  2023-06-15  4:08 ` [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Peng Fan
  2 siblings, 0 replies; 4+ messages in thread
From: Marek Vasut @ 2023-06-14 13:42 UTC (permalink / raw)
  To: u-boot
  Cc: Hai Pham, Takeshi Kihara, Marek Vasut, Ying-Chun Liu (PaulLiu),
	Jaehoon Chung, Loic Poulain, Peng Fan, Simon Glass

From: Hai Pham <hai.pham.ud@renesas.com>

When tuning command (CMD21) fails with command error, call
mmc_send_stop_transmission() to send stop command (CMD12).

Reviewed-by: Takeshi Kihara <takeshi.kihara.df@renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Hai Pham <hai.pham.ud@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
[Marek: Add dev_dbg() message in case tuning abort fails
        Move tuning opcode check from mmc_abort_tuning()]
---
V2: Update on previous patch changes
---
Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Cc: Hai Pham <hai.pham.ud@renesas.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Loic Poulain <loic.poulain@linaro.org>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Takeshi Kihara <takeshi.kihara.df@renesas.com>
---
 drivers/mmc/renesas-sdhi.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c
index 280d96dbc2d..484712b919e 100644
--- a/drivers/mmc/renesas-sdhi.c
+++ b/drivers/mmc/renesas-sdhi.c
@@ -611,6 +611,17 @@ int renesas_sdhi_execute_tuning(struct udevice *dev, uint opcode)
 			priv->smpcmp |= BIT(i);
 
 		mdelay(1);
+
+		/*
+		 * eMMC specification specifies that CMD12 can be used to stop a tuning
+		 * command, but SD specification does not, so do nothing unless it is
+		 * eMMC.
+		 */
+		if (ret && (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200)) {
+			ret = mmc_send_stop_transmission(mmc, true);
+			if (ret < 0)
+				dev_dbg(dev, "Tuning abort fail (%d)\n", ret);
+		}
 	}
 
 	ret = renesas_sdhi_select_tuning(priv, taps);
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment
  2023-06-14 13:42 [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Marek Vasut
  2023-06-14 13:42 ` [PATCH v2 2/3] mmc: Introduce mmc_send_stop_transmission() Marek Vasut
  2023-06-14 13:42 ` [PATCH v2 3/3] mmc: renesas-sdhi: Send stop when MMC tuning command fails Marek Vasut
@ 2023-06-15  4:08 ` Peng Fan
  2 siblings, 0 replies; 4+ messages in thread
From: Peng Fan @ 2023-06-15  4:08 UTC (permalink / raw)
  To: Marek Vasut, u-boot
  Cc: Ying-Chun Liu (PaulLiu),
	Hai Pham, Jaehoon Chung, Loic Poulain, Peng Fan, Simon Glass,
	Takeshi Kihara



On 6/14/2023 9:42 PM, Marek Vasut wrote:
> Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
> 
> 
> The MMC_CMD_STOP_TRANSMISSION response is R1 for read transfers
> per JEDEC Standard No. 84-B51 Page 126 . Correct the response
> type and add a comment about it.

Sorry, I may miss one point. CMD12 for SD is R1b. But CMD12
for eMMC is R1 and R1b.

I am not sure how we should do with current code.

Thanks,
Peng.

> 
> Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
> ---
> V2: New patch
> ---
> Cc: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
> Cc: Hai Pham <hai.pham.ud@renesas.com>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Loic Poulain <loic.poulain@linaro.org>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Takeshi Kihara <takeshi.kihara.df@renesas.com>
> ---
>   drivers/mmc/mmc.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 965bc8f0dba..f9b2f940389 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -427,7 +427,12 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
>          if (blkcnt > 1) {
>                  cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
>                  cmd.cmdarg = 0;
> -               cmd.resp_type = MMC_RSP_R1b;
> +               /*
> +                * JEDEC Standard No. 84-B51 Page 126
> +                * CMD12 STOP_TRANSMISSION R1/R1b[3]
> +                * NOTE 3 R1 for read cases and R1b for write cases.
> +                */
> +               cmd.resp_type = MMC_RSP_R1;
>                  if (mmc_send_cmd(mmc, &cmd, NULL)) {
>   #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
>                          pr_err("mmc fail to send stop cmd\n");
> --
> 2.39.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-15  4:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 13:42 [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Marek Vasut
2023-06-14 13:42 ` [PATCH v2 2/3] mmc: Introduce mmc_send_stop_transmission() Marek Vasut
2023-06-14 13:42 ` [PATCH v2 3/3] mmc: renesas-sdhi: Send stop when MMC tuning command fails Marek Vasut
2023-06-15  4:08 ` [PATCH v2 1/3] mmc: Fix MMC_CMD_STOP_TRANSMISSION response type and add comment Peng Fan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.