linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Lai <jasonlai.genesyslogic@gmail.com>
To: ulf.hansson@linaro.org, adrian.hunter@intel.com
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	ben.chuang@genesyslogic.com.tw, greg.tu@genesyslogic.com.tw,
	jason.lai@genesyslogiv.com.tw,
	AKASHI Takahiro <takahiro.akashi@linaro.org>
Subject: [RFC PATCH v3.2 06/29] mmc: core: UHS-II support, generate UHS-II SD command packet
Date: Thu, 22 Jul 2021 12:01:01 +0800	[thread overview]
Message-ID: <20210722040124.7573-6-jasonlai.genesyslogic@gmail.com> (raw)
In-Reply-To: <20210722040124.7573-1-jasonlai.genesyslogic@gmail.com>

In SD-TRAN protocol, legacy SD commands should be "encapsulated" in SD
packets as described in SD specification.
Please see section 7.1 and 7.2.1 in "UHS-II Simplified Addendum."

Signed-off-by: Ben Chuang <ben.chuang@genesyslogic.com.tw>
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
 drivers/mmc/core/core.c | 18 +++++++++++
 drivers/mmc/core/uhs2.c | 70 +++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/uhs2.h |  1 +
 3 files changed, 89 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 300812c69e13..d53722c21f29 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -338,6 +338,8 @@ static int mmc_mrq_prep(struct mmc_host *host, struct mmc_request *mrq)

 int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 {
+	struct uhs2_command uhs2_cmd;
+	u32 payload[4]; /* for maximum size */
 	int err;

 	init_completion(&mrq->cmd_completion);
@@ -355,6 +357,13 @@ int mmc_start_request(struct mmc_host *host, struct mmc_request *mrq)
 	if (err)
 		return err;

+	if (host->flags & MMC_UHS2_SUPPORT &&
+	    host->flags & MMC_UHS2_INITIALIZED) {
+		uhs2_cmd.payload = payload;
+		mrq->cmd->uhs2_cmd = &uhs2_cmd;
+		uhs2_prepare_sd_cmd(host, mrq);
+	}
+
 	led_trigger_event(host->led, LED_FULL);
 	__mmc_start_request(host, mrq);

@@ -434,6 +443,8 @@ EXPORT_SYMBOL(mmc_wait_for_req_done);
  */
 int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)
 {
+	struct uhs2_command uhs2_cmd;
+	u32 payload[4]; /* for maximum size */
 	int err;

 	/*
@@ -454,6 +465,13 @@ int mmc_cqe_start_req(struct mmc_host *host, struct mmc_request *mrq)
 	if (err)
 		goto out_err;

+	if (host->flags & MMC_UHS2_SUPPORT &&
+	    host->flags & MMC_UHS2_INITIALIZED) {
+		uhs2_cmd.payload = payload;
+		mrq->cmd->uhs2_cmd = &uhs2_cmd;
+		uhs2_prepare_sd_cmd(host, mrq);
+	}
+
 	err = host->cqe_ops->cqe_request(host, mrq);
 	if (err)
 		goto out_err;
diff --git a/drivers/mmc/core/uhs2.c b/drivers/mmc/core/uhs2.c
index acb46b5b57ef..1f6d0e0cf355 100644
--- a/drivers/mmc/core/uhs2.c
+++ b/drivers/mmc/core/uhs2.c
@@ -807,3 +807,73 @@ int mmc_uhs2_rescan_try_freq(struct mmc_host *host, unsigned int freq)
 	return err;
 }
 EXPORT_SYMBOL_GPL(mmc_uhs2_rescan_try_freq);
+
+/**
+ * uhs2_prepare_sd_cmd - prepare for SD command packet
+ * @host:	MMC host
+ * @mrq:	MMC request
+ *
+ * Initialize and fill in a header and a payload of SD command packet.
+ * The caller should allocate uhs2_command in host->cmd->uhs2_cmd in
+ * advance.
+ *
+ * Return:	0 on success, non-zero error on failure
+ */
+int uhs2_prepare_sd_cmd(struct mmc_host *host, struct mmc_request *mrq)
+{
+	struct mmc_command *cmd;
+	struct uhs2_command *uhs2_cmd;
+	u16 header = 0, arg = 0;
+	u32 *payload;
+	u8 plen = 0;
+
+	cmd = mrq->cmd;
+	header = host->uhs2_dev_prop.node_id;
+	if ((cmd->flags & MMC_CMD_MASK) == MMC_CMD_ADTC)
+		header |= UHS2_PACKET_TYPE_DCMD;
+	else
+		header |= UHS2_PACKET_TYPE_CCMD;
+
+	arg = cmd->opcode << UHS2_SD_CMD_INDEX_POS;
+
+	uhs2_cmd = cmd->uhs2_cmd;
+	payload = uhs2_cmd->payload;
+	plen = 2; /* at the maximum */
+
+	if ((cmd->flags & MMC_CMD_MASK) == MMC_CMD_ADTC &&
+	    !cmd->uhs2_tmode0_flag) {
+		if (host->flags & MMC_UHS2_2L_HD)
+			arg |= UHS2_DCMD_2L_HD_MODE;
+
+		arg |= UHS2_DCMD_LM_TLEN_EXIST;
+
+		if (cmd->data->blocks == 1 &&
+		    cmd->data->blksz != 512 &&
+		    cmd->opcode != MMC_READ_SINGLE_BLOCK &&
+		    cmd->opcode != MMC_WRITE_BLOCK) {
+			arg |= UHS2_DCMD_TLUM_BYTE_MODE;
+			payload[1] = uhs2_dcmd_convert_msb(cmd->data->blksz);
+		} else {
+			payload[1] = uhs2_dcmd_convert_msb(cmd->data->blocks);
+		}
+
+		if (cmd->opcode == SD_IO_RW_EXTENDED) {
+			arg &= ~(UHS2_DCMD_LM_TLEN_EXIST |
+				UHS2_DCMD_TLUM_BYTE_MODE |
+				UHS2_NATIVE_DCMD_DAM_IO);
+			payload[1] = 0;
+			plen = 1;
+		}
+	} else {
+		plen = 1;
+	}
+
+	payload[0] = uhs2_dcmd_convert_msb(cmd->arg);
+	pr_debug("%s: %s: sd_cmd->arg = 0x%x, payload[0]= 0x%x.\n",
+		 mmc_hostname(host), __func__, cmd->arg, payload[0]);
+
+	uhs2_cmd_assemble(cmd, uhs2_cmd, header, arg, payload, plen, NULL, 0);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(uhs2_prepare_sd_cmd);
diff --git a/drivers/mmc/core/uhs2.h b/drivers/mmc/core/uhs2.h
index e3389d4dda3b..48486ba21062 100644
--- a/drivers/mmc/core/uhs2.h
+++ b/drivers/mmc/core/uhs2.h
@@ -16,5 +16,6 @@
 #define UHS2_PHY_INIT_ERR	1

 int mmc_uhs2_rescan_try_freq(struct mmc_host *host, unsigned int freq);
+int uhs2_prepare_sd_cmd(struct mmc_host *host, struct mmc_request *mrq);

 #endif /* MMC_UHS2_H */
--
2.32.0


  parent reply	other threads:[~2021-07-22  4:02 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22  4:00 [RFC PATCH v3.2 01/29] mmc: add UHS-II related definitions in public headers Jason Lai
2021-07-22  4:00 ` [RFC PATCH v3.2 02/29] mmc: core: UHS-II support, modify power-up sequence Jason Lai
2021-07-22  4:00 ` [RFC PATCH v3.2 03/29] mmc: core: UHS-II support, skip set_chip_select() Jason Lai
2021-07-22  4:00 ` [RFC PATCH v3.2 04/29] mmc: core: UHS-II support, try to select UHS-II interface Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 05/29] mmc: core: UHS-II support, skip TMODE setup in some cases Jason Lai
2021-07-22  4:01 ` Jason Lai [this message]
2021-07-22  4:01 ` [RFC PATCH v3.2 07/29] mmc: core: UHS-II support, set APP_CMD bit if necessary Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 08/29] mmc: sdhci: add a kernel configuration for enabling UHS-II support Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 09/29] mmc: sdhci: add UHS-II related definitions in headers Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 10/29] mmc: sdhci: add UHS-II module Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 11/29] mmc: sdhci-uhs2: dump UHS-II registers Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 12/29] mmc: sdhci-uhs2: add reset function Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 13/29] mmc: sdhci-uhs2: add set_power() to support vdd2 Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 14/29] mmc: sdhci-uhs2: skip signal_voltage_switch() Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 15/29] mmc: sdhci-uhs2: add set_timeout() Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 16/29] mmc: sdhci-uhs2: add set_ios() Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 17/29] mmc: sdhci-uhs2: add detect_init() to detect the interface Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 18/29] mmc: sdhci-uhs2: add clock operations Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 19/29] mmc: sdhci-uhs2: add set_reg() to initialise the interface Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 20/29] mmc: sdhci-uhs2: add request() and others Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 21/29] mmc: sdhci-uhs2: add irq() " Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 22/29] mmc: sdhci-uhs2: add add_host() and others to set up the driver Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 23/29] mmc: sdhci-uhs2: add pre-detect_init hook Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 24/29] mmc: core: add post-mmc_attach_sd hook Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 25/29] mmc: sdhci-uhs2: " Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 26/29] mmc: sdhci-pci: add UHS-II support framework Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 27/29] mmc: sdhci-pci-gli: enable UHS-II mode for GL9755 Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 28/29] mmc: Remove duplicate code Jason Lai
2021-07-22  4:01 ` [RFC PATCH v3.2 29/29] mmc: core: Apply Ulf's patch for supporting UHS-II card Jason Lai

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=20210722040124.7573-6-jasonlai.genesyslogic@gmail.com \
    --to=jasonlai.genesyslogic@gmail.com \
    --cc=adrian.hunter@intel.com \
    --cc=ben.chuang@genesyslogic.com.tw \
    --cc=greg.tu@genesyslogic.com.tw \
    --cc=jason.lai@genesyslogiv.com.tw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=takahiro.akashi@linaro.org \
    --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 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).