diff mbox series

[PATCHv3] mmc-utils: Add basic erase error check

Message ID c91cdde6288d4db6aad45f5d50d129c8@hyperstone.com (mailing list archive)
State New, archived
Headers show
Series [PATCHv3] mmc-utils: Add basic erase error check | expand

Commit Message

Christian Loehle Jan. 16, 2023, 11:18 a.m. UTC
Check for erase specific R1 errors so e.g. an OOR erase is not
reported as successful when it never executed.

There could be checks for more error bits but R1_ERASE_SEQ_ERROR
on CMD38 should catch all that are reported by hardware anyway.

Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
---
-v3: Check for ERASE_PARAM on CMD36
-v2: Remove unneeded error bit checking
 mmc_cmds.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Avri Altman Jan. 16, 2023, 11:21 a.m. UTC | #1
> Check for erase specific R1 errors so e.g. an OOR erase is not reported as
> successful when it never executed.
> 
> There could be checks for more error bits but R1_ERASE_SEQ_ERROR on
> CMD38 should catch all that are reported by hardware anyway.
> 
> Signed-off-by: Christian Loehle <cloehle@hyperstone.com>
Reviewed-by: Avri Altman <avri.altman@wdc.com>

> ---
> -v3: Check for ERASE_PARAM on CMD36
> -v2: Remove unneeded error bit checking
>  mmc_cmds.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index e6d3273..6c50bbe 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -54,7 +54,6 @@
>  #define WPTYPE_PWRON 2
>  #define WPTYPE_PERM 3
> 
> -
>  int read_extcsd(int fd, __u8 *ext_csd)
>  {
>         int ret = 0;
> @@ -2668,6 +2667,18 @@ static int erase(int dev_fd, __u32 argin, __u32 start,
> __u32 end)
>         if (ret)
>                 perror("Erase multi-cmd ioctl");
> 
> +       /* Does not work for SPI cards */
> +       if (multi_cmd->cmds[1].response[0] & R1_ERASE_PARAM) {
> +               fprintf(stderr, "Erase start response: 0x%08x\n",
> +                               multi_cmd->cmds[0].response[0]);
> +               ret = -EIO;
> +       }
> +       if (multi_cmd->cmds[2].response[0] & R1_ERASE_SEQ_ERROR) {
> +               fprintf(stderr, "Erase response: 0x%08x\n",
> +                               multi_cmd->cmds[2].response[0]);
> +               ret = -EIO;
> +       }
> +
>         free(multi_cmd);
>         return ret;
>  }
> --
> 2.37.3
> 
> 
> Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz Managing Director:
> Dr. Jan Peter Berns.
> Commercial register of local courts: Freiburg HRB381782
Ulf Hansson Feb. 9, 2023, 2:19 p.m. UTC | #2
On Mon, 16 Jan 2023 at 12:19, Christian Löhle <CLoehle@hyperstone.com> wrote:
>
> Check for erase specific R1 errors so e.g. an OOR erase is not
> reported as successful when it never executed.
>
> There could be checks for more error bits but R1_ERASE_SEQ_ERROR
> on CMD38 should catch all that are reported by hardware anyway.
>
> Signed-off-by: Christian Loehle <cloehle@hyperstone.com>

Applied to git.kernel.org/pub/scm/utils/mmc/mmc-utils.git master, thanks!

Kind regards
Uffe


> ---
> -v3: Check for ERASE_PARAM on CMD36
> -v2: Remove unneeded error bit checking
>  mmc_cmds.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index e6d3273..6c50bbe 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -54,7 +54,6 @@
>  #define WPTYPE_PWRON 2
>  #define WPTYPE_PERM 3
>
> -
>  int read_extcsd(int fd, __u8 *ext_csd)
>  {
>         int ret = 0;
> @@ -2668,6 +2667,18 @@ static int erase(int dev_fd, __u32 argin, __u32 start, __u32 end)
>         if (ret)
>                 perror("Erase multi-cmd ioctl");
>
> +       /* Does not work for SPI cards */
> +       if (multi_cmd->cmds[1].response[0] & R1_ERASE_PARAM) {
> +               fprintf(stderr, "Erase start response: 0x%08x\n",
> +                               multi_cmd->cmds[0].response[0]);
> +               ret = -EIO;
> +       }
> +       if (multi_cmd->cmds[2].response[0] & R1_ERASE_SEQ_ERROR) {
> +               fprintf(stderr, "Erase response: 0x%08x\n",
> +                               multi_cmd->cmds[2].response[0]);
> +               ret = -EIO;
> +       }
> +
>         free(multi_cmd);
>         return ret;
>  }
> --
> 2.37.3
>
>
> Hyperstone GmbH | Reichenaustr. 39a  | 78467 Konstanz
> Managing Director: Dr. Jan Peter Berns.
> Commercial register of local courts: Freiburg HRB381782
>
diff mbox series

Patch

diff --git a/mmc_cmds.c b/mmc_cmds.c
index e6d3273..6c50bbe 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -54,7 +54,6 @@ 
 #define WPTYPE_PWRON 2
 #define WPTYPE_PERM 3
 
-
 int read_extcsd(int fd, __u8 *ext_csd)
 {
 	int ret = 0;
@@ -2668,6 +2667,18 @@  static int erase(int dev_fd, __u32 argin, __u32 start, __u32 end)
 	if (ret)
 		perror("Erase multi-cmd ioctl");
 
+	/* Does not work for SPI cards */
+	if (multi_cmd->cmds[1].response[0] & R1_ERASE_PARAM) {
+		fprintf(stderr, "Erase start response: 0x%08x\n",
+				multi_cmd->cmds[0].response[0]);
+		ret = -EIO;
+	}
+	if (multi_cmd->cmds[2].response[0] & R1_ERASE_SEQ_ERROR) {
+		fprintf(stderr, "Erase response: 0x%08x\n",
+				multi_cmd->cmds[2].response[0]);
+		ret = -EIO;
+	}
+
 	free(multi_cmd);
 	return ret;
 }