Subject: [PATCH 0/2] MediaTek SCP IPI cleanups

Cleanups bringing no functional changes.
Tested on MT8173 Elm, MT8192 Asurada, MT8195 Tomato.

This series applies only on top of [1].

[1]: https://lore.kernel.org/lkml/[email protected]/

AngeloGioacchino Del Regno (2):
remoteproc/mtk_scp: Use readl_poll_timeout_atomic() for polling
remoteproc/mtk_scp: Remove timeout variable from scp_ipi_send()

drivers/remoteproc/mtk_scp_ipi.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)

--
2.39.0


Subject: [PATCH 1/2] remoteproc/mtk_scp: Use readl_poll_timeout_atomic() for polling

Convert the usage of an open-coded custom tight poll while loop
with the provided readl_poll_timeout_atomic() macro.

This cleanup brings no functional change.

Signed-off-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/remoteproc/mtk_scp_ipi.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/remoteproc/mtk_scp_ipi.c b/drivers/remoteproc/mtk_scp_ipi.c
index 4c0d121c2f54..af47504bdb61 100644
--- a/drivers/remoteproc/mtk_scp_ipi.c
+++ b/drivers/remoteproc/mtk_scp_ipi.c
@@ -6,13 +6,17 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
+#include <linux/time64.h>
#include <linux/remoteproc/mtk_scp.h>

#include "mtk_common.h"

+#define SCP_TIMEOUT_US (2000 * USEC_PER_MSEC)
+
/**
* scp_ipi_register() - register an ipi function
*
@@ -157,6 +161,7 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
{
struct mtk_share_obj __iomem *send_obj = scp->send_buf;
unsigned long timeout;
+ u32 val;
int ret;

if (WARN_ON(id <= SCP_IPI_INIT) || WARN_ON(id >= SCP_IPI_MAX) ||
@@ -173,14 +178,12 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
mutex_lock(&scp->send_lock);

/* Wait until SCP receives the last command */
- timeout = jiffies + msecs_to_jiffies(2000);
- do {
- if (time_after(jiffies, timeout)) {
- dev_err(scp->dev, "%s: IPI timeout!\n", __func__);
- ret = -ETIMEDOUT;
- goto unlock_mutex;
- }
- } while (readl(scp->reg_base + scp->data->host_to_scp_reg));
+ ret = readl_poll_timeout_atomic(scp->reg_base + scp->data->host_to_scp_reg,
+ val, !val, 0, SCP_TIMEOUT_US);
+ if (ret) {
+ dev_err(scp->dev, "%s: IPI timeout!\n", __func__);
+ goto unlock_mutex;
+ }

scp_memcpy_aligned(send_obj->share_buf, buf, len);

--
2.39.0

Subject: [PATCH 2/2] remoteproc/mtk_scp: Remove timeout variable from scp_ipi_send()

That variable was used twice, but now it's just used once to store
msecs_to_jiffies(wait), fed to wait_event_timeout(): we might as
well remove it for the sake of cleaning up.

This brings no functional changes.

Signed-off-by: AngeloGioacchino Del Regno <[email protected]>
---
drivers/remoteproc/mtk_scp_ipi.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/remoteproc/mtk_scp_ipi.c b/drivers/remoteproc/mtk_scp_ipi.c
index af47504bdb61..fc55df649b40 100644
--- a/drivers/remoteproc/mtk_scp_ipi.c
+++ b/drivers/remoteproc/mtk_scp_ipi.c
@@ -160,7 +160,6 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,
unsigned int wait)
{
struct mtk_share_obj __iomem *send_obj = scp->send_buf;
- unsigned long timeout;
u32 val;
int ret;

@@ -197,10 +196,9 @@ int scp_ipi_send(struct mtk_scp *scp, u32 id, void *buf, unsigned int len,

if (wait) {
/* wait for SCP's ACK */
- timeout = msecs_to_jiffies(wait);
ret = wait_event_timeout(scp->ack_wq,
scp->ipi_id_ack[id],
- timeout);
+ msecs_to_jiffies(wait));
scp->ipi_id_ack[id] = false;
if (WARN(!ret, "scp ipi %d ack time out !", id))
ret = -EIO;
--
2.39.0

2023-01-04 23:02:49

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH 0/2] MediaTek SCP IPI cleanups

On Wed, Jan 04, 2023 at 12:53:39PM +0100, AngeloGioacchino Del Regno wrote:
> Cleanups bringing no functional changes.
> Tested on MT8173 Elm, MT8192 Asurada, MT8195 Tomato.
>
> This series applies only on top of [1].
>
> [1]: https://lore.kernel.org/lkml/[email protected]/
>
> AngeloGioacchino Del Regno (2):
> remoteproc/mtk_scp: Use readl_poll_timeout_atomic() for polling
> remoteproc/mtk_scp: Remove timeout variable from scp_ipi_send()
>

I have applied both patches.

Thanks,
Mathieu

> drivers/remoteproc/mtk_scp_ipi.c | 23 ++++++++++++-----------
> 1 file changed, 12 insertions(+), 11 deletions(-)
>
> --
> 2.39.0
>