Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * MMC crypto engine (inline encryption) support
0004  *
0005  * Copyright 2020 Google LLC
0006  */
0007 
0008 #include <linux/blk-crypto.h>
0009 #include <linux/mmc/host.h>
0010 
0011 #include "core.h"
0012 #include "crypto.h"
0013 #include "queue.h"
0014 
0015 void mmc_crypto_set_initial_state(struct mmc_host *host)
0016 {
0017     /* Reset might clear all keys, so reprogram all the keys. */
0018     if (host->caps2 & MMC_CAP2_CRYPTO)
0019         blk_crypto_reprogram_all_keys(&host->crypto_profile);
0020 }
0021 
0022 void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host)
0023 {
0024     if (host->caps2 & MMC_CAP2_CRYPTO)
0025         blk_crypto_register(&host->crypto_profile, q);
0026 }
0027 EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
0028 
0029 void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
0030 {
0031     struct request *req = mmc_queue_req_to_req(mqrq);
0032     struct mmc_request *mrq = &mqrq->brq.mrq;
0033     struct blk_crypto_keyslot *keyslot;
0034 
0035     if (!req->crypt_ctx)
0036         return;
0037 
0038     mrq->crypto_ctx = req->crypt_ctx;
0039 
0040     keyslot = req->crypt_keyslot;
0041     if (keyslot)
0042         mrq->crypto_key_slot = blk_crypto_keyslot_index(keyslot);
0043 }
0044 EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);