crypto.c 1002 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * MMC crypto engine (inline encryption) support
  4. *
  5. * Copyright 2020 Google LLC
  6. */
  7. #include <linux/blk-crypto.h>
  8. #include <linux/mmc/host.h>
  9. #include "core.h"
  10. #include "crypto.h"
  11. #include "queue.h"
  12. void mmc_crypto_set_initial_state(struct mmc_host *host)
  13. {
  14. /* Reset might clear all keys, so reprogram all the keys. */
  15. if (host->caps2 & MMC_CAP2_CRYPTO)
  16. blk_ksm_reprogram_all_keys(&host->ksm);
  17. }
  18. void mmc_crypto_setup_queue(struct request_queue *q, struct mmc_host *host)
  19. {
  20. if (host->caps2 & MMC_CAP2_CRYPTO)
  21. blk_ksm_register(&host->ksm, q);
  22. }
  23. EXPORT_SYMBOL_GPL(mmc_crypto_setup_queue);
  24. void mmc_crypto_prepare_req(struct mmc_queue_req *mqrq)
  25. {
  26. struct request *req = mmc_queue_req_to_req(mqrq);
  27. struct mmc_request *mrq = &mqrq->brq.mrq;
  28. if (!req->crypt_ctx)
  29. return;
  30. mrq->crypto_ctx = req->crypt_ctx;
  31. if (req->crypt_keyslot)
  32. mrq->crypto_key_slot = blk_ksm_get_slot_idx(req->crypt_keyslot);
  33. }
  34. EXPORT_SYMBOL_GPL(mmc_crypto_prepare_req);