Skip to contentSkip to conversation

mmc: mtk-sd: reduce CIT for better performance

PATCH Superseded Wenbin Mei 5 participants 7 messages Jun 6, 2023 – Jun 9, 2023

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Wenbin Mei

author
#0 lore raw

v5 cover mmc: mtk-sd: reduce CIT for better performance

change v5:
1. add version change log and the previous patch link
2. change comment in msdc_cqe_cit_cal() to increase readability.
3. change the type of hclk_freq from "u64" to "unsigned long".
4. don't open code FIELD_GET.

change v4:
1. remove else case in msdc_cqe_cit_cal() function due to it doesn't need.
2. fix build error.

change v3:
1. add msdc_cqe_cit_cal() function to calculate the CIT value.

change v2:
1. add more comments.

author
#1 lore raw

PATCH v5 1/1 mmc: mtk-sd: reduce CIT for better performance

CQHCI_SSC1 indicates to CQE the polling period to use when using periodic SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek SoCs, let's decrease it to 0x40 that corresponds to 2.35us, which can improve the performance of some eMMC devices.

---
the previous patche link:
v4: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v3: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v2: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v1: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

---
 drivers/mmc/host/cqhci.h  |  2 ++
 drivers/mmc/host/mtk-sd.c | 47 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
drivers/mmc/host/cqhci.h +2 -0
index ba9387ed90eb..e35c655edefc 100644
@@ -23,6 +23,8 @@
 /* capabilities */
 #define CQHCI_CAP			0x04
 #define CQHCI_CAP_CS			0x10000000 /* Crypto Support */
+#define CQHCI_CAP_ITCFMUL		GENMASK(15, 12)
+#define CQHCI_ITCFMUL(x)		FIELD_GET(CQHCI_CAP_ITCFMUL, (x))
 
 /* configuration */
 #define CQHCI_CFG			0x08
drivers/mmc/host/mtk-sd.c +47 -0

74 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer Reviewed-by on v5 1/1
#2 lore raw

Il 06/06/23 13:32, Wenbin Mei ha scritto:

Quoted 10 lines

CQHCI_SSC1 indicates to CQE the polling period to use when using periodic SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek SoCs, let's decrease it to 0x40 that corresponds to 2.35us, which can improve the performance of some eMMC devices.

maintainer Acked-by on v5 1/1
#3 lore raw
In reply to Wenbin Mei
Quoted 10 lines · Wenbin Mei

CQHCI_SSC1 indicates to CQE the polling period to use when using periodic SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek SoCs, let's decrease it to 0x40 that corresponds to 2.35us, which can improve the performance of some eMMC devices.

For cqhci:

Quoted 106 lines

---
the previous patche link:
v4: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v3: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v2: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v1: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

---
 drivers/mmc/host/cqhci.h  |  2 ++
 drivers/mmc/host/mtk-sd.c | 47 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
drivers/mmc/host/cqhci.h +2 -0
index ba9387ed90eb..e35c655edefc 100644
@@ -23,6 +23,8 @@
 /* capabilities */
 #define CQHCI_CAP			0x04
 #define CQHCI_CAP_CS			0x10000000 /* Crypto Support */
+#define CQHCI_CAP_ITCFMUL		GENMASK(15, 12)
+#define CQHCI_ITCFMUL(x)		FIELD_GET(CQHCI_CAP_ITCFMUL, (x))
 
 /* configuration */
 #define CQHCI_CFG			0x08
drivers/mmc/host/mtk-sd.c +47 -0
index 8ce864169986..b582f19f82f2 100644
@@ -473,6 +473,7 @@ struct msdc_host {
 	struct msdc_tune_para def_tune_para; /* default tune setting */
 	struct msdc_tune_para saved_tune_para; /* tune result of CMD21/CMD19 */
 	struct cqhci_host *cq_host;
+	u32 cq_ssc1_time;
 };
 
 static const struct mtk_mmc_compatible mt2701_compat = {
@@ -2450,9 +2451,50 @@ static void msdc_hs400_enhanced_strobe(struct mmc_host *mmc,
 	}
 }
 
