ocs-hcu.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Intel Keem Bay OCS HCU Crypto Driver.
  4. *
  5. * Copyright (C) 2018-2020 Intel Corporation
  6. */
  7. #include <linux/dma-mapping.h>
  8. #ifndef _CRYPTO_OCS_HCU_H
  9. #define _CRYPTO_OCS_HCU_H
  10. #define OCS_HCU_DMA_BIT_MASK DMA_BIT_MASK(32)
  11. #define OCS_HCU_HW_KEY_LEN 64
  12. struct ocs_hcu_dma_list;
  13. enum ocs_hcu_algo {
  14. OCS_HCU_ALGO_SHA256 = 2,
  15. OCS_HCU_ALGO_SHA224 = 3,
  16. OCS_HCU_ALGO_SHA384 = 4,
  17. OCS_HCU_ALGO_SHA512 = 5,
  18. OCS_HCU_ALGO_SM3 = 6,
  19. };
  20. /**
  21. * struct ocs_hcu_dev - OCS HCU device context.
  22. * @list: List of device contexts.
  23. * @dev: OCS HCU device.
  24. * @io_base: Base address of OCS HCU registers.
  25. * @engine: Crypto engine for the device.
  26. * @irq: IRQ number.
  27. * @irq_done: Completion for IRQ.
  28. * @irq_err: Flag indicating an IRQ error has happened.
  29. */
  30. struct ocs_hcu_dev {
  31. struct list_head list;
  32. struct device *dev;
  33. void __iomem *io_base;
  34. struct crypto_engine *engine;
  35. int irq;
  36. struct completion irq_done;
  37. bool irq_err;
  38. };
  39. /**
  40. * struct ocs_hcu_idata - Intermediate data generated by the HCU.
  41. * @msg_len_lo: Length of data the HCU has operated on in bits, low 32b.
  42. * @msg_len_hi: Length of data the HCU has operated on in bits, high 32b.
  43. * @digest: The digest read from the HCU. If the HCU is terminated, it will
  44. * contain the actual hash digest. Otherwise it is the intermediate
  45. * state.
  46. */
  47. struct ocs_hcu_idata {
  48. u32 msg_len_lo;
  49. u32 msg_len_hi;
  50. u8 digest[SHA512_DIGEST_SIZE];
  51. };
  52. /**
  53. * struct ocs_hcu_hash_ctx - Context for OCS HCU hashing operation.
  54. * @algo: The hashing algorithm being used.
  55. * @idata: The current intermediate data.
  56. */
  57. struct ocs_hcu_hash_ctx {
  58. enum ocs_hcu_algo algo;
  59. struct ocs_hcu_idata idata;
  60. };
  61. irqreturn_t ocs_hcu_irq_handler(int irq, void *dev_id);
  62. struct ocs_hcu_dma_list *ocs_hcu_dma_list_alloc(struct ocs_hcu_dev *hcu_dev,
  63. int max_nents);
  64. void ocs_hcu_dma_list_free(struct ocs_hcu_dev *hcu_dev,
  65. struct ocs_hcu_dma_list *dma_list);
  66. int ocs_hcu_dma_list_add_tail(struct ocs_hcu_dev *hcu_dev,
  67. struct ocs_hcu_dma_list *dma_list,
  68. dma_addr_t addr, u32 len);
  69. int ocs_hcu_hash_init(struct ocs_hcu_hash_ctx *ctx, enum ocs_hcu_algo algo);
  70. int ocs_hcu_hash_update(struct ocs_hcu_dev *hcu_dev,
  71. struct ocs_hcu_hash_ctx *ctx,
  72. const struct ocs_hcu_dma_list *dma_list);
  73. int ocs_hcu_hash_finup(struct ocs_hcu_dev *hcu_dev,
  74. const struct ocs_hcu_hash_ctx *ctx,
  75. const struct ocs_hcu_dma_list *dma_list,
  76. u8 *dgst, size_t dgst_len);
  77. int ocs_hcu_hash_final(struct ocs_hcu_dev *hcu_dev,
  78. const struct ocs_hcu_hash_ctx *ctx, u8 *dgst,
  79. size_t dgst_len);
  80. int ocs_hcu_digest(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo,
  81. void *data, size_t data_len, u8 *dgst, size_t dgst_len);
  82. int ocs_hcu_hmac(struct ocs_hcu_dev *hcu_dev, enum ocs_hcu_algo algo,
  83. const u8 *key, size_t key_len,
  84. const struct ocs_hcu_dma_list *dma_list,
  85. u8 *dgst, size_t dgst_len);
  86. #endif /* _CRYPTO_OCS_HCU_H */