[PATCH 2/7] firmware: imx: scu: Support reception of messages of any size

Peng Fan peng.fan at nxp.com
Mon Jul 20 21:25:17 EDT 2020


> Subject: [PATCH 2/7] firmware: imx: scu: Support reception of messages of
> any size

Could fast_ipc be used for your case? I am not fans to use the legacy method
which is error prone.

Thanks,
Peng.

> 
> From: Franck LENORMAND <franck.lenormand at nxp.com>
> 
> The word of a message can arrive in any order and the current driver cannot
> receive more than 4-word message.
> 
> To fix this, a new variable rx_pos is added to imx_sc_chan structure to save
> the position at which the word receive must be stored.
> 
> The position is initialized by the index of the channel.
> 
> The position is incremented by SCU_MU_RX_CHAN_NUM each time a word
> is received on the channel.
> 
> This allow the words to be received in any order and be stored in the
> expected order.
> 
> Signed-off-by: Franck LENORMAND <franck.lenormand at oss.nxp.com>
> ---
>  drivers/firmware/imx/imx-scu.c | 21 +++++++++++++++------
>  1 file changed, 15 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/firmware/imx/imx-scu.c b/drivers/firmware/imx/imx-scu.c
> index 2ab0482..7c13595 100644
> --- a/drivers/firmware/imx/imx-scu.c
> +++ b/drivers/firmware/imx/imx-scu.c
> @@ -1,6 +1,6 @@
>  // SPDX-License-Identifier: GPL-2.0+
>  /*
> - * Copyright 2018 NXP
> + * Copyright 2018,2020 NXP
>   *  Author: Dong Aisheng <aisheng.dong at nxp.com>
>   *
>   * Implementation of the SCU IPC functions using MUs (client side).
> @@ -19,6 +19,8 @@
>  #include <linux/of_platform.h>
>  #include <linux/platform_device.h>
> 
> +#define SCU_MU_TX_CHAN_NUM		4
> +#define SCU_MU_RX_CHAN_NUM		4
>  #define SCU_MU_CHAN_NUM		8
>  #define MAX_RX_TIMEOUT		(msecs_to_jiffies(30))
> 
> @@ -29,6 +31,7 @@ struct imx_sc_chan {
>  	struct mbox_chan *ch;
>  	int idx;
>  	struct completion tx_done;
> +	u8 rx_pos;
>  };
> 
>  struct imx_sc_ipc {
> @@ -136,16 +139,14 @@ static void imx_scu_rx_callback(struct mbox_client
> *c, void *msg)
>  		return;
>  	}
> 
> -	if (sc_chan->idx == 0) {
> +	if (sc_chan->rx_pos == 0) {
>  		hdr = msg;
>  		sc_ipc->rx_size = hdr->size;
>  		dev_dbg(sc_ipc->dev, "msg rx size %u\n", sc_ipc->rx_size);
> -		if (sc_ipc->rx_size > 4)
> -			dev_warn(sc_ipc->dev, "RPC does not support receiving over 4
> words: %u\n",
> -				 sc_ipc->rx_size);
>  	}
> 
> -	sc_ipc->msg[sc_chan->idx] = *data;
> +	sc_ipc->msg[sc_chan->rx_pos] = *data;
> +	sc_chan->rx_pos += SCU_MU_RX_CHAN_NUM;
>  	sc_ipc->count++;
> 
>  	dev_dbg(sc_ipc->dev, "mu %u msg %u 0x%x\n", sc_chan->idx, @@
> -205,6 +206,7 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void *msg,
> bool have_resp)
>  	uint8_t saved_svc, saved_func;
>  	struct imx_sc_rpc_msg *hdr;
>  	int ret;
> +	int i;
> 
>  	if (WARN_ON(!sc_ipc || !msg))
>  		return -EINVAL;
> @@ -212,6 +214,13 @@ int imx_scu_call_rpc(struct imx_sc_ipc *sc_ipc, void
> *msg, bool have_resp)
>  	mutex_lock(&sc_ipc->lock);
>  	reinit_completion(&sc_ipc->done);
> 
> +	/* Set the indexes for the reception chans */
> +	for (i = SCU_MU_TX_CHAN_NUM; i < SCU_MU_CHAN_NUM; i++) {
> +		struct imx_sc_chan *sc_chan = &sc_ipc->chans[i];
> +
> +		sc_chan->rx_pos = sc_chan->idx;
> +	}
> +
>  	if (have_resp) {
>  		sc_ipc->msg = msg;
>  		saved_svc = ((struct imx_sc_rpc_msg *)msg)->svc;
> --
> 2.7.4




More information about the linux-arm-kernel mailing list