mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Marcin Niestroj <m.niestroj@grinn-global.com>
To: barebox@lists.infradead.org
Cc: Marcin Niestroj <m.niestroj@grinn-global.com>
Subject: [PATCH 18/18] crypto: caam - allow retrieving 'era' from register
Date: Mon,  3 Sep 2018 13:44:52 +0200	[thread overview]
Message-ID: <20180903114452.4611-28-m.niestroj@grinn-global.com> (raw)
In-Reply-To: <20180903114452.4611-1-m.niestroj@grinn-global.com>

Pick commit 654f2b937b389295581bcb4aa26011a63db7bc8f from Linux
upstream.

    crypto: caam - allow retrieving 'era' from register

    The 'era' information can be retrieved from CAAM registers, so
    introduce a caam_get_era_from_hw() function that gets it via register
    reads in case the 'fsl,sec-era' property is not passed in the device
    tree.

    This function is based on the U-Boot implementation from
    drivers/crypto/fsl/sec.c

    Signed-off-by: Fabio Estevam <fabio.estevam@nxp.com>
    Reviewed-by: Horia Geantă <horia.geanta@nxp.com>
    Tested-by: Breno Lima <breno.lima@nxp.com>
    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
---
 drivers/crypto/caam/ctrl.c | 56 +++++++++++++++++++++++++++++++++++---
 drivers/crypto/caam/regs.h |  6 ++++
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/drivers/crypto/caam/ctrl.c b/drivers/crypto/caam/ctrl.c
index 3b24c5ea2..9e62bd6fd 100644
--- a/drivers/crypto/caam/ctrl.c
+++ b/drivers/crypto/caam/ctrl.c
@@ -282,11 +282,56 @@ start_rng:
 	clrsetbits_32(&r4tst->rtmctl, RTMCTL_PRGM, RTMCTL_SAMP_MODE_RAW_ES_SC);
 }
 
+static int caam_get_era_from_hw(struct caam_ctrl __iomem *ctrl)
+{
+	static const struct {
+		u16 ip_id;
+		u8 maj_rev;
+		u8 era;
+	} id[] = {
+		{0x0A10, 1, 1},
+		{0x0A10, 2, 2},
+		{0x0A12, 1, 3},
+		{0x0A14, 1, 3},
+		{0x0A14, 2, 4},
+		{0x0A16, 1, 4},
+		{0x0A10, 3, 4},
+		{0x0A11, 1, 4},
+		{0x0A18, 1, 4},
+		{0x0A11, 2, 5},
+		{0x0A12, 2, 5},
+		{0x0A13, 1, 5},
+		{0x0A1C, 1, 5}
+	};
+	u32 ccbvid, id_ms;
+	u8 maj_rev, era;
+	u16 ip_id;
+	int i;
+
+	ccbvid = rd_reg32(&ctrl->perfmon.ccb_id);
+	era = (ccbvid & CCBVID_ERA_MASK) >> CCBVID_ERA_SHIFT;
+	if (era)	/* This is '0' prior to CAAM ERA-6 */
+		return era;
+
+	id_ms = rd_reg32(&ctrl->perfmon.caam_id_ms);
+	ip_id = (id_ms & SECVID_MS_IPID_MASK) >> SECVID_MS_IPID_SHIFT;
+	maj_rev = (id_ms & SECVID_MS_MAJ_REV_MASK) >> SECVID_MS_MAJ_REV_SHIFT;
+
+	for (i = 0; i < ARRAY_SIZE(id); i++)
+		if (id[i].ip_id == ip_id && id[i].maj_rev == maj_rev)
+			return id[i].era;
+
+	return -ENOTSUPP;
+}
+
 /**
  * caam_get_era() - Return the ERA of the SEC on SoC, based
- * on "sec-era" propery in the DTS. This property is updated by u-boot.
+ * on "sec-era" optional property in the DTS. This property is updated
+ * by u-boot.
+ * In case this property is not passed an attempt to retrieve the CAAM
+ * era via register reads will be made.
  **/
-static int caam_get_era(void)
+static int caam_get_era(struct caam_ctrl __iomem *ctrl)
 {
 	struct device_node *caam_node;
 	int ret;
@@ -295,7 +340,10 @@ static int caam_get_era(void)
 	caam_node = of_find_compatible_node(NULL, NULL, "fsl,sec-v4.0");
 	ret = of_property_read_u32(caam_node, "fsl,sec-era", &prop);
 
-	return IS_ERR_VALUE(ret) ? -ENOTSUPP : prop;
+	if (!ret)
+		return prop;
+	else
+		return caam_get_era_from_hw(ctrl);
 }
 
 /* Probe routine for CAAM top (controller) level */
