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 06/12] mmc: core: Enable re-use of mmc_blk_in_tran_state()
Date: Tue,  4 Feb 2020 09:54:43 +0100	[thread overview]
Message-ID: <20200204085449.32585-7-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20200204085449.32585-1-ulf.hansson@linaro.org>

To allow subsequent changes to re-use the code from the static function
mmc_blk_in_tran_state(), let's move it to a public header. While at it,
let's also rename it to mmc_ready_for_data(), as to try to better describe
its purpose.

Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
 drivers/mmc/core/block.c | 24 ++++--------------------
 include/linux/mmc/mmc.h  | 10 ++++++++++
 2 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 663d87924e5e..8ac12e3fff27 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -436,16 +436,6 @@ static int ioctl_do_sanitize(struct mmc_card *card)
 	return err;
 }
 
-static inline bool mmc_blk_in_tran_state(u32 status)
-{
-	/*
-	 * Some cards mishandle the status bits, so make sure to check both the
-	 * busy indication and the card state.
-	 */
-	return status & R1_READY_FOR_DATA &&
-	       (R1_CURRENT_STATE(status) == R1_STATE_TRAN);
-}
-
 static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
 			    u32 *resp_errs)
 {
@@ -477,13 +467,7 @@ static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms,
 				 __func__, status);
 			return -ETIMEDOUT;
 		}
-
-		/*
-		 * Some cards mishandle the status bits,
-		 * so make sure to check both the busy
-		 * indication and the card state.
-		 */
-	} while (!mmc_blk_in_tran_state(status));
+	} while (!mmc_ready_for_data(status));
 
 	return err;
 }
@@ -1666,7 +1650,7 @@ static void mmc_blk_read_single(struct mmc_queue *mq, struct request *req)
 			goto error_exit;
 
 		if (!mmc_host_is_spi(host) &&
-		    !mmc_blk_in_tran_state(status)) {
+		    !mmc_ready_for_data(status)) {
 			err = mmc_blk_fix_state(card, req);
 			if (err)
 				goto error_exit;
@@ -1726,7 +1710,7 @@ static bool mmc_blk_status_error(struct request *req, u32 status)
 	return brq->cmd.resp[0]  & CMD_ERRORS    ||
 	       brq->stop.resp[0] & stop_err_bits ||
 	       status            & stop_err_bits ||
-	       (rq_data_dir(req) == WRITE && !mmc_blk_in_tran_state(status));
+	       (rq_data_dir(req) == WRITE && !mmc_ready_for_data(status));
 }
 
 static inline bool mmc_blk_cmd_started(struct mmc_blk_request *brq)
@@ -1788,7 +1772,7 @@ static void mmc_blk_mq_rw_recovery(struct mmc_queue *mq, struct request *req)
 
 	/* Try to get back to "tran" state */
 	if (!mmc_host_is_spi(mq->card->host) &&
-	    (err || !mmc_blk_in_tran_state(status)))
+	    (err || !mmc_ready_for_data(status)))
 		err = mmc_blk_fix_state(mq->card, req);
 
 	/*
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 897a87c4c827..4b85ef05a906 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -161,6 +161,16 @@ static inline bool mmc_op_multi(u32 opcode)
 #define R1_STATE_PRG	7
 #define R1_STATE_DIS	8
 
+static inline bool mmc_ready_for_data(u32 status)
+{
+	/*
+	 * Some cards mishandle the status bits, so make sure to check both the
+	 * busy indication and the card state.
+	 */
+	return status & R1_READY_FOR_DATA &&
+	       R1_CURRENT_STATE(status) == R1_STATE_TRAN;
+}
+
 /*
  * MMC/SD in SPI mode reports R1 status always, and R2 for SEND_STATUS
  * R1 is the low order byte; R2 is the next highest byte, when present.
-- 
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 ` Ulf Hansson [this message]
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 ` [PATCH 12/12] mmc: core: Re-work the error path for the eMMC sanitize command Ulf Hansson
2020-02-11 22:29   ` 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-7-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).