public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: "Pali Rohár" <pali@kernel.org>
To: "Stefan Roese" <sr@denx.de>, "Marek Behún" <marek.behun@nic.cz>,
	"Konstantin Porotchkin" <kostap@marvell.com>,
	"Vladimir Vid" <vladimir.vid@sartura.hr>
Cc: u-boot@lists.denx.de
Subject: [PATCH u-boot-mvebu v3 5/5] arm: mvebu: a37xx: Add support for reading Security OTP values
Date: Wed, 23 Feb 2022 14:15:49 +0100	[thread overview]
Message-ID: <20220223131549.11991-6-pali@kernel.org> (raw)
In-Reply-To: <20220223131549.11991-1-pali@kernel.org>

It is not possible for the A53 core (on which U-Boot is running) to read it
directly. For this purpose Marvell defined mbox API for sending OTP
commands between CM3 and A53 cores.

Implement these Marvell fuse reading mbox commands via U-Boot fuse API.

Banks 0-43 are used for accessing Security OTP (44 rows with 67 bits via 44
banks and words 0-2).

Note that of the 67 bits, the 3 upper bits are: 1 lock bit and 2
auxiliary bits (meant for testing during the manufacture of the SOC, as
I understand it).

Also note that the lock bit and the auxiliary bits are not readable
via Marvell commands.

With CZ.NIC's commands the lock bit is readable.

Write support is not implemented yet.

Signed-off-by: Pali Rohár <pali@kernel.org>
Reviewed-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Stefan Roese <sr@denx.de>
---
 arch/arm/mach-mvebu/armada3700/efuse.c | 39 ++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-mvebu/armada3700/efuse.c b/arch/arm/mach-mvebu/armada3700/efuse.c
index 03778f17ea49..50c73f36c565 100644
--- a/arch/arm/mach-mvebu/armada3700/efuse.c
+++ b/arch/arm/mach-mvebu/armada3700/efuse.c
@@ -8,6 +8,7 @@
 #include <common.h>
 #include <asm/io.h>
 #include <linux/delay.h>
+#include <mach/mbox.h>
 #include <mach/soc.h>
 
 #define OTP_NB_REG_BASE		((void __iomem *)MVEBU_REGISTER(0x12600))
@@ -77,6 +78,41 @@ static void otp_read_parallel(void __iomem *base, u32 *data, u32 count)
 	}
 }
 
