[PATCH v8 2/2] mmc: sdhci-msm: Use pm ops instead of macro to restore crypto keys
From: Neeraj Soni
Date: Wed Aug 26 2026 - 05:57:14 EST
From: Ram Prakash Gupta <ram.gupta@xxxxxxxxxxxxxxxx>
Inline Crypto Engine (ICE) keys are lost after hibernation entry and this
needs to be restored when hibernation exits. ICE keys are re-programmed
during sdhci_msm_ice_init() but it may not cover cases where the
hibernation image is already restored.
Unwrap the pm ops and use directly in driver to add the call to restore
Inline Crypto Engine (ICE) keys. This ensures that ICE is brought into
same state as before hibernation. If hibernation image creation itself
fails then device boots through normal flow where there is no need to
reprogram the keys.
Also set MMC_CAP2_CRYPTO_NO_REPROG to indicate that re-programming of ICE
keys is not needed during MMC runtime suspend/resume or suspend-to-RAM
since the rail powering the ICE will not be turned off.
During CQE recovery, key would be lost only when BCR reset is performed
which do not happen right now and will be taken up once it is fixed as part
of recovery flow.
Signed-off-by: Ram Prakash Gupta <ram.gupta@xxxxxxxxxxxxxxxx>
Signed-off-by: Seshu Madhavi Puppala <quic_spuppala@xxxxxxxxxxx>
Co-developed-by: Ram Prakash Gupta <quic_rampraka@xxxxxxxxxxx>
Signed-off-by: Ram Prakash Gupta <quic_rampraka@xxxxxxxxxxx>
Co-developed-by: Sarthak Garg <quic_sartgarg@xxxxxxxxxxx>
Signed-off-by: Sarthak Garg <quic_sartgarg@xxxxxxxxxxx>
Signed-off-by: Debraj Mukhopadhyay <quic_dmukhopa@xxxxxxxxxxx>
Signed-off-by: Neeraj Soni <neeraj.soni@xxxxxxxxxxxxxxxx>
---
drivers/mmc/host/sdhci-msm.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci-msm.c b/drivers/mmc/host/sdhci-msm.c
index 4aff965f0e2e..460994164d2d 100644
--- a/drivers/mmc/host/sdhci-msm.c
+++ b/drivers/mmc/host/sdhci-msm.c
@@ -1959,6 +1959,7 @@ static int sdhci_msm_ice_init(struct sdhci_msm_host *msm_host,
}
mmc->caps2 |= MMC_CAP2_CRYPTO;
+ mmc->caps2 |= MMC_CAP2_CRYPTO_NO_REPROG;
return 0;
}
@@ -2055,6 +2056,12 @@ static int sdhci_msm_ice_prepare_key(struct blk_crypto_profile *profile,
return qcom_ice_prepare_key(msm_host->ice, lt_key, lt_key_size, eph_key);
}
+static void sdhci_msm_ice_restore(struct sdhci_host *host)
+{
+ if (host->mmc->caps2 & MMC_CAP2_CRYPTO)
+ blk_crypto_reprogram_all_keys(&host->mmc->crypto_profile);
+}
+
static void sdhci_msm_non_cqe_ice_init(struct sdhci_host *host)
{
struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host);
@@ -2149,6 +2156,10 @@ sdhci_msm_ice_suspend(struct sdhci_msm_host *msm_host)
{
return 0;
}
+
+static inline void sdhci_msm_ice_restore(struct sdhci_host *host)
+{
+}
#endif /* !CONFIG_MMC_CRYPTO */
/*****************************************************************************\
@@ -2983,9 +2994,28 @@ static int sdhci_msm_runtime_resume(struct device *dev)
return ret;
}
+static int sdhci_msm_restore(struct device *dev)
+{
+ struct sdhci_host *host = dev_get_drvdata(dev);
+ int ret;
+
+ ret = pm_runtime_force_resume(dev);
+ if (ret)
+ return ret;
+
+ sdhci_msm_ice_restore(host);
+
+ return ret;
+}
+
static const struct dev_pm_ops sdhci_msm_pm_ops = {
- SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
RUNTIME_PM_OPS(sdhci_msm_runtime_suspend, sdhci_msm_runtime_resume, NULL)
+ .suspend = pm_sleep_ptr(pm_runtime_force_suspend),
+ .resume = pm_sleep_ptr(pm_runtime_force_resume),
+ .freeze = pm_sleep_ptr(pm_runtime_force_suspend),
+ .restore = pm_sleep_ptr(sdhci_msm_restore),
+ .thaw = pm_sleep_ptr(pm_runtime_force_resume),
+ .poweroff = pm_sleep_ptr(pm_runtime_force_suspend),
};
static struct platform_driver sdhci_msm_driver = {
--
2.34.1