Skip to contentSkip to conversation

mmc: dw_mmc: Avoid hung state if GEN_CMD transfer fails

PATCH In review Mårten Lindahl 4 participants 4 messages Nov 3, 2021 – Nov 15, 2021

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

PATCH 1/1 mmc: dw_mmc: Avoid hung state if GEN_CMD transfer fails

If we get a data error during a block transfer command, a stop command (CMD12) is normally initiated. But this does not work for the general command (CMD56), but instead the action is ignored and an uninitialized command struct is used for the stop action, with unexpected result.

Fix this by adding a check for GEN_CMD when preparing stop transmission.

---
 drivers/mmc/host/dw_mmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/dw_mmc.c +2 -1
index 6578cc64ae9e..988c32e93e03 100644
@@ -335,7 +335,8 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
 	    cmdr == MMC_WRITE_BLOCK ||
 	    cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
 	    cmdr == MMC_SEND_TUNING_BLOCK ||
-	    cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
+	    cmdr == MMC_SEND_TUNING_BLOCK_HS200 ||
+	    cmdr == MMC_GEN_CMD) {
 		stop->opcode = MMC_STOP_TRANSMISSION;
 		stop->arg = 0;
 		stop->flags = MMC_RSP_R1B | MMC_CMD_AC;
Signature · 1 line
2.20.1
#1 lore raw
Quoted 17 lines · Mårten Lindahl

If we get a data error during a block transfer command, a stop command (CMD12) is normally initiated. But this does not work for the general command (CMD56), but instead the action is ignored and an uninitialized command struct is used for the stop action, with unexpected result.

Fix this by adding a check for GEN_CMD when preparing stop transmission.

---
 drivers/mmc/host/dw_mmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..988c32e93e03 100644

drivers/mmc/host/dw_mmc.c static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd) · line 342

Quoted 9 lines
drivers/mmc/host/dw_mmc.c +2 -1
@@ -335,7 +335,8 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
 	    cmdr == MMC_WRITE_BLOCK ||
 	    cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
 	    cmdr == MMC_SEND_TUNING_BLOCK ||
-	    cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
+	    cmdr == MMC_SEND_TUNING_BLOCK_HS200 ||
+	    cmdr == MMC_GEN_CMD) {
 		stop->opcode = MMC_STOP_TRANSMISSION;
 		stop->arg = 0;
 		stop->flags = MMC_RSP_R1B | MMC_CMD_AC;

While this fix looks correct for CMD56, the "Data transfer mode" sections of the eMMC and SD specifications list several more data commands, all of which can be aborted by CMD12, but which aren't handled in the if above.

If I'm not mistaken, those will also result in an uninitialized stop command being sent in the case of an error, since the driver calls send_stop_abort() on any data error.

Is there a reason why those other commands should not be in the list above, or should we fix this list so that CMD12 is initialized for all data commands except SD_IO_RW_EXTENDED?

#2 lore raw
Quoted 13 lines · Vincent Whitchurch
Quoted 12 lines · Mårten Lindahl

If we get a data error during a block transfer command, a stop command (CMD12) is normally initiated. But this does not work for the general command (CMD56), but instead the action is ignored and an uninitialized command struct is used for the stop action, with unexpected result.

Fix this by adding a check for GEN_CMD when preparing stop transmission.

---
 drivers/mmc/host/dw_mmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 5 lines
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..988c32e93e03 100644

drivers/mmc/host/dw_mmc.c static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd) · line 342

Quoted 9 lines
drivers/mmc/host/dw_mmc.c +2 -1
@@ -335,7 +335,8 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
 	    cmdr == MMC_WRITE_BLOCK ||
 	    cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
 	    cmdr == MMC_SEND_TUNING_BLOCK ||
-	    cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
+	    cmdr == MMC_SEND_TUNING_BLOCK_HS200 ||
+	    cmdr == MMC_GEN_CMD) {
 		stop->opcode = MMC_STOP_TRANSMISSION;
 		stop->arg = 0;
 		stop->flags = MMC_RSP_R1B | MMC_CMD_AC;

Hi!

Quoted 6 lines

While this fix looks correct for CMD56, the "Data transfer mode" sections of the eMMC and SD specifications list several more data commands, all of which can be aborted by CMD12, but which aren't handled in the if above.

Quoted 7 lines

If I'm not mistaken, those will also result in an uninitialized stop command being sent in the case of an error, since the driver calls send_stop_abort() on any data error.

Is there a reason why those other commands should not be in the list above, or should we fix this list so that CMD12 is initialized for all data commands except SD_IO_RW_EXTENDED?

I agree that there are more commands that according to the specification should be included in the list. The most obvious ones that I identify are:
CMD26, CMD27, CMD30, CMD46, and CMD47.

But the reason why I added just CMD56 is that I have an easy way to test this specific command, and which was how I saw the need for this fix.

My suggestion is to separate adding the other commands to one (or more) separate patch(es), to when there are good test cases for those.

Kind regards
Mårten

#3 lore raw
Quoted 49 lines · Marten Lindahl
Quoted 13 lines · Vincent Whitchurch
Quoted 12 lines · Mårten Lindahl

If we get a data error during a block transfer command, a stop command (CMD12) is normally initiated. But this does not work for the general command (CMD56), but instead the action is ignored and an uninitialized command struct is used for the stop action, with unexpected result.

Fix this by adding a check for GEN_CMD when preparing stop transmission.

---
 drivers/mmc/host/dw_mmc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines
Quoted 5 lines
drivers/mmc/host/dw_mmc.c +0 -0
index 6578cc64ae9e..988c32e93e03 100644

drivers/mmc/host/dw_mmc.c static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd) · line 342

Quoted 9 lines
drivers/mmc/host/dw_mmc.c +2 -1
@@ -335,7 +335,8 @@ static u32 dw_mci_prep_stop_abort(struct dw_mci *host, struct mmc_command *cmd)
        cmdr == MMC_WRITE_BLOCK ||
        cmdr == MMC_WRITE_MULTIPLE_BLOCK ||
        cmdr == MMC_SEND_TUNING_BLOCK ||
-       cmdr == MMC_SEND_TUNING_BLOCK_HS200) {
+       cmdr == MMC_SEND_TUNING_BLOCK_HS200 ||
+       cmdr == MMC_GEN_CMD) {
            stop->opcode = MMC_STOP_TRANSMISSION;
            stop->arg = 0;
            stop->flags = MMC_RSP_R1B | MMC_CMD_AC;

Hi!

Quoted 6 lines

While this fix looks correct for CMD56, the "Data transfer mode" sections of the eMMC and SD specifications list several more data commands, all of which can be aborted by CMD12, but which aren't handled in the if above.

Quoted 7 lines

If I'm not mistaken, those will also result in an uninitialized stop command being sent in the case of an error, since the driver calls send_stop_abort() on any data error.

Is there a reason why those other commands should not be in the list above, or should we fix this list so that CMD12 is initialized for all data commands except SD_IO_RW_EXTENDED?

I agree that there are more commands that according to the specification should be included in the list. The most obvious ones that I identify are:
CMD26, CMD27, CMD30, CMD46, and CMD47.

Quoted 5 lines

But the reason why I added just CMD56 is that I have an easy way to test this specific command, and which was how I saw the need for this fix.

My suggestion is to separate adding the other commands to one (or more) separate patch(es), to when there are good test cases for those.

I agree with both of you, it would be nice to make a change that takes care of all the relevant commands at once, rather than having to come back to this later again.

On the other hand, as it's not always straightforward to test the other commands, I am fine with this as well.

So, applied for next, thanks!

Kind regards
Uffe