linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ulf Hansson <ulf.hansson@linaro.org>
To: linux-mmc@vger.kernel.org, Ulf Hansson <ulf.hansson@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Wolfram Sang <wsa+renesas@sang-engineering.com>,
	Ludovic Barre <ludovic.barre@st.com>,
	Baolin Wang <baolin.wang7@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Chaotian Jing <chaotian.jing@mediatek.com>,
	Shawn Lin <shawn.lin@rock-chips.com>,
	mirq-linux@rere.qmqm.pl
Subject: [PATCH 12/12] mmc: core: Re-work the error path for the eMMC sanitize command
Date: Tue,  4 Feb 2020 09:54:49 +0100	[thread overview]
Message-ID: <20200204085449.32585-13-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org>

The error path for sanitize operations that returns with a -ETIMEDOUT error
code, is for some reason very tightly coupled with the internal request
handling code of the mmc core. For example, mmc_wait_for_req_done() runs
code at completion of requests, to check specific sanitize errors. This is
inefficient, as at it affects all types of requests.

To improve the behaviour, let's move the error management for sanitize
requests into ioctl_do_sanitize(), as it's really there it belongs. Moving
the error handling requires retuning to be held, so let's do that.

While updating this code, let's also take the opportunity to clean it up a
bit.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/core/block.c   | 33 +++++++++++++++++++--------------
 drivers/mmc/core/core.c    | 17 -----------------
 drivers/mmc/core/mmc_ops.c |  3 ---
 include/linux/mmc/core.h   |  3 ---
 4 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 8ac12e3fff27..db59c51052df 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -410,29 +410,34 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
 
 static int ioctl_do_sanitize(struct mmc_card *card)
 {
+	struct mmc_host *host = card->host;
 	int err;
 
 	if (!mmc_can_sanitize(card)) {
-			pr_warn("%s: %s - SANITIZE is not supported\n",
-				mmc_hostname(card->host), __func__);
-			err = -EOPNOTSUPP;
-			goto out;
+		pr_warn("%s: SANITIZE is not supported\n", mmc_hostname(host));
+		return -EOPNOTSUPP;
 	}
 
-	pr_debug("%s: %s - SANITIZE IN PROGRESS...\n",
-		mmc_hostname(card->host), __func__);
+	pr_debug("%s: SANITIZE IN PROGRESS...\n", mmc_hostname(host));
 
-	err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
-					EXT_CSD_SANITIZE_START, 1,
-					MMC_SANITIZE_REQ_TIMEOUT);
+	mmc_retune_hold(host);
 
+	err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_SANITIZE_START,
+			 1, MMC_SANITIZE_REQ_TIMEOUT);
 	if (err)
-		pr_err("%s: %s - EXT_CSD_SANITIZE_START failed. err=%d\n",
-		       mmc_hostname(card->host), __func__, err);
+		pr_err("%s: SANITIZE failed err=%d\n", mmc_hostname(host), err);
 
-	pr_debug("%s: %s - SANITIZE COMPLETED\n", mmc_hostname(card->host),
-					     __func__);
-out:
+	/*
+	 * If the santize operation timed out, the card is probably still busy
+	 * in the R1_STATE_PRG. Rather than continue to wait, let's try to abort
+	 * it with a HPI command to get back into R1_STATE_TRAN.
+	 */
+	if (err == -ETIMEDOUT && !mmc_interrupt_hpi(card))
+		pr_warn("%s: Sanitize aborted\n", mmc_hostname(host));
+
+	mmc_retune_release(host);
+
+	pr_debug("%s: SANITIZE COMPLETED\n", mmc_hostname(host));
 	return err;
 }
 
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 6b38c194d74f..95db8ffbdd35 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -403,23 +403,6 @@ void mmc_wait_for_req_done(struct mmc_host *host, struct mmc_request *mrq)
 
 		cmd = mrq->cmd;
 