+static int rwtm_otp_read(u8 row, u32 word, u32 *data)
+{
+	u32 out[3];
+	u32 in[2];
+	int res = -EINVAL;
+
+	if (word < 2) {
+		/*
+		 * MBOX_CMD_OTP_READ_32B command is supported by Marvell
+		 * fuse.bin firmware and also by new CZ.NIC wtmi firmware.
+		 * This command returns raw bits without ECC corrections.
+		 * It does not provide access to the lock bit.
+		 */
+		in[0] = row;
+		in[1] = word * 32;
+		res = mbox_do_cmd(MBOX_CMD_OTP_READ_32B, in, 2, out, 1);
+		if (!res)
+			*data = out[0];
+	} else if (word == 2) {
+		/*
+		 * MBOX_CMD_OTP_READ command is supported only by new CZ.NIC
+		 * wtmi firmware and provides access to all bits, including
+		 * lock bit without doing ECC corrections. For compatibility
+		 * with Marvell fuse.bin firmware, use this command only for
+		 * accessing lock bit.
+		 */
+		in[0] = row;
+		res = mbox_do_cmd(MBOX_CMD_OTP_READ, in, 1, out, 3);
+		if (!res)
+			*data = out[2];
+	}
+
+	return res;
+}
+
 /*
  * Banks 0-43 are used for accessing Security OTP (44 rows with 67 bits via 44 banks and words 0-2)
  * Bank 44 is used for accessing North Bridge OTP (69 bits via words 0-2)
@@ -96,8 +132,7 @@ int fuse_read(u32 bank, u32 word, u32 *val)
 	if (bank <= RWTM_MAX_BANK) {
 		if (word >= RWTM_ROW_WORDS)
 			return -EINVAL;
-		/* TODO: not implemented yet */
-		return -ENOSYS;
+		return rwtm_otp_read(bank, word, val);
 	} else if (bank == OTP_NB_BANK) {
 		u32 data[OTP_NB_WORDS];
 		if (word >= OTP_NB_WORDS)
-- 
2.20.1


  parent reply	other threads:[~2022-02-23 13:18 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-17  9:26 [PATCH u-boot-mvebu 0/5] arm: mvebu: a37xx: Add support for reading OTP Pali Rohár
2022-02-17  9:26 ` [PATCH u-boot-mvebu 1/5] arm: mvebu: a37xx: Add support for reading NB and SB fuse OTP value Pali Rohár
2022-02-17 14:10   ` Marek Behún
2022-02-17  9:26 ` [PATCH u-boot-mvebu 2/5] arm: mvebu: a37xx: Enable fuse command on all Armada 3720 boards Pali Rohár
2022-02-17 14:11   ` Marek Behún
2022-02-17  9:26 ` [PATCH u-boot-mvebu 3/5] arm: mvebu: a37xx: Move generic mbox code to arch/arm/mach-mvebu Pali Rohár
2022-02-17 14:11   ` Marek Behún
2022-02-17  9:26 ` [PATCH u-boot-mvebu 4/5] arm: mvebu: a37xx: Extend mbox_do_cmd() code Pali Rohár
2022-02-17 14:16   ` Marek Behún
2022-02-17 17:13     ` Pali Rohár
2022-02-17 18:40       ` Marek Behún
2022-02-17  9:26 ` [PATCH u-boot-mvebu 5/5] arm: mvebu: a37xx: Add support for reading Security OTP values Pali Rohár
2022-02-17 14:31   ` Marek Behún
2022-02-17 16:50     ` Pali Rohár
2022-02-17 18:39       ` Marek Behún
2022-02-22 20:47     ` Pali Rohár
2022-02-23 14:50       ` Marek Behún
2022-02-17 18:50 ` [PATCH u-boot-mvebu v2 0/5] arm: mvebu: a37xx: Add support for reading OTP Pali Rohár
2022-02-17 18:50   ` [PATCH u-boot-mvebu v2 1/5] arm: mvebu: a37xx: Add support for reading NB and SB fuse OTP value Pali Rohár
2022-02-18 14:15     ` Stefan Roese
2022-02-17 18:50   ` [PATCH u-boot-mvebu v2 2/5] arm: mvebu: a37xx: Enable fuse command on all Armada 3720 boards Pali Rohár
2022-02-18 14:15     ` Stefan Roese
2022-02-17 18:50   ` [PATCH u-boot-mvebu v2 3/5] arm: mvebu: a37xx: Move generic mbox code to arch/arm/mach-mvebu Pali Rohár
2022-02-18 14:15     ` Stefan Roese
2022-02-17 18:50   ` [PATCH u-boot-mvebu v2 4/5] arm: mvebu: a37xx: Extend mbox_do_cmd() code Pali Rohár
2022-02-18 14:16     ` Stefan Roese
2022-02-17 18:50   ` [PATCH u-boot-mvebu v2 5/5] arm: mvebu: a37xx: Add support for reading Security OTP values Pali Rohár
2022-02-17 20:54     ` Marek Behún
2022-02-18 14:16     ` Stefan Roese
2022-02-22 20:51     ` Pali Rohár
2022-02-23 13:15 ` [PATCH u-boot-mvebu v3 0/5] arm: mvebu: a37xx: Add support for reading OTP Pali Rohár
2022-02-23 13:15   ` [PATCH u-boot-mvebu v3 1/5] arm: mvebu: a37xx: Add support for reading NB and SB fuse OTP value Pali Rohár
2022-02-23 13:15   ` [PATCH u-boot-mvebu v3 2/5] arm: mvebu: a37xx: Enable fuse command on all Armada 3720 boards Pali Rohár
2022-02-23 13:15   ` [PATCH u-boot-mvebu v3 3/5] arm: mvebu: a37xx: Move generic mbox code to arch/arm/mach-mvebu Pali Rohár
2022-02-23 13:15   ` [PATCH u-boot-mvebu v3 4/5] arm: mvebu: a37xx: Extend mbox_do_cmd() code Pali Rohár
2022-02-23 13:15   ` Pali Rohár [this message]
2022-03-08 11:42   ` [PATCH u-boot-mvebu v3 0/5] arm: mvebu: a37xx: Add support for reading OTP Pali Rohár
2022-03-08 11:57     ` Stefan Roese
2022-04-20 18:22       ` Pali Rohár
2022-04-21  6:25         ` Stefan Roese
2022-04-21 14:03   ` Stefan Roese

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=20220223131549.11991-6-pali@kernel.org \
    --to=pali@kernel.org \
    --cc=kostap@marvell.com \
    --cc=marek.behun@nic.cz \
    --cc=sr@denx.de \
    --cc=u-boot@lists.denx.de \
    --cc=vladimir.vid@sartura.hr \
    /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