Commit 4014f317 authored by Olof Johansson's avatar Olof Johansson

Merge tag 'mvebu-fixes-5.13-1' of...

Merge tag 'mvebu-fixes-5.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/gclement/mvebu into arm/drivers

mvebu fixes for 5.13 (part 1)

Few fixes for the Turris Mox rWTM firmware found on the Armada 3700
SoCs.

* tag 'mvebu-fixes-5.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/gclement/mvebu:
  firmware: turris-mox-rwtm: show message about HWRNG registration
  firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng
  firmware: turris-mox-rwtm: report failures better
  firmware: turris-mox-rwtm: fix reply status decoding function

Link: https://lore.kernel.org/r/87eecx0w6s.fsf@BL-laptopSigned-off-by: default avatarOlof Johansson <olof@lixom.net>
parents 25da503e fae20160
...@@ -147,11 +147,14 @@ MOX_ATTR_RO(pubkey, "%s\n", pubkey); ...@@ -147,11 +147,14 @@ MOX_ATTR_RO(pubkey, "%s\n", pubkey);
static int mox_get_status(enum mbox_cmd cmd, u32 retval) static int mox_get_status(enum mbox_cmd cmd, u32 retval)
{ {
if (MBOX_STS_CMD(retval) != cmd || if (MBOX_STS_CMD(retval) != cmd)
MBOX_STS_ERROR(retval) != MBOX_STS_SUCCESS)
return -EIO; return -EIO;
else if (MBOX_STS_ERROR(retval) == MBOX_STS_FAIL) else if (MBOX_STS_ERROR(retval) == MBOX_STS_FAIL)
return -(int)MBOX_STS_VALUE(retval); return -(int)MBOX_STS_VALUE(retval);
else if (MBOX_STS_ERROR(retval) == MBOX_STS_BADCMD)
return -ENOSYS;
else if (MBOX_STS_ERROR(retval) != MBOX_STS_SUCCESS)
return -EIO;
else else
return MBOX_STS_VALUE(retval); return MBOX_STS_VALUE(retval);
} }
...@@ -201,11 +204,14 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ...@@ -201,11 +204,14 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
return ret; return ret;
ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval); ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval);
if (ret < 0 && ret != -ENODATA) { if (ret == -ENODATA) {
return ret;
} else if (ret == -ENODATA) {
dev_warn(rwtm->dev, dev_warn(rwtm->dev,
"Board does not have manufacturing information burned!\n"); "Board does not have manufacturing information burned!\n");
} else if (ret == -ENOSYS) {
dev_notice(rwtm->dev,
"Firmware does not support the BOARD_INFO command\n");
} else if (ret < 0) {
return ret;
} else { } else {
rwtm->serial_number = reply->status[1]; rwtm->serial_number = reply->status[1];
rwtm->serial_number <<= 32; rwtm->serial_number <<= 32;
...@@ -234,10 +240,13 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ...@@ -234,10 +240,13 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
return ret; return ret;
ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval); ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval);
if (ret < 0 && ret != -ENODATA) { if (ret == -ENODATA) {
return ret;
} else if (ret == -ENODATA) {
dev_warn(rwtm->dev, "Board has no public key burned!\n"); dev_warn(rwtm->dev, "Board has no public key burned!\n");
} else if (ret == -ENOSYS) {
dev_notice(rwtm->dev,
"Firmware does not support the ECDSA_PUB_KEY command\n");
} else if (ret < 0) {
return ret;
} else { } else {
u32 *s = reply->status; u32 *s = reply->status;
...@@ -251,6 +260,27 @@ static int mox_get_board_info(struct mox_rwtm *rwtm) ...@@ -251,6 +260,27 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
return 0; 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) static int mox_hwrng_read(struct hwrng *rng, void *data, size_t max, bool wait)
{ {
struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv; struct mox_rwtm *rwtm = (struct mox_rwtm *) rng->priv;
...@@ -488,6 +518,13 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) ...@@ -488,6 +518,13 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev)
if (ret < 0) if (ret < 0)
dev_warn(dev, "Cannot read board information: %i\n", ret); 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.name = DRIVER_NAME "_hwrng";
rwtm->hwrng.read = mox_hwrng_read; rwtm->hwrng.read = mox_hwrng_read;
rwtm->hwrng.priv = (unsigned long) rwtm; rwtm->hwrng.priv = (unsigned long) rwtm;
...@@ -505,6 +542,8 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev) ...@@ -505,6 +542,8 @@ static int turris_mox_rwtm_probe(struct platform_device *pdev)
goto free_channel; goto free_channel;
} }
dev_info(dev, "HWRNG successfully registered\n");
return 0; return 0;
free_channel: free_channel:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment