qce50.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _DRIVERS_CRYPTO_MSM_QCE50_H_
  6. #define _DRIVERS_CRYPTO_MSM_QCE50_H_
  7. #include "linux/msm-sps.h"
  8. /* MAX Data xfer block size between BAM and CE */
  9. #define MAX_CE_BAM_BURST_SIZE 0x40
  10. #define QCEBAM_BURST_SIZE MAX_CE_BAM_BURST_SIZE
  11. #define GET_VIRT_ADDR(x) \
  12. ((uintptr_t)pce_dev->coh_vmem + \
  13. ((uintptr_t)x - (uintptr_t)pce_dev->coh_pmem))
  14. #define GET_PHYS_ADDR(x) \
  15. (phys_addr_t)(((uintptr_t)pce_dev->coh_pmem + \
  16. ((uintptr_t)x - (uintptr_t)pce_dev->coh_vmem)))
  17. #define CRYPTO_REG_SIZE 4
  18. #define NUM_OF_CRYPTO_AUTH_IV_REG 16
  19. #define NUM_OF_CRYPTO_CNTR_IV_REG 4
  20. #define NUM_OF_CRYPTO_AUTH_BYTE_COUNT_REG 4
  21. #define CRYPTO_TOTAL_REGISTERS_DUMPED 26
  22. #define CRYPTO_RESULT_DUMP_SIZE \
  23. ALIGN((CRYPTO_TOTAL_REGISTERS_DUMPED * CRYPTO_REG_SIZE), \
  24. QCEBAM_BURST_SIZE)
  25. /* QCE max number of descriptor in a descriptor list */
  26. #define QCE_MAX_NUM_DESC 128
  27. #define SPS_MAX_PKT_SIZE (32 * 1024 - 64)
  28. /* default bam ipc log level */
  29. #define QCE_BAM_DEFAULT_IPC_LOGLVL 2
  30. /* State of consumer/producer Pipe */
  31. enum qce_pipe_st_enum {
  32. QCE_PIPE_STATE_IDLE = 0,
  33. QCE_PIPE_STATE_IN_PROG = 1,
  34. QCE_PIPE_STATE_COMP = 2,
  35. QCE_PIPE_STATE_LAST
  36. };
  37. enum qce_xfer_type_enum {
  38. QCE_XFER_HASHING,
  39. QCE_XFER_CIPHERING,
  40. QCE_XFER_AEAD,
  41. QCE_XFER_F8,
  42. QCE_XFER_F9,
  43. QCE_XFER_TYPE_LAST
  44. };
  45. struct qce_sps_ep_conn_data {
  46. struct sps_pipe *pipe;
  47. struct sps_connect connect;
  48. struct sps_register_event event;
  49. };
  50. /* CE Result DUMP format*/
  51. struct ce_result_dump_format {
  52. uint32_t auth_iv[NUM_OF_CRYPTO_AUTH_IV_REG];
  53. uint32_t auth_byte_count[NUM_OF_CRYPTO_AUTH_BYTE_COUNT_REG];
  54. uint32_t encr_cntr_iv[NUM_OF_CRYPTO_CNTR_IV_REG];
  55. __be32 status;
  56. __be32 status2;
  57. };
  58. struct qce_cmdlist_info {
  59. unsigned long cmdlist;
  60. struct sps_command_element *crypto_cfg;
  61. struct sps_command_element *crypto_cfg_le;
  62. struct sps_command_element *encr_seg_cfg;
  63. struct sps_command_element *encr_seg_size;
  64. struct sps_command_element *encr_seg_start;
  65. struct sps_command_element *encr_key;
  66. struct sps_command_element *encr_xts_key;
  67. struct sps_command_element *encr_cntr_iv;
  68. struct sps_command_element *encr_ccm_cntr_iv;
  69. struct sps_command_element *encr_mask_0;
  70. struct sps_command_element *encr_mask_1;
  71. struct sps_command_element *encr_mask_2;
  72. struct sps_command_element *encr_mask_3;
  73. struct sps_command_element *encr_xts_du_size;
  74. struct sps_command_element *pattern_info;
  75. struct sps_command_element *block_offset;
  76. struct sps_command_element *auth_seg_cfg;
  77. struct sps_command_element *auth_seg_size;
  78. struct sps_command_element *auth_seg_start;
  79. struct sps_command_element *auth_key;
  80. struct sps_command_element *auth_iv;
  81. struct sps_command_element *auth_nonce_info;
  82. struct sps_command_element *auth_bytecount;
  83. struct sps_command_element *seg_size;
  84. struct sps_command_element *go_proc;
  85. ptrdiff_t size;
  86. };
  87. struct qce_cmdlistptr_ops {
  88. struct qce_cmdlist_info cipher_aes_128_cbc_ctr;
  89. struct qce_cmdlist_info cipher_aes_256_cbc_ctr;
  90. struct qce_cmdlist_info cipher_aes_128_ecb;
  91. struct qce_cmdlist_info cipher_aes_256_ecb;
  92. struct qce_cmdlist_info cipher_aes_128_xts;
  93. struct qce_cmdlist_info cipher_aes_256_xts;
  94. struct qce_cmdlist_info cipher_des_cbc;
  95. struct qce_cmdlist_info cipher_des_ecb;
  96. struct qce_cmdlist_info cipher_3des_cbc;
  97. struct qce_cmdlist_info cipher_3des_ecb;
  98. struct qce_cmdlist_info auth_sha1;
  99. struct qce_cmdlist_info auth_sha256;
  100. struct qce_cmdlist_info auth_sha1_hmac;
  101. struct qce_cmdlist_info auth_sha256_hmac;
  102. struct qce_cmdlist_info auth_aes_128_cmac;
  103. struct qce_cmdlist_info auth_aes_256_cmac;
  104. struct qce_cmdlist_info aead_hmac_sha1_cbc_aes_128;
  105. struct qce_cmdlist_info aead_hmac_sha1_cbc_aes_256;
  106. struct qce_cmdlist_info aead_hmac_sha1_cbc_des;
  107. struct qce_cmdlist_info aead_hmac_sha1_cbc_3des;
  108. struct qce_cmdlist_info aead_hmac_sha256_cbc_aes_128;
  109. struct qce_cmdlist_info aead_hmac_sha256_cbc_aes_256;
  110. struct qce_cmdlist_info aead_hmac_sha256_cbc_des;
  111. struct qce_cmdlist_info aead_hmac_sha256_cbc_3des;
  112. struct qce_cmdlist_info aead_aes_128_ccm;
  113. struct qce_cmdlist_info aead_aes_256_ccm;
  114. struct qce_cmdlist_info cipher_null;
  115. struct qce_cmdlist_info f8_kasumi;
  116. struct qce_cmdlist_info f8_snow3g;
  117. struct qce_cmdlist_info f9_kasumi;
  118. struct qce_cmdlist_info f9_snow3g;
  119. struct qce_cmdlist_info unlock_all_pipes;
  120. };
  121. struct qce_ce_cfg_reg_setting {
  122. uint32_t crypto_cfg_be;
  123. uint32_t crypto_cfg_le;
  124. uint32_t encr_cfg_aes_cbc_128;
  125. uint32_t encr_cfg_aes_cbc_256;
  126. uint32_t encr_cfg_aes_ecb_128;
  127. uint32_t encr_cfg_aes_ecb_256;
  128. uint32_t encr_cfg_aes_xts_128;
  129. uint32_t encr_cfg_aes_xts_256;
  130. uint32_t encr_cfg_aes_ctr_128;
  131. uint32_t encr_cfg_aes_ctr_256;
  132. uint32_t encr_cfg_aes_ccm_128;
  133. uint32_t encr_cfg_aes_ccm_256;
  134. uint32_t encr_cfg_des_cbc;
  135. uint32_t encr_cfg_des_ecb;
  136. uint32_t encr_cfg_3des_cbc;
  137. uint32_t encr_cfg_3des_ecb;
  138. uint32_t encr_cfg_kasumi;
  139. uint32_t encr_cfg_snow3g;
  140. uint32_t auth_cfg_cmac_128;
  141. uint32_t auth_cfg_cmac_256;
  142. uint32_t auth_cfg_sha1;
  143. uint32_t auth_cfg_sha256;
  144. uint32_t auth_cfg_hmac_sha1;
  145. uint32_t auth_cfg_hmac_sha256;
  146. uint32_t auth_cfg_aes_ccm_128;
  147. uint32_t auth_cfg_aes_ccm_256;
  148. uint32_t auth_cfg_aead_sha1_hmac;
  149. uint32_t auth_cfg_aead_sha256_hmac;
  150. uint32_t auth_cfg_kasumi;
  151. uint32_t auth_cfg_snow3g;
  152. /* iv0 - bits 127:96 - CRYPTO_CNTR_MASK_REG0*/
  153. uint32_t encr_cntr_mask_0;
  154. /* iv1 - bits 95:64 - CRYPTO_CNTR_MASK_REG1*/
  155. uint32_t encr_cntr_mask_1;
  156. /* iv2 - bits 63:32 - CRYPTO_CNTR_MASK_REG2*/
  157. uint32_t encr_cntr_mask_2;
  158. /* iv3 - bits 31:0 - CRYPTO_CNTR_MASK_REG*/
  159. uint32_t encr_cntr_mask_3;
  160. };
  161. struct ce_bam_info {
  162. uint32_t bam_irq;
  163. uint32_t bam_mem;
  164. void __iomem *bam_iobase;
  165. uint32_t ce_device;
  166. uint32_t ce_hw_instance;
  167. uint32_t bam_ee;
  168. unsigned int pipe_pair_index[QCE_OFFLOAD_OPER_LAST];
  169. unsigned int src_pipe_index[QCE_OFFLOAD_OPER_LAST];
  170. unsigned int dest_pipe_index[QCE_OFFLOAD_OPER_LAST];
  171. unsigned long bam_handle;
  172. int ce_burst_size;
  173. uint32_t minor_version;
  174. uint32_t major_version;
  175. struct qce_sps_ep_conn_data producer[QCE_OFFLOAD_OPER_LAST];
  176. struct qce_sps_ep_conn_data consumer[QCE_OFFLOAD_OPER_LAST];
  177. };
  178. /* SPS data structure with buffers, commandlists & commmand pointer lists */
  179. struct ce_sps_data {
  180. enum qce_pipe_st_enum producer_state; /* Producer pipe state */
  181. int consumer_status; /* consumer pipe status */
  182. int producer_status; /* producer pipe status */
  183. struct sps_transfer in_transfer;
  184. struct sps_transfer out_transfer;
  185. struct qce_cmdlistptr_ops cmdlistptr;
  186. uint32_t result_dump; /* reuslt dump virtual address */
  187. uint32_t result_dump_null;
  188. uint32_t result_dump_phy; /* result dump physical address (32 bits) */
  189. uint32_t result_dump_null_phy;
  190. uint32_t ignore_buffer; /* ignore buffer virtual address */
  191. struct ce_result_dump_format *result; /* ponter to result dump */
  192. struct ce_result_dump_format *result_null;
  193. };
  194. struct ce_request_info {
  195. atomic_t in_use;
  196. bool in_prog;
  197. enum qce_xfer_type_enum xfer_type;
  198. struct ce_sps_data ce_sps;
  199. qce_comp_func_ptr_t qce_cb; /* qce callback function pointer */
  200. void *user;
  201. void *areq;
  202. int assoc_nents;
  203. struct scatterlist *asg; /* Formatted associated data sg */
  204. int src_nents;
  205. int dst_nents;
  206. dma_addr_t phy_iv_in;
  207. unsigned char dec_iv[16];
  208. int dir;
  209. enum qce_cipher_mode_enum mode;
  210. dma_addr_t phy_ota_src;
  211. dma_addr_t phy_ota_dst;
  212. unsigned int ota_size;
  213. unsigned int req_len;
  214. unsigned int offload_op;
  215. };
  216. struct qce_driver_stats {
  217. int no_of_timeouts;
  218. int no_of_dummy_reqs;
  219. int current_mode;
  220. int outstanding_reqs;
  221. };
  222. #endif /* _DRIVERS_CRYPTO_MSM_QCE50_H */