hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mmc/core/crypto.c
....@@ -1,40 +1,41 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+// SPDX-License-Identifier: GPL-2.0-only
22 /*
3
+ * MMC crypto engine (inline encryption) support
4
+ *
35 * Copyright 2020 Google LLC
46 */
57
68 #include <linux/blk-crypto.h>
7
-#include <linux/blkdev.h>
8
-#include <linux/keyslot-manager.h>
99 #include <linux/mmc/host.h>
1010
1111 #include "core.h"
12
+#include "crypto.h"
1213 #include "queue.h"
1314
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)
1523 {
1624 if (host->caps2 & MMC_CAP2_CRYPTO)
17
- q->ksm = host->ksm;
25
+ blk_ksm_register(&host->ksm, q);
1826 }
1927 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
-}
2528
2629 void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
2730 {
2831 struct request *req = mmc_queue_req_to_req(mqrq);
2932 struct mmc_request *mrq = &mqrq->brq.mrq;
30
- const struct bio_crypt_ctx *bc;
3133
32
- if (!bio_crypt_should_process(req))
34
+ if (!req->crypt_ctx)
3335 return;
3436
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);
3940 }
4041 EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);