eip93-main.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright (C) 2019 - 2021
  4. *
  5. * Richard van Schagen <vschagen@icloud.com>
  6. * Christian Marangi <ansuelsmth@gmail.com
  7. */
  8. #ifndef _EIP93_MAIN_H_
  9. #define _EIP93_MAIN_H_
  10. #include <crypto/internal/aead.h>
  11. #include <crypto/internal/hash.h>
  12. #include <crypto/internal/skcipher.h>
  13. #include <linux/bitfield.h>
  14. #include <linux/interrupt.h>
  15. #define EIP93_RING_BUSY_DELAY 500
  16. #define EIP93_RING_NUM 512
  17. #define EIP93_RING_BUSY 32
  18. #define EIP93_CRA_PRIORITY 1500
  19. #define EIP93_RING_SA_STATE_ADDR(base, idx) ((base) + (idx))
  20. #define EIP93_RING_SA_STATE_DMA(dma_base, idx) ((u32 __force)(dma_base) + \
  21. ((idx) * sizeof(struct sa_state)))
  22. /* cipher algorithms */
  23. #define EIP93_ALG_DES BIT(0)
  24. #define EIP93_ALG_3DES BIT(1)
  25. #define EIP93_ALG_AES BIT(2)
  26. #define EIP93_ALG_MASK GENMASK(2, 0)
  27. /* hash and hmac algorithms */
  28. #define EIP93_HASH_MD5 BIT(3)
  29. #define EIP93_HASH_SHA1 BIT(4)
  30. #define EIP93_HASH_SHA224 BIT(5)
  31. #define EIP93_HASH_SHA256 BIT(6)
  32. #define EIP93_HASH_HMAC BIT(7)
  33. #define EIP93_HASH_MASK GENMASK(6, 3)
  34. /* cipher modes */
  35. #define EIP93_MODE_CBC BIT(8)
  36. #define EIP93_MODE_ECB BIT(9)
  37. #define EIP93_MODE_CTR BIT(10)
  38. #define EIP93_MODE_RFC3686 BIT(11)
  39. #define EIP93_MODE_MASK GENMASK(10, 8)
  40. /* cipher encryption/decryption operations */
  41. #define EIP93_ENCRYPT BIT(12)
  42. #define EIP93_DECRYPT BIT(13)
  43. #define EIP93_BUSY BIT(14)
  44. /* descriptor flags */
  45. #define EIP93_DESC_DMA_IV BIT(0)
  46. #define EIP93_DESC_IPSEC BIT(1)
  47. #define EIP93_DESC_FINISH BIT(2)
  48. #define EIP93_DESC_LAST BIT(3)
  49. #define EIP93_DESC_FAKE_HMAC BIT(4)
  50. #define EIP93_DESC_PRNG BIT(5)
  51. #define EIP93_DESC_HASH BIT(6)
  52. #define EIP93_DESC_AEAD BIT(7)
  53. #define EIP93_DESC_SKCIPHER BIT(8)
  54. #define EIP93_DESC_ASYNC BIT(9)
  55. #define IS_DMA_IV(desc_flags) ((desc_flags) & EIP93_DESC_DMA_IV)
  56. #define IS_DES(flags) ((flags) & EIP93_ALG_DES)
  57. #define IS_3DES(flags) ((flags) & EIP93_ALG_3DES)
  58. #define IS_AES(flags) ((flags) & EIP93_ALG_AES)
  59. #define IS_HASH_MD5(flags) ((flags) & EIP93_HASH_MD5)
  60. #define IS_HASH_SHA1(flags) ((flags) & EIP93_HASH_SHA1)
  61. #define IS_HASH_SHA224(flags) ((flags) & EIP93_HASH_SHA224)
  62. #define IS_HASH_SHA256(flags) ((flags) & EIP93_HASH_SHA256)
  63. #define IS_HMAC(flags) ((flags) & EIP93_HASH_HMAC)
  64. #define IS_CBC(mode) ((mode) & EIP93_MODE_CBC)
  65. #define IS_ECB(mode) ((mode) & EIP93_MODE_ECB)
  66. #define IS_CTR(mode) ((mode) & EIP93_MODE_CTR)
  67. #define IS_RFC3686(mode) ((mode) & EIP93_MODE_RFC3686)
  68. #define IS_BUSY(flags) ((flags) & EIP93_BUSY)
  69. #define IS_ENCRYPT(dir) ((dir) & EIP93_ENCRYPT)
  70. #define IS_DECRYPT(dir) ((dir) & EIP93_DECRYPT)
  71. #define IS_CIPHER(flags) ((flags) & (EIP93_ALG_DES | \
  72. EIP93_ALG_3DES | \
  73. EIP93_ALG_AES))
  74. #define IS_HASH(flags) ((flags) & (EIP93_HASH_MD5 | \
  75. EIP93_HASH_SHA1 | \
  76. EIP93_HASH_SHA224 | \
  77. EIP93_HASH_SHA256))
  78. /**
  79. * struct eip93_device - crypto engine device structure
  80. */
  81. struct eip93_device {
  82. void __iomem *base;
  83. struct device *dev;
  84. struct clk *clk;
  85. int irq;
  86. struct eip93_ring *ring;
  87. };
  88. struct eip93_desc_ring {
  89. void *base;
  90. void *base_end;
  91. dma_addr_t base_dma;
  92. /* write and read pointers */
  93. void *read;
  94. void *write;
  95. /* descriptor element offset */
  96. u32 offset;
  97. };
  98. struct eip93_state_pool {
  99. void *base;
  100. dma_addr_t base_dma;
  101. };
  102. struct eip93_ring {
  103. struct tasklet_struct done_task;
  104. /* command/result rings */
  105. struct eip93_desc_ring cdr;
  106. struct eip93_desc_ring rdr;
  107. spinlock_t write_lock;
  108. spinlock_t read_lock;
  109. /* aync idr */
  110. spinlock_t idr_lock;
  111. struct idr crypto_async_idr;
  112. };
  113. enum eip93_alg_type {
  114. EIP93_ALG_TYPE_AEAD,
  115. EIP93_ALG_TYPE_SKCIPHER,
  116. EIP93_ALG_TYPE_HASH,
  117. };
  118. struct eip93_alg_template {
  119. struct eip93_device *eip93;
  120. enum eip93_alg_type type;
  121. u32 flags;
  122. union {
  123. struct aead_alg aead;
  124. struct skcipher_alg skcipher;
  125. struct ahash_alg ahash;
  126. } alg;
  127. };
  128. #endif /* _EIP93_MAIN_H_ */