ufshcd-crypto.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright 2019 Google LLC
  4. */
  5. #ifndef _UFSHCD_CRYPTO_H
  6. #define _UFSHCD_CRYPTO_H
  7. #include <scsi/scsi_cmnd.h>
  8. #include "ufshcd.h"
  9. #include "ufshcd-priv.h"
  10. #include "ufshci.h"
  11. #ifdef CONFIG_SCSI_UFS_CRYPTO
  12. static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
  13. struct ufshcd_lrb *lrbp)
  14. {
  15. if (!rq || !rq->crypt_keyslot) {
  16. lrbp->crypto_key_slot = -1;
  17. return;
  18. }
  19. lrbp->crypto_key_slot = blk_crypto_keyslot_index(rq->crypt_keyslot);
  20. lrbp->data_unit_num = rq->crypt_ctx->bc_dun[0];
  21. }
  22. static inline void
  23. ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
  24. u32 *dword_1, u32 *dword_3)
  25. {
  26. if (lrbp->crypto_key_slot >= 0) {
  27. *dword_0 |= UTP_REQ_DESC_CRYPTO_ENABLE_CMD;
  28. *dword_0 |= lrbp->crypto_key_slot;
  29. *dword_1 = lower_32_bits(lrbp->data_unit_num);
  30. *dword_3 = upper_32_bits(lrbp->data_unit_num);
  31. }
  32. }
  33. static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
  34. struct ufshcd_lrb *lrbp)
  35. {
  36. if (!(hba->android_quirks & UFSHCD_ANDROID_QUIRK_KEYS_IN_PRDT))
  37. return;
  38. if (!(scsi_cmd_to_rq(lrbp->cmd)->crypt_ctx))
  39. return;
  40. memzero_explicit(lrbp->ucd_prdt_ptr,
  41. hba->sg_entry_size * scsi_sg_count(lrbp->cmd));
  42. }
  43. bool ufshcd_crypto_enable(struct ufs_hba *hba);
  44. int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba);
  45. void ufshcd_init_crypto(struct ufs_hba *hba);
  46. void ufshcd_crypto_register(struct ufs_hba *hba, struct request_queue *q);
  47. #else /* CONFIG_SCSI_UFS_CRYPTO */
  48. static inline void ufshcd_prepare_lrbp_crypto(struct request *rq,
  49. struct ufshcd_lrb *lrbp) { }
  50. static inline void
  51. ufshcd_prepare_req_desc_hdr_crypto(struct ufshcd_lrb *lrbp, u32 *dword_0,
  52. u32 *dword_1, u32 *dword_3) { }
  53. static inline void ufshcd_crypto_clear_prdt(struct ufs_hba *hba,
  54. struct ufshcd_lrb *lrbp) { }
  55. static inline bool ufshcd_crypto_enable(struct ufs_hba *hba)
  56. {
  57. return false;
  58. }
  59. static inline int ufshcd_hba_init_crypto_capabilities(struct ufs_hba *hba)
  60. {
  61. return 0;
  62. }
  63. static inline void ufshcd_init_crypto(struct ufs_hba *hba) { }
  64. static inline void ufshcd_crypto_register(struct ufs_hba *hba,
  65. struct request_queue *q) { }
  66. #endif /* CONFIG_SCSI_UFS_CRYPTO */
  67. #endif /* _UFSHCD_CRYPTO_H */