qce50.h 7.2 KB

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