Skip to contentSkip to conversation

mmc: mediatek: add Inline Crypto Engine support

PATCH Superseded Peng Zhou 2 participants 2 messages Jan 29, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peng Zhou

author
#0 lore raw

PATCH 1/2 mmc: mediatek: add Inline Crypto Engine support

Add Inline Crypto Engine(ICE) support into Mediatek MMC Host.

- add crypto clock control and ungate it before CQHCI init
- set MMC_CAP2_CRYPTO property of MMC

Change-Id I6dc35391fd2841609c5be0df1fe1d12ec28ee0c4
---
 drivers/mmc/host/mtk-sd.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/mmc/host/mtk-sd.c +14 -2
index de09c6347524..e870afd66ae8 100644
@@ -441,6 +441,7 @@ struct msdc_host {
 	struct clk *bus_clk;	/* bus clock which used to access register */
 	struct clk *src_clk_cg; /* msdc source clock control gate */
 	struct clk *sys_clk_cg;	/* msdc subsys clock control gate */
+	struct clk *crypto_clk; /* msdc crypto clock */
 	struct clk_bulk_data bulk_clks[MSDC_NR_CLOCKS];
 	u32 mclk;		/* mmc subsystem clock frequency */
 	u32 src_clk_freq;	/* source clock frequency */
@@ -802,6 +803,7 @@ static void msdc_set_busy_timeout(struct msdc_host *host, u64 ns, u64 clks)
 
 static void msdc_gate_clock(struct msdc_host *host)
 {
+	clk_disable_unprepare(host->crypto_clk);
 	clk_bulk_disable_unprepare(MSDC_NR_CLOCKS, host->bulk_clks);
 	clk_disable_unprepare(host->src_clk_cg);
 	clk_disable_unprepare(host->src_clk);
@@ -822,7 +824,7 @@ static void msdc_ungate_clock(struct msdc_host *host)
 		dev_err(host->dev, "Cannot enable pclk/axi/ahb clock gates\n");
 		return;
 	}
-
+	clk_prepare_enable(host->crypto_clk);
 	while (!(readl(host->base + MSDC_CFG) & MSDC_CFG_CKSTB))
 		cpu_relax();
 }
@@ -2510,6 +2512,16 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		goto host_free;
 	}
 
+	/* only eMMC has crypto property */
+#ifdef CONFIG_MMC_CRYPTO
+	if ((mmc->caps2 & MMC_CAP2_NO_SD) && (mmc->caps2 & MMC_CAP2_NO_SDIO))
+		mmc->caps2 |= MMC_CAP2_CRYPTO;
+#endif
+	if (mmc->caps2 & MMC_CAP2_CRYPTO) {
+		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
+		if (IS_ERR(host->crypto_clk))
+	}
+
 	host->irq = platform_get_irq(pdev, 0);
 	if (host->irq < 0) {
 		ret = -EINVAL;
@@ -2580,6 +2592,7 @@ static int msdc_drv_probe(struct platform_device *pdev)
 		host->dma_mask = DMA_BIT_MASK(32);
 	mmc_dev(mmc)->dma_mask = &host->dma_mask;
 
+	msdc_ungate_clock(host);
 	if (mmc->caps2 & MMC_CAP2_CQE) {
 		host->cq_host = devm_kzalloc(mmc->parent,
 					     sizeof(*host->cq_host),
@@ -2616,7 +2629,6 @@ static int msdc_drv_probe(struct platform_device *pdev)
 	spin_lock_init(&host->lock);
 
 	platform_set_drvdata(pdev, mmc);
-	msdc_ungate_clock(host);
 	msdc_init_hw(host);
 
 	ret = devm_request_irq(&pdev->dev, host->irq, msdc_irq,
Signature · 1 line
2.18.0
#1 lore raw

Hi Peng,

Quoted 7 lines · Peng Zhou

Add Inline Crypto Engine(ICE) support into Mediatek MMC Host.

- add crypto clock control and ungate it before CQHCI init
- set MMC_CAP2_CRYPTO property of MMC

Change-Id I6dc35391fd2841609c5be0df1fe1d12ec28ee0c4

This is patch 1 of 2, but I only received patch 1. Is there a cover letter and patch 2 as well?

Also, what branch does this apply too? I tried mmc/next as well as v5.11-rc5, but neither works.

Quoted 9 lines
---
 drivers/mmc/host/mtk-sd.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/mmc/host/mtk-sd.c +0 -0
index de09c6347524..e870afd66ae8 100644

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

Quoted 5 lines
drivers/mmc/host/mtk-sd.c +1 -0
@@ -441,6 +441,7 @@ struct msdc_host {
 	struct clk *bus_clk;	/* bus clock which used to access register */
 	struct clk *src_clk_cg; /* msdc source clock control gate */
 	struct clk *sys_clk_cg;	/* msdc subsys clock control gate */
+	struct clk *crypto_clk; /* msdc crypto clock */
 	struct clk_bulk_data bulk_clks[MSDC_NR_CLOCKS];

Perhaps the new clock should go in bulk_clks so that it doesn't have to be handled separately?

drivers/mmc/host/mtk-sd.c static int msdc_drv_probe(struct platform_device *pdev) · line 2519

Quoted 6 lines
drivers/mmc/host/mtk-sd.c +5 -0
+	/* only eMMC has crypto property */
+#ifdef CONFIG_MMC_CRYPTO
+	if ((mmc->caps2 & MMC_CAP2_NO_SD) && (mmc->caps2 & MMC_CAP2_NO_SDIO))
+		mmc->caps2 |= MMC_CAP2_CRYPTO;
+#endif

This #ifdef is unnecessary (i.e., the code can just be unconditional) because MMC_CAP2_CRYPTO is #defined to 0 when !CONFIG_MMC_CRYPTO.

drivers/mmc/host/mtk-sd.c static int msdc_drv_probe(struct platform_device *pdev) · line 2524

Quoted 5 lines
drivers/mmc/host/mtk-sd.c +5 -0
+	if (mmc->caps2 & MMC_CAP2_CRYPTO) {
+		host->crypto_clk = devm_clk_get(&pdev->dev, "crypto_clk");
+		if (IS_ERR(host->crypto_clk))
+	}
+

Why is there nothing under IS_ERR()?

- Eric