@@ -593,7 +641,7 @@ static int caam_probe(struct device_d *dev)
 
 	/* Report "alive" for developer to see */
 	dev_dbg(dev, "device ID = 0x%016llx (Era %d)\n", caam_id,
-		 caam_get_era());
+		 caam_get_era(ctrl));
 	dev_dbg(dev, "job rings = %d, qi = %d\n",
 		 ctrlpriv->total_jobrs, ctrlpriv->qi_present);
 
diff --git a/drivers/crypto/caam/regs.h b/drivers/crypto/caam/regs.h
index d50e9ad69..6c9d6d75a 100644
--- a/drivers/crypto/caam/regs.h
+++ b/drivers/crypto/caam/regs.h
@@ -307,11 +307,17 @@ struct caam_perfmon {
 
 	/* Component Instantiation Parameters			fe0-fff */
 	u32 rtic_id;		/* RVID - RTIC Version ID	*/
+#define CCBVID_ERA_MASK		0xff000000
+#define CCBVID_ERA_SHIFT	24
 	u32 ccb_id;		/* CCBVID - CCB Version ID	*/
 	u32 cha_id_ms;		/* CHAVID - CHA Version ID Most Significant*/
 	u32 cha_id_ls;		/* CHAVID - CHA Version ID Least Significant*/
 	u32 cha_num_ms;		/* CHANUM - CHA Number Most Significant	*/
 	u32 cha_num_ls;		/* CHANUM - CHA Number Least Significant*/
+#define SECVID_MS_IPID_MASK	0xffff0000
+#define SECVID_MS_IPID_SHIFT	16
+#define SECVID_MS_MAJ_REV_MASK	0x0000ff00
+#define SECVID_MS_MAJ_REV_SHIFT	8
 	u32 caam_id_ms;		/* CAAMVID - CAAM Version ID MS	*/
 	u32 caam_id_ls;		/* CAAMVID - CAAM Version ID LS	*/
 };