-		/*
-		 * If host has timed out waiting for the sanitize
-		 * to complete, card might be still in programming state
-		 * so let's try to bring the card out of programming
-		 * state.
-		 */
-		if (cmd->sanitize_busy && cmd->error == -ETIMEDOUT) {
-			if (!mmc_interrupt_hpi(host->card)) {
-				pr_warn("%s: %s: Interrupted sanitize\n",
-					mmc_hostname(host), __func__);
-				cmd->error = 0;
-				break;
-			} else {
-				pr_err("%s: %s: Failed to interrupt sanitize\n",
-				       mmc_hostname(host), __func__);
-			}
-		}
 		if (!cmd->error || !cmd->retries ||
 		    mmc_card_removed(host->card))
 			break;
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index aa0cab190cd8..c08f8b723a3b 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -595,9 +595,6 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
 		cmd.flags |= MMC_RSP_SPI_R1 | MMC_RSP_R1;
 	}
 
-	if (index == EXT_CSD_SANITIZE_START)
-		cmd.sanitize_busy = true;
-
 	err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES);
 	if (err)
 		goto out;
diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h
index b7ba8810a3b5..29aa50711626 100644
--- a/include/linux/mmc/core.h
+++ b/include/linux/mmc/core.h
@@ -107,9 +107,6 @@ struct mmc_command {
  */
 
 	unsigned int		busy_timeout;	/* busy detect timeout in ms */
-	/* Set this flag only for blocking sanitize request */
-	bool			sanitize_busy;
-
 	struct mmc_data		*data;		/* data segment associated with cmd */
 	struct mmc_request	*mrq;		/* associated request */
 };
-- 
2.17.1


  parent reply	other threads:[~2020-02-04  8:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-04  8:54 [PATCH 00/12] mmc: core: Improve code for polling and HW busy detect Ulf Hansson
2020-02-04  8:54 ` [PATCH 01/12] mmc: core: Throttle polling rate for CMD6 Ulf Hansson
2020-02-12 13:51   ` Ludovic BARRE
2020-02-12 14:18     ` Ulf Hansson
2020-02-12 14:24       ` Ludovic BARRE
2020-02-04  8:54 ` [PATCH 02/12] mmc: core: Drop unused define Ulf Hansson
2020-02-04  8:54 ` [PATCH 03/12] mmc: core: Extend mmc_switch_status() to rid of __mmc_switch_status() Ulf Hansson
2020-02-04  8:54 ` [PATCH 04/12] mmc: core: Drop redundant in-parameter to __mmc_switch() Ulf Hansson
2020-02-04  8:54 ` [PATCH 05/12] mmc: core: Split up mmc_poll_for_busy() Ulf Hansson
2020-02-04  8:54 ` [PATCH 06/12] mmc: core: Enable re-use of mmc_blk_in_tran_state() Ulf Hansson
2020-02-04  8:54 ` [PATCH 07/12] mmc: core: Update CMD13 busy check for CMD6 commands Ulf Hansson
2020-02-04  8:54 ` [PATCH 08/12] mmc: core: Convert to mmc_poll_for_busy() for erase/trim/discard Ulf Hansson
2020-02-04  8:54 ` [PATCH 09/12] mmc: core: Drop redundant out-parameter to mmc_send_hpi_cmd() Ulf Hansson
2020-02-04  8:54 ` [PATCH 10/12] mmc: core: Convert to mmc_poll_for_busy() for HPI commands Ulf Hansson
2020-02-04  8:54 ` [PATCH 11/12] mmc: core: Fixup support for HW busy detection " Ulf Hansson
2020-02-04  8:54 ` Ulf Hansson [this message]
2020-02-11 22:29   ` [PATCH 12/12] mmc: core: Re-work the error path for the eMMC sanitize command kbuild test robot
2020-02-11 13:17 ` [PATCH 00/12] mmc: core: Improve code for polling and HW busy detect Baolin Wang
2020-02-13  6:23   ` Baolin Wang
2020-02-13 11:08     ` Ulf Hansson
2020-02-13 14:42     ` Ludovic BARRE
2020-02-14 14:21       ` Ulf Hansson
2020-02-18 23:38 ` Ulf Hansson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200204085449.32585-13-ulf.hansson@linaro.org \
    --to=ulf.hansson@linaro.org \
    --cc=adrian.hunter@intel.com \
    --cc=baolin.wang7@gmail.com \
    --cc=chaotian.jing@mediatek.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ludovic.barre@st.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=shawn.lin@rock-chips.com \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).