1 // SPDX-License-Identifier: GPL-2.0-only
3 * MMC crypto engine (inline encryption) support
5 * Copyright 2020 Google LLC
8 #include <linux/blk-crypto.h>
9 #include <linux/mmc/host.h>
15 void mmc_crypto_set_initial_state(struct mmc_host *host)
17 /* Reset might clear all keys, so reprogram all the keys. */
18 if (host->caps2 & MMC_CAP2_CRYPTO)
19 blk_ksm_reprogram_all_keys(&host->ksm);
22 void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host)
24 if (host->caps2 & MMC_CAP2_CRYPTO)
25 blk_ksm_register(&host->ksm, q);
27 EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
29 void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
31 struct request *req = mmc_queue_req_to_req(mqrq);
32 struct mmc_request *mrq = &mqrq->brq.mrq;
34 if (!req->crypt_keyslot)
37 mrq->crypto_enabled = true;
38 mrq->crypto_key_slot = blk_ksm_get_slot_idx(req->crypt_keyslot);
41 * For now we assume that all MMC drivers set max_dun_bytes_supported=4,
42 * which is the limit for CQHCI crypto. So all DUNs should be 32-bit.
44 WARN_ON_ONCE(req->crypt_ctx->bc_dun[0] > U32_MAX);
46 mrq->data_unit_num = req->crypt_ctx->bc_dun[0];
48 EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);