-- 
2.18.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2018-09-03 12:06 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-03 11:23 [PATCH 00/18] crypto: caam: Pull CAAM support improvements from Linux Marcin Niestroj
2018-09-03 11:23 ` [PATCH 01/18] crypto: caam - fix RNG init descriptor ret. code checking Marcin Niestroj
2018-09-03 11:23 ` [PATCH 02/18] crypto: caam - fix warning in APPEND_MATH_IMM_u64 Marcin Niestroj
2018-09-03 11:23 ` [PATCH 03/18] crypto: caam - fix writing to JQCR_MS when using service interface Marcin Niestroj
2018-09-03 11:23 ` [PATCH 04/18] crypto: caam - handle core endianness != caam endianness Marcin Niestroj
2018-09-03 11:23 ` [PATCH 05/18] crypto: caam - add support for iMX6UL Marcin Niestroj
2018-09-03 11:23 ` [PATCH 06/18] crypto: caam - fix sparse warnings Marcin Niestroj
2018-09-03 11:23 ` [PATCH 07/18] crypto: caam - trivial code clean-up Marcin Niestroj
2018-09-03 11:23 ` [PATCH 08/18] crypto: caam - remove unreachable code in report_ccb_status() Marcin Niestroj
2018-09-03 11:23 ` [PATCH 09/18] crypto: caam - constify pointer to descriptor buffer Marcin Niestroj
2018-09-03 11:24 ` [PATCH 10/18] crypto: caam - avoid double inclusion in desc_constr.h Marcin Niestroj
2018-09-03 11:24 ` [PATCH 11/18] crypto: caam - clean-up in caam_init_rng() Marcin Niestroj
2018-09-03 11:24 ` [PATCH 12/18] crypto: caam - fix incorrect define Marcin Niestroj
2018-09-03 11:24 ` [PATCH 13/18] crypto: caam - constify key data Marcin Niestroj
2018-09-03 11:24 ` [PATCH 14/18] crypto: caam - fix endless loop when DECO acquire fails Marcin Niestroj
2018-09-03 11:24 ` [PATCH 15/18] crypto: caam - do not use mem and emi_slow clock for imx7x Marcin Niestroj
2018-09-03 11:24 ` [PATCH 16/18] crypto: caam - sync desc.h with Linux Marcin Niestroj
2018-09-03 11:24 ` [PATCH 17/18] crypto: caam - staticize caam_get_era() Marcin Niestroj
2018-09-03 11:24 ` [PATCH 18/18] crypto: caam - allow retrieving 'era' from register Marcin Niestroj
2018-09-03 11:44 ` [PATCH 10/18] crypto: caam - avoid double inclusion in desc_constr.h Marcin Niestroj
2018-09-03 11:44   ` [PATCH 11/18] crypto: caam - clean-up in caam_init_rng() Marcin Niestroj
2018-09-03 11:44   ` [PATCH 12/18] crypto: caam - fix incorrect define Marcin Niestroj
2018-09-03 11:44   ` [PATCH 13/18] crypto: caam - constify key data Marcin Niestroj
2018-09-03 11:44   ` [PATCH 14/18] crypto: caam - fix endless loop when DECO acquire fails Marcin Niestroj
2018-09-03 11:44   ` [PATCH 15/18] crypto: caam - do not use mem and emi_slow clock for imx7x Marcin Niestroj
2018-09-03 11:44   ` [PATCH 16/18] crypto: caam - sync desc.h with Linux Marcin Niestroj
2018-09-03 11:44   ` [PATCH 17/18] crypto: caam - staticize caam_get_era() Marcin Niestroj
2018-09-03 11:44   ` [PATCH 18/18] crypto: caam - allow retrieving 'era' from register Marcin Niestroj
2018-09-03 11:44   ` [PATCH 00/18] crypto: caam: Pull CAAM support improvements from Linux Marcin Niestroj
2018-09-03 11:44   ` [PATCH 01/18] crypto: caam - fix RNG init descriptor ret. code checking Marcin Niestroj
2018-09-03 11:44   ` [PATCH 02/18] crypto: caam - fix warning in APPEND_MATH_IMM_u64 Marcin Niestroj
2018-09-03 11:44   ` [PATCH 03/18] crypto: caam - fix writing to JQCR_MS when using service interface Marcin Niestroj
2018-09-03 11:44   ` [PATCH 04/18] crypto: caam - handle core endianness != caam endianness Marcin Niestroj
2018-09-03 11:44   ` [PATCH 05/18] crypto: caam - add support for iMX6UL Marcin Niestroj
2018-09-03 11:44   ` [PATCH 06/18] crypto: caam - fix sparse warnings Marcin Niestroj
2018-09-03 11:44   ` [PATCH 07/18] crypto: caam - trivial code clean-up Marcin Niestroj
2018-09-03 11:44   ` [PATCH 08/18] crypto: caam - remove unreachable code in report_ccb_status() Marcin Niestroj
2018-09-03 11:44   ` [PATCH 09/18] crypto: caam - constify pointer to descriptor buffer Marcin Niestroj
2018-09-03 11:44   ` [PATCH 10/18] crypto: caam - avoid double inclusion in desc_constr.h Marcin Niestroj
2018-09-03 11:44   ` [PATCH 11/18] crypto: caam - clean-up in caam_init_rng() Marcin Niestroj
2018-09-03 11:44   ` [PATCH 12/18] crypto: caam - fix incorrect define Marcin Niestroj
2018-09-03 11:44   ` [PATCH 13/18] crypto: caam - constify key data Marcin Niestroj
2018-09-03 11:44   ` [PATCH 14/18] crypto: caam - fix endless loop when DECO acquire fails Marcin Niestroj
2018-09-03 11:44   ` [PATCH 15/18] crypto: caam - do not use mem and emi_slow clock for imx7x Marcin Niestroj
2018-09-03 11:44   ` [PATCH 16/18] crypto: caam - sync desc.h with Linux Marcin Niestroj
2018-09-03 11:44   ` [PATCH 17/18] crypto: caam - staticize caam_get_era() Marcin Niestroj
2018-09-03 11:44   ` Marcin Niestroj [this message]
2018-09-04  8:05 ` [PATCH 00/18] crypto: caam: Pull CAAM support improvements from Linux Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180903114452.4611-28-m.niestroj@grinn-global.com \
    --to=m.niestroj@grinn-global.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox