--- zzzz-none-000/linux-5.4.213/drivers/mmc/host/sdhci.c 2022-09-15 10:04:56.000000000 +0000 +++ alder-5690pro-762/linux-5.4.213/drivers/mmc/host/sdhci.c 2024-08-14 09:02:07.000000000 +0000 @@ -248,6 +248,8 @@ /* Resetting the controller clears many */ host->preset_enabled = false; } + if (host->is_crypto_en) + host->crypto_reset_reqd = true; } static void sdhci_set_default_irqs(struct sdhci_host *host) @@ -1820,6 +1822,30 @@ } EXPORT_SYMBOL_GPL(sdhci_set_power); +static int sdhci_crypto_cfg(struct sdhci_host *host, struct mmc_request *mrq, + u32 slot) +{ + int err = 0; + + if (host->crypto_reset_reqd && host->ops->crypto_engine_reset) { + err = host->ops->crypto_engine_reset(host); + if (err) { + pr_err("%s: crypto reset failed\n", + mmc_hostname(host->mmc)); + return err; + } + host->crypto_reset_reqd = false; + } + if (host->ops->crypto_engine_cfg) { + err = host->ops->crypto_engine_cfg(host, mrq, slot); + if (err) { + pr_err("%s: failed to configure crypto\n", + mmc_hostname(host->mmc)); + } + } + return err; +} + /*****************************************************************************\ * * * MMC callbacks * @@ -1856,6 +1882,13 @@ mrq->cmd->error = -ENOMEDIUM; sdhci_finish_mrq(host, mrq); } else { + if (host->is_crypto_en) { + spin_unlock_irqrestore(&host->lock, flags); + if (sdhci_crypto_cfg(host, mrq, 0)) + goto end_req; + spin_lock_irqsave(&host->lock, flags); + } + if (mrq->sbc && !(host->flags & SDHCI_AUTO_CMD23)) sdhci_send_command(host, mrq->sbc); else @@ -1863,6 +1896,14 @@ } spin_unlock_irqrestore(&host->lock, flags); + return; + +end_req: + mrq->cmd->error = -EIO; + if (mrq->data) + mrq->data->error = -EIO; + sdhci_dumpregs(host); + mmc_request_done(host->mmc, mrq); } EXPORT_SYMBOL_GPL(sdhci_request);