xref: /OK3568_Linux_fs/kernel/drivers/mmc/core/crypto.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * MMC crypto engine (inline encryption) support
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright 2020 Google LLC
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #include <linux/blk-crypto.h>
9*4882a593Smuzhiyun #include <linux/mmc/host.h>
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include "core.h"
12*4882a593Smuzhiyun #include "crypto.h"
13*4882a593Smuzhiyun #include "queue.h"
14*4882a593Smuzhiyun 
mmc_crypto_set_initial_state(struct mmc_host * host)15*4882a593Smuzhiyun void mmc_crypto_set_initial_state(struct mmc_host *host)
16*4882a593Smuzhiyun {
17*4882a593Smuzhiyun 	/* Reset might clear all keys, so reprogram all the keys. */
18*4882a593Smuzhiyun 	if (host->caps2 & MMC_CAP2_CRYPTO)
19*4882a593Smuzhiyun 		blk_ksm_reprogram_all_keys(&host->ksm);
20*4882a593Smuzhiyun }
21*4882a593Smuzhiyun 
mmc_crypto_setup_queue(struct request_queue * q,struct mmc_host * host)22*4882a593Smuzhiyun void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun 	if (host->caps2 & MMC_CAP2_CRYPTO)
25*4882a593Smuzhiyun 		blk_ksm_register(&host->ksm, q);
26*4882a593Smuzhiyun }
27*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
28*4882a593Smuzhiyun 
mmc_crypto_prepare_req(struct mmc_queue_req * mqrq)29*4882a593Smuzhiyun void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
30*4882a593Smuzhiyun {
31*4882a593Smuzhiyun 	struct request *req = mmc_queue_req_to_req(mqrq);
32*4882a593Smuzhiyun 	struct mmc_request *mrq = &mqrq->brq.mrq;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun 	if (!req->crypt_ctx)
35*4882a593Smuzhiyun 		return;
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	mrq->crypto_ctx = req->crypt_ctx;
38*4882a593Smuzhiyun 	if (req->crypt_keyslot)
39*4882a593Smuzhiyun 		mrq->crypto_key_slot = blk_ksm_get_slot_idx(req->crypt_keyslot);
40*4882a593Smuzhiyun }
41*4882a593Smuzhiyun EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);
42