cc_driver.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2012-2018 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/sha.h>
  18. #include <crypto/aead.h>
  19. #include <crypto/authenc.h>
  20. #include <crypto/hash.h>
  21. #include <crypto/skcipher.h>
  22. #include <linux/version.h>
  23. #include <linux/clk.h>
  24. #include <linux/platform_device.h>
  25. /* Registers definitions from shared/hw/ree_include */
  26. #include "cc_host_regs.h"
  27. #define CC_DEV_SHA_MAX 512
  28. #include "cc_crypto_ctx.h"
  29. #include "cc_hw_queue_defs.h"
  30. #include "cc_sram_mgr.h"
  31. extern bool cc_dump_desc;
  32. extern bool cc_dump_bytes;
  33. #define DRV_MODULE_VERSION "4.0"
  34. enum cc_hw_rev {
  35. CC_HW_REV_630 = 630,
  36. CC_HW_REV_710 = 710,
  37. CC_HW_REV_712 = 712
  38. };
  39. #define CC_COHERENT_CACHE_PARAMS 0xEEE
  40. /* Maximum DMA mask supported by IP */
  41. #define DMA_BIT_MASK_LEN 48
  42. #define CC_AXI_IRQ_MASK ((1 << CC_AXIM_CFG_BRESPMASK_BIT_SHIFT) | \
  43. (1 << CC_AXIM_CFG_RRESPMASK_BIT_SHIFT) | \
  44. (1 << CC_AXIM_CFG_INFLTMASK_BIT_SHIFT) | \
  45. (1 << CC_AXIM_CFG_COMPMASK_BIT_SHIFT))
  46. #define CC_AXI_ERR_IRQ_MASK BIT(CC_HOST_IRR_AXI_ERR_INT_BIT_SHIFT)
  47. #define CC_COMP_IRQ_MASK BIT(CC_HOST_IRR_AXIM_COMP_INT_BIT_SHIFT)
  48. #define AXIM_MON_COMP_VALUE GENMASK(CC_AXIM_MON_COMP_VALUE_BIT_SIZE + \
  49. CC_AXIM_MON_COMP_VALUE_BIT_SHIFT, \
  50. CC_AXIM_MON_COMP_VALUE_BIT_SHIFT)
  51. /* Register name mangling macro */
  52. #define CC_REG(reg_name) CC_ ## reg_name ## _REG_OFFSET
  53. /* TEE FIPS status interrupt */
  54. #define CC_GPR0_IRQ_MASK BIT(CC_HOST_IRR_GPR0_BIT_SHIFT)
  55. #define CC_CRA_PRIO 400
  56. #define MIN_HW_QUEUE_SIZE 50 /* Minimum size required for proper function */
  57. #define MAX_REQUEST_QUEUE_SIZE 4096
  58. #define MAX_MLLI_BUFF_SIZE 2080
  59. #define MAX_ICV_NENTS_SUPPORTED 2
  60. /* Definitions for HW descriptors DIN/DOUT fields */
  61. #define NS_BIT 1
  62. #define AXI_ID 0
  63. /* AXI_ID is not actually the AXI ID of the transaction but the value of AXI_ID
  64. * field in the HW descriptor. The DMA engine +8 that value.
  65. */
  66. #define CC_MAX_IVGEN_DMA_ADDRESSES 3
  67. struct cc_crypto_req {
  68. void (*user_cb)(struct device *dev, void *req, int err);
  69. void *user_arg;
  70. dma_addr_t ivgen_dma_addr[CC_MAX_IVGEN_DMA_ADDRESSES];
  71. /* For the first 'ivgen_dma_addr_len' addresses of this array,
  72. * generated IV would be placed in it by send_request().
  73. * Same generated IV for all addresses!
  74. */
  75. /* Amount of 'ivgen_dma_addr' elements to be filled. */
  76. unsigned int ivgen_dma_addr_len;
  77. /* The generated IV size required, 8/16 B allowed. */
  78. unsigned int ivgen_size;
  79. struct completion seq_compl; /* request completion */
  80. };
  81. /**
  82. * struct cc_drvdata - driver private data context
  83. * @cc_base: virt address of the CC registers
  84. * @irq: device IRQ number
  85. * @irq_mask: Interrupt mask shadow (1 for masked interrupts)
  86. * @fw_ver: SeP loaded firmware version
  87. */
  88. struct cc_drvdata {
  89. void __iomem *cc_base;
  90. int irq;
  91. u32 irq_mask;
  92. u32 fw_ver;
  93. struct completion hw_queue_avail; /* wait for HW queue availability */
  94. struct platform_device *plat_dev;
  95. cc_sram_addr_t mlli_sram_addr;
  96. void *buff_mgr_handle;
  97. void *cipher_handle;
  98. void *hash_handle;
  99. void *aead_handle;
  100. void *request_mgr_handle;
  101. void *fips_handle;
  102. void *ivgen_handle;
  103. void *sram_mgr_handle;
  104. void *debugfs;
  105. struct clk *clk;
  106. bool coherent;
  107. char *hw_rev_name;
  108. enum cc_hw_rev hw_rev;
  109. u32 hash_len_sz;
  110. u32 axim_mon_offset;
  111. u32 sig_offset;
  112. u32 ver_offset;
  113. bool pm_on;
  114. };
  115. struct cc_crypto_alg {
  116. struct list_head entry;
  117. int cipher_mode;
  118. int flow_mode; /* Note: currently, refers to the cipher mode only. */
  119. int auth_mode;
  120. unsigned int data_unit;
  121. struct cc_drvdata *drvdata;
  122. struct skcipher_alg skcipher_alg;
  123. struct aead_alg aead_alg;
  124. };
  125. struct cc_alg_template {
  126. char name[CRYPTO_MAX_ALG_NAME];
  127. char driver_name[CRYPTO_MAX_ALG_NAME];
  128. unsigned int blocksize;
  129. union {
  130. struct skcipher_alg skcipher;
  131. struct aead_alg aead;
  132. } template_u;
  133. int cipher_mode;
  134. int flow_mode; /* Note: currently, refers to the cipher mode only. */
  135. int auth_mode;
  136. u32 min_hw_rev;
  137. unsigned int data_unit;
  138. struct cc_drvdata *drvdata;
  139. };
  140. struct async_gen_req_ctx {
  141. dma_addr_t iv_dma_addr;
  142. u8 *iv;
  143. enum drv_crypto_direction op_type;
  144. };
  145. static inline struct device *drvdata_to_dev(struct cc_drvdata *drvdata)
  146. {
  147. return &drvdata->plat_dev->dev;
  148. }
  149. void __dump_byte_array(const char *name, const u8 *buf, size_t len);
  150. static inline void dump_byte_array(const char *name, const u8 *the_array,
  151. size_t size)
  152. {
  153. if (cc_dump_bytes)
  154. __dump_byte_array(name, the_array, size);
  155. }
  156. int init_cc_regs(struct cc_drvdata *drvdata, bool is_probe);
  157. void fini_cc_regs(struct cc_drvdata *drvdata);
  158. int cc_clk_on(struct cc_drvdata *drvdata);
  159. void cc_clk_off(struct cc_drvdata *drvdata);
  160. static inline void cc_iowrite(struct cc_drvdata *drvdata, u32 reg, u32 val)
  161. {
  162. iowrite32(val, (drvdata->cc_base + reg));
  163. }
  164. static inline u32 cc_ioread(struct cc_drvdata *drvdata, u32 reg)
  165. {
  166. return ioread32(drvdata->cc_base + reg);
  167. }
  168. static inline gfp_t cc_gfp_flags(struct crypto_async_request *req)
  169. {
  170. return (req->flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
  171. GFP_KERNEL : GFP_ATOMIC;
  172. }
  173. static inline void set_queue_last_ind(struct cc_drvdata *drvdata,
  174. struct cc_hw_desc *pdesc)
  175. {
  176. if (drvdata->hw_rev >= CC_HW_REV_712)
  177. set_queue_last_ind_bit(pdesc);
  178. }
  179. #endif /*__CC_DRIVER_H__*/