cc_driver.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
  3. /* \file cc_driver.h
  4. * ARM CryptoCell Linux Crypto Driver
  5. */
  6. #ifndef __CC_DRIVER_H__
  7. #define __CC_DRIVER_H__
  8. #ifdef COMP_IN_WQ
  9. #include <linux/workqueue.h>
  10. #else
  11. #include <linux/interrupt.h>
  12. #endif
  13. #include <linux/dma-mapping.h>
  14. #include <crypto/algapi.h>
  15. #include <crypto/internal/skcipher.h>
  16. #include <crypto/aes.h>
  17. #include <crypto/sha1.h>
  18. #include <crypto/sha2.h>
  19. #include <crypto/aead.h>
  20. #include <crypto/authenc.h>
  21. #include <crypto/hash.h>
  22. #include <crypto/skcipher.h>
  23. #include <linux/clk.h>
  24. #include <linux/platform_device.h>
  25. #include "cc_host_regs.h"
  26. #include "cc_crypto_ctx.h"
  27. #include "cc_hw_queue_defs.h"
  28. #include "cc_sram_mgr.h"
  29. extern bool cc_dump_desc;
  30. extern bool cc_dump_bytes;
  31. #define DRV_MODULE_VERSION "5.0"
  32. enum cc_hw_rev {
  33. CC_HW_REV_630 = 630,
  34. CC_HW_REV_710 = 710,
  35. CC_HW_REV_712 = 712,
  36. CC_HW_REV_713 = 713
  37. };
  38. enum cc_std_body {
  39. CC_STD_NIST = 0x1,
  40. CC_STD_OSCCA = 0x2,
  41. CC_STD_ALL = 0x3
  42. };
  43. #define CC_PINS_FULL 0x0
  44. #define CC_PINS_SLIM 0x9F
  45. /* Maximum DMA mask supported by IP */
  46. #define DMA_BIT_MASK_LEN 48
  47. #define CC_AXI_IRQ_MASK ((1 << CC_AXIM_CFG_BRESPMASK_BIT_SHIFT) | \
  48. (1 << CC_AXIM_CFG_RRESPMASK_BIT_SHIFT) | \
  49. (1 << CC_AXIM_CFG_INFLTMASK_BIT_SHIFT) | \
  50. (1 << CC_AXIM_CFG_COMPMASK_BIT_SHIFT))
  51. #define CC_AXI_ERR_IRQ_MASK BIT(CC_HOST_IRR_AXI_ERR_INT_BIT_SHIFT)
  52. #define CC_COMP_IRQ_MASK BIT(CC_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT)
  53. #define CC_SECURITY_DISABLED_MASK BIT(CC_SECURITY_DISABLED_VALUE_BIT_SHIFT)
  54. #define CC_NVM_IS_IDLE_MASK BIT(CC_NVM_IS_IDLE_VALUE_BIT_SHIFT)
  55. #define AXIM_MON_COMP_VALUE CC_GENMASK(CC_AXIM_MON_COMP_VALUE)
  56. #define CC_CPP_AES_ABORT_MASK ( \
  57. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_0_MASK_BIT_SHIFT) | \
  58. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_1_MASK_BIT_SHIFT) | \
  59. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_2_MASK_BIT_SHIFT) | \
  60. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_3_MASK_BIT_SHIFT) | \
  61. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_4_MASK_BIT_SHIFT) | \
  62. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_5_MASK_BIT_SHIFT) | \
  63. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_6_MASK_BIT_SHIFT) | \
  64. BIT(CC_HOST_IMR_REE_OP_ABORTED_AES_7_MASK_BIT_SHIFT))
  65. #define CC_CPP_SM4_ABORT_MASK ( \
  66. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_0_MASK_BIT_SHIFT) | \
  67. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_1_MASK_BIT_SHIFT) | \
  68. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_2_MASK_BIT_SHIFT) | \
  69. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_3_MASK_BIT_SHIFT) | \
  70. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_4_MASK_BIT_SHIFT) | \
  71. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_5_MASK_BIT_SHIFT) | \
  72. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_6_MASK_BIT_SHIFT) | \
  73. BIT(CC_HOST_IMR_REE_OP_ABORTED_SM_7_MASK_BIT_SHIFT))
  74. /* Register name mangling macro */
  75. #define CC_REG(reg_name) CC_ ## reg_name ## _REG_OFFSET
  76. /* TEE FIPS status interrupt */
  77. #define CC_GPR0_IRQ_MASK BIT(CC_HOST_IRR_GPR0_BIT_SHIFT)
  78. #define CC_CRA_PRIO 400
  79. #define MIN_HW_QUEUE_SIZE 50 /* Minimum size required for proper function */
  80. #define MAX_REQUEST_QUEUE_SIZE 4096
  81. #define MAX_MLLI_BUFF_SIZE 2080
  82. /* Definitions for HW descriptors DIN/DOUT fields */
  83. #define NS_BIT 1
  84. #define AXI_ID 0
  85. /* AXI_ID is not actually the AXI ID of the transaction but the value of AXI_ID
  86. * field in the HW descriptor. The DMA engine +8 that value.
  87. */
  88. struct cc_cpp_req {
  89. bool is_cpp;
  90. enum cc_cpp_alg alg;
  91. u8 slot;
  92. };
  93. #define CC_MAX_IVGEN_DMA_ADDRESSES 3
  94. struct cc_crypto_req {
  95. void (*user_cb)(struct device *dev, void *req, int err);
  96. void *user_arg;
  97. struct completion seq_compl; /* request completion */
  98. struct cc_cpp_req cpp;
  99. };
  100. /**
  101. * struct cc_drvdata - driver private data context
  102. * @cc_base: virt address of the CC registers
  103. * @irq: bitmap indicating source of last interrupt
  104. */
  105. struct cc_drvdata {
  106. void __iomem *cc_base;
  107. int irq;
  108. struct completion hw_queue_avail; /* wait for HW queue availability */
  109. struct platform_device *plat_dev;
  110. u32 mlli_sram_addr;
  111. struct dma_pool *mlli_buffs_pool;
  112. struct list_head alg_list;
  113. void *hash_handle;
  114. void *aead_handle;
  115. void *request_mgr_handle;
  116. void *fips_handle;
  117. u32 sram_free_offset; /* offset to non-allocated area in SRAM */
  118. struct dentry *dir; /* for debugfs */
  119. struct clk *clk;
  120. bool coherent;
  121. char *hw_rev_name;
  122. enum cc_hw_rev hw_rev;
  123. u32 axim_mon_offset;
  124. u32 sig_offset;
  125. u32 ver_offset;
  126. int std_bodies;
  127. bool sec_disabled;
  128. u32 comp_mask;
  129. u32 cache_params;
  130. u32 ace_const;
  131. };
  132. struct cc_crypto_alg {
  133. struct list_head entry;
  134. int cipher_mode;
  135. int flow_mode; /* Note: currently, refers to the cipher mode only. */
  136. int auth_mode;
  137. struct cc_drvdata *drvdata;
  138. struct skcipher_alg skcipher_alg;
  139. struct aead_alg aead_alg;
  140. };
  141. struct cc_alg_template {
  142. char name[CRYPTO_MAX_ALG_NAME];
  143. char driver_name[CRYPTO_MAX_ALG_NAME];
  144. unsigned int blocksize;
  145. union {
  146. struct skcipher_alg skcipher;
  147. struct aead_alg aead;
  148. } template_u;
  149. int cipher_mode;
  150. int flow_mode; /* Note: currently, refers to the cipher mode only. */
  151. int auth_mode;
  152. u32 min_hw_rev;
  153. enum cc_std_body std_body;
  154. bool sec_func;
  155. unsigned int data_unit;
  156. struct cc_drvdata *drvdata;
  157. };
  158. struct async_gen_req_ctx {
  159. dma_addr_t iv_dma_addr;
  160. u8 *iv;
  161. enum drv_crypto_direction op_type;
  162. };
  163. static inline struct device *drvdata_to_dev(struct cc_drvdata *drvdata)
  164. {
  165. return &drvdata->plat_dev->dev;
  166. }
  167. void __dump_byte_array(const char *name, const u8 *buf, size_t len);
  168. static inline void dump_byte_array(const char *name, const u8 *the_array,
  169. size_t size)
  170. {
  171. if (cc_dump_bytes)
  172. __dump_byte_array(name, the_array, size);
  173. }
  174. bool cc_wait_for_reset_completion(struct cc_drvdata *drvdata);
  175. int init_cc_regs(struct cc_drvdata *drvdata);
  176. void fini_cc_regs(struct cc_drvdata *drvdata);
  177. unsigned int cc_get_default_hash_len(struct cc_drvdata *drvdata);
  178. static inline void cc_iowrite(struct cc_drvdata *drvdata, u32 reg, u32 val)
  179. {
  180. iowrite32(val, (drvdata->cc_base + reg));
  181. }
  182. static inline u32 cc_ioread(struct cc_drvdata *drvdata, u32 reg)
  183. {
  184. return ioread32(drvdata->cc_base + reg);
  185. }
  186. static inline gfp_t cc_gfp_flags(struct crypto_async_request *req)
  187. {
  188. return (req->flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
  189. GFP_KERNEL : GFP_ATOMIC;
  190. }
  191. static inline void set_queue_last_ind(struct cc_drvdata *drvdata,
  192. struct cc_hw_desc *pdesc)
  193. {
  194. if (drvdata->hw_rev >= CC_HW_REV_712)
  195. set_queue_last_ind_bit(pdesc);
  196. }
  197. #endif /*__CC_DRIVER_H__*/