icp_qat_hw.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. This file is provided under a dual BSD/GPLv2 license. When using or
  3. redistributing this file, you may do so under either license.
  4. GPL LICENSE SUMMARY
  5. Copyright(c) 2014 Intel Corporation.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. Contact Information:
  14. qat-linux@intel.com
  15. BSD LICENSE
  16. Copyright(c) 2014 Intel Corporation.
  17. Redistribution and use in source and binary forms, with or without
  18. modification, are permitted provided that the following conditions
  19. are met:
  20. * Redistributions of source code must retain the above copyright
  21. notice, this list of conditions and the following disclaimer.
  22. * Redistributions in binary form must reproduce the above copyright
  23. notice, this list of conditions and the following disclaimer in
  24. the documentation and/or other materials provided with the
  25. distribution.
  26. * Neither the name of Intel Corporation nor the names of its
  27. contributors may be used to endorse or promote products derived
  28. from this software without specific prior written permission.
  29. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. */
  41. #ifndef _ICP_QAT_HW_H_
  42. #define _ICP_QAT_HW_H_
  43. enum icp_qat_hw_ae_id {
  44. ICP_QAT_HW_AE_0 = 0,
  45. ICP_QAT_HW_AE_1 = 1,
  46. ICP_QAT_HW_AE_2 = 2,
  47. ICP_QAT_HW_AE_3 = 3,
  48. ICP_QAT_HW_AE_4 = 4,
  49. ICP_QAT_HW_AE_5 = 5,
  50. ICP_QAT_HW_AE_6 = 6,
  51. ICP_QAT_HW_AE_7 = 7,
  52. ICP_QAT_HW_AE_8 = 8,
  53. ICP_QAT_HW_AE_9 = 9,
  54. ICP_QAT_HW_AE_10 = 10,
  55. ICP_QAT_HW_AE_11 = 11,
  56. ICP_QAT_HW_AE_DELIMITER = 12
  57. };
  58. enum icp_qat_hw_qat_id {
  59. ICP_QAT_HW_QAT_0 = 0,
  60. ICP_QAT_HW_QAT_1 = 1,
  61. ICP_QAT_HW_QAT_2 = 2,
  62. ICP_QAT_HW_QAT_3 = 3,
  63. ICP_QAT_HW_QAT_4 = 4,
  64. ICP_QAT_HW_QAT_5 = 5,
  65. ICP_QAT_HW_QAT_DELIMITER = 6
  66. };
  67. enum icp_qat_hw_auth_algo {
  68. ICP_QAT_HW_AUTH_ALGO_NULL = 0,
  69. ICP_QAT_HW_AUTH_ALGO_SHA1 = 1,
  70. ICP_QAT_HW_AUTH_ALGO_MD5 = 2,
  71. ICP_QAT_HW_AUTH_ALGO_SHA224 = 3,
  72. ICP_QAT_HW_AUTH_ALGO_SHA256 = 4,
  73. ICP_QAT_HW_AUTH_ALGO_SHA384 = 5,
  74. ICP_QAT_HW_AUTH_ALGO_SHA512 = 6,
  75. ICP_QAT_HW_AUTH_ALGO_AES_XCBC_MAC = 7,
  76. ICP_QAT_HW_AUTH_ALGO_AES_CBC_MAC = 8,
  77. ICP_QAT_HW_AUTH_ALGO_AES_F9 = 9,
  78. ICP_QAT_HW_AUTH_ALGO_GALOIS_128 = 10,
  79. ICP_QAT_HW_AUTH_ALGO_GALOIS_64 = 11,
  80. ICP_QAT_HW_AUTH_ALGO_KASUMI_F9 = 12,
  81. ICP_QAT_HW_AUTH_ALGO_SNOW_3G_UIA2 = 13,
  82. ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3 = 14,
  83. ICP_QAT_HW_AUTH_RESERVED_1 = 15,
  84. ICP_QAT_HW_AUTH_RESERVED_2 = 16,
  85. ICP_QAT_HW_AUTH_ALGO_SHA3_256 = 17,
  86. ICP_QAT_HW_AUTH_RESERVED_3 = 18,
  87. ICP_QAT_HW_AUTH_ALGO_SHA3_512 = 19,
  88. ICP_QAT_HW_AUTH_ALGO_DELIMITER = 20
  89. };
  90. enum icp_qat_hw_auth_mode {
  91. ICP_QAT_HW_AUTH_MODE0 = 0,
  92. ICP_QAT_HW_AUTH_MODE1 = 1,
  93. ICP_QAT_HW_AUTH_MODE2 = 2,
  94. ICP_QAT_HW_AUTH_MODE_DELIMITER = 3
  95. };
  96. struct icp_qat_hw_auth_config {
  97. uint32_t config;
  98. uint32_t reserved;
  99. };
  100. #define QAT_AUTH_MODE_BITPOS 4
  101. #define QAT_AUTH_MODE_MASK 0xF
  102. #define QAT_AUTH_ALGO_BITPOS 0
  103. #define QAT_AUTH_ALGO_MASK 0xF
  104. #define QAT_AUTH_CMP_BITPOS 8
  105. #define QAT_AUTH_CMP_MASK 0x7F
  106. #define QAT_AUTH_SHA3_PADDING_BITPOS 16
  107. #define QAT_AUTH_SHA3_PADDING_MASK 0x1
  108. #define QAT_AUTH_ALGO_SHA3_BITPOS 22
  109. #define QAT_AUTH_ALGO_SHA3_MASK 0x3
  110. #define ICP_QAT_HW_AUTH_CONFIG_BUILD(mode, algo, cmp_len) \
  111. (((mode & QAT_AUTH_MODE_MASK) << QAT_AUTH_MODE_BITPOS) | \
  112. ((algo & QAT_AUTH_ALGO_MASK) << QAT_AUTH_ALGO_BITPOS) | \
  113. (((algo >> 4) & QAT_AUTH_ALGO_SHA3_MASK) << \
  114. QAT_AUTH_ALGO_SHA3_BITPOS) | \
  115. (((((algo == ICP_QAT_HW_AUTH_ALGO_SHA3_256) || \
  116. (algo == ICP_QAT_HW_AUTH_ALGO_SHA3_512)) ? 1 : 0) \
  117. & QAT_AUTH_SHA3_PADDING_MASK) << QAT_AUTH_SHA3_PADDING_BITPOS) | \
  118. ((cmp_len & QAT_AUTH_CMP_MASK) << QAT_AUTH_CMP_BITPOS))
  119. struct icp_qat_hw_auth_counter {
  120. __be32 counter;
  121. uint32_t reserved;
  122. };
  123. #define QAT_AUTH_COUNT_MASK 0xFFFFFFFF
  124. #define QAT_AUTH_COUNT_BITPOS 0
  125. #define ICP_QAT_HW_AUTH_COUNT_BUILD(val) \
  126. (((val) & QAT_AUTH_COUNT_MASK) << QAT_AUTH_COUNT_BITPOS)
  127. struct icp_qat_hw_auth_setup {
  128. struct icp_qat_hw_auth_config auth_config;
  129. struct icp_qat_hw_auth_counter auth_counter;
  130. };
  131. #define QAT_HW_DEFAULT_ALIGNMENT 8
  132. #define QAT_HW_ROUND_UP(val, n) (((val) + ((n) - 1)) & (~(n - 1)))
  133. #define ICP_QAT_HW_NULL_STATE1_SZ 32
  134. #define ICP_QAT_HW_MD5_STATE1_SZ 16
  135. #define ICP_QAT_HW_SHA1_STATE1_SZ 20
  136. #define ICP_QAT_HW_SHA224_STATE1_SZ 32
  137. #define ICP_QAT_HW_SHA256_STATE1_SZ 32
  138. #define ICP_QAT_HW_SHA3_256_STATE1_SZ 32
  139. #define ICP_QAT_HW_SHA384_STATE1_SZ 64
  140. #define ICP_QAT_HW_SHA512_STATE1_SZ 64
  141. #define ICP_QAT_HW_SHA3_512_STATE1_SZ 64
  142. #define ICP_QAT_HW_SHA3_224_STATE1_SZ 28
  143. #define ICP_QAT_HW_SHA3_384_STATE1_SZ 48
  144. #define ICP_QAT_HW_AES_XCBC_MAC_STATE1_SZ 16
  145. #define ICP_QAT_HW_AES_CBC_MAC_STATE1_SZ 16
  146. #define ICP_QAT_HW_AES_F9_STATE1_SZ 32
  147. #define ICP_QAT_HW_KASUMI_F9_STATE1_SZ 16
  148. #define ICP_QAT_HW_GALOIS_128_STATE1_SZ 16
  149. #define ICP_QAT_HW_SNOW_3G_UIA2_STATE1_SZ 8
  150. #define ICP_QAT_HW_ZUC_3G_EIA3_STATE1_SZ 8
  151. #define ICP_QAT_HW_NULL_STATE2_SZ 32
  152. #define ICP_QAT_HW_MD5_STATE2_SZ 16
  153. #define ICP_QAT_HW_SHA1_STATE2_SZ 20
  154. #define ICP_QAT_HW_SHA224_STATE2_SZ 32
  155. #define ICP_QAT_HW_SHA256_STATE2_SZ 32
  156. #define ICP_QAT_HW_SHA3_256_STATE2_SZ 0
  157. #define ICP_QAT_HW_SHA384_STATE2_SZ 64
  158. #define ICP_QAT_HW_SHA512_STATE2_SZ 64
  159. #define ICP_QAT_HW_SHA3_512_STATE2_SZ 0
  160. #define ICP_QAT_HW_SHA3_224_STATE2_SZ 0
  161. #define ICP_QAT_HW_SHA3_384_STATE2_SZ 0
  162. #define ICP_QAT_HW_AES_XCBC_MAC_KEY_SZ 16
  163. #define ICP_QAT_HW_AES_CBC_MAC_KEY_SZ 16
  164. #define ICP_QAT_HW_AES_CCM_CBC_E_CTR0_SZ 16
  165. #define ICP_QAT_HW_F9_IK_SZ 16
  166. #define ICP_QAT_HW_F9_FK_SZ 16
  167. #define ICP_QAT_HW_KASUMI_F9_STATE2_SZ (ICP_QAT_HW_F9_IK_SZ + \
  168. ICP_QAT_HW_F9_FK_SZ)
  169. #define ICP_QAT_HW_AES_F9_STATE2_SZ ICP_QAT_HW_KASUMI_F9_STATE2_SZ
  170. #define ICP_QAT_HW_SNOW_3G_UIA2_STATE2_SZ 24
  171. #define ICP_QAT_HW_ZUC_3G_EIA3_STATE2_SZ 32
  172. #define ICP_QAT_HW_GALOIS_H_SZ 16
  173. #define ICP_QAT_HW_GALOIS_LEN_A_SZ 8
  174. #define ICP_QAT_HW_GALOIS_E_CTR0_SZ 16
  175. struct icp_qat_hw_auth_sha512 {
  176. struct icp_qat_hw_auth_setup inner_setup;
  177. uint8_t state1[ICP_QAT_HW_SHA512_STATE1_SZ];
  178. struct icp_qat_hw_auth_setup outer_setup;
  179. uint8_t state2[ICP_QAT_HW_SHA512_STATE2_SZ];
  180. };
  181. struct icp_qat_hw_auth_algo_blk {
  182. struct icp_qat_hw_auth_sha512 sha;
  183. };
  184. #define ICP_QAT_HW_GALOIS_LEN_A_BITPOS 0
  185. #define ICP_QAT_HW_GALOIS_LEN_A_MASK 0xFFFFFFFF
  186. enum icp_qat_hw_cipher_algo {
  187. ICP_QAT_HW_CIPHER_ALGO_NULL = 0,
  188. ICP_QAT_HW_CIPHER_ALGO_DES = 1,
  189. ICP_QAT_HW_CIPHER_ALGO_3DES = 2,
  190. ICP_QAT_HW_CIPHER_ALGO_AES128 = 3,
  191. ICP_QAT_HW_CIPHER_ALGO_AES192 = 4,
  192. ICP_QAT_HW_CIPHER_ALGO_AES256 = 5,
  193. ICP_QAT_HW_CIPHER_ALGO_ARC4 = 6,
  194. ICP_QAT_HW_CIPHER_ALGO_KASUMI = 7,
  195. ICP_QAT_HW_CIPHER_ALGO_SNOW_3G_UEA2 = 8,
  196. ICP_QAT_HW_CIPHER_ALGO_ZUC_3G_128_EEA3 = 9,
  197. ICP_QAT_HW_CIPHER_DELIMITER = 10
  198. };
  199. enum icp_qat_hw_cipher_mode {
  200. ICP_QAT_HW_CIPHER_ECB_MODE = 0,
  201. ICP_QAT_HW_CIPHER_CBC_MODE = 1,
  202. ICP_QAT_HW_CIPHER_CTR_MODE = 2,
  203. ICP_QAT_HW_CIPHER_F8_MODE = 3,
  204. ICP_QAT_HW_CIPHER_XTS_MODE = 6,
  205. ICP_QAT_HW_CIPHER_MODE_DELIMITER = 7
  206. };
  207. struct icp_qat_hw_cipher_config {
  208. uint32_t val;
  209. uint32_t reserved;
  210. };
  211. enum icp_qat_hw_cipher_dir {
  212. ICP_QAT_HW_CIPHER_ENCRYPT = 0,
  213. ICP_QAT_HW_CIPHER_DECRYPT = 1,
  214. };
  215. enum icp_qat_hw_cipher_convert {
  216. ICP_QAT_HW_CIPHER_NO_CONVERT = 0,
  217. ICP_QAT_HW_CIPHER_KEY_CONVERT = 1,
  218. };
  219. #define QAT_CIPHER_MODE_BITPOS 4
  220. #define QAT_CIPHER_MODE_MASK 0xF
  221. #define QAT_CIPHER_ALGO_BITPOS 0
  222. #define QAT_CIPHER_ALGO_MASK 0xF
  223. #define QAT_CIPHER_CONVERT_BITPOS 9
  224. #define QAT_CIPHER_CONVERT_MASK 0x1
  225. #define QAT_CIPHER_DIR_BITPOS 8
  226. #define QAT_CIPHER_DIR_MASK 0x1
  227. #define QAT_CIPHER_MODE_F8_KEY_SZ_MULT 2
  228. #define QAT_CIPHER_MODE_XTS_KEY_SZ_MULT 2
  229. #define ICP_QAT_HW_CIPHER_CONFIG_BUILD(mode, algo, convert, dir) \
  230. (((mode & QAT_CIPHER_MODE_MASK) << QAT_CIPHER_MODE_BITPOS) | \
  231. ((algo & QAT_CIPHER_ALGO_MASK) << QAT_CIPHER_ALGO_BITPOS) | \
  232. ((convert & QAT_CIPHER_CONVERT_MASK) << QAT_CIPHER_CONVERT_BITPOS) | \
  233. ((dir & QAT_CIPHER_DIR_MASK) << QAT_CIPHER_DIR_BITPOS))
  234. #define ICP_QAT_HW_DES_BLK_SZ 8
  235. #define ICP_QAT_HW_3DES_BLK_SZ 8
  236. #define ICP_QAT_HW_NULL_BLK_SZ 8
  237. #define ICP_QAT_HW_AES_BLK_SZ 16
  238. #define ICP_QAT_HW_KASUMI_BLK_SZ 8
  239. #define ICP_QAT_HW_SNOW_3G_BLK_SZ 8
  240. #define ICP_QAT_HW_ZUC_3G_BLK_SZ 8
  241. #define ICP_QAT_HW_NULL_KEY_SZ 256
  242. #define ICP_QAT_HW_DES_KEY_SZ 8
  243. #define ICP_QAT_HW_3DES_KEY_SZ 24
  244. #define ICP_QAT_HW_AES_128_KEY_SZ 16
  245. #define ICP_QAT_HW_AES_192_KEY_SZ 24
  246. #define ICP_QAT_HW_AES_256_KEY_SZ 32
  247. #define ICP_QAT_HW_AES_128_F8_KEY_SZ (ICP_QAT_HW_AES_128_KEY_SZ * \
  248. QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
  249. #define ICP_QAT_HW_AES_192_F8_KEY_SZ (ICP_QAT_HW_AES_192_KEY_SZ * \
  250. QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
  251. #define ICP_QAT_HW_AES_256_F8_KEY_SZ (ICP_QAT_HW_AES_256_KEY_SZ * \
  252. QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
  253. #define ICP_QAT_HW_AES_128_XTS_KEY_SZ (ICP_QAT_HW_AES_128_KEY_SZ * \
  254. QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
  255. #define ICP_QAT_HW_AES_256_XTS_KEY_SZ (ICP_QAT_HW_AES_256_KEY_SZ * \
  256. QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
  257. #define ICP_QAT_HW_KASUMI_KEY_SZ 16
  258. #define ICP_QAT_HW_KASUMI_F8_KEY_SZ (ICP_QAT_HW_KASUMI_KEY_SZ * \
  259. QAT_CIPHER_MODE_F8_KEY_SZ_MULT)
  260. #define ICP_QAT_HW_AES_128_XTS_KEY_SZ (ICP_QAT_HW_AES_128_KEY_SZ * \
  261. QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
  262. #define ICP_QAT_HW_AES_256_XTS_KEY_SZ (ICP_QAT_HW_AES_256_KEY_SZ * \
  263. QAT_CIPHER_MODE_XTS_KEY_SZ_MULT)
  264. #define ICP_QAT_HW_ARC4_KEY_SZ 256
  265. #define ICP_QAT_HW_SNOW_3G_UEA2_KEY_SZ 16
  266. #define ICP_QAT_HW_SNOW_3G_UEA2_IV_SZ 16
  267. #define ICP_QAT_HW_ZUC_3G_EEA3_KEY_SZ 16
  268. #define ICP_QAT_HW_ZUC_3G_EEA3_IV_SZ 16
  269. #define ICP_QAT_HW_MODE_F8_NUM_REG_TO_CLEAR 2
  270. #define INIT_SHRAM_CONSTANTS_TABLE_SZ 1024
  271. struct icp_qat_hw_cipher_aes256_f8 {
  272. struct icp_qat_hw_cipher_config cipher_config;
  273. uint8_t key[ICP_QAT_HW_AES_256_F8_KEY_SZ];
  274. };
  275. struct icp_qat_hw_cipher_algo_blk {
  276. struct icp_qat_hw_cipher_aes256_f8 aes;
  277. } __aligned(64);
  278. #endif