Skip to contentSkip to conversation

mmc: core: Add capability for hosts supporting long HW busy wait

PATCH In review Sowjanya Komatineni 2 participants 5 messages Mar 10, 2020 – Mar 17, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 mmc: core: Add capability for hosts supporting long HW busy wait

Some mmc operation like SLEEP_AWAKE and cache flush through SWITCH command takes longer time and for host controllers supporting HW busy detection, core driver converts R1B type to R1 type response for these commands if operation time is more than HW busy timeout and uses SW poll for busy state.

This patch adds a host capability MMC_CAP2_LONG_WAIT_HW_BUSY for hosts supporting long or infinite busy wait of HW busy detection for these long mmc operations and prevents core driver from converting R1B to R1 response type.

---
 drivers/mmc/core/mmc.c     | 3 ++-
 drivers/mmc/core/mmc_ops.c | 3 ++-
 include/linux/mmc/host.h   | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/mmc/core/mmc.c +2 -1
index c2abd41..5aea3a6 100644
@@ -1916,7 +1916,8 @@ static int mmc_sleep(struct mmc_host *host)
 	 * from doing hw busy detection, which is done by converting to a R1
 	 * response instead of a R1B.
 	 */
-	if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout)) {
+	if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout) &&
+	    !(host->caps2 & MMC_CAP2_LONG_WAIT_HW_BUSY)) {
 		cmd.flags = MMC_RSP_R1 | MMC_CMD_AC;
 	} else {
 		cmd.flags = MMC_RSP_R1B | MMC_CMD_AC;
drivers/mmc/core/mmc_ops.c +2 -1
index aa0cab1..251b4c7 100644
@@ -579,7 +579,8 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value,
 	 * the host to avoid HW busy detection, by converting to a R1 response
 	 * instead of a R1B.
 	 */
-	if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout))
+	if (host->max_busy_timeout && (timeout_ms > host->max_busy_timeout) &&
+	    !(host->caps2 & MMC_CAP2_LONG_WAIT_HW_BUSY))
 		use_r1b_resp = false;
 
 	cmd.opcode = MMC_SWITCH;
include/linux/mmc/host.h +1 -0
index 6aaa15e..1cda4dd 100644
@@ -371,6 +371,7 @@ struct mmc_host {
 #define MMC_CAP2_CQE_DCMD	(1 << 24)	/* CQE can issue a direct command */
 #define MMC_CAP2_AVOID_3_3V	(1 << 25)	/* Host must negotiate down from 3.3V */
 #define MMC_CAP2_MERGE_CAPABLE	(1 << 26)	/* Host can merge a segment over the segment size */
+#define MMC_CAP2_LONG_WAIT_HW_BUSY (1 << 27)	/* Host can support long busy timeout, do not convert R1B to R1 response */
 
 	int			fixed_drv_type;	/* fixed driver type for non-removable media */
 
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/3 mmc: tegra: Implement HW busy wait timeout based on command busy time

Tegra host supports HW busy detection and timeouts based on the count programmed in SDHCI_TIMEOUT_CONTROL register and max busy timeout it supports is 11s in finite busy wait mode.

Some operations like SLEEP_AWAKE, ERASE and flush cache through SWITCH commands take longer than 11s and Tegra host supports infinite HW busy wait mode where HW waits forever till the card is busy without HW timeout.

This patch implements Tegra specific set_timeout sdhci_ops to allow switching between finite and infinite HW busy detection wait modes based on the device command expected operation time.

---
 drivers/mmc/host/sdhci-tegra.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/mmc/host/sdhci-tegra.c +31 -0
index 403ac44..40a221d 100644
@@ -45,6 +45,7 @@
 #define SDHCI_TEGRA_CAP_OVERRIDES_DQS_TRIM_SHIFT	8
 
 #define SDHCI_TEGRA_VENDOR_MISC_CTRL			0x120
+#define SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT		BIT(0)
 #define SDHCI_MISC_CTRL_ENABLE_SDR104			0x8
 #define SDHCI_MISC_CTRL_ENABLE_SDR50			0x10
 #define SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300		0x20
@@ -1227,6 +1228,34 @@ static u32 sdhci_tegra_cqhci_irq(struct sdhci_host *host, u32 intmask)
 	return 0;
 }
 
+static void tegra_sdhci_set_timeout(struct sdhci_host *host,
+				    struct mmc_command *cmd)
+{
+	u32 val;
+
+	/*
+	 * HW busy detection timeout is based on programmed data timeout
+	 * counter and maximum supported timeout is 11s which may not be
+	 * enough for long operations like cache flush, sleep awake, erase.
+	 *
+	 * ERASE_TIMEOUT_LIMIT bit of VENDOR_MISC_CTRL register allows
+	 * host controller to wait for busy state until the card is busy
+	 * without HW timeout.
+	 *
+	 * So, use infinite busy wait mode for operations that may take
+	 * more than maximum HW busy timeout of 11s otherwise use finite
+	 * busy wait mode.
+	 */
+	val = sdhci_readl(host, SDHCI_TEGRA_VENDOR_MISC_CTRL);
+	if (cmd && cmd->busy_timeout >= 11 * HZ)
+		val |= SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT;
+	else
+		val &= ~SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT;
+	sdhci_writel(host, val, SDHCI_TEGRA_VENDOR_MISC_CTRL);
+
+	__sdhci_set_timeout(host, cmd);
+}
+
 static const struct cqhci_host_ops sdhci_tegra_cqhci_ops = {
 	.write_l    = tegra_cqhci_writel,
 	.enable	= sdhci_tegra_cqe_enable,
@@ -1366,6 +1395,7 @@ static const struct sdhci_ops tegra210_sdhci_ops = {
 	.set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
 	.voltage_switch = tegra_sdhci_voltage_switch,
 	.get_max_clock = tegra_sdhci_get_max_clock,
+	.set_timeout = tegra_sdhci_set_timeout,
 };
 
 static const struct sdhci_pltfm_data sdhci_tegra210_pdata = {
@@ -1403,6 +1433,7 @@ static const struct sdhci_ops tegra186_sdhci_ops = {
 	.voltage_switch = tegra_sdhci_voltage_switch,
 	.get_max_clock = tegra_sdhci_get_max_clock,
 	.irq = sdhci_tegra_cqhci_irq,
+	.set_timeout = tegra_sdhci_set_timeout,
 };
 
 static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
Signature · 1 line
2.7.4
maintainer Acked-by on v1 2/3
#2 lore raw

Re: [PATCH v1 2/3] mmc: tegra: Implement HW busy wait timeout based on command busy time

Quoted 9 lines · Sowjanya Komatineni

Tegra host supports HW busy detection and timeouts based on the count programmed in SDHCI_TIMEOUT_CONTROL register and max busy timeout it supports is 11s in finite busy wait mode.

Some operations like SLEEP_AWAKE, ERASE and flush cache through SWITCH commands take longer than 11s and Tegra host supports infinite HW busy wait mode where HW waits forever till the card is busy without HW timeout.

Quoted 7 lines

This patch implements Tegra specific set_timeout sdhci_ops to allow switching between finite and infinite HW busy detection wait modes based on the device command expected operation time.

---
 drivers/mmc/host/sdhci-tegra.c | 31 +++++++++++++++++++++++++++++++
Quoted 66 lines
 1 file changed, 31 insertions(+)
drivers/mmc/host/sdhci-tegra.c +31 -0
index 403ac44..40a221d 100644
@@ -45,6 +45,7 @@
 #define SDHCI_TEGRA_CAP_OVERRIDES_DQS_TRIM_SHIFT	8
 
 #define SDHCI_TEGRA_VENDOR_MISC_CTRL			0x120
+#define SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT		BIT(0)
 #define SDHCI_MISC_CTRL_ENABLE_SDR104			0x8
 #define SDHCI_MISC_CTRL_ENABLE_SDR50			0x10
 #define SDHCI_MISC_CTRL_ENABLE_SDHCI_SPEC_300		0x20
@@ -1227,6 +1228,34 @@ static u32 sdhci_tegra_cqhci_irq(struct sdhci_host *host, u32 intmask)
 	return 0;
 }
 
+static void tegra_sdhci_set_timeout(struct sdhci_host *host,
+				    struct mmc_command *cmd)
+{
+	u32 val;
+
+	/*
+	 * HW busy detection timeout is based on programmed data timeout
+	 * counter and maximum supported timeout is 11s which may not be
+	 * enough for long operations like cache flush, sleep awake, erase.
+	 *
+	 * ERASE_TIMEOUT_LIMIT bit of VENDOR_MISC_CTRL register allows
+	 * host controller to wait for busy state until the card is busy
+	 * without HW timeout.
+	 *
+	 * So, use infinite busy wait mode for operations that may take
+	 * more than maximum HW busy timeout of 11s otherwise use finite
+	 * busy wait mode.
+	 */
+	val = sdhci_readl(host, SDHCI_TEGRA_VENDOR_MISC_CTRL);
+	if (cmd && cmd->busy_timeout >= 11 * HZ)
+		val |= SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT;
+	else
+		val &= ~SDHCI_MISC_CTRL_ERASE_TIMEOUT_LIMIT;
+	sdhci_writel(host, val, SDHCI_TEGRA_VENDOR_MISC_CTRL);
+
+	__sdhci_set_timeout(host, cmd);
+}
+
 static const struct cqhci_host_ops sdhci_tegra_cqhci_ops = {
 	.write_l    = tegra_cqhci_writel,
 	.enable	= sdhci_tegra_cqe_enable,
@@ -1366,6 +1395,7 @@ static const struct sdhci_ops tegra210_sdhci_ops = {
 	.set_uhs_signaling = tegra_sdhci_set_uhs_signaling,
 	.voltage_switch = tegra_sdhci_voltage_switch,
 	.get_max_clock = tegra_sdhci_get_max_clock,
+	.set_timeout = tegra_sdhci_set_timeout,
 };
 
 static const struct sdhci_pltfm_data sdhci_tegra210_pdata = {
@@ -1403,6 +1433,7 @@ static const struct sdhci_ops tegra186_sdhci_ops = {
 	.voltage_switch = tegra_sdhci_voltage_switch,
 	.get_max_clock = tegra_sdhci_get_max_clock,
 	.irq = sdhci_tegra_cqhci_irq,
+	.set_timeout = tegra_sdhci_set_timeout,
 };
 
 static const struct sdhci_pltfm_data sdhci_tegra186_pdata = {
#3 lore raw

PATCH 3/3 mmc: tegra: Enable host capability MMC_CAP2_LONG_WAIT_HW_BUSY

In reply to Sowjanya Komatineni

Some mmc operations take longer than maximum HW busy detection and mmc core driver converts R1B type to R1 type response for these operations based on host max busy timeout and command operation time and uses SW poll for busy.

Tegra host support long HW busy detection where host waits forever till the card is busy.

This patch enables MMC_CAP2_LONG_WAIT_HW_BUSY capability for Tegra host.

---
 drivers/mmc/host/sdhci-tegra.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 40a221d..9d0f371 100644
@@ -1583,6 +1583,7 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
 	if (tegra_host->soc_data->nvquirks & NVQUIRK_ENABLE_DDR50)
 		host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+	host->mmc->caps2 |= MMC_CAP2_LONG_WAIT_HW_BUSY;
 	tegra_sdhci_parse_dt(host);
 
 	tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",
Signature · 1 line
2.7.4
maintainer Acked-by on v1 3/3
#4 lore raw

Re: [PATCH v1 3/3] mmc: tegra: Enable host capability MMC_CAP2_LONG_WAIT_HW_BUSY

Quoted 5 lines · Sowjanya Komatineni

Some mmc operations take longer than maximum HW busy detection and mmc core driver converts R1B type to R1 type response for these operations based on host max busy timeout and command operation time and uses SW poll for busy.

Quoted 7 lines

Tegra host support long HW busy detection where host waits forever till the card is busy.

This patch enables MMC_CAP2_LONG_WAIT_HW_BUSY capability for Tegra host.

Quoted 17 lines
---
 drivers/mmc/host/sdhci-tegra.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mmc/host/sdhci-tegra.c +1 -0
index 40a221d..9d0f371 100644
@@ -1583,6 +1583,7 @@ static int sdhci_tegra_probe(struct platform_device *pdev)
 	if (tegra_host->soc_data->nvquirks & NVQUIRK_ENABLE_DDR50)
 		host->mmc->caps |= MMC_CAP_1_8V_DDR;
 
+	host->mmc->caps2 |= MMC_CAP2_LONG_WAIT_HW_BUSY;
 	tegra_sdhci_parse_dt(host);
 
 	tegra_host->power_gpio = devm_gpiod_get_optional(&pdev->dev, "power",