xref: /openbmc/linux/drivers/mmc/core/crypto.c (revision 03ab8e6297acd1bc0eedaa050e2a1635c576fd11)
193f1c150SEric Biggers // SPDX-License-Identifier: GPL-2.0-only
293f1c150SEric Biggers /*
393f1c150SEric Biggers  * MMC crypto engine (inline encryption) support
493f1c150SEric Biggers  *
593f1c150SEric Biggers  * Copyright 2020 Google LLC
693f1c150SEric Biggers  */
793f1c150SEric Biggers 
893f1c150SEric Biggers #include <linux/blk-crypto.h>
993f1c150SEric Biggers #include <linux/mmc/host.h>
1093f1c150SEric Biggers 
1193f1c150SEric Biggers #include "core.h"
1293f1c150SEric Biggers #include "crypto.h"
1393f1c150SEric Biggers #include "queue.h"
1493f1c150SEric Biggers 
mmc_crypto_set_initial_state(struct mmc_host * host)1593f1c150SEric Biggers void mmc_crypto_set_initial_state(struct mmc_host *host)
1693f1c150SEric Biggers {
1793f1c150SEric Biggers 	/* Reset might clear all keys, so reprogram all the keys. */
1893f1c150SEric Biggers 	if (host->caps2 & MMC_CAP2_CRYPTO)
19*cb77cb5aSEric Biggers 		blk_crypto_reprogram_all_keys(&host->crypto_profile);
2093f1c150SEric Biggers }
2193f1c150SEric Biggers 
mmc_crypto_setup_queue(struct request_queue * q,struct mmc_host * host)2293f1c150SEric Biggers void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host)
2393f1c150SEric Biggers {
2493f1c150SEric Biggers 	if (host->caps2 & MMC_CAP2_CRYPTO)
25*cb77cb5aSEric Biggers 		blk_crypto_register(&host->crypto_profile, q);
2693f1c150SEric Biggers }
2793f1c150SEric Biggers EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
2893f1c150SEric Biggers 
mmc_crypto_prepare_req(struct mmc_queue_req * mqrq)2993f1c150SEric Biggers void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
3093f1c150SEric Biggers {
3193f1c150SEric Biggers 	struct request *req = mmc_queue_req_to_req(mqrq);
3293f1c150SEric Biggers 	struct mmc_request *mrq = &mqrq->brq.mrq;
33*cb77cb5aSEric Biggers 	struct blk_crypto_keyslot *keyslot;
3493f1c150SEric Biggers 
3586c639ceSEric Biggers 	if (!req->crypt_ctx)
3693f1c150SEric Biggers 		return;
3793f1c150SEric Biggers 
3886c639ceSEric Biggers 	mrq->crypto_ctx = req->crypt_ctx;
39*cb77cb5aSEric Biggers 
40*cb77cb5aSEric Biggers 	keyslot = req->crypt_keyslot;
41*cb77cb5aSEric Biggers 	if (keyslot)
42*cb77cb5aSEric Biggers 		mrq->crypto_key_slot = blk_crypto_keyslot_index(keyslot);
4393f1c150SEric Biggers }
4493f1c150SEric Biggers EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);
45