diff mbox series

[v3,mvebu,+,mvebu/dt64,3/6] firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng

Message ID 20210506090802.14268-3-pali@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v3,mvebu,+,mvebu/dt64,1/6] firmware: turris-mox-rwtm: fix reply status decoding function | expand

Commit Message

Pali Rohár May 6, 2021, 9:07 a.m. UTC
When Marvell's rWTM firmware, which does not support the GET_RANDOM
command, is used, kernel prints an error message
  hwrng: no data available
every 10 seconds.

Fail probing of this driver if the rWTM firmware does not support the
GET_RANDOM command.

This makes it possible to put this driver's compatible into generic
armada-37xx device tree, to be available for other Armada 3720 devices
besides Turris MOX. If they use the rWTM firmware from CZ.NIC, they will
have HWRNG available, and if not, the driver won't be complaining.

Signed-off-by: Pali Rohár <pali@kernel.org>
Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/firmware/turris-mox-rwtm.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

Comments

Andrew Lunn May 12, 2021, 12:56 a.m. UTC | #1
On Thu, May 06, 2021 at 11:07:59AM +0200, Pali Rohár wrote:
> When Marvell's rWTM firmware, which does not support the GET_RANDOM
> command, is used, kernel prints an error message
>   hwrng: no data available
> every 10 seconds.
> 
> Fail probing of this driver if the rWTM firmware does not support the
> GET_RANDOM command.
> 
> This makes it possible to put this driver's compatible into generic
> armada-37xx device tree, to be available for other Armada 3720 devices
> besides Turris MOX. If they use the rWTM firmware from CZ.NIC, they will
> have HWRNG available, and if not, the driver won't be complaining.

We start getting into questions of if this is relevant for stable.
Running Turris MOX with plain Marvell rWTM will spam the log. So i
would say it is a fix, for that situation.

However, i would drop the second part of the description. Making the
Turris MOX firmware work on none Turris MOX hardware is a new feature,
and so not applicable to stable.

    Andrew
Pali Rohár May 20, 2021, 11:38 a.m. UTC | #2
On Wednesday 12 May 2021 02:56:09 Andrew Lunn wrote:
> However, i would drop the second part of the description. Making the
> Turris MOX firmware work on none Turris MOX hardware is a new feature,
> and so not applicable to stable.

Done in v4.
diff mbox series

Patch

diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index d7e3489e4bf2..3ef9687dddca 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -260,6 +260,27 @@  static int mox_get_board_info(struct mox_rwtm *rwtm)
 	return 0;
 }
 
+static int check_get_random_support(struct mox_rwtm *rwtm)
+{
+	struct armada_37xx_rwtm_tx_msg msg;
+	int ret;
+
+	msg.command = MBOX_CMD_GET_RANDOM;
+	msg.args[0] = 1;
+	msg.args[1] = rwtm->buf_phys;
+	msg.args[2] = 4;
+
+	ret = mbox_send_message(rwtm->mbox, &msg);
+	if (ret < 0)
+		return ret;
+
+	ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+	if (ret < 0)
+		return ret;
+
+	return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
+}
+
 static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
 {
 	struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv;
@@ -497,6 +518,13 @@  static int turris_mox_rwtm_probe(struct platform_device *pdev)
 	if (ret < 0)
 		dev_warn(dev, "Cannot read board information: %i\n", ret);
 
+	ret = check_get_random_support(rwtm);
+	if (ret < 0) {
+		dev_notice(dev,
+			   "Firmware does not support the GET_RANDOM command\n");
+		goto free_channel;
+	}
+
 	rwtm->hwrng.name = DRIVER_NAME "_hwrng";
 	rwtm->hwrng.read = mox_hwrng_read;
 	rwtm->hwrng.priv = (unsigned long) rwtm;