All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avri Altman <avri.altman@wdc.com>
To: Ulf Hansson <ulf.hansson@linaro.org>, linux-mmc@vger.kernel.org
Cc: Adrian Hunter <adrian.hunter@intel.com>,
	Daniil Lunev <dlunev@google.com>,
	Asutosh Das <quic_asutoshd@quicinc.com>,
	Avri Altman <avri.altman@wdc.com>
Subject: [PATCH v3 1/2] mmc: core: Mark close-ended ffu in progress
Date: Wed, 25 Oct 2023 14:30:34 +0300	[thread overview]
Message-ID: <20231025113035.1881418-2-avri.altman@wdc.com> (raw)
In-Reply-To: <20231025113035.1881418-1-avri.altman@wdc.com>

Field Firmware Update (ffu) may use close-ended or open ended sequence.
Each such sequence is comprised of a write commands enclosed between 2
switch commands - to and from ffu mode. So for the close-ended case, it
will be: cmd6->cmd23-cmd25-cmd6.

Capture this sequence and make it available for the host modules, should
it is needed.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/mmc/core/block.c | 34 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h |  1 +
 include/linux/mmc/mmc.h  |  1 +
 3 files changed, 36 insertions(+)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 3a8f27c3e310..ee5ec4686582 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -96,6 +96,10 @@ static int max_devices;
 static DEFINE_IDA(mmc_blk_ida);
 static DEFINE_IDA(mmc_rpmb_ida);
 
+static unsigned int ffu_progress;
+#define MMC_FFU_START	BIT(0)	/* FFU in progress */
+#define MMC_FFU_SBC	BIT(1)	/* close-ended FFU in progress */
+
 struct mmc_blk_busy_data {
 	struct mmc_card *card;
 	u32 status;
@@ -464,6 +468,34 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd __user *ic_ptr,
 	return 0;
 }
 
+bool mmc_is_ffu_cmd(struct mmc_command *cmd)
+{
+	return ((ffu_progress & MMC_FFU_SBC) &&
+		cmd->opcode == MMC_WRITE_MULTIPLE_BLOCK);
+}
+
+static void mmc_blk_ffu_progress(struct mmc_command *cmd)
+{
+	if (MMC_EXTRACT_INDEX_FROM_ARG(cmd->arg) != EXT_CSD_MODE_CONFIG &&
+	    ffu_progress == 0)
+		return;
+
+	if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd->arg) == EXT_CSD_MODE_CONFIG) &&
+	    (cmd->opcode == MMC_SWITCH)) {
+		u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd->arg);
+
+		if (value == 1)
+			ffu_progress = MMC_FFU_START;
+		else
+			ffu_progress = 0;
+
+		return;
+	} else if (ffu_progress == MMC_FFU_START &&
+		   cmd->opcode == MMC_SET_BLOCK_COUNT) {
+		ffu_progress |= MMC_FFU_SBC;
+	}
+}
+
 static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
 			       struct mmc_blk_ioc_data *idata)
 {
@@ -548,6 +580,8 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
 	    (cmd.opcode == MMC_SWITCH))
 		return mmc_sanitize(card, idata->ic.cmd_timeout_ms);
 
+	mmc_blk_ffu_progress(&cmd);
+
 	/* If it's an R1B response we need some more preparations. */
 	busy_timeout_ms = idata->ic.cmd_timeout_ms ? : MMC_BLK_TIMEOUT_MS;
 	r1b_resp = (cmd.flags & MMC_RSP_R1B) == MMC_RSP_R1B;
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index 2f445c651742..e2cb20f7c50c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -677,5 +677,6 @@ int mmc_send_status(struct mmc_card *card, u32 *status);
 int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error);
 int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode);
 int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd);
+bool mmc_is_ffu_cmd(struct mmc_command *cmd);
 
 #endif /* LINUX_MMC_HOST_H */
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 6f7993803ee7..d4d10cabaa57 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -254,6 +254,7 @@ static inline bool mmc_ready_for_data(u32 status)
  */
 
 #define EXT_CSD_CMDQ_MODE_EN		15	/* R/W */
+#define EXT_CSD_MODE_CONFIG		30	/* R/W */
 #define EXT_CSD_FLUSH_CACHE		32      /* W */
 #define EXT_CSD_CACHE_CTRL		33      /* R/W */
 #define EXT_CSD_POWER_OFF_NOTIFICATION	34	/* R/W */
-- 
2.42.0


  reply	other threads:[~2023-10-25 11:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-25 11:30 [PATCH v3 0/2] mmc: host: Disable auto-cmd12 during ffu Avri Altman
2023-10-25 11:30 ` Avri Altman [this message]
2023-10-25 11:30 ` [PATCH v3 2/2] mmc: host: msm: " Avri Altman
2023-10-26  8:38 ` [PATCH v3 0/2] mmc: host: " Adrian Hunter
2023-10-26 10:03   ` Ulf Hansson
2023-10-26 10:06   ` Avri Altman
2023-10-27  9:41     ` Ulf Hansson
2023-10-27 10:54       ` Adrian Hunter

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=20231025113035.1881418-2-avri.altman@wdc.com \
    --to=avri.altman@wdc.com \
    --cc=adrian.hunter@intel.com \
    --cc=dlunev@google.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=quic_asutoshd@quicinc.com \
    --cc=ulf.hansson@linaro.org \
    /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 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.