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 @@ -3520,13 +3520,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 @@ -3534,23 +3535,23 @@ 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 + ccha_inst = rd_reg32(&vreg->ccha) & CHA_VER_NUM_MASK;
77 + ptha_inst = rd_reg32(&vreg->ptha) & CHA_VER_NUM_MASK;
79 gcm_support = aesa & CHA_VER_MISC_AES_GCM;
81 --- a/drivers/crypto/caam/caamhash.c
82 +++ b/drivers/crypto/caam/caamhash.c
83 @@ -1991,12 +1991,14 @@ int caam_algapi_hash_init(struct device
84 * presence and attributes of MD block.
87 - md_vid = (rd_reg32(&priv->ctrl->perfmon.cha_id_ls) &
88 + struct caam_perfmon __iomem *perfmon = &priv->jr[0]->perfmon;
90 + md_vid = (rd_reg32(&perfmon->cha_id_ls) &
91 CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
92 - md_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
93 + md_inst = (rd_reg32(&perfmon->cha_num_ls) &
94 CHA_ID_LS_MD_MASK) >> CHA_ID_LS_MD_SHIFT;
96 - u32 mdha = rd_reg32(&priv->ctrl->vreg.mdha);
97 + u32 mdha = rd_reg32(&priv->jr[0]->vreg.mdha);
99 md_vid = (mdha & CHA_VER_VID_MASK) >> CHA_VER_VID_SHIFT;
100 md_inst = mdha & CHA_VER_NUM_MASK;
101 --- a/drivers/crypto/caam/caampkc.c
102 +++ b/drivers/crypto/caam/caampkc.c
103 @@ -1099,10 +1099,10 @@ int caam_pkc_init(struct device *ctrldev
105 /* Determine public key hardware accelerator presence. */
106 if (priv->era < 10) {
107 - pk_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
108 + pk_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
109 CHA_ID_LS_PK_MASK) >> CHA_ID_LS_PK_SHIFT;
111 - pkha = rd_reg32(&priv->ctrl->vreg.pkha);
112 + pkha = rd_reg32(&priv->jr[0]->vreg.pkha);
113 pk_inst = pkha & CHA_VER_NUM_MASK;
116 --- a/drivers/crypto/caam/caamrng.c
117 +++ b/drivers/crypto/caam/caamrng.c
118 @@ -363,10 +363,10 @@ int caam_rng_init(struct device *ctrldev
120 /* Check for an instantiated RNG before registration */
122 - rng_inst = (rd_reg32(&priv->ctrl->perfmon.cha_num_ls) &
123 + rng_inst = (rd_reg32(&priv->jr[0]->perfmon.cha_num_ls) &
124 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
126 - rng_inst = rd_reg32(&priv->ctrl->vreg.rng) & CHA_VER_NUM_MASK;
127 + rng_inst = rd_reg32(&priv->jr[0]->vreg.rng) & CHA_VER_NUM_MASK;
131 --- a/drivers/crypto/caam/ctrl.c
132 +++ b/drivers/crypto/caam/ctrl.c
133 @@ -379,7 +379,7 @@ start_rng:
134 RTMCTL_SAMP_MODE_RAW_ES_SC);
137 -static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
138 +static int caam_get_era_from_hw(struct caam_perfmon __iomem *perfmon)
140 static const struct {
142 @@ -405,12 +405,12 @@ static int caam_get_era_from_hw(struct c
146 - ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
147 + ccbvid = rd_reg32(&perfmon->ccb_id);
148 era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
149 if (era) /* This is '0' prior to CAAM ERA-6 */
152 - id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
153 + id_ms = rd_reg32(&perfmon->caam_id_ms);
154 ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
155 maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
157 @@ -428,7 +428,7 @@ static int caam_get_era_from_hw(struct c
158 * In case this property is not passed an attempt to retrieve the CAAM
159 * era via register reads will be made.
161 -static int caam_get_era(struct caam_ctrl __iomem *ctrl)
162 +static int caam_get_era(struct caam_perfmon __iomem *perfmon)
164 struct device_node *caam_node;
166 @@ -441,7 +441,7 @@ static int caam_get_era(struct caam_ctrl
170 - return caam_get_era_from_hw(ctrl);
171 + return caam_get_era_from_hw(perfmon);
175 @@ -575,8 +575,8 @@ static int caam_probe(struct platform_de
176 struct device_node *nprop, *np;
177 struct caam_ctrl __iomem *ctrl;
178 struct caam_drv_private *ctrlpriv;
179 + struct caam_perfmon __iomem *perfmon;
180 #ifdef CONFIG_DEBUG_FS
181 - struct caam_perfmon *perfmon;
182 struct dentry *dfs_root;
184 u32 scfgr, comp_params;
185 @@ -616,9 +616,36 @@ static int caam_probe(struct platform_de
189 - caam_little_end = !(bool)(rd_reg32(&ctrl->perfmon.status) &
191 + for_each_available_child_of_node(nprop, np)
192 + if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
193 + of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
196 + if (of_property_read_u32_index(np, "reg", 0, ®)) {
197 + dev_err(dev, "%s read reg property error\n",
202 + ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
203 + ((__force uint8_t *)ctrl + reg);
205 + ctrlpriv->total_jobrs++;
210 + * Wherever possible, instead of accessing registers from the global page,
211 + * use the alias registers in the first (cf. DT nodes order)
214 + perfmon = ring ? (struct caam_perfmon *)&ctrlpriv->jr[0]->perfmon :
215 + (struct caam_perfmon *)&ctrl->perfmon;
217 + caam_little_end = !(bool)(rd_reg32(&perfmon->status) &
218 (CSTA_PLEND | CSTA_ALT_PLEND));
219 - comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ms);
220 + comp_params = rd_reg32(&perfmon->comp_parms_ms);
221 if (comp_params & CTPR_MS_PS && rd_reg32(&ctrl->mcr) & MCFGR_LONG_PTR)
222 caam_ptr_sz = sizeof(u64);
224 @@ -718,7 +745,7 @@ static int caam_probe(struct platform_de
228 - ctrlpriv->era = caam_get_era(ctrl);
229 + ctrlpriv->era = caam_get_era(perfmon);
230 ctrlpriv->domain = iommu_get_domain_for_dev(dev);
232 #ifdef CONFIG_DEBUG_FS
233 @@ -727,8 +754,6 @@ static int caam_probe(struct platform_de
234 * "caam" and nprop->full_name. The OF name isn't distinctive,
235 * but does separate instances
237 - perfmon = (struct caam_perfmon __force *)&ctrl->perfmon;
239 dfs_root = debugfs_create_dir(dev_name(dev), NULL);
240 ret = devm_add_action_or_reset(dev, caam_remove_debugfs, dfs_root);
242 @@ -754,31 +779,24 @@ static int caam_probe(struct platform_de
247 - for_each_available_child_of_node(nprop, np)
248 - if (of_device_is_compatible(np, "fsl,sec-v4.0-job-ring") ||
249 - of_device_is_compatible(np, "fsl,sec4.0-job-ring")) {
250 - ctrlpriv->jr[ring] = (struct caam_job_ring __iomem __force *)
251 - ((__force uint8_t *)ctrl +
252 - (ring + JR_BLOCK_NUMBER) *
255 - ctrlpriv->total_jobrs++;
259 /* If no QI and no rings specified, quit and go home */
260 if ((!ctrlpriv->qi_present) && (!ctrlpriv->total_jobrs)) {
261 dev_err(dev, "no queues configured, terminating\n");
265 - if (ctrlpriv->era < 10)
266 - rng_vid = (rd_reg32(&ctrl->perfmon.cha_id_ls) &
267 + if (ctrlpriv->era < 10) {
268 + rng_vid = (rd_reg32(&perfmon->cha_id_ls) &
269 CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
271 - rng_vid = (rd_reg32(&ctrl->vreg.rng) & CHA_VER_VID_MASK) >>
273 + struct version_regs __iomem *vreg;
275 + vreg = ring ? (struct version_regs *)&ctrlpriv->jr[0]->vreg :
276 + (struct version_regs *)&ctrl->vreg;
278 + rng_vid = (rd_reg32(&vreg->rng) & CHA_VER_VID_MASK) >>
283 * If SEC has RNG version >= 4 and RNG state handle has not been
284 @@ -847,8 +865,8 @@ static int caam_probe(struct platform_de
286 /* NOTE: RTIC detection ought to go here, around Si time */
288 - caam_id = (u64)rd_reg32(&ctrl->perfmon.caam_id_ms) << 32 |
289 - (u64)rd_reg32(&ctrl->perfmon.caam_id_ls);
290 + caam_id = (u64)rd_reg32(&perfmon->caam_id_ms) << 32 |
291 + (u64)rd_reg32(&perfmon->caam_id_ls);
293 /* Report "alive" for developer to see */
294 dev_info(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,