.. | .. |
---|
1 | | -// SPDX-License-Identifier: GPL-2.0 |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
2 | 2 | /* |
---|
| 3 | + * MMC crypto engine (inline encryption) support |
---|
| 4 | + * |
---|
3 | 5 | * Copyright 2020 Google LLC |
---|
4 | 6 | */ |
---|
5 | 7 | |
---|
6 | 8 | #include <linux/blk-crypto.h> |
---|
7 | | -#include <linux/blkdev.h> |
---|
8 | | -#include <linux/keyslot-manager.h> |
---|
9 | 9 | #include <linux/mmc/host.h> |
---|
10 | 10 | |
---|
11 | 11 | #include "core.h" |
---|
| 12 | +#include "crypto.h" |
---|
12 | 13 | #include "queue.h" |
---|
13 | 14 | |
---|
14 | | -void mmc_crypto_setup_queue(struct mmc_host *host, struct request_queue *q) |
---|
| 15 | +void mmc_crypto_set_initial_state(struct mmc_host *host) |
---|
| 16 | +{ |
---|
| 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); |
---|
| 20 | +} |
---|
| 21 | + |
---|
| 22 | +void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host) |
---|
15 | 23 | { |
---|
16 | 24 | if (host->caps2 & MMC_CAP2_CRYPTO) |
---|
17 | | - q->ksm = host->ksm; |
---|
| 25 | + blk_ksm_register(&host->ksm, q); |
---|
18 | 26 | } |
---|
19 | 27 | EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue); |
---|
20 | | - |
---|
21 | | -void mmc_crypto_free_host(struct mmc_host *host) |
---|
22 | | -{ |
---|
23 | | - keyslot_manager_destroy(host->ksm); |
---|
24 | | -} |
---|
25 | 28 | |
---|
26 | 29 | void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq) |
---|
27 | 30 | { |
---|
28 | 31 | struct request *req = mmc_queue_req_to_req(mqrq); |
---|
29 | 32 | struct mmc_request *mrq = &mqrq->brq.mrq; |
---|
30 | | - const struct bio_crypt_ctx *bc; |
---|
31 | 33 | |
---|
32 | | - if (!bio_crypt_should_process(req)) |
---|
| 34 | + if (!req->crypt_ctx) |
---|
33 | 35 | return; |
---|
34 | 36 | |
---|
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; |
---|
| 37 | + mrq->crypto_ctx = req->crypt_ctx; |
---|
| 38 | + if (req->crypt_keyslot) |
---|
| 39 | + mrq->crypto_key_slot = blk_ksm_get_slot_idx(req->crypt_keyslot); |
---|
39 | 40 | } |
---|
40 | 41 | EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req); |
---|