+static void msdc_cqe_cit_cal(struct msdc_host *host, u64 timer_ns)
+{
+	struct mmc_host *mmc = mmc_from_priv(host);
+	struct cqhci_host *cq_host = mmc->cqe_private;
+	u8 itcfmul;
+	unsigned long hclk_freq;
+	u64 value;
+
+	/*
+	 * On MediaTek SoCs the MSDC controller's CQE uses msdc_hclk as ITCFVAL
+	 * so we multiply/divide the HCLK frequency by ITCFMUL to calculate the
+	 * Send Status Command Idle Timer (CIT) value.
+	 */
+	hclk_freq = clk_get_rate(host->h_clk);
+	itcfmul = CQHCI_ITCFMUL(cqhci_readl(cq_host, CQHCI_CAP));
+	switch (itcfmul) {
+	case 0x0:
+		do_div(hclk_freq, 1000);
+		break;
+	case 0x1:
+		do_div(hclk_freq, 100);
+		break;
+	case 0x2:
+		do_div(hclk_freq, 10);
+		break;
+	case 0x3:
+		break;
+	case 0x4:
+		hclk_freq = hclk_freq * 10;
+		break;
+	default:
+		host->cq_ssc1_time = 0x40;
+		return;
+	}
+
+	value = hclk_freq * timer_ns;
+	do_div(value, 1000000000);
+	host->cq_ssc1_time = value;
+}
+
 static void msdc_cqe_enable(struct mmc_host *mmc)
 {
 	struct msdc_host *host = mmc_priv(mmc);
+	struct cqhci_host *cq_host = mmc->cqe_private;
 
 	/* enable cmdq irq */
 	writel(MSDC_INT_CMDQ, host->base + MSDC_INTEN);
@@ -2462,6 +2504,9 @@ static void msdc_cqe_enable(struct mmc_host *mmc)
 	msdc_set_busy_timeout(host, 20 * 1000000000ULL, 0);
 	/* default read data timeout 1s */
 	msdc_set_timeout(host, 1000000000ULL, 0);
+
+	/* Set the send status command idle timer */
+	cqhci_writel(cq_host, host->cq_ssc1_time, CQHCI_SSC1);
 }
 
 static void msdc_cqe_disable(struct mmc_host *mmc, bool recovery)
@@ -2803,6 +2848,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		/* cqhci 16bit length */
 		/* 0 size, means 65536 so we don't have to -1 here */
 		mmc->max_seg_size = 64 * 1024;
+		/* Reduce CIT to 0x40 that corresponds to 2.35us */
+		msdc_cqe_cit_cal(host, 2350);
 	}
 
 	ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq,
Reviewed-by on v5 1/1
#4 lore raw
In reply to Wenbin Mei
Quoted 7 lines · Wenbin Mei

CQHCI_SSC1 indicates to CQE the polling period to use when using periodic SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek SoCs, let's decrease it to 0x40 that corresponds to 2.35us, which can improve the performance of some eMMC devices.

Signature · 2 lines
Regards,
Alexandre
#5 lore raw
In reply to Wenbin Mei
Quoted 11 lines · Wenbin Mei

CQHCI_SSC1 indicates to CQE the polling period to use when using periodic SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek SoCs, let's decrease it to 0x40 that corresponds to 2.35us, which can improve the performance of some eMMC devices.

Applied for next, thanks!

Kind regards
Uffe

Quoted 109 lines

---
the previous patche link:
v4: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v3: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v2: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/
v1: https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

---
 drivers/mmc/host/cqhci.h  |  2 ++
 drivers/mmc/host/mtk-sd.c | 47 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)
drivers/mmc/host/cqhci.h +2 -0
index ba9387ed90eb..e35c655edefc 100644
@@ -23,6 +23,8 @@
 /* capabilities */
 #define CQHCI_CAP                      0x04
 #define CQHCI_CAP_CS                   0x10000000 /* Crypto Support */
+#define CQHCI_CAP_ITCFMUL              GENMASK(15, 12)
+#define CQHCI_ITCFMUL(x)               FIELD_GET(CQHCI_CAP_ITCFMUL, (x))
 
 /* configuration */
 #define CQHCI_CFG                      0x08
drivers/mmc/host/mtk-sd.c +47 -1
index 8ce864169986..b582f19f82f2 100644
@@ -473,6 +473,7 @@ struct msdc_host {
        struct msdc_tune_para def_tune_para; /* default tune setting */
        struct msdc_tune_para saved_tune_para; /* tune result of CMD21/CMD19 */
        struct cqhci_host *cq_host;
+       u32 cq_ssc1_time;
 };
 
 static const struct mtk_mmc_compatible mt2701_compat = {
@@ -2450,9 +2451,50 @@ static void msdc_hs400_enhanced_strobe(struct mmc_host *mmc,
        }
 }
 
+static void msdc_cqe_cit_cal(struct msdc_host *host, u64 timer_ns)
+{
+       struct mmc_host *mmc = mmc_from_priv(host);
+       struct cqhci_host *cq_host = mmc->cqe_private;
+       u8 itcfmul;
+       unsigned long hclk_freq;
+       u64 value;
+
+       /*
+        * On MediaTek SoCs the MSDC controller's CQE uses msdc_hclk as ITCFVAL
+        * so we multiply/divide the HCLK frequency by ITCFMUL to calculate the
+        * Send Status Command Idle Timer (CIT) value.
+        */
+       hclk_freq = clk_get_rate(host->h_clk);
+       itcfmul = CQHCI_ITCFMUL(cqhci_readl(cq_host, CQHCI_CAP));
+       switch (itcfmul) {
+       case 0x0:
+               do_div(hclk_freq, 1000);
+               break;
+       case 0x1:
+               do_div(hclk_freq, 100);
+               break;
+       case 0x2:
+               do_div(hclk_freq, 10);
+               break;
+       case 0x3:
+               break;
+       case 0x4:
+               hclk_freq = hclk_freq * 10;
+               break;
+       default:
+               host->cq_ssc1_time = 0x40;
+               return;
+       }
+
+       value = hclk_freq * timer_ns;
+       do_div(value, 1000000000);
+       host->cq_ssc1_time = value;
+}
+
 static void msdc_cqe_enable(struct mmc_host *mmc)
 {
        struct msdc_host *host = mmc_priv(mmc);
+       struct cqhci_host *cq_host = mmc->cqe_private;
 
        /* enable cmdq irq */
        writel(MSDC_INT_CMDQ, host->base + MSDC_INTEN);
@@ -2462,6 +2504,9 @@ static void msdc_cqe_enable(struct mmc_host *mmc)
        msdc_set_busy_timeout(host, 20 * 1000000000ULL, 0);
        /* default read data timeout 1s */
        msdc_set_timeout(host, 1000000000ULL, 0);
+
+       /* Set the send status command idle timer */
+       cqhci_writel(cq_host, host->cq_ssc1_time, CQHCI_SSC1);
 }
 
 static void msdc_cqe_disable(struct mmc_host *mmc, bool recovery)
@@ -2803,6 +2848,8 @@ static int msdc_drv_probe(struct platform_device *pdev)
                /* cqhci 16bit length */
                /* 0 size, means 65536 so we don't have to -1 here */
                mmc->max_seg_size = 64 * 1024;
+               /* Reduce CIT to 0x40 that corresponds to 2.35us */
+               msdc_cqe_cit_cal(host, 2350);
        }
 
        ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq,
--

2.25.1

#6 lore raw
Quoted 17 lines · Ulf Hansson

External email : Please do not click links or open attachments until you have verified the sender or the content.

Quoted 2 lines · Wenbin Mei

CQHCI_SSC1 indicates to CQE the polling period to use when using

periodic

Quoted 4 lines

SEND_QUEUE_STATUS(CMD13) polling.
Since MSDC CQE uses msdc_hclk as ITCFVAL, so driver should use hclk frequency to get the actual time.
The default value 0x1000 that corresponds to 150us for MediaTek

SoCs, let's

Quoted 1 line

decrease it to 0x40 that corresponds to 2.35us, which can improve

the

Quoted 2 lines

performance of some eMMC devices.

Quoted 8 lines
Quoted 2 lines

Applied for next, thanks!

Kind regards
Uffe

Hi Ulf,

Sorry for the trouble.
Because the v5 version build failed, I have uploader two patches, one is new fix patch, the other is v6 version.

If you choose the v6 version to apply, please ignore the fix patch. Thanks!

Begards,
Wenbin

Quoted 110 lines
Quoted 4 lines

---
the previous patche link:
v4:

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Quoted 1 line

v3:

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Quoted 1 line

v2:

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Quoted 1 line

v1:

https://patchwork.kernel.org/project/linux-mediatek/patch/[email protected]/

Quoted 3 lines
---
 drivers/mmc/host/cqhci.h  |  2 ++
 drivers/mmc/host/mtk-sd.c | 47

+++++++++++++++++++++++++++++++++++++++

drivers/mmc/host/cqhci.h line 25

Quoted 10 lines
 2 files changed, 49 insertions(+)
drivers/mmc/host/cqhci.h +0 -0
index ba9387ed90eb..e35c655edefc 100644
@@ -23,6 +23,8 @@
 /* capabilities */
 #define CQHCI_CAP                      0x04
 #define CQHCI_CAP_CS                   0x10000000 /* Crypto

Support */

drivers/mmc/host/cqhci.h line 27

Quoted 2 lines
drivers/mmc/host/cqhci.h +2 -0
+#define CQHCI_CAP_ITCFMUL              GENMASK(15, 12)
+#define

CQHCI_ITCFMUL(x) FIELD_GET(CQHCI_CAP_ITCFMUL, (x))

drivers/mmc/host/mtk-sd.c struct msdc_host { · line 473

Quoted 9 lines
drivers/mmc/host/cqhci.h +0 -0
 /* configuration */
 #define CQHCI_CFG                      0x08
drivers/mmc/host/mtk-sd.c +0 -0
index 8ce864169986..b582f19f82f2 100644
@@ -473,6 +473,7 @@ struct msdc_host {
        struct msdc_tune_para def_tune_para; /* default tune

setting */

drivers/mmc/host/mtk-sd.c struct msdc_host { · line 474

Quoted 1 line
drivers/mmc/host/mtk-sd.c +0 -0
        struct msdc_tune_para saved_tune_para; /* tune result of

CMD21/CMD19 */

drivers/mmc/host/mtk-sd.c static void

Quoted 6 lines
drivers/mmc/host/mtk-sd.c +1 -0
        struct cqhci_host *cq_host;
+       u32 cq_ssc1_time;
 };
 
 static const struct mtk_mmc_compatible mt2701_compat = {
@@ -2450,9 +2451,50 @@ static void

msdc_hs400_enhanced_strobe(struct mmc_host *mmc,

drivers/mmc/host/mtk-sd.c static void msdc_hs400_enhanced_strobe(struct mmc_host *mmc,

Quoted 13 lines
drivers/mmc/host/mtk-sd.c +10 -0
        }
 }
 
+static void msdc_cqe_cit_cal(struct msdc_host *host, u64 timer_ns)
+{
+       struct mmc_host *mmc = mmc_from_priv(host);
+       struct cqhci_host *cq_host = mmc->cqe_private;
+       u8 itcfmul;
+       unsigned long hclk_freq;
+       u64 value;
+
+       /*
+        * On MediaTek SoCs the MSDC controller's CQE uses

msdc_hclk as ITCFVAL

drivers/mmc/host/mtk-sd.c static void · line 2464

Quoted 1 line
drivers/mmc/host/mtk-sd.c +1 -0
+        * so we multiply/divide the HCLK frequency by ITCFMUL to

calculate the

drivers/mmc/host/mtk-sd.c static void msdc_cqe_enable(struct mmc_host

Quoted 37 lines
drivers/mmc/host/mtk-sd.c +30 -0
+        * Send Status Command Idle Timer (CIT) value.
+        */
+       hclk_freq = clk_get_rate(host->h_clk);
+       itcfmul = CQHCI_ITCFMUL(cqhci_readl(cq_host, CQHCI_CAP));
+       switch (itcfmul) {
+       case 0x0:
+               do_div(hclk_freq, 1000);
+               break;
+       case 0x1:
+               do_div(hclk_freq, 100);
+               break;
+       case 0x2:
+               do_div(hclk_freq, 10);
+               break;
+       case 0x3:
+               break;
+       case 0x4:
+               hclk_freq = hclk_freq * 10;
+               break;
+       default:
+               host->cq_ssc1_time = 0x40;
+               return;
+       }
+
+       value = hclk_freq * timer_ns;
+       do_div(value, 1000000000);
+       host->cq_ssc1_time = value;
+}
+
 static void msdc_cqe_enable(struct mmc_host *mmc)
 {
        struct msdc_host *host = mmc_priv(mmc);
+       struct cqhci_host *cq_host = mmc->cqe_private;
 
        /* enable cmdq irq */
        writel(MSDC_INT_CMDQ, host->base + MSDC_INTEN);
@@ -2462,6 +2504,9 @@ static void msdc_cqe_enable(struct mmc_host

*mmc)

Quoted 8 lines
drivers/mmc/host/mtk-sd.c +3 -0
        msdc_set_busy_timeout(host, 20 * 1000000000ULL, 0);
        /* default read data timeout 1s */
        msdc_set_timeout(host, 1000000000ULL, 0);
+
+       /* Set the send status command idle timer */
+       cqhci_writel(cq_host, host->cq_ssc1_time, CQHCI_SSC1);
 }
 
Quoted 15 lines

drivers/mmc/host/mtk-sd.c static int msdc_drv_probe(struct

Quoted 2 lines
drivers/mmc/host/mtk-sd.c +0 -0
 static void msdc_cqe_disable(struct mmc_host *mmc, bool recovery)
@@ -2803,6 +2848,8 @@ static int msdc_drv_probe(struct

platform_device *pdev)

drivers/mmc/host/mtk-sd.c static int msdc_drv_probe(struct · line 2849

Quoted 2 lines
drivers/mmc/host/mtk-sd.c +0 -0
                /* cqhci 16bit length */
                /* 0 size, means 65536 so we don't have to -1 here

*/

Quoted 9 lines
drivers/mmc/host/mtk-sd.c +2 -1
                mmc->max_seg_size = 64 * 1024;
+               /* Reduce CIT to 0x40 that corresponds to 2.35us */
+               msdc_cqe_cit_cal(host, 2350);
        }
 
        ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq,
--

2.25.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel