1 From 3d21ebe0b870b9b65b3be0c1473e7148256c4d16 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Horia=20Geant=C4=83?= <horia.geanta@nxp.com>
3 Date: Tue, 24 Sep 2019 14:56:48 +0300
4 Subject: [PATCH] MLKU-114-1 crypto: caam - reduce page 0 regs access to
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
12 1. if of_property_read_u32_index(,,index=0,) is to be used,
13 DT bindings (fsl-sec4.txt) should be updated to mandate for
14 -checked that all existing DTs are configured like this
15 -this might create problems in the future, if DTs are needed where
16 JR DT nodes would exist without the controller DT node
17 (directly on simple bus etc.)
20 How to determine caam_ptr_sz if MCFGR is not accesible?
22 Signed-off-by: Horia Geantă <horia.geanta@nxp.com>
24 drivers/crypto/caam/caamalg.c | 21 ++++++------
25 drivers/crypto/caam/caamhash.c | 8 +++--
26 drivers/crypto/caam/caampkc.c | 4 +--
27 drivers/crypto/caam/caamrng.c | 4 +--
28 drivers/crypto/caam/ctrl.c | 78 ++++++++++++++++++++++++++----------------
29 5 files changed, 68 insertions(+), 47 deletions(-)
31 --- a/drivers/crypto/caam/caamalg.c
32 +++ b/drivers/crypto/caam/caamalg.c
33 @@ -3542,13 +3542,14 @@ int caam_algapi_init(struct device *ctrl
34 * First, detect presence and attributes of DES, AES, and MD blocks.
37 + struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon;
38 u32 cha_vid, cha_inst, aes_rn;
40 - cha_vid = rd_reg32(&priv->ctrl->perfmon.cha_id_ls);
41 + cha_vid = rd_reg32(&perfmon->cha_id_ls);
42 aes_vid = cha_vid & CHA_ID_LS_AES_MASK;
43 md_vid = (cha_vid & CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
45 - cha_inst = rd_reg32(&priv->ctrl->perfmon.cha_num_ls);
46 + cha_inst = rd_reg32(&perfmon->cha_num_ls);
47 des_inst = (cha_inst & CHA_ID_LS_DES_MASK) >>
49 aes_inst = cha_inst & CHA_ID_LS_AES_MASK;
50 @@ -3558,24 +3559,24 @@ int caam_algapi_init(struct device *ctrl
54 - aes_rn = rd_reg32(&priv->ctrl->perfmon.cha_rev_ls) &
56 + aes_rn = rd_reg32(&perfmon->cha_rev_ls) & CHA_ID_LS_AES_MASK;
57 gcm_support = !(aes_vid == CHA_VER_VID_AES_LP && aes_rn < 8);
59 + struct version_regs __iomem *vreg = &priv->jr[0]->vreg;
62 - aesa = rd_reg32(&priv->ctrl->vreg.aesa);
63 - mdha = rd_reg32(&priv->ctrl->vreg.mdha);
64 + aesa = rd_reg32(&vreg->aesa);
65 + mdha = rd_reg32(&vreg->mdha);
67 aes_vid = (aesa & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
68 md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
70 - des_inst = rd_reg32(&priv->ctrl->vreg.desa) & CHA_VER_NUM_MASK;
71 + des_inst = rd_reg32(&vreg->desa) & CHA_VER_NUM_MASK;
72 aes_inst = aesa & CHA_VER_NUM_MASK;
73 md_inst = mdha & CHA_VER_NUM_MASK;
74 - ccha_inst = rd_reg32(&priv->ctrl->vreg.ccha) & CHA_VER_NUM_MASK;
75 - ptha_inst = rd_reg32(&priv->ctrl->vreg.ptha) & CHA_VER_NUM_MASK;
76 - arc4_inst = rd_reg32(&priv->ctrl->vreg.afha) & CHA_VER_NUM_MASK;
77 + ccha_inst = rd_reg32(&vreg->ccha) & CHA_VER_NUM_MASK;
78 + ptha_inst = rd_reg32(&vreg->ptha) & CHA_VER_NUM_MASK;
79 + arc4_inst = rd_reg32(&vreg->afha) & CHA_VER_NUM_MASK;
81 gcm_support = aesa & CHA_VER_MISC_AES_GCM;
83 --- a/drivers/crypto/caam/caamhash.c
84 +++ b/drivers/crypto/caam/caamhash.c
85 @@ -1991,12 +1991,14 @@ int caam_algapi_hash_init(struct device
86 * presence and attributes of MD block.
89 - md_vid = (rd_reg32(&priv->ctrl->perfmon.cha_id_ls) &
90 + struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon;
92 + md_vid = (rd_reg32(&perfmon->cha_id_ls) &
93 CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
94 - md_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
95 + md_inst = (rd_reg32(&perfmon->cha_num_ls) &
96 CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
98 - u32 mdha = rd_reg32(&priv->ctrl->vreg.mdha);
99 + u32 mdha = rd_reg32(&priv->jr[0]->vreg.mdha);
101 md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
102 md_inst = mdha & CHA_VER_NUM_MASK;
103 --- a/drivers/crypto/caam/caampkc.c
104 +++ b/drivers/crypto/caam/caampkc.c
105 @@ -1099,10 +1099,10 @@ int caam_pkc_init(struct device *ctrldev
107 /* Determine public key hardware accelerator presence. */
109 - pk_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
110 + pk_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
111 CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT;
113 - pk_inst = rd_reg32(&priv->ctrl->vreg.pkha) & CHA_VER_NUM_MASK;
114 + pk_inst = rd_reg32(&priv->jr[0]->vreg.pkha) & CHA_VER_NUM_MASK;
116 /* Do not register algorithms if PKHA is not present. */
118 --- a/drivers/crypto/caam/caamrng.c
119 +++ b/drivers/crypto/caam/caamrng.c
120 @@ -363,10 +363,10 @@ int caam_rng_init(struct device *ctrldev
122 /* Check for an instantiated RNG before registration */
124 - rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
125 + rng_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
126 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
128 - rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK;
129 + rng_inst = rd_reg32(&priv->jr[0]->vreg.rng) & CHA_VER_NUM_MASK;
133 --- a/drivers/crypto/caam/ctrl.c
134 +++ b/drivers/crypto/caam/ctrl.c
135 @@ -379,7 +379,7 @@ start_rng:
136 RTMCTL_SAMP_MODE_RAW_ES_SC);
139 -static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
140 +static int caam_get_era_from_hw(struct caam_perfmon __iomem *perfmon)
142 static const struct {
144 @@ -405,12 +405,12 @@ static int caam_get_era_from_hw(struct c
148 - ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
149 + ccbvid = rd_reg32(&perfmon->ccb_id);
150 era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
151 if (era) /* This is '0' prior to CAAM ERA-6 */
154 - id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
155 + id_ms = rd_reg32(&perfmon->caam_id_ms);
156 ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
157 maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
159 @@ -428,7 +428,7 @@ static int caam_get_era_from_hw(struct c
160 * In case this property is not passed an attempt to retrieve the CAAM
161 * era via register reads will be made.
163 -static int caam_get_era(struct caam_ctrl __iomem *ctrl)
164 +static int caam_get_era(struct caam_perfmon __iomem *perfmon)
166 struct device_node *caam_node;
168 @@ -441,7 +441,7 @@ static int caam_get_era(struct caam_ctrl
172 - return caam_get_era_from_hw(ctrl);
173 + return caam_get_era_from_hw(perfmon);
177 @@ -575,8 +575,8 @@ static int caam_probe(struct platform_de
178 struct device_node *nprop, *np;
179 struct caam_ctrl __iomem *ctrl;
180 struct caam_drv_private *ctrlpriv;
181 + struct caam_perfmon __iomem *perfmon;
182 #ifdef CONFIG_DEBUG_FS
183 - struct caam_perfmon *perfmon;
184 struct dentry *dfs_root;
186 u32 scfgr, comp_params;
187 @@ -616,9 +616,36 @@ static int caam_probe(struct platform_de
191 - caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) &
193 + for_each_available_child_of_node(nprop, np)
194 + if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
195 + of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
198 + if (of_property_read_u32_index(np, "reg", 0, ®)) {
199 + dev_err(dev, "%s read reg property error\n",
204 + ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
205 + ((__force uint8_t *)ctrl + reg);
207 + ctrlpriv->total_jobrs++;
212 + * Wherever possible, instead of accessing registers from the global page,
213 + * use the alias registers in the first (cf. DT nodes order)
216 + perfmon = ring ? (struct caam_perfmon *)&ctrlpriv->jr[0]->perfmon :
217 + (struct caam_perfmon *)&ctrl->perfmon;
219 + caam_little_end = !(bool)(rd_reg32(&perfmon->status) &
220 (CSTA_PLEND | CSTA_ALT_PLEND));
221 - comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
222 + comp_params = rd_reg32(&perfmon->comp_parms_ms);
223 if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
224 caam_ptr_sz = sizeof(u64);
226 @@ -718,7 +745,7 @@ static int caam_probe(struct platform_de
230 - ctrlpriv->era = caam_get_era(ctrl);
231 + ctrlpriv->era = caam_get_era(perfmon);
232 ctrlpriv->domain = iommu_get_domain_for_dev(dev);
234 #ifdef CONFIG_DEBUG_FS
235 @@ -727,8 +754,6 @@ static int caam_probe(struct platform_de
236 * "caam" and nprop->full_name. The OF name isn't distinctive,
237 * but does separate instances
239 - perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
241 dfs_root = debugfs_create_dir(dev_name(dev), NULL);
242 ret = devm_add_action_or_reset(dev, caam_remove_debugfs, dfs_root);
244 @@ -754,31 +779,24 @@ static int caam_probe(struct platform_de
249 - for_each_available_child_of_node(nprop, np)
250 - if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
251 - of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
252 - ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
253 - ((__force uint8_t *)ctrl +
254 - (ring + JR_BLOCK_NUMBER) *
257 - ctrlpriv->total_jobrs++;
261 /* If no QI and no rings specified, quit and go home */
262 if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
263 dev_err(dev, "no queues configured, terminating\n");
267 - if (ctrlpriv->era < 10)
268 - rng_vid = (rd_reg32(&ctrl->perfmon.cha_id_ls) &
269 + if (ctrlpriv->era < 10) {
270 + rng_vid = (rd_reg32(&perfmon->cha_id_ls) &
271 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
273 - rng_vid = (rd_reg32(&ctrl->vreg.rng) & CHA_VER_VID_MASK) >>
275 + struct version_regs __iomem *vreg;
277 + vreg = ring ? (struct version_regs *)&ctrlpriv->jr[0]->vreg :
278 + (struct version_regs *)&ctrl->vreg;
280 + rng_vid = (rd_reg32(&vreg->rng) & CHA_VER_VID_MASK) >>
285 * If SEC has RNG version >= 4 and RNG state handle has not been
286 @@ -847,8 +865,8 @@ static int caam_probe(struct platform_de
288 /* NOTE: RTIC detection ought to go here, around Si time */
290 - caam_id = (u64)rd_reg32(&ctrl->perfmon.caam_id_ms) << 32 |
291 - (u64)rd_reg32(&ctrl->perfmon.caam_id_ls);
292 + caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 |
293 + (u64)rd_reg32(&perfmon->caam_id_ls);
295 /* Report "alive" for developer to see */
296 dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,