mmc_crypto.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2019 MediaTek Inc.
  4. */
  5. #ifndef _MMC_CRYPTO_H
  6. #define _MMC_CRYPTO_H
  7. #ifdef CONFIG_MMC_CRYPTO
  8. #include <linux/keyslot-manager.h>
  9. #include <linux/mmc/host.h>
  10. #include <linux/mmc/core.h>
  11. #include <linux/blkdev.h>
  12. #define NUM_KEYSLOTS(host) \
  13. (((u32)(host->crypto_capabilities.config_count) & 0xFF))
  14. /* vendor's host structure will be hook by mmc_host->private */
  15. static inline void *get_ll_mmc_host(struct mmc_host *host)
  16. {
  17. return (void *)host->private;
  18. }
  19. static inline bool mmc_keyslot_valid(struct mmc_host *host, unsigned int slot)
  20. {
  21. /*
  22. * The actual number of configurations supported is (CFGC+1), so slot
  23. * numbers range from 0 to config_count inclusive.
  24. */
  25. return slot < NUM_KEYSLOTS(host);
  26. }
  27. static inline bool mmc_is_crypto_supported(struct mmc_host *host)
  28. {
  29. return host->crypto_capabilities.reg_val != 0;
  30. }
  31. static inline bool mmc_is_crypto_enabled(struct mmc_host *host)
  32. {
  33. return host->caps2 & MMC_CAP2_CRYPTO;
  34. }
  35. struct keyslot_mgmt_ll_ops;
  36. /* Crypto Variant Ops Support */
  37. int mmc_init_crypto(struct mmc_host *host);
  38. int mmc_prepare_mqr_crypto(struct mmc_host *host,
  39. struct mmc_queue_req *mqr);
  40. int mmc_swcq_prepare_mqr_crypto(struct mmc_host *host,
  41. struct mmc_request *mrq);
  42. int mmc_complete_mqr_crypto(struct mmc_host *host);
  43. void mmc_crypto_debug(struct mmc_host *host);
  44. int mmc_crypto_suspend(struct mmc_host *host);
  45. int mmc_crypto_resume(struct mmc_host *host);
  46. void mmc_crypto_set_vops(struct mmc_host *host,
  47. struct mmc_crypto_variant_ops *crypto_vops);
  48. #else /* CONFIG_MMC_CRYPTO */
  49. #include "queue.h"
  50. static inline bool mmc_keyslot_valid(struct mmc_host *host,
  51. unsigned int slot)
  52. {
  53. return false;
  54. }
  55. static inline bool mmc_is_crypto_supported(struct mmc_host *host)
  56. {
  57. return false;
  58. }
  59. static inline bool mmc_is_crypto_enabled(struct mmc_host *host)
  60. {
  61. return false;
  62. }
  63. static inline int mmc_init_crypto(struct mmc_host *host)
  64. {
  65. return 0;
  66. }
  67. static inline int mmc_swcq_prepare_mqr_crypto(struct mmc_host *host,
  68. struct mmc_request *mrq)
  69. {
  70. return 0;
  71. }
  72. static inline int mmc_complete_mqr_crypto(struct mmc_host *host)
  73. {
  74. return 0;
  75. }
  76. static inline void mmc_crypto_debug(struct mmc_host *host) { }
  77. static inline int mmc_crypto_suspend(struct mmc_host *host)
  78. {
  79. return 0;
  80. }
  81. static inline int mmc_crypto_resume(struct mmc_host *host)
  82. {
  83. return 0;
  84. }
  85. static inline void mmc_crypto_set_vops(struct mmc_host *host,
  86. struct mmc_crypto_variant_ops *crypto_vops) { }
  87. #endif /* CONFIG_MMC_CRYPTO */
  88. #endif /* _MMC_CRYPTO_H */