octeon-crypto.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2012-2013 Cavium Inc., All Rights Reserved.
  7. *
  8. * MD5/SHA1/SHA256/SHA512 instruction definitions added by
  9. * Aaro Koskinen <aaro.koskinen@iki.fi>.
  10. *
  11. */
  12. #ifndef __LINUX_OCTEON_CRYPTO_H
  13. #define __LINUX_OCTEON_CRYPTO_H
  14. #include <linux/sched.h>
  15. #include <asm/mipsregs.h>
  16. #define OCTEON_CR_OPCODE_PRIORITY 300
  17. extern unsigned long octeon_crypto_enable(struct octeon_cop2_state *state);
  18. extern void octeon_crypto_disable(struct octeon_cop2_state *state,
  19. unsigned long flags);
  20. /*
  21. * Macros needed to implement MD5/SHA1/SHA256:
  22. */
  23. /*
  24. * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256).
  25. */
  26. #define write_octeon_64bit_hash_dword(value, index) \
  27. do { \
  28. __asm__ __volatile__ ( \
  29. "dmtc2 %[rt],0x0048+" STR(index) \
  30. : \
  31. : [rt] "d" (cpu_to_be64(value))); \
  32. } while (0)
  33. /*
  34. * The index can be 0-1 (MD5) or 0-2 (SHA1), 0-3 (SHA256).
  35. */
  36. #define read_octeon_64bit_hash_dword(index) \
  37. ({ \
  38. u64 __value; \
  39. \
  40. __asm__ __volatile__ ( \
  41. "dmfc2 %[rt],0x0048+" STR(index) \
  42. : [rt] "=d" (__value) \
  43. : ); \
  44. \
  45. be64_to_cpu(__value); \
  46. })
  47. /*
  48. * The index can be 0-6.
  49. */
  50. #define write_octeon_64bit_block_dword(value, index) \
  51. do { \
  52. __asm__ __volatile__ ( \
  53. "dmtc2 %[rt],0x0040+" STR(index) \
  54. : \
  55. : [rt] "d" (cpu_to_be64(value))); \
  56. } while (0)
  57. /*
  58. * The value is the final block dword (64-bit).
  59. */
  60. #define octeon_md5_start(value) \
  61. do { \
  62. __asm__ __volatile__ ( \
  63. "dmtc2 %[rt],0x4047" \
  64. : \
  65. : [rt] "d" (cpu_to_be64(value))); \
  66. } while (0)
  67. /*
  68. * The value is the final block dword (64-bit).
  69. */
  70. #define octeon_sha1_start(value) \
  71. do { \
  72. __asm__ __volatile__ ( \
  73. "dmtc2 %[rt],0x4057" \
  74. : \
  75. : [rt] "d" (value)); \
  76. } while (0)
  77. /*
  78. * The value is the final block dword (64-bit).
  79. */
  80. #define octeon_sha256_start(value) \
  81. do { \
  82. __asm__ __volatile__ ( \
  83. "dmtc2 %[rt],0x404f" \
  84. : \
  85. : [rt] "d" (value)); \
  86. } while (0)
  87. /*
  88. * Macros needed to implement SHA512:
  89. */
  90. /*
  91. * The index can be 0-7.
  92. */
  93. #define write_octeon_64bit_hash_sha512(value, index) \
  94. do { \
  95. __asm__ __volatile__ ( \
  96. "dmtc2 %[rt],0x0250+" STR(index) \
  97. : \
  98. : [rt] "d" (value)); \
  99. } while (0)
  100. /*
  101. * The index can be 0-7.
  102. */
  103. #define read_octeon_64bit_hash_sha512(index) \
  104. ({ \
  105. u64 __value; \
  106. \
  107. __asm__ __volatile__ ( \
  108. "dmfc2 %[rt],0x0250+" STR(index) \
  109. : [rt] "=d" (__value) \
  110. : ); \
  111. \
  112. __value; \
  113. })
  114. /*
  115. * The index can be 0-14.
  116. */
  117. #define write_octeon_64bit_block_sha512(value, index) \
  118. do { \
  119. __asm__ __volatile__ ( \
  120. "dmtc2 %[rt],0x0240+" STR(index) \
  121. : \
  122. : [rt] "d" (value)); \
  123. } while (0)
  124. /*
  125. * The value is the final block word (64-bit).
  126. */
  127. #define octeon_sha512_start(value) \
  128. do { \
  129. __asm__ __volatile__ ( \
  130. "dmtc2 %[rt],0x424f" \
  131. : \
  132. : [rt] "d" (value)); \
  133. } while (0)
  134. /*
  135. * The value is the final block dword (64-bit).
  136. */
  137. #define octeon_sha1_start(value) \
  138. do { \
  139. __asm__ __volatile__ ( \
  140. "dmtc2 %[rt],0x4057" \
  141. : \
  142. : [rt] "d" (value)); \
  143. } while (0)
  144. /*
  145. * The value is the final block dword (64-bit).
  146. */
  147. #define octeon_sha256_start(value) \
  148. do { \
  149. __asm__ __volatile__ ( \
  150. "dmtc2 %[rt],0x404f" \
  151. : \
  152. : [rt] "d" (value)); \
  153. } while (0)
  154. /*
  155. * Macros needed to implement SHA512:
  156. */
  157. /*
  158. * The index can be 0-7.
  159. */
  160. #define write_octeon_64bit_hash_sha512(value, index) \
  161. do { \
  162. __asm__ __volatile__ ( \
  163. "dmtc2 %[rt],0x0250+" STR(index) \
  164. : \
  165. : [rt] "d" (value)); \
  166. } while (0)
  167. /*
  168. * The index can be 0-7.
  169. */
  170. #define read_octeon_64bit_hash_sha512(index) \
  171. ({ \
  172. u64 __value; \
  173. \
  174. __asm__ __volatile__ ( \
  175. "dmfc2 %[rt],0x0250+" STR(index) \
  176. : [rt] "=d" (__value) \
  177. : ); \
  178. \
  179. __value; \
  180. })
  181. /*
  182. * The index can be 0-14.
  183. */
  184. #define write_octeon_64bit_block_sha512(value, index) \
  185. do { \
  186. __asm__ __volatile__ ( \
  187. "dmtc2 %[rt],0x0240+" STR(index) \
  188. : \
  189. : [rt] "d" (value)); \
  190. } while (0)
  191. /*
  192. * The value is the final block word (64-bit).
  193. */
  194. #define octeon_sha512_start(value) \
  195. do { \
  196. __asm__ __volatile__ ( \
  197. "dmtc2 %[rt],0x424f" \
  198. : \
  199. : [rt] "d" (value)); \
  200. } while (0)
  201. #endif /* __LINUX_OCTEON_CRYPTO_H */