• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2020 Google LLC
4  */
5 
6 #include <linux/blk-crypto.h>
7 #include <linux/blkdev.h>
8 #include <linux/keyslot-manager.h>
9 #include <linux/mmc/host.h>
10 
11 #include "core.h"
12 #include "queue.h"
13 
mmc_crypto_setup_queue(struct mmc_host * host,struct request_queue * q)14 void mmc_crypto_setup_queue(struct mmc_host *host, struct request_queue *q)
15 {
16 	if (host->caps2 & MMC_CAP2_CRYPTO)
17 		q->ksm = host->ksm;
18 }
19 EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
20 
mmc_crypto_free_host(struct mmc_host * host)21 void mmc_crypto_free_host(struct mmc_host *host)
22 {
23 	keyslot_manager_destroy(host->ksm);
24 }
25 
mmc_crypto_prepare_req(struct mmc_queue_req * mqrq)26 void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
27 {
28 	struct request *req = mmc_queue_req_to_req(mqrq);
29 	struct mmc_request *mrq = &mqrq->brq.mrq;
30 	const struct bio_crypt_ctx *bc;
31 
32 	if (!bio_crypt_should_process(req))
33 		return;
34 
35 	bc = req->bio->bi_crypt_context;
36 	mrq->crypto_key_slot = bc->bc_keyslot;
37 	mrq->data_unit_num = bc->bc_dun[0];
38 	mrq->crypto_key = bc->bc_key;
39 }
40 EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);
41