Revert "unicode: Don't special case ignorable code points"
[linux.git] / drivers / crypto / caam / intern.h
blobe513201508720944861e31a6740a256f86f5f831
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * CAAM/SEC 4.x driver backend
4 * Private/internal definitions between modules
6 * Copyright 2008-2011 Freescale Semiconductor, Inc.
7 * Copyright 2019, 2023 NXP
8 */
10 #ifndef INTERN_H
11 #define INTERN_H
13 #include "ctrl.h"
14 #include <crypto/engine.h>
16 /* Currently comes from Kconfig param as a ^2 (driver-required) */
17 #define JOBR_DEPTH (1 << CONFIG_CRYPTO_DEV_FSL_CAAM_RINGSIZE)
20 * Maximum size for crypto-engine software queue based on Job Ring
21 * size (JOBR_DEPTH) and a THRESHOLD (reserved for the non-crypto-API
22 * requests that are not passed through crypto-engine)
24 #define THRESHOLD 15
25 #define CRYPTO_ENGINE_MAX_QLEN (JOBR_DEPTH - THRESHOLD)
27 /* Kconfig params for interrupt coalescing if selected (else zero) */
28 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_INTC
29 #define JOBR_INTC JRCFG_ICEN
30 #define JOBR_INTC_TIME_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_TIME_THLD
31 #define JOBR_INTC_COUNT_THLD CONFIG_CRYPTO_DEV_FSL_CAAM_INTC_COUNT_THLD
32 #else
33 #define JOBR_INTC 0
34 #define JOBR_INTC_TIME_THLD 0
35 #define JOBR_INTC_COUNT_THLD 0
36 #endif
39 * Storage for tracking each in-process entry moving across a ring
40 * Each entry on an output ring needs one of these
42 struct caam_jrentry_info {
43 void (*callbk)(struct device *dev, u32 *desc, u32 status, void *arg);
44 void *cbkarg; /* Argument per ring entry */
45 u32 *desc_addr_virt; /* Stored virt addr for postprocessing */
46 dma_addr_t desc_addr_dma; /* Stored bus addr for done matching */
47 u32 desc_size; /* Stored size for postprocessing, header derived */
50 struct caam_jr_state {
51 dma_addr_t inpbusaddr;
52 dma_addr_t outbusaddr;
55 struct caam_jr_dequeue_params {
56 struct device *dev;
57 int enable_itr;
60 /* Private sub-storage for a single JobR */
61 struct caam_drv_private_jr {
62 struct list_head list_node; /* Job Ring device list */
63 struct device *dev;
64 int ridx;
65 struct caam_job_ring __iomem *rregs; /* JobR's register space */
66 struct tasklet_struct irqtask;
67 struct caam_jr_dequeue_params tasklet_params;
68 int irq; /* One per queue */
69 bool hwrng;
71 /* Number of scatterlist crypt transforms active on the JobR */
72 atomic_t tfm_count ____cacheline_aligned;
74 /* Job ring info */
75 struct caam_jrentry_info *entinfo; /* Alloc'ed 1 per ring entry */
76 spinlock_t inplock ____cacheline_aligned; /* Input ring index lock */
77 u32 inpring_avail; /* Number of free entries in input ring */
78 int head; /* entinfo (s/w ring) head index */
79 void *inpring; /* Base of input ring, alloc
80 * DMA-safe */
81 int out_ring_read_index; /* Output index "tail" */
82 int tail; /* entinfo (s/w ring) tail index */
83 void *outring; /* Base of output ring, DMA-safe */
84 struct crypto_engine *engine;
86 struct caam_jr_state state; /* State of the JR during PM */
89 struct caam_ctl_state {
90 struct masterid deco_mid[16];
91 struct masterid jr_mid[4];
92 u32 mcr;
93 u32 scfgr;
97 * Driver-private storage for a single CAAM block instance
99 struct caam_drv_private {
100 /* Physical-presence section */
101 struct caam_ctrl __iomem *ctrl; /* controller region */
102 struct caam_deco __iomem *deco; /* DECO/CCB views */
103 struct caam_assurance __iomem *assure;
104 struct caam_queue_if __iomem *qi; /* QI control region */
105 struct caam_job_ring __iomem *jr[4]; /* JobR's register space */
107 struct iommu_domain *domain;
110 * Detected geometry block. Filled in from device tree if powerpc,
111 * or from register-based version detection code
113 u8 total_jobrs; /* Total Job Rings in device */
114 u8 qi_present; /* Nonzero if QI present in device */
115 u8 blob_present; /* Nonzero if BLOB support present in device */
116 u8 mc_en; /* Nonzero if MC f/w is active */
117 u8 optee_en; /* Nonzero if OP-TEE f/w is active */
118 bool pr_support; /* RNG prediction resistance available */
119 int secvio_irq; /* Security violation interrupt number */
120 int virt_en; /* Virtualization enabled in CAAM */
121 int era; /* CAAM Era (internal HW revision) */
123 #define RNG4_MAX_HANDLES 2
124 /* RNG4 block */
125 u32 rng4_sh_init; /* This bitmap shows which of the State
126 Handles of the RNG4 block are initialized
127 by this driver */
129 struct clk_bulk_data *clks;
130 int num_clks;
132 * debugfs entries for developer view into driver/device
133 * variables at runtime.
135 #ifdef CONFIG_DEBUG_FS
136 struct dentry *ctl; /* controller dir */
137 struct debugfs_blob_wrapper ctl_kek_wrap, ctl_tkek_wrap, ctl_tdsk_wrap;
138 #endif
140 int caam_off_during_pm; /* If the CAAM is reset after suspend */
141 struct caam_ctl_state state; /* State of the CTL during PM */
144 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API
146 int caam_algapi_init(struct device *dev);
147 void caam_algapi_exit(void);
149 #else
151 static inline int caam_algapi_init(struct device *dev)
153 return 0;
156 static inline void caam_algapi_exit(void)
160 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API */
162 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API
164 int caam_algapi_hash_init(struct device *dev);
165 void caam_algapi_hash_exit(void);
167 #else
169 static inline int caam_algapi_hash_init(struct device *dev)
171 return 0;
174 static inline void caam_algapi_hash_exit(void)
178 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API */
180 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API
182 int caam_pkc_init(struct device *dev);
183 void caam_pkc_exit(void);
185 #else
187 static inline int caam_pkc_init(struct device *dev)
189 return 0;
192 static inline void caam_pkc_exit(void)
196 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API */
198 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API
200 int caam_rng_init(struct device *dev);
201 void caam_rng_exit(struct device *dev);
203 #else
205 static inline int caam_rng_init(struct device *dev)
207 return 0;
210 static inline void caam_rng_exit(struct device *dev) {}
212 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API */
214 #ifdef CONFIG_CRYPTO_DEV_FSL_CAAM_PRNG_API
216 int caam_prng_register(struct device *dev);
217 void caam_prng_unregister(void *data);
219 #else
221 static inline int caam_prng_register(struct device *dev)
223 return 0;
226 static inline void caam_prng_unregister(void *data) {}
227 #endif /* CONFIG_CRYPTO_DEV_FSL_CAAM_PRNG_API */
229 #ifdef CONFIG_CAAM_QI
231 int caam_qi_algapi_init(struct device *dev);
232 void caam_qi_algapi_exit(void);
234 #else
236 static inline int caam_qi_algapi_init(struct device *dev)
238 return 0;
241 static inline void caam_qi_algapi_exit(void)
245 #endif /* CONFIG_CAAM_QI */
247 static inline u64 caam_get_dma_mask(struct device *dev)
249 struct device_node *nprop = dev->of_node;
251 if (caam_ptr_sz != sizeof(u64))
252 return DMA_BIT_MASK(32);
254 if (caam_dpaa2)
255 return DMA_BIT_MASK(49);
257 if (of_device_is_compatible(nprop, "fsl,sec-v5.0-job-ring") ||
258 of_device_is_compatible(nprop, "fsl,sec-v5.0"))
259 return DMA_BIT_MASK(40);
261 return DMA_BIT_MASK(36);
265 #endif /* INTERN_H */