intern.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * CAAM/SEC 4.x driver backend
  4. * Private/internal definitions between modules
  5. *
  6. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  7. * Copyright 2019 NXP
  8. */
  9. #ifndef INTERN_H
  10. #define INTERN_H
  11. #include "ctrl.h"
  12. /* Currently comes from Kconfig param as a ^2 (driver-required) */
  13. #define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE)
  14. /* Kconfig params for interrupt coalescing if selected (else zero) */
  15. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_INTC
  16. #define JOBR_INTC JRCFG_ICEN
  17. #define JOBR_INTC_TIME_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD
  18. #define JOBR_INTC_COUNT_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_COUNT_THLD
  19. #else
  20. #define JOBR_INTC 0
  21. #define JOBR_INTC_TIME_THLD 0
  22. #define JOBR_INTC_COUNT_THLD 0
  23. #endif
  24. /*
  25. * Storage for tracking each in-process entry moving across a ring
  26. * Each entry on an output ring needs one of these
  27. */
  28. struct caam_jrentry_info {
  29. void (*callbk)(struct device *dev, u32 *desc, u32 status, void *arg);
  30. void *cbkarg; /* Argument per ring entry */
  31. u32 *desc_addr_virt; /* Stored virt addr for postprocessing */
  32. dma_addr_t desc_addr_dma; /* Stored bus addr for done matching */
  33. u32 desc_size; /* Stored size for postprocessing, header derived */
  34. };
  35. /* Private sub-storage for a single JobR */
  36. struct caam_drv_private_jr {
  37. struct list_head list_node; /* Job Ring device list */
  38. struct device *dev;
  39. int ridx;
  40. struct caam_job_ring __iomem *rregs; /* JobR's register space */
  41. struct tasklet_struct irqtask;
  42. int irq; /* One per queue */
  43. /* Number of scatterlist crypt transforms active on the JobR */
  44. atomic_t tfm_count ____cacheline_aligned;
  45. /* Job ring info */
  46. struct caam_jrentry_info *entinfo; /* Alloc'ed 1 per ring entry */
  47. spinlock_t inplock ____cacheline_aligned; /* Input ring index lock */
  48. u32 inpring_avail; /* Number of free entries in input ring */
  49. int head; /* entinfo (s/w ring) head index */
  50. void *inpring; /* Base of input ring, alloc
  51. * DMA-safe */
  52. int out_ring_read_index; /* Output index "tail" */
  53. int tail; /* entinfo (s/w ring) tail index */
  54. void *outring; /* Base of output ring, DMA-safe */
  55. };
  56. /*
  57. * Driver-private storage for a single CAAM block instance
  58. */
  59. struct caam_drv_private {
  60. /* Physical-presence section */
  61. struct caam_ctrl __iomem *ctrl; /* controller region */
  62. struct caam_deco __iomem *deco; /* DECO/CCB views */
  63. struct caam_assurance __iomem *assure;
  64. struct caam_queue_if __iomem *qi; /* QI control region */
  65. struct caam_job_ring __iomem *jr[4]; /* JobR's register space */
  66. struct iommu_domain *domain;
  67. /*
  68. * Detected geometry block. Filled in from device tree if powerpc,
  69. * or from register-based version detection code
  70. */
  71. u8 total_jobrs; /* Total Job Rings in device */
  72. u8 qi_present; /* Nonzero if QI present in device */
  73. #ifdef CONFIG_CAAM_QI
  74. u8 qi_init; /* Nonzero if QI has been initialized */
  75. #endif
  76. u8 mc_en; /* Nonzero if MC f/w is active */
  77. int secvio_irq; /* Security violation interrupt number */
  78. int virt_en; /* Virtualization enabled in CAAM */
  79. int era; /* CAAM Era (internal HW revision) */
  80. #define RNG4_MAX_HANDLES 2
  81. /* RNG4 block */
  82. u32 rng4_sh_init; /* This bitmap shows which of the State
  83. Handles of the RNG4 block are initialized
  84. by this driver */
  85. struct clk_bulk_data *clks;
  86. int num_clks;
  87. /*
  88. * debugfs entries for developer view into driver/device
  89. * variables at runtime.
  90. */
  91. #ifdef CONFIG_DEBUG_FS
  92. struct dentry *dfs_root;
  93. struct dentry *ctl; /* controller dir */
  94. struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;
  95. #endif
  96. };
  97. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API
  98. int caam_algapi_init(struct device *dev);
  99. void caam_algapi_exit(void);
  100. #else
  101. static inline int caam_algapi_init(struct device *dev)
  102. {
  103. return 0;
  104. }
  105. static inline void caam_algapi_exit(void)
  106. {
  107. }
  108. #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API */
  109. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API
  110. int caam_algapi_hash_init(struct device *dev);
  111. void caam_algapi_hash_exit(void);
  112. #else
  113. static inline int caam_algapi_hash_init(struct device *dev)
  114. {
  115. return 0;
  116. }
  117. static inline void caam_algapi_hash_exit(void)
  118. {
  119. }
  120. #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */
  121. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API
  122. int caam_pkc_init(struct device *dev);
  123. void caam_pkc_exit(void);
  124. #else
  125. static inline int caam_pkc_init(struct device *dev)
  126. {
  127. return 0;
  128. }
  129. static inline void caam_pkc_exit(void)
  130. {
  131. }
  132. #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */
  133. #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API
  134. int caam_rng_init(struct device *dev);
  135. void caam_rng_exit(void);
  136. #else
  137. static inline int caam_rng_init(struct device *dev)
  138. {
  139. return 0;
  140. }
  141. static inline void caam_rng_exit(void)
  142. {
  143. }
  144. #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API */
  145. #ifdef CONFIG_CAAM_QI
  146. int caam_qi_algapi_init(struct device *dev);
  147. void caam_qi_algapi_exit(void);
  148. #else
  149. static inline int caam_qi_algapi_init(struct device *dev)
  150. {
  151. return 0;
  152. }
  153. static inline void caam_qi_algapi_exit(void)
  154. {
  155. }
  156. #endif /* CONFIG_CAAM_QI */
  157. #ifdef CONFIG_DEBUG_FS
  158. static int caam_debugfs_u64_get(void *data, u64 *val)
  159. {
  160. *val = caam64_to_cpu(*(u64 *)data);
  161. return 0;
  162. }
  163. static int caam_debugfs_u32_get(void *data, u64 *val)
  164. {
  165. *val = caam32_to_cpu(*(u32 *)data);
  166. return 0;
  167. }
  168. DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u32_ro, caam_debugfs_u32_get, NULL, "%llu\n");
  169. DEFINE_SIMPLE_ATTRIBUTE(caam_fops_u64_ro, caam_debugfs_u64_get, NULL, "%llu\n");
  170. #endif
  171. static inline u64 caam_get_dma_mask(struct device *dev)
  172. {
  173. struct device_node *nprop = dev->of_node;
  174. if (caam_ptr_sz != sizeof(u64))
  175. return DMA_BIT_MASK(32);
  176. if (caam_dpaa2)
  177. return DMA_BIT_MASK(49);
  178. if (of_device_is_compatible(nprop, "fsl,sec-v5.0-job-ring") ||
  179. of_device_is_compatible(nprop, "fsl,sec-v5.0"))
  180. return DMA_BIT_MASK(40);
  181. return DMA_BIT_MASK(36);
  182. }
  183. #endif /* INTERN_H */