icp_qat_fw.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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_FW_H_
  42. #define _ICP_QAT_FW_H_
  43. #include <linux/types.h>
  44. #include "icp_qat_hw.h"
  45. #define QAT_FIELD_SET(flags, val, bitpos, mask) \
  46. { (flags) = (((flags) & (~((mask) << (bitpos)))) | \
  47. (((val) & (mask)) << (bitpos))) ; }
  48. #define QAT_FIELD_GET(flags, bitpos, mask) \
  49. (((flags) >> (bitpos)) & (mask))
  50. #define ICP_QAT_FW_REQ_DEFAULT_SZ 128
  51. #define ICP_QAT_FW_RESP_DEFAULT_SZ 32
  52. #define ICP_QAT_FW_COMN_ONE_BYTE_SHIFT 8
  53. #define ICP_QAT_FW_COMN_SINGLE_BYTE_MASK 0xFF
  54. #define ICP_QAT_FW_NUM_LONGWORDS_1 1
  55. #define ICP_QAT_FW_NUM_LONGWORDS_2 2
  56. #define ICP_QAT_FW_NUM_LONGWORDS_3 3
  57. #define ICP_QAT_FW_NUM_LONGWORDS_4 4
  58. #define ICP_QAT_FW_NUM_LONGWORDS_5 5
  59. #define ICP_QAT_FW_NUM_LONGWORDS_6 6
  60. #define ICP_QAT_FW_NUM_LONGWORDS_7 7
  61. #define ICP_QAT_FW_NUM_LONGWORDS_10 10
  62. #define ICP_QAT_FW_NUM_LONGWORDS_13 13
  63. #define ICP_QAT_FW_NULL_REQ_SERV_ID 1
  64. enum icp_qat_fw_comn_resp_serv_id {
  65. ICP_QAT_FW_COMN_RESP_SERV_NULL,
  66. ICP_QAT_FW_COMN_RESP_SERV_CPM_FW,
  67. ICP_QAT_FW_COMN_RESP_SERV_DELIMITER
  68. };
  69. enum icp_qat_fw_comn_request_id {
  70. ICP_QAT_FW_COMN_REQ_NULL = 0,
  71. ICP_QAT_FW_COMN_REQ_CPM_FW_PKE = 3,
  72. ICP_QAT_FW_COMN_REQ_CPM_FW_LA = 4,
  73. ICP_QAT_FW_COMN_REQ_CPM_FW_DMA = 7,
  74. ICP_QAT_FW_COMN_REQ_CPM_FW_COMP = 9,
  75. ICP_QAT_FW_COMN_REQ_DELIMITER
  76. };
  77. struct icp_qat_fw_comn_req_hdr_cd_pars {
  78. union {
  79. struct {
  80. uint64_t content_desc_addr;
  81. uint16_t content_desc_resrvd1;
  82. uint8_t content_desc_params_sz;
  83. uint8_t content_desc_hdr_resrvd2;
  84. uint32_t content_desc_resrvd3;
  85. } s;
  86. struct {
  87. uint32_t serv_specif_fields[4];
  88. } s1;
  89. } u;
  90. };
  91. struct icp_qat_fw_comn_req_mid {
  92. uint64_t opaque_data;
  93. uint64_t src_data_addr;
  94. uint64_t dest_data_addr;
  95. uint32_t src_length;
  96. uint32_t dst_length;
  97. };
  98. struct icp_qat_fw_comn_req_cd_ctrl {
  99. uint32_t content_desc_ctrl_lw[ICP_QAT_FW_NUM_LONGWORDS_5];
  100. };
  101. struct icp_qat_fw_comn_req_hdr {
  102. uint8_t resrvd1;
  103. uint8_t service_cmd_id;
  104. uint8_t service_type;
  105. uint8_t hdr_flags;
  106. uint16_t serv_specif_flags;
  107. uint16_t comn_req_flags;
  108. };
  109. struct icp_qat_fw_comn_req_rqpars {
  110. uint32_t serv_specif_rqpars_lw[ICP_QAT_FW_NUM_LONGWORDS_13];
  111. };
  112. struct icp_qat_fw_comn_req {
  113. struct icp_qat_fw_comn_req_hdr comn_hdr;
  114. struct icp_qat_fw_comn_req_hdr_cd_pars cd_pars;
  115. struct icp_qat_fw_comn_req_mid comn_mid;
  116. struct icp_qat_fw_comn_req_rqpars serv_specif_rqpars;
  117. struct icp_qat_fw_comn_req_cd_ctrl cd_ctrl;
  118. };
  119. struct icp_qat_fw_comn_error {
  120. uint8_t xlat_err_code;
  121. uint8_t cmp_err_code;
  122. };
  123. struct icp_qat_fw_comn_resp_hdr {
  124. uint8_t resrvd1;
  125. uint8_t service_id;
  126. uint8_t response_type;
  127. uint8_t hdr_flags;
  128. struct icp_qat_fw_comn_error comn_error;
  129. uint8_t comn_status;
  130. uint8_t cmd_id;
  131. };
  132. struct icp_qat_fw_comn_resp {
  133. struct icp_qat_fw_comn_resp_hdr comn_hdr;
  134. uint64_t opaque_data;
  135. uint32_t resrvd[ICP_QAT_FW_NUM_LONGWORDS_4];
  136. };
  137. #define ICP_QAT_FW_COMN_REQ_FLAG_SET 1
  138. #define ICP_QAT_FW_COMN_REQ_FLAG_CLR 0
  139. #define ICP_QAT_FW_COMN_VALID_FLAG_BITPOS 7
  140. #define ICP_QAT_FW_COMN_VALID_FLAG_MASK 0x1
  141. #define ICP_QAT_FW_COMN_HDR_RESRVD_FLD_MASK 0x7F
  142. #define ICP_QAT_FW_COMN_OV_SRV_TYPE_GET(icp_qat_fw_comn_req_hdr_t) \
  143. icp_qat_fw_comn_req_hdr_t.service_type
  144. #define ICP_QAT_FW_COMN_OV_SRV_TYPE_SET(icp_qat_fw_comn_req_hdr_t, val) \
  145. icp_qat_fw_comn_req_hdr_t.service_type = val
  146. #define ICP_QAT_FW_COMN_OV_SRV_CMD_ID_GET(icp_qat_fw_comn_req_hdr_t) \
  147. icp_qat_fw_comn_req_hdr_t.service_cmd_id
  148. #define ICP_QAT_FW_COMN_OV_SRV_CMD_ID_SET(icp_qat_fw_comn_req_hdr_t, val) \
  149. icp_qat_fw_comn_req_hdr_t.service_cmd_id = val
  150. #define ICP_QAT_FW_COMN_HDR_VALID_FLAG_GET(hdr_t) \
  151. ICP_QAT_FW_COMN_VALID_FLAG_GET(hdr_t.hdr_flags)
  152. #define ICP_QAT_FW_COMN_HDR_VALID_FLAG_SET(hdr_t, val) \
  153. ICP_QAT_FW_COMN_VALID_FLAG_SET(hdr_t, val)
  154. #define ICP_QAT_FW_COMN_VALID_FLAG_GET(hdr_flags) \
  155. QAT_FIELD_GET(hdr_flags, \
  156. ICP_QAT_FW_COMN_VALID_FLAG_BITPOS, \
  157. ICP_QAT_FW_COMN_VALID_FLAG_MASK)
  158. #define ICP_QAT_FW_COMN_HDR_RESRVD_FLD_GET(hdr_flags) \
  159. (hdr_flags & ICP_QAT_FW_COMN_HDR_RESRVD_FLD_MASK)
  160. #define ICP_QAT_FW_COMN_VALID_FLAG_SET(hdr_t, val) \
  161. QAT_FIELD_SET((hdr_t.hdr_flags), (val), \
  162. ICP_QAT_FW_COMN_VALID_FLAG_BITPOS, \
  163. ICP_QAT_FW_COMN_VALID_FLAG_MASK)
  164. #define ICP_QAT_FW_COMN_HDR_FLAGS_BUILD(valid) \
  165. (((valid) & ICP_QAT_FW_COMN_VALID_FLAG_MASK) << \
  166. ICP_QAT_FW_COMN_VALID_FLAG_BITPOS)
  167. #define QAT_COMN_PTR_TYPE_BITPOS 0
  168. #define QAT_COMN_PTR_TYPE_MASK 0x1
  169. #define QAT_COMN_CD_FLD_TYPE_BITPOS 1
  170. #define QAT_COMN_CD_FLD_TYPE_MASK 0x1
  171. #define QAT_COMN_PTR_TYPE_FLAT 0x0
  172. #define QAT_COMN_PTR_TYPE_SGL 0x1
  173. #define QAT_COMN_CD_FLD_TYPE_64BIT_ADR 0x0
  174. #define QAT_COMN_CD_FLD_TYPE_16BYTE_DATA 0x1
  175. #define ICP_QAT_FW_COMN_FLAGS_BUILD(cdt, ptr) \
  176. ((((cdt) & QAT_COMN_CD_FLD_TYPE_MASK) << QAT_COMN_CD_FLD_TYPE_BITPOS) \
  177. | (((ptr) & QAT_COMN_PTR_TYPE_MASK) << QAT_COMN_PTR_TYPE_BITPOS))
  178. #define ICP_QAT_FW_COMN_PTR_TYPE_GET(flags) \
  179. QAT_FIELD_GET(flags, QAT_COMN_PTR_TYPE_BITPOS, QAT_COMN_PTR_TYPE_MASK)
  180. #define ICP_QAT_FW_COMN_CD_FLD_TYPE_GET(flags) \
  181. QAT_FIELD_GET(flags, QAT_COMN_CD_FLD_TYPE_BITPOS, \
  182. QAT_COMN_CD_FLD_TYPE_MASK)
  183. #define ICP_QAT_FW_COMN_PTR_TYPE_SET(flags, val) \
  184. QAT_FIELD_SET(flags, val, QAT_COMN_PTR_TYPE_BITPOS, \
  185. QAT_COMN_PTR_TYPE_MASK)
  186. #define ICP_QAT_FW_COMN_CD_FLD_TYPE_SET(flags, val) \
  187. QAT_FIELD_SET(flags, val, QAT_COMN_CD_FLD_TYPE_BITPOS, \
  188. QAT_COMN_CD_FLD_TYPE_MASK)
  189. #define ICP_QAT_FW_COMN_NEXT_ID_BITPOS 4
  190. #define ICP_QAT_FW_COMN_NEXT_ID_MASK 0xF0
  191. #define ICP_QAT_FW_COMN_CURR_ID_BITPOS 0
  192. #define ICP_QAT_FW_COMN_CURR_ID_MASK 0x0F
  193. #define ICP_QAT_FW_COMN_NEXT_ID_GET(cd_ctrl_hdr_t) \
  194. ((((cd_ctrl_hdr_t)->next_curr_id) & ICP_QAT_FW_COMN_NEXT_ID_MASK) \
  195. >> (ICP_QAT_FW_COMN_NEXT_ID_BITPOS))
  196. #define ICP_QAT_FW_COMN_NEXT_ID_SET(cd_ctrl_hdr_t, val) \
  197. { ((cd_ctrl_hdr_t)->next_curr_id) = ((((cd_ctrl_hdr_t)->next_curr_id) \
  198. & ICP_QAT_FW_COMN_CURR_ID_MASK) | \
  199. ((val << ICP_QAT_FW_COMN_NEXT_ID_BITPOS) \
  200. & ICP_QAT_FW_COMN_NEXT_ID_MASK)); }
  201. #define ICP_QAT_FW_COMN_CURR_ID_GET(cd_ctrl_hdr_t) \
  202. (((cd_ctrl_hdr_t)->next_curr_id) & ICP_QAT_FW_COMN_CURR_ID_MASK)
  203. #define ICP_QAT_FW_COMN_CURR_ID_SET(cd_ctrl_hdr_t, val) \
  204. { ((cd_ctrl_hdr_t)->next_curr_id) = ((((cd_ctrl_hdr_t)->next_curr_id) \
  205. & ICP_QAT_FW_COMN_NEXT_ID_MASK) | \
  206. ((val) & ICP_QAT_FW_COMN_CURR_ID_MASK)); }
  207. #define QAT_COMN_RESP_CRYPTO_STATUS_BITPOS 7
  208. #define QAT_COMN_RESP_CRYPTO_STATUS_MASK 0x1
  209. #define QAT_COMN_RESP_PKE_STATUS_BITPOS 6
  210. #define QAT_COMN_RESP_PKE_STATUS_MASK 0x1
  211. #define QAT_COMN_RESP_CMP_STATUS_BITPOS 5
  212. #define QAT_COMN_RESP_CMP_STATUS_MASK 0x1
  213. #define QAT_COMN_RESP_XLAT_STATUS_BITPOS 4
  214. #define QAT_COMN_RESP_XLAT_STATUS_MASK 0x1
  215. #define QAT_COMN_RESP_CMP_END_OF_LAST_BLK_BITPOS 3
  216. #define QAT_COMN_RESP_CMP_END_OF_LAST_BLK_MASK 0x1
  217. #define ICP_QAT_FW_COMN_RESP_STATUS_BUILD(crypto, comp, xlat, eolb) \
  218. ((((crypto) & QAT_COMN_RESP_CRYPTO_STATUS_MASK) << \
  219. QAT_COMN_RESP_CRYPTO_STATUS_BITPOS) | \
  220. (((comp) & QAT_COMN_RESP_CMP_STATUS_MASK) << \
  221. QAT_COMN_RESP_CMP_STATUS_BITPOS) | \
  222. (((xlat) & QAT_COMN_RESP_XLAT_STATUS_MASK) << \
  223. QAT_COMN_RESP_XLAT_STATUS_BITPOS) | \
  224. (((eolb) & QAT_COMN_RESP_CMP_END_OF_LAST_BLK_MASK) << \
  225. QAT_COMN_RESP_CMP_END_OF_LAST_BLK_BITPOS))
  226. #define ICP_QAT_FW_COMN_RESP_CRYPTO_STAT_GET(status) \
  227. QAT_FIELD_GET(status, QAT_COMN_RESP_CRYPTO_STATUS_BITPOS, \
  228. QAT_COMN_RESP_CRYPTO_STATUS_MASK)
  229. #define ICP_QAT_FW_COMN_RESP_CMP_STAT_GET(status) \
  230. QAT_FIELD_GET(status, QAT_COMN_RESP_CMP_STATUS_BITPOS, \
  231. QAT_COMN_RESP_CMP_STATUS_MASK)
  232. #define ICP_QAT_FW_COMN_RESP_XLAT_STAT_GET(status) \
  233. QAT_FIELD_GET(status, QAT_COMN_RESP_XLAT_STATUS_BITPOS, \
  234. QAT_COMN_RESP_XLAT_STATUS_MASK)
  235. #define ICP_QAT_FW_COMN_RESP_CMP_END_OF_LAST_BLK_FLAG_GET(status) \
  236. QAT_FIELD_GET(status, QAT_COMN_RESP_CMP_END_OF_LAST_BLK_BITPOS, \
  237. QAT_COMN_RESP_CMP_END_OF_LAST_BLK_MASK)
  238. #define ICP_QAT_FW_COMN_STATUS_FLAG_OK 0
  239. #define ICP_QAT_FW_COMN_STATUS_FLAG_ERROR 1
  240. #define ICP_QAT_FW_COMN_STATUS_CMP_END_OF_LAST_BLK_FLAG_CLR 0
  241. #define ICP_QAT_FW_COMN_STATUS_CMP_END_OF_LAST_BLK_FLAG_SET 1
  242. #define ERR_CODE_NO_ERROR 0
  243. #define ERR_CODE_INVALID_BLOCK_TYPE -1
  244. #define ERR_CODE_NO_MATCH_ONES_COMP -2
  245. #define ERR_CODE_TOO_MANY_LEN_OR_DIS -3
  246. #define ERR_CODE_INCOMPLETE_LEN -4
  247. #define ERR_CODE_RPT_LEN_NO_FIRST_LEN -5
  248. #define ERR_CODE_RPT_GT_SPEC_LEN -6
  249. #define ERR_CODE_INV_LIT_LEN_CODE_LEN -7
  250. #define ERR_CODE_INV_DIS_CODE_LEN -8
  251. #define ERR_CODE_INV_LIT_LEN_DIS_IN_BLK -9
  252. #define ERR_CODE_DIS_TOO_FAR_BACK -10
  253. #define ERR_CODE_OVERFLOW_ERROR -11
  254. #define ERR_CODE_SOFT_ERROR -12
  255. #define ERR_CODE_FATAL_ERROR -13
  256. #define ERR_CODE_SSM_ERROR -14
  257. #define ERR_CODE_ENDPOINT_ERROR -15
  258. enum icp_qat_fw_slice {
  259. ICP_QAT_FW_SLICE_NULL = 0,
  260. ICP_QAT_FW_SLICE_CIPHER = 1,
  261. ICP_QAT_FW_SLICE_AUTH = 2,
  262. ICP_QAT_FW_SLICE_DRAM_RD = 3,
  263. ICP_QAT_FW_SLICE_DRAM_WR = 4,
  264. ICP_QAT_FW_SLICE_COMP = 5,
  265. ICP_QAT_FW_SLICE_XLAT = 6,
  266. ICP_QAT_FW_SLICE_DELIMITER
  267. };
  268. #endif