qce.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * QTI Crypto Engine driver API
  4. *
  5. * Copyright (c) 2010-2021, The Linux Foundation. All rights reserved.
  6. */
  7. #ifndef __CRYPTO_MSM_QCE_H
  8. #define __CRYPTO_MSM_QCE_H
  9. #include <linux/types.h>
  10. #include <linux/platform_device.h>
  11. #include <linux/crypto.h>
  12. #include <crypto/skcipher.h>
  13. #include <crypto/algapi.h>
  14. #include <crypto/aes.h>
  15. #include <crypto/des.h>
  16. #include <crypto/sha1.h>
  17. #include <crypto/sha2.h>
  18. #include <crypto/aead.h>
  19. #include <crypto/authenc.h>
  20. #include <crypto/scatterwalk.h>
  21. /* SHA digest size in bytes */
  22. #define SHA256_DIGESTSIZE 32
  23. #define SHA1_DIGESTSIZE 20
  24. #define AES_CE_BLOCK_SIZE 16
  25. /* key size in bytes */
  26. #define HMAC_KEY_SIZE (SHA1_DIGESTSIZE) /* hmac-sha1 */
  27. #define SHA_HMAC_KEY_SIZE 64
  28. #define DES_KEY_SIZE 8
  29. #define TRIPLE_DES_KEY_SIZE 24
  30. #define AES128_KEY_SIZE 16
  31. #define AES192_KEY_SIZE 24
  32. #define AES256_KEY_SIZE 32
  33. #define MAX_CIPHER_KEY_SIZE AES256_KEY_SIZE
  34. /* iv length in bytes */
  35. #define AES_IV_LENGTH 16
  36. #define DES_IV_LENGTH 8
  37. #define MAX_IV_LENGTH AES_IV_LENGTH
  38. /* Maximum number of bytes per transfer */
  39. #define QCE_MAX_OPER_DATA 0xFF00
  40. /* Maximum Nonce bytes */
  41. #define MAX_NONCE 16
  42. /* Crypto clock control flags */
  43. #define QCE_CLK_ENABLE_FIRST 1
  44. #define QCE_BW_REQUEST_FIRST 2
  45. #define QCE_CLK_DISABLE_FIRST 3
  46. #define QCE_BW_REQUEST_RESET_FIRST 4
  47. /* default average and peak bw for crypto device */
  48. #define CRYPTO_AVG_BW 384
  49. #define CRYPTO_PEAK_BW 384
  50. typedef void (*qce_comp_func_ptr_t)(void *areq,
  51. unsigned char *icv, unsigned char *iv, int ret);
  52. /* Cipher algorithms supported */
  53. enum qce_cipher_alg_enum {
  54. CIPHER_ALG_DES = 0,
  55. CIPHER_ALG_3DES = 1,
  56. CIPHER_ALG_AES = 2,
  57. CIPHER_ALG_LAST
  58. };
  59. /* Hash and hmac algorithms supported */
  60. enum qce_hash_alg_enum {
  61. QCE_HASH_SHA1 = 0,
  62. QCE_HASH_SHA256 = 1,
  63. QCE_HASH_SHA1_HMAC = 2,
  64. QCE_HASH_SHA256_HMAC = 3,
  65. QCE_HASH_AES_CMAC = 4,
  66. QCE_HASH_LAST
  67. };
  68. /* Cipher encryption/decryption operations */
  69. enum qce_cipher_dir_enum {
  70. QCE_ENCRYPT = 0,
  71. QCE_DECRYPT = 1,
  72. QCE_CIPHER_DIR_LAST
  73. };
  74. /* Cipher algorithms modes */
  75. enum qce_cipher_mode_enum {
  76. QCE_MODE_CBC = 0,
  77. QCE_MODE_ECB = 1,
  78. QCE_MODE_CTR = 2,
  79. QCE_MODE_XTS = 3,
  80. QCE_MODE_CCM = 4,
  81. QCE_CIPHER_MODE_LAST
  82. };
  83. /* Cipher operation type */
  84. enum qce_req_op_enum {
  85. QCE_REQ_ABLK_CIPHER = 0,
  86. QCE_REQ_ABLK_CIPHER_NO_KEY = 1,
  87. QCE_REQ_AEAD = 2,
  88. QCE_REQ_LAST
  89. };
  90. /* Offload operation type */
  91. enum qce_offload_op_enum {
  92. QCE_OFFLOAD_NONE = 0, /* kernel pipe */
  93. QCE_OFFLOAD_HLOS_HLOS = 1,
  94. QCE_OFFLOAD_HLOS_HLOS_1 = 2,
  95. QCE_OFFLOAD_HLOS_CPB = 3,
  96. QCE_OFFLOAD_HLOS_CPB_1 = 4,
  97. QCE_OFFLOAD_CPB_HLOS = 5,
  98. QCE_OFFLOAD_OPER_LAST
  99. };
  100. /* Algorithms/features supported in CE HW engine */
  101. struct ce_hw_support {
  102. bool sha1_hmac_20; /* Supports 20 bytes of HMAC key*/
  103. bool sha1_hmac; /* supports max HMAC key of 64 bytes*/
  104. bool sha256_hmac; /* supports max HMAC key of 64 bytes*/
  105. bool sha_hmac; /* supports SHA1 and SHA256 MAX HMAC key of 64 bytes*/
  106. bool cmac;
  107. bool aes_key_192;
  108. bool aes_xts;
  109. bool aes_ccm;
  110. bool ota;
  111. bool aligned_only;
  112. bool bam;
  113. bool is_shared;
  114. bool hw_key;
  115. bool use_sw_aes_cbc_ecb_ctr_algo;
  116. bool use_sw_aead_algo;
  117. bool use_sw_aes_xts_algo;
  118. bool use_sw_ahash_algo;
  119. bool use_sw_hmac_algo;
  120. bool use_sw_aes_ccm_algo;
  121. bool clk_mgmt_sus_res;
  122. bool req_bw_before_clk;
  123. unsigned int ce_device;
  124. unsigned int ce_hw_instance;
  125. unsigned int max_request;
  126. };
  127. /* Sha operation parameters */
  128. struct qce_sha_req {
  129. qce_comp_func_ptr_t qce_cb; /* call back */
  130. enum qce_hash_alg_enum alg; /* sha algorithm */
  131. unsigned char *digest; /* sha digest */
  132. struct scatterlist *src; /* pointer to scatter list entry */
  133. uint32_t auth_data[4]; /* byte count */
  134. unsigned char *authkey; /* auth key */
  135. unsigned int authklen; /* auth key length */
  136. bool first_blk; /* first block indicator */
  137. bool last_blk; /* last block indicator */
  138. unsigned int size; /* data length in bytes */
  139. void *areq;
  140. unsigned int flags;
  141. int current_req_info;
  142. };
  143. struct qce_req {
  144. enum qce_req_op_enum op; /* operation type */
  145. qce_comp_func_ptr_t qce_cb; /* call back */
  146. void *areq;
  147. enum qce_cipher_alg_enum alg; /* cipher algorithms*/
  148. enum qce_cipher_dir_enum dir; /* encryption? decryption? */
  149. enum qce_cipher_mode_enum mode; /* algorithm mode */
  150. enum qce_hash_alg_enum auth_alg;/* authentication algorithm for aead */
  151. unsigned char *authkey; /* authentication key */
  152. unsigned int authklen; /* authentication key kength */
  153. unsigned int authsize; /* authentication key kength */
  154. unsigned char nonce[MAX_NONCE];/* nonce for ccm mode */
  155. unsigned char *assoc; /* Ptr to formatted associated data */
  156. unsigned int assoclen; /* Formatted associated data length */
  157. struct scatterlist *asg; /* Formatted associated data sg */
  158. unsigned char *enckey; /* cipher key */
  159. unsigned int encklen; /* cipher key length */
  160. unsigned char *iv; /* initialization vector */
  161. unsigned int ivsize; /* initialization vector size*/
  162. unsigned int iv_ctr_size; /* iv increment counter size*/
  163. unsigned int cryptlen; /* data length */
  164. unsigned int use_pmem; /* is source of data PMEM allocated? */
  165. struct qcedev_pmem_info *pmem; /* pointer to pmem_info structure*/
  166. unsigned int flags;
  167. enum qce_offload_op_enum offload_op; /* Offload usecase */
  168. bool is_pattern_valid; /* Is pattern setting required */
  169. unsigned int pattern_info; /* Pattern info for offload operation */
  170. unsigned int block_offset; /* partial first block for AES CTR */
  171. bool is_copy_op; /* copy buffers without crypto ops */
  172. int current_req_info;
  173. };
  174. struct qce_pm_table {
  175. int (*suspend)(void *handle);
  176. int (*resume)(void *handle);
  177. };
  178. extern struct qce_pm_table qce_pm_table;
  179. struct qce_error {
  180. bool no_error;
  181. bool timer_error;
  182. bool key_paused;
  183. bool generic_error;
  184. };
  185. void *qce_open(struct platform_device *pdev, int *rc);
  186. int qce_close(void *handle);
  187. int qce_aead_req(void *handle, struct qce_req *req);
  188. int qce_ablk_cipher_req(void *handle, struct qce_req *req);
  189. int qce_hw_support(void *handle, struct ce_hw_support *support);
  190. int qce_process_sha_req(void *handle, struct qce_sha_req *s_req);
  191. int qce_enable_clk(void *handle);
  192. int qce_disable_clk(void *handle);
  193. void qce_get_driver_stats(void *handle);
  194. void qce_clear_driver_stats(void *handle);
  195. void qce_dump_req(void *handle);
  196. void qce_get_crypto_status(void *handle, struct qce_error *error);
  197. int qce_manage_timeout(void *handle, int req_info);
  198. int qce_set_irqs(void *handle, bool enable);
  199. #endif /* __CRYPTO_MSM_QCE_H */