Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b34b02c authored by Pruthvi Kurada's avatar Pruthvi Kurada
Browse files

mmc: Enable Inline Crypto Engine clocks before programming key



Due to mmc optimizations mmc host controllers are turned off during
mmc suspend. These clocks have to be turned ON during ICE program/evict
key. In PFK based FBE there would be numerous calls to program/evict
ICE key.
The change ensure required clocks are turned on before programming
crypto key to avoid any unclocked access.
Validations done:-
1) Flash P SDM660 build and let device bootup successfully to UI.
2) adb shell getprop ro.crypto.state: encrypted
   adb shell getprop ro.crypto.type: file
3) Create files under /data and /data/misc/vold/user_key
4) Flash T build except userdata i.e. OTA to T.
5) Device able to boot successfully to UI.
6) Files created earlier got retained after flashing T build.

Change-Id: Ia1629a6b373895af42b1c724aebbe7ae6fc7de93
Signed-off-by: default avatarPruthvi Kurada <quic_pkurada@quicinc.com>
parent 84f30745
Loading
Loading
Loading
Loading
+34 −0
Original line number Original line Diff line number Diff line
@@ -106,10 +106,25 @@ static int cqhci_crypto_qti_keyslot_program(struct keyslot_manager *ksm,
	int err = 0;
	int err = 0;
	u8 data_unit_mask;
	u8 data_unit_mask;
	int crypto_alg_id;
	int crypto_alg_id;
	struct sdhci_host *sdhci = mmc_priv(host->mmc);
	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(sdhci);
	struct sdhci_msm_host *msm_host = pltfm_host->priv;


	crypto_alg_id = cqhci_crypto_cap_find(host, key->crypto_mode,
	crypto_alg_id = cqhci_crypto_cap_find(host, key->crypto_mode,
					       key->data_unit_size);
					       key->data_unit_size);


	if (!IS_ERR(msm_host->pclk) && !IS_ERR(msm_host->ice_clk)) {
		err = clk_prepare_enable(msm_host->pclk);
		if (err)
			return err;
		err = clk_prepare_enable(msm_host->ice_clk);
		if (err)
			return err;
	} else {
		pr_err("%s: Invalid clock value\n", __func__);
		return -EINVAL;
	}

	pm_runtime_get_sync(&host->mmc->card->dev);
	pm_runtime_get_sync(&host->mmc->card->dev);


	if (!cqhci_is_crypto_enabled(host) ||
	if (!cqhci_is_crypto_enabled(host) ||
@@ -132,6 +147,8 @@ static int cqhci_crypto_qti_keyslot_program(struct keyslot_manager *ksm,
	if (err)
	if (err)
		pr_err("%s: failed with error %d\n", __func__, err);
		pr_err("%s: failed with error %d\n", __func__, err);


	clk_disable_unprepare(msm_host->pclk);
	clk_disable_unprepare(msm_host->ice_clk);
	pm_runtime_put_sync(&host->mmc->card->dev);
	pm_runtime_put_sync(&host->mmc->card->dev);
	return err;
	return err;
}
}
@@ -143,6 +160,21 @@ static int cqhci_crypto_qti_keyslot_evict(struct keyslot_manager *ksm,
	int err = 0;
	int err = 0;
	int val = 0;
	int val = 0;
	struct cqhci_host *host = keyslot_manager_private(ksm);
	struct cqhci_host *host = keyslot_manager_private(ksm);
	struct sdhci_host *sdhci = mmc_priv(host->mmc);
	struct sdhci_pltfm_host *pltfm_host = sdhci_priv(sdhci);
	struct sdhci_msm_host *msm_host = pltfm_host->priv;

	if (!IS_ERR(msm_host->pclk) && !IS_ERR(msm_host->ice_clk)) {
		err = clk_prepare_enable(msm_host->pclk);
		if (err)
			return err;
		err = clk_prepare_enable(msm_host->ice_clk);
		if (err)
			return err;
	} else {
		pr_err("%s: Invalid clock value\n", __func__);
		return -EINVAL;
	}
	pm_runtime_get_sync(&host->mmc->card->dev);
	pm_runtime_get_sync(&host->mmc->card->dev);


	if (!cqhci_is_crypto_enabled(host) ||
	if (!cqhci_is_crypto_enabled(host) ||
@@ -155,6 +187,8 @@ static int cqhci_crypto_qti_keyslot_evict(struct keyslot_manager *ksm,
	if (err)
	if (err)
		pr_err("%s: failed with error %d\n", __func__, err);
		pr_err("%s: failed with error %d\n", __func__, err);


	clk_disable_unprepare(msm_host->pclk);
	clk_disable_unprepare(msm_host->ice_clk);
	pm_runtime_put_sync(&host->mmc->card->dev);
	pm_runtime_put_sync(&host->mmc->card->dev);
	val = atomic_read(&keycache) & ~(1 << slot);
	val = atomic_read(&keycache) & ~(1 << slot);
	atomic_set(&keycache, val);
	atomic_set(&keycache, val);