Skip to contentSkip to conversation

mmc: sdhci-sprd: Add SD HS mode online tuning

PATCH Superseded Wenchao Chen 4 participants 11 messages Aug 15, 2023 – Aug 24, 2023

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover mmc: sdhci-sprd: Add SD HS mode online tuning

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/2 mmc: core: Add host specific tuning support for SD HS mode

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

---
 drivers/mmc/core/sd.c    | 12 ++++++++++++
 include/linux/mmc/host.h |  6 ++++++
 2 files changed, 18 insertions(+)
drivers/mmc/core/sd.c +12 -0
index 246ce027ae0a..ac2da8f2fbce 100644
@@ -1518,6 +1518,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 		 */
 		mmc_set_clock(host, mmc_sd_get_max_clock(card));
 
+		if (host->ops->prepare_hs_tuning) {
+			err = host->ops->prepare_hs_tuning(host, card);
+			if (err)
+				goto free_card;
+		}
+
 		/*
 		 * Switch to wider bus (if supported).
 		 */
@@ -1529,6 +1535,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
 			mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
 		}
+
+		if (host->ops->execute_hs_tuning) {
+			err = host->ops->execute_hs_tuning(host, card);
+			if (err)
+				goto free_card;
+		}
 	}
 cont:
 	if (!oldcard) {
include/linux/mmc/host.h +6 -0
index 461d1543893b..13cf894b9e3c 100644
@@ -184,6 +184,12 @@ struct mmc_host_ops {
 	/* Execute HS400 tuning depending host driver */
 	int	(*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);
 
+	/* Prepare HS tuning depending host driver */
+	int	(*prepare_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
+	/* Execute HS tuning depending host driver */
+	int	(*execute_hs_tuning)(struct mmc_host *host, struct mmc_card *card);
+
 	/* Prepare switch to DDR during the HS400 init sequence */
 	int	(*hs400_prepare_ddr)(struct mmc_host *host);
 
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH V2 1/2] mmc: core: Add host specific tuning support for SD HS mode

Quoted 3 lines · Wenchao Chen

Added .prepare_hs_tuning and .execute_hs_tuning host callbacks to support host-specific tuning for SD high speed mode.

Please clarify this is entirely optional, host specific - and that there is nothing in the SD spec that mentions this.

Quoted 12 lines
---
 drivers/mmc/core/sd.c    | 12 ++++++++++++
 include/linux/mmc/host.h |  6 ++++++
 2 files changed, 18 insertions(+)
drivers/mmc/core/sd.c +0 -0
index 246ce027ae0a..ac2da8f2fbce 100644

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1521

Quoted 4 lines
drivers/mmc/core/sd.c +1 -0
@@ -1518,6 +1518,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
                 */
                mmc_set_clock(host, mmc_sd_get_max_clock(card));
 
+               if (host->ops->prepare_hs_tuning) {

Shouldn't we check if we actually succeeded to enable MMC_TIMING_SD_HS before invoking this callback?

Quoted 9 lines
drivers/mmc/core/sd.c +5 -0
+                       err = host->ops->prepare_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }
+
                /*
                 * Switch to wider bus (if supported).
                 */

drivers/mmc/core/sd.c static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, · line 1539

Quoted 5 lines
drivers/mmc/core/sd.c +2 -0
@@ -1529,6 +1535,12 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
 
                        mmc_set_bus_width(host, MMC_BUS_WIDTH_4);
                }
+
+               if (host->ops->execute_hs_tuning) {

Ditto.

Quoted 12 lines
drivers/mmc/core/sd.c +4 -0
+                       err = host->ops->execute_hs_tuning(host, card);
+                       if (err)
+                               goto free_card;
+               }
        }
 cont:
        if (!oldcard) {
include/linux/mmc/host.h +0 -0
index 461d1543893b..13cf894b9e3c 100644

include/linux/mmc/host.h struct mmc_host_ops { · line 187

Quoted 4 lines
include/linux/mmc/host.h +1 -0
@@ -184,6 +184,12 @@ struct mmc_host_ops {
        /* Execute HS400 tuning depending host driver */
        int     (*execute_hs400_tuning)(struct mmc_host *host, struct mmc_card *card);
 
+       /* Prepare HS tuning depending host driver */

How about rephrasing this into something along the lines of "Optional callback to prepare for SD high-speed tuning"

include/linux/mmc/host.h struct mmc_host_ops { · line 188

Quoted 1 line
include/linux/mmc/host.h +1 -0
+       int     (*prepare_hs_tuning)(struct mmc_host *host, struct mmc_card *card);

To make it more clear this if for SD high-speed, maybe we should rename the callback into:

"prepare_sd_hs_tuning"

include/linux/mmc/host.h struct mmc_host_ops { · line 190

Quoted 2 lines
include/linux/mmc/host.h +2 -0
+
+       /* Execute HS tuning depending host driver */

How about rephrasing this to something along the lines of "Optional callback to execute SD high-speed tuning"

include/linux/mmc/host.h struct mmc_host_ops { · line 191

Quoted 1 line
include/linux/mmc/host.h +1 -0
+       int     (*execute_hs_tuning)(struct mmc_host *host, struct mmc_card *card);

Maybe execute_sd_hs_tuning instead?

include/linux/mmc/host.h struct mmc_host_ops { · line 195

Quoted 4 lines
include/linux/mmc/host.h +1 -0
+
        /* Prepare switch to DDR during the HS400 init sequence */
        int     (*hs400_prepare_ddr)(struct mmc_host *host);
 

Kind regards
Uffe

#3 lore raw

PATCH v2 2/2 mmc: sdhci-sprd: Add SD HS mode online tuning

In reply to Wenchao Chen

First of all, Unisoc's IC provides cmd delay and read delay to ensure that the host can get the correct data. However, according to SD Spec, there is no need to do tuning in high speed mode, but with the development of chip processes, it is more and more difficult to find a suitable delay to cover all the chips. Therefore, we need SD high speed mode online tuning.

In addition, we added mmc_sd_switch() and mmc_send_status() to the header file to allow it to be usable by the drive

---
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   2 +
 3 files changed, 155 insertions(+)
drivers/mmc/core/sd_ops.c +1 -0
index ef8d1dce5af1..a59cd592f06e 100644
@@ -323,6 +323,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	return mmc_send_adtc_data(card, card->host, SD_SWITCH, cmd_args, resp,
 				  64);
 }
+EXPORT_SYMBOL_GPL(mmc_sd_switch);
 
 int mmc_app_sd_status(struct mmc_card *card, void *ssr)
 {
drivers/mmc/host/sdhci-sprd.c +152 -0

182 lines not on this page · raw message

include/linux/mmc/host.h +2 -0
index 13cf894b9e3c..5d069510dc4b 100644
@@ -671,6 +671,8 @@ static inline void mmc_debugfs_err_stats_inc(struct mmc_host *host,
 	host->err_stats[stat] += 1;
 }
 
+int mmc_sd_switch(struct mmc_card *card, int mode, int group, u8 value, u8 *resp);
+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);
Signature · 1 line
2.17.1
#4 lore raw
Quoted 23 lines · Wenchao Chen

First of all, Unisoc's IC provides cmd delay and read delay to ensure that the host can get the correct data. However, according to SD Spec, there is no need to do tuning in high speed mode, but with the development of chip processes, it is more and more difficult to find a suitable delay to cover all the chips. Therefore, we need SD high speed mode online tuning.

In addition, we added mmc_sd_switch() and mmc_send_status() to the header file to allow it to be usable by the drive

---
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   2 +
 3 files changed, 155 insertions(+)
drivers/mmc/core/sd_ops.c +0 -0
index ef8d1dce5af1..a59cd592f06e 100644

drivers/mmc/core/sd_ops.c int mmc_sd_switch(struct mmc_card *card, int mode, int group, · line 326

Quoted 4 lines
drivers/mmc/core/sd_ops.c +1 -0
@@ -323,6 +323,7 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group,
        return mmc_send_adtc_data(card, card->host, SD_SWITCH, cmd_args, resp,
                                  64);
 }
+EXPORT_SYMBOL_GPL(mmc_sd_switch);

Please move changes in include/linux/mmc/host.h and drivers/mmc/core/sd_ops.c into patch1. When doing that, please update the commit messages too.

[...]

Other than the above, this looks okay to me!

Kind regards
Uffe

maintainer
#5 lore raw
In reply to Wenchao Chen
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

What about hooking ->set_ios() as Ulf suggested?

Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
#6 lore raw
Quoted 10 lines · Adrian Hunter
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

What about hooking ->set_ios() as Ulf suggested?

I've tried that, but it's not a good way to do it.
We found that sdhci_runtime_resume_host() calls ->set_ios, but we don't want to do that.
We just need SD HS mode tuning at mmc_sd_init_card().

Quoted 12 lines
Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
maintainer
#7 lore raw
Quoted 9 lines · Wenchao Chen
Quoted 8 lines · Adrian Hunter
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

Quoted 6 lines
Quoted 2 lines

What about hooking ->set_ios() as Ulf suggested?

I've tried that, but it's not a good way to do it.
We found that sdhci_runtime_resume_host() calls ->set_ios, but we don't want to do that.

Given that sdhci_sprd_runtime_resume() calls sdhci_runtime_resume_host(), it should be possible to determine when to tune, right?

Quoted 14 lines

We just need SD HS mode tuning at mmc_sd_init_card().

Quoted 12 lines
Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
#8 lore raw
Quoted 14 lines · Adrian Hunter
Quoted 12 lines · Wenchao Chen
Quoted 10 lines · Adrian Hunter
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

What about hooking ->set_ios() as Ulf suggested?

Quoted 7 lines
Quoted 3 lines

I've tried that, but it's not a good way to do it.
We found that sdhci_runtime_resume_host() calls ->set_ios, but we don't want to do that.

Given that sdhci_sprd_runtime_resume() calls sdhci_runtime_resume_host(), it should be possible to determine when to tune, right?

You mean like this? For example:
static int sdhci_sprd_runtime_resume(struct device *dev) {
...
sprd_host->need_hs_tuning = false; sdhci_runtime_resume_host(host, 1); sprd_host->need_hs_tuning = true;
...
}

Quoted 15 lines
Quoted 14 lines

We just need SD HS mode tuning at mmc_sd_init_card().

Quoted 12 lines
Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
maintainer
#9 lore raw
Quoted 23 lines · Wenchao Chen
Quoted 14 lines · Adrian Hunter
Quoted 12 lines · Wenchao Chen
Quoted 10 lines · Adrian Hunter
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

What about hooking ->set_ios() as Ulf suggested?

Quoted 7 lines
Quoted 3 lines

I've tried that, but it's not a good way to do it.
We found that sdhci_runtime_resume_host() calls ->set_ios, but we don't want to do that.

Given that sdhci_sprd_runtime_resume() calls sdhci_runtime_resume_host(), it should be possible to determine when to tune, right?

Quoted 7 lines

You mean like this? For example:
static int sdhci_sprd_runtime_resume(struct device *dev) {
...
sprd_host->need_hs_tuning = false; sdhci_runtime_resume_host(host, 1); sprd_host->need_hs_tuning = true;

Yes

Quoted 18 lines

...
}

Quoted 15 lines
Quoted 14 lines

We just need SD HS mode tuning at mmc_sd_init_card().

Quoted 12 lines
Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)
#10 lore raw
Quoted 33 lines · Adrian Hunter
Quoted 23 lines · Wenchao Chen
Quoted 14 lines · Adrian Hunter
Quoted 12 lines · Wenchao Chen
Quoted 10 lines · Adrian Hunter
Quoted 5 lines · Wenchao Chen

Change in v2:
- add mmc_sd_switch() and mmc_send_status() to the header file
- split up core changes from host driver changes
- Use pr_debug instead of dev_info and dev_dbg
- Optimize the best sampled value algorithm

What about hooking ->set_ios() as Ulf suggested?

Quoted 7 lines
Quoted 3 lines

I've tried that, but it's not a good way to do it.
We found that sdhci_runtime_resume_host() calls ->set_ios, but we don't want to do that.

Given that sdhci_sprd_runtime_resume() calls sdhci_runtime_resume_host(), it should be possible to determine when to tune, right?

Quoted 7 lines

You mean like this? For example:
static int sdhci_sprd_runtime_resume(struct device *dev) {
...
sprd_host->need_hs_tuning = false; sdhci_runtime_resume_host(host, 1); sprd_host->need_hs_tuning = true;

Quoted 2 lines

Yes

This works, but we found a problem: if sd hs tuning fails, ->set_ios is of type void with no return value.

Quoted 19 lines
Quoted 18 lines

...
}

Quoted 15 lines
Quoted 14 lines

We just need SD HS mode tuning at mmc_sd_init_card().

Quoted 12 lines
Quoted 11 lines

Wenchao Chen (2):
mmc: core: Add host specific tuning support for SD HS mode
mmc: sdhci-sprd: Add SD HS mode online tuning

 drivers/mmc/core/sd.c         |  12 +++
 drivers/mmc/core/sd_ops.c     |   1 +
 drivers/mmc/host/sdhci-sprd.c | 152 ++++++++++++++++++++++++++++++++++
 include/linux/mmc/host.h      |   8 ++
 4 files changed, 173 insertions(+)