2022-10-14 03:55:33

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V7 0/7] remoteproc: imx_rproc: support i.MX8QM/QXP

From: Peng Fan <[email protected]>

V7:
patch 3/7: use dev_err, and R-b from Mathieu
patch 4/7: Add comment when "num_pd <= 1", add R-b from Mathieu
patch 5/7: Typo has->have, add R-b from Mathieu
patch 6/7: add detach hook to free the mbox. As wrote in the patch commit log,
imx_rproc_xtr_mbox_init is called both in probe and attach hook to resolve
mbox defer probe, so there is check in imx_rproc_xtr_mbox_init.
Moved imx_rproc_free_mbox out from parition notify to detach hook
patch 7/7: since detach hook moved to patch 6/7, so only enable recovery feature.

V6:
Two changes are made:
1.
In V5, patch 3 has a wrong logic in imx_rproc_put_scu, see [1], however
patch 4 fixed the wrong logic, as below:

- if (!imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
- return;
+ if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
+ return imx_rproc_detach_pd(rproc);

In V6, patch 3 fixed the wrong logic, drop the fix in patch 4. And patch 4
changed as below, because put scu not has return value.
imx_rproc_detach_pd(rproc);
return;

2. Include patch 7/7 to enable attach recovery, because the attach recovery
feature has been supported in remoteproc core.

[1] https://lore.kernel.org/linux-remoteproc/DU0PR04MB941763C3EBF8AE9A9CD69445884C9@DU0PR04MB9417.eurprd04.prod.outlook.com/T/#m87e2864260d0a1c431b577068ba79e1d64c595f1

V5:
The patchset could not apply on latest remoteproc for-next branch,
so rebased. Only patch 6 has a minor conflict, other patches are not
changed.

V4:
https://lore.kernel.org/all/[email protected]/
Add R-b from DT maintainer
Fix probe failure and driver remove path in patch 3, 4
Add comments about i.MX8QM entries filter in patch 5

V3:
Drop the dependency in V2.
Tested on i.MX8QM/8MM
Use 'fsl,resource-id' and 'fsl,entry-address' Per dt maintainer
Drop 'reg' property Per remoteproc maintainer
Drop mcore self recovery, until we land in common framework support.
https://patchwork.kernel.org/project/linux-remoteproc/cover/[email protected]/

V2:
https://patchwork.kernel.org/project/linux-remoteproc/cover/[email protected]/
Depends on https://patchwork.kernel.org/project/linux-remoteproc/list/?series=621311
Tested on i.MX8QXP/QM/8MP
Addressed Mathieu's comments
Drop V1 patch 5/9, patch 3/9 is replaced with upper dependency patchset
Move V1 patch 4/9 out to https://patchwork.kernel.org/project/linux-remoteproc/patch/[email protected]/
Update commit log
Drop magic number to get entry address from device tree in patch 4/6

The V1 patchset:
https://patchwork.kernel.org/project/linux-remoteproc/patch/[email protected]/

Peng Fan (7):
dt-bindings: remoteproc: imx_rproc: support i.MX8QXP
dt-bindings: remoteproc: imx_rproc: support i.MX8QM
remoteproc: imx_rproc: support attaching to i.MX8QXP M4
remoteproc: imx_rproc: support kicking Mcore from Linux for i.MX8QXP
remoteproc: imx_rproc: support i.MX8QM
remoteproc: imx_rproc: request mbox channel later
remoteproc: imx_rproc: Enable attach recovery for i.MX8QM/QXP

.../bindings/remoteproc/fsl,imx-rproc.yaml | 16 +
drivers/remoteproc/imx_rproc.c | 285 +++++++++++++++++-
2 files changed, 295 insertions(+), 6 deletions(-)

--
2.37.1


2022-10-14 04:18:39

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel later

From: Peng Fan <[email protected]>

It is possible that when remote processor crash, the communication
channel will be broken with garbage value in mailbox, such as
when Linux is issuing a message through mailbox, remote processor
crashes, we need free & rebuild the mailbox channels to make sure
no garbage value in mailbox channels.

So move the request/free to start/stop for managing remote procesosr in
Linux, move to attach/detach for remote processor is out of control of
Linux.

Previous, we just request mbox when attach for CM4 boot early before
Linux, but if mbox defer probe, remoteproc core will do resource cleanup
and corrupt resource table for later probe.

So move request mbox ealier and still keep mbox request when attach
for self recovery case, but keep a check when request/free mbox.

Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 39 ++++++++++++++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 917e6db39572..1183de84a4c0 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -84,6 +84,8 @@ struct imx_rproc_mem {
#define ATT_CORE_MASK 0xffff
#define ATT_CORE(I) BIT((I))

+static int imx_rproc_xtr_mbox_init(struct rproc *rproc);
+static void imx_rproc_free_mbox(struct rproc *rproc);
static int imx_rproc_detach_pd(struct rproc *rproc);

struct imx_rproc {
@@ -357,6 +359,10 @@ static int imx_rproc_start(struct rproc *rproc)
struct arm_smccc_res res;
int ret;

+ ret = imx_rproc_xtr_mbox_init(rproc);
+ if (ret)
+ return ret;
+
switch (dcfg->method) {
case IMX_RPROC_MMIO:
ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
@@ -407,6 +413,8 @@ static int imx_rproc_stop(struct rproc *rproc)

if (ret)
dev_err(dev, "Failed to stop remote core\n");
+ else
+ imx_rproc_free_mbox(rproc);

return ret;
}
@@ -592,6 +600,22 @@ static void imx_rproc_kick(struct rproc *rproc, int vqid)

static int imx_rproc_attach(struct rproc *rproc)
{
+ return imx_rproc_xtr_mbox_init(rproc);
+}
+
+static int imx_rproc_detach(struct rproc *rproc)
+{
+ struct imx_rproc *priv = rproc->priv;
+ const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+
+ if (dcfg->method != IMX_RPROC_SCU_API)
+ return -EOPNOTSUPP;
+
+ if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
+ return -EOPNOTSUPP;
+
+ imx_rproc_free_mbox(rproc);
+
return 0;
}

@@ -610,6 +634,7 @@ static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc
static const struct rproc_ops imx_rproc_ops = {
.prepare = imx_rproc_prepare,
.attach = imx_rproc_attach,
+ .detach = imx_rproc_detach,
.start = imx_rproc_start,
.stop = imx_rproc_stop,
.kick = imx_rproc_kick,
@@ -720,6 +745,9 @@ static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
struct device *dev = priv->dev;
struct mbox_client *cl;

+ if (priv->tx_ch && priv->rx_ch)
+ return 0;
+
if (!of_get_property(dev->of_node, "mbox-names", NULL))
return 0;

@@ -749,8 +777,15 @@ static void imx_rproc_free_mbox(struct rproc *rproc)
{
struct imx_rproc *priv = rproc->priv;

- mbox_free_channel(priv->tx_ch);
- mbox_free_channel(priv->rx_ch);
+ if (priv->tx_ch) {
+ mbox_free_channel(priv->tx_ch);
+ priv->tx_ch = NULL;
+ }
+
+ if (priv->rx_ch) {
+ mbox_free_channel(priv->rx_ch);
+ priv->rx_ch = NULL;
+ }
}

static void imx_rproc_put_scu(struct rproc *rproc)
--
2.37.1

2022-10-14 04:23:05

by Peng Fan (OSS)

[permalink] [raw]
Subject: [PATCH V7 5/7] remoteproc: imx_rproc: support i.MX8QM

From: Peng Fan <[email protected]>

Most logic are same as i.MX8QXP, but i.MX8QM has two general purpose
M4 cores, the two cores runs independently and they have different resource
id, different start address from SCFW view.

Reviewed-by: Mathieu Poirier <[email protected]>
Signed-off-by: Peng Fan <[email protected]>
---
drivers/remoteproc/imx_rproc.c | 47 +++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index 372cb4a346b0..917e6db39572 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -3,6 +3,7 @@
* Copyright (c) 2017 Pengutronix, Oleksij Rempel <[email protected]>
*/

+#include <dt-bindings/firmware/imx/rsrc.h>
#include <linux/arm-smccc.h>
#include <linux/clk.h>
#include <linux/err.h>
@@ -75,10 +76,13 @@ struct imx_rproc_mem {
size_t size;
};

-/* att flags */
+/* att flags: lower 16 bits specifying core, higher 16 bits for flags */
/* M4 own area. Can be mapped at probe */
-#define ATT_OWN BIT(1)
-#define ATT_IOMEM BIT(2)
+#define ATT_OWN BIT(31)
+#define ATT_IOMEM BIT(30)
+
+#define ATT_CORE_MASK 0xffff
+#define ATT_CORE(I) BIT((I))

static int imx_rproc_detach_pd(struct rproc *rproc);

@@ -101,6 +105,7 @@ struct imx_rproc {
u32 rsrc_id; /* resource id */
u32 entry; /* cpu start address */
int num_pd;
+ u32 core_index;
struct device **pd_dev;
struct device_link **pd_dev_link;
};
@@ -131,6 +136,19 @@ static const struct imx_rproc_att imx_rproc_att_imx93[] = {
{ 0xD0000000, 0xa0000000, 0x10000000, 0 },
};

+static const struct imx_rproc_att imx_rproc_att_imx8qm[] = {
+ /* dev addr , sys addr , size , flags */
+ { 0x08000000, 0x08000000, 0x10000000, 0},
+ /* TCML */
+ { 0x1FFE0000, 0x34FE0000, 0x00020000, ATT_OWN | ATT_IOMEM | ATT_CORE(0)},
+ { 0x1FFE0000, 0x38FE0000, 0x00020000, ATT_OWN | ATT_IOMEM | ATT_CORE(1)},
+ /* TCMU */
+ { 0x20000000, 0x35000000, 0x00020000, ATT_OWN | ATT_IOMEM | ATT_CORE(0)},
+ { 0x20000000, 0x39000000, 0x00020000, ATT_OWN | ATT_IOMEM | ATT_CORE(1)},
+ /* DDR (Data) */
+ { 0x80000000, 0x80000000, 0x60000000, 0 },
+};
+
static const struct imx_rproc_att imx_rproc_att_imx8qxp[] = {
{ 0x08000000, 0x08000000, 0x10000000, 0 },
/* TCML/U */
@@ -281,6 +299,12 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mq = {
.method = IMX_RPROC_MMIO,
};

+static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qm = {
+ .att = imx_rproc_att_imx8qm,
+ .att_size = ARRAY_SIZE(imx_rproc_att_imx8qm),
+ .method = IMX_RPROC_SCU_API,
+};
+
static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qxp = {
.att = imx_rproc_att_imx8qxp,
.att_size = ARRAY_SIZE(imx_rproc_att_imx8qxp),
@@ -397,6 +421,17 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da,
for (i = 0; i < dcfg->att_size; i++) {
const struct imx_rproc_att *att = &dcfg->att[i];

+ /*
+ * Ignore entries not belong to current core:
+ * i.MX8QM has dual general M4_[0,1] cores, M4_0's own entries
+ * has "ATT_CORE(0) & BIT(0)" true, M4_1's own entries has
+ * "ATT_CORE(1) & BIT(1)" true.
+ */
+ if (att->flags & ATT_CORE_MASK) {
+ if (!((BIT(priv->core_index)) & (att->flags & ATT_CORE_MASK)))
+ continue;
+ }
+
if (da >= att->da && da + len < att->da + att->size) {
unsigned int offset = da - att->da;

@@ -852,6 +887,11 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
return ret;
}

+ if (priv->rsrc_id == IMX_SC_R_M4_1_PID0)
+ priv->core_index = 1;
+ else
+ priv->core_index = 0;
+
/*
* If Mcore resource is not owned by Acore partition, It is kicked by ROM,
* and Linux could only do IPC with Mcore and nothing else.
@@ -1048,6 +1088,7 @@ static const struct of_device_id imx_rproc_of_match[] = {
{ .compatible = "fsl,imx8mn-cm7", .data = &imx_rproc_cfg_imx8mn },
{ .compatible = "fsl,imx8mp-cm7", .data = &imx_rproc_cfg_imx8mn },
{ .compatible = "fsl,imx8qxp-cm4", .data = &imx_rproc_cfg_imx8qxp },
+ { .compatible = "fsl,imx8qm-cm4", .data = &imx_rproc_cfg_imx8qm },
{ .compatible = "fsl,imx8ulp-cm33", .data = &imx_rproc_cfg_imx8ulp },
{ .compatible = "fsl,imx93-cm33", .data = &imx_rproc_cfg_imx93 },
{},
--
2.37.1

2022-10-14 18:07:32

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel later

On Fri, Oct 14, 2022 at 11:10:36AM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <[email protected]>
>
> It is possible that when remote processor crash, the communication
> channel will be broken with garbage value in mailbox, such as
> when Linux is issuing a message through mailbox, remote processor
> crashes, we need free & rebuild the mailbox channels to make sure
> no garbage value in mailbox channels.
>
> So move the request/free to start/stop for managing remote procesosr in
> Linux, move to attach/detach for remote processor is out of control of
> Linux.
>
> Previous, we just request mbox when attach for CM4 boot early before
> Linux, but if mbox defer probe, remoteproc core will do resource cleanup
> and corrupt resource table for later probe.
>
> So move request mbox ealier and still keep mbox request when attach
> for self recovery case, but keep a check when request/free mbox.
>
> Signed-off-by: Peng Fan <[email protected]>
> ---
> drivers/remoteproc/imx_rproc.c | 39 ++++++++++++++++++++++++++++++++--
> 1 file changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index 917e6db39572..1183de84a4c0 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -84,6 +84,8 @@ struct imx_rproc_mem {
> #define ATT_CORE_MASK 0xffff
> #define ATT_CORE(I) BIT((I))
>
> +static int imx_rproc_xtr_mbox_init(struct rproc *rproc);
> +static void imx_rproc_free_mbox(struct rproc *rproc);
> static int imx_rproc_detach_pd(struct rproc *rproc);
>
> struct imx_rproc {
> @@ -357,6 +359,10 @@ static int imx_rproc_start(struct rproc *rproc)
> struct arm_smccc_res res;
> int ret;
>
> + ret = imx_rproc_xtr_mbox_init(rproc);
> + if (ret)
> + return ret;
> +
> switch (dcfg->method) {
> case IMX_RPROC_MMIO:
> ret = regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask,
> @@ -407,6 +413,8 @@ static int imx_rproc_stop(struct rproc *rproc)
>
> if (ret)
> dev_err(dev, "Failed to stop remote core\n");
> + else
> + imx_rproc_free_mbox(rproc);
>
> return ret;
> }
> @@ -592,6 +600,22 @@ static void imx_rproc_kick(struct rproc *rproc, int vqid)
>
> static int imx_rproc_attach(struct rproc *rproc)
> {
> + return imx_rproc_xtr_mbox_init(rproc);
> +}
> +
> +static int imx_rproc_detach(struct rproc *rproc)
> +{
> + struct imx_rproc *priv = rproc->priv;
> + const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> +
> + if (dcfg->method != IMX_RPROC_SCU_API)
> + return -EOPNOTSUPP;
> +
> + if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
> + return -EOPNOTSUPP;
> +
> + imx_rproc_free_mbox(rproc);
> +
> return 0;
> }
>
> @@ -610,6 +634,7 @@ static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc
> static const struct rproc_ops imx_rproc_ops = {
> .prepare = imx_rproc_prepare,
> .attach = imx_rproc_attach,
> + .detach = imx_rproc_detach,
> .start = imx_rproc_start,
> .stop = imx_rproc_stop,
> .kick = imx_rproc_kick,
> @@ -720,6 +745,9 @@ static int imx_rproc_xtr_mbox_init(struct rproc *rproc)
> struct device *dev = priv->dev;
> struct mbox_client *cl;
>
> + if (priv->tx_ch && priv->rx_ch)
> + return 0;
> +

You did exactly the same things as in V6. I asked you why this is needed and
all you did is point me to the code in _probe(), which I can read on my own.

Again - why is this needed when we know it will be done in start() and attach()?


> if (!of_get_property(dev->of_node, "mbox-names", NULL))
> return 0;
>
> @@ -749,8 +777,15 @@ static void imx_rproc_free_mbox(struct rproc *rproc)
> {
> struct imx_rproc *priv = rproc->priv;
>
> - mbox_free_channel(priv->tx_ch);
> - mbox_free_channel(priv->rx_ch);
> + if (priv->tx_ch) {
> + mbox_free_channel(priv->tx_ch);
> + priv->tx_ch = NULL;
> + }
> +
> + if (priv->rx_ch) {
> + mbox_free_channel(priv->rx_ch);
> + priv->rx_ch = NULL;
> + }
> }
>
> static void imx_rproc_put_scu(struct rproc *rproc)
> --
> 2.37.1
>

2022-10-17 03:23:53

by Peng Fan

[permalink] [raw]
Subject: RE: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel later

Hi Mathieu,

> Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel
> later
>
> On Fri, Oct 14, 2022 at 11:10:36AM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <[email protected]>
> >
> > It is possible that when remote processor crash, the communication
> > channel will be broken with garbage value in mailbox, such as when
> > Linux is issuing a message through mailbox, remote processor crashes,
> > we need free & rebuild the mailbox channels to make sure no garbage
> > value in mailbox channels.
> >
> > So move the request/free to start/stop for managing remote procesosr
> > in Linux, move to attach/detach for remote processor is out of control
> > of Linux.
> >
> > Previous, we just request mbox when attach for CM4 boot early before
> > Linux, but if mbox defer probe, remoteproc core will do resource
> > cleanup and corrupt resource table for later probe.
> >
> > So move request mbox ealier and still keep mbox request when attach
> > for self recovery case, but keep a check when request/free mbox.
> >
> > Signed-off-by: Peng Fan <[email protected]>
> > ---
> > drivers/remoteproc/imx_rproc.c | 39
> > ++++++++++++++++++++++++++++++++--
> > 1 file changed, 37 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index 917e6db39572..1183de84a4c0
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -84,6 +84,8 @@ struct imx_rproc_mem {
> > #define ATT_CORE_MASK 0xffff
> > #define ATT_CORE(I) BIT((I))
> >
> > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc); static void
> > +imx_rproc_free_mbox(struct rproc *rproc);
> > static int imx_rproc_detach_pd(struct rproc *rproc);
> >
> > struct imx_rproc {
> > @@ -357,6 +359,10 @@ static int imx_rproc_start(struct rproc *rproc)
> > struct arm_smccc_res res;
> > int ret;
> >
> > + ret = imx_rproc_xtr_mbox_init(rproc);
> > + if (ret)
> > + return ret;
> > +
> > switch (dcfg->method) {
> > case IMX_RPROC_MMIO:
> > ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> > dcfg->src_mask, @@ -407,6 +413,8 @@ static int imx_rproc_stop(struct
> > rproc *rproc)
> >
> > if (ret)
> > dev_err(dev, "Failed to stop remote core\n");
> > + else
> > + imx_rproc_free_mbox(rproc);
> >
> > return ret;
> > }
> > @@ -592,6 +600,22 @@ static void imx_rproc_kick(struct rproc *rproc,
> > int vqid)
> >
> > static int imx_rproc_attach(struct rproc *rproc) {
> > + return imx_rproc_xtr_mbox_init(rproc); }
> > +
> > +static int imx_rproc_detach(struct rproc *rproc) {
> > + struct imx_rproc *priv = rproc->priv;
> > + const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > +
> > + if (dcfg->method != IMX_RPROC_SCU_API)
> > + return -EOPNOTSUPP;
> > +
> > + if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
> > + return -EOPNOTSUPP;
> > +
> > + imx_rproc_free_mbox(rproc);
> > +
> > return 0;
> > }
> >
> > @@ -610,6 +634,7 @@ static struct resource_table
> > *imx_rproc_get_loaded_rsc_table(struct rproc *rproc static const struct
> rproc_ops imx_rproc_ops = {
> > .prepare = imx_rproc_prepare,
> > .attach = imx_rproc_attach,
> > + .detach = imx_rproc_detach,
> > .start = imx_rproc_start,
> > .stop = imx_rproc_stop,
> > .kick = imx_rproc_kick,
> > @@ -720,6 +745,9 @@ static int imx_rproc_xtr_mbox_init(struct rproc
> *rproc)
> > struct device *dev = priv->dev;
> > struct mbox_client *cl;
> >
> > + if (priv->tx_ch && priv->rx_ch)
> > + return 0;
> > +
>
> You did exactly the same things as in V6. I asked you why this is needed and
> all you did is point me to the code in _probe(), which I can read on my own.
>

Sorry for not wrote down clear.

> Again - why is this needed when we know it will be done in start() and
> attach()?

start() and attach() not able to handle mbox defer probe. So I add
the mbox requesting in probe to handle mbox defer probe, and add
a check when requesting mbox channel in start/attach. During first
time attach/start remote core, the imx_rproc_xtr_mbox_init just
return, because channel requested in probe flow.

Since mbox requested in probe, why still add it in start() and attach()?
It is to support runtime stop and start(M4 is under control of Linux),
to support runtime detach(only for i.MX8QM/QXP attach recovery,
m4 out of control from linux) and attach.

Thanks,
Peng.
>
>
> > if (!of_get_property(dev->of_node, "mbox-names", NULL))
> > return 0;
> >
> > @@ -749,8 +777,15 @@ static void imx_rproc_free_mbox(struct rproc
> > *rproc) {
> > struct imx_rproc *priv = rproc->priv;
> >
> > - mbox_free_channel(priv->tx_ch);
> > - mbox_free_channel(priv->rx_ch);
> > + if (priv->tx_ch) {
> > + mbox_free_channel(priv->tx_ch);
> > + priv->tx_ch = NULL;
> > + }
> > +
> > + if (priv->rx_ch) {
> > + mbox_free_channel(priv->rx_ch);
> > + priv->rx_ch = NULL;
> > + }
> > }
> >
> > static void imx_rproc_put_scu(struct rproc *rproc)
> > --
> > 2.37.1
> >

2022-10-17 18:44:20

by Mathieu Poirier

[permalink] [raw]
Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel later

On Mon, Oct 17, 2022 at 03:13:16AM +0000, Peng Fan wrote:
> Hi Mathieu,
>
> > Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel
> > later
> >
> > On Fri, Oct 14, 2022 at 11:10:36AM +0800, Peng Fan (OSS) wrote:
> > > From: Peng Fan <[email protected]>
> > >
> > > It is possible that when remote processor crash, the communication
> > > channel will be broken with garbage value in mailbox, such as when
> > > Linux is issuing a message through mailbox, remote processor crashes,
> > > we need free & rebuild the mailbox channels to make sure no garbage
> > > value in mailbox channels.
> > >
> > > So move the request/free to start/stop for managing remote procesosr
> > > in Linux, move to attach/detach for remote processor is out of control
> > > of Linux.
> > >
> > > Previous, we just request mbox when attach for CM4 boot early before
> > > Linux, but if mbox defer probe, remoteproc core will do resource
> > > cleanup and corrupt resource table for later probe.
> > >
> > > So move request mbox ealier and still keep mbox request when attach
> > > for self recovery case, but keep a check when request/free mbox.
> > >
> > > Signed-off-by: Peng Fan <[email protected]>
> > > ---
> > > drivers/remoteproc/imx_rproc.c | 39
> > > ++++++++++++++++++++++++++++++++--
> > > 1 file changed, 37 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > b/drivers/remoteproc/imx_rproc.c index 917e6db39572..1183de84a4c0
> > > 100644
> > > --- a/drivers/remoteproc/imx_rproc.c
> > > +++ b/drivers/remoteproc/imx_rproc.c
> > > @@ -84,6 +84,8 @@ struct imx_rproc_mem {
> > > #define ATT_CORE_MASK 0xffff
> > > #define ATT_CORE(I) BIT((I))
> > >
> > > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc); static void
> > > +imx_rproc_free_mbox(struct rproc *rproc);
> > > static int imx_rproc_detach_pd(struct rproc *rproc);
> > >
> > > struct imx_rproc {
> > > @@ -357,6 +359,10 @@ static int imx_rproc_start(struct rproc *rproc)
> > > struct arm_smccc_res res;
> > > int ret;
> > >
> > > + ret = imx_rproc_xtr_mbox_init(rproc);
> > > + if (ret)
> > > + return ret;
> > > +
> > > switch (dcfg->method) {
> > > case IMX_RPROC_MMIO:
> > > ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> > > dcfg->src_mask, @@ -407,6 +413,8 @@ static int imx_rproc_stop(struct
> > > rproc *rproc)
> > >
> > > if (ret)
> > > dev_err(dev, "Failed to stop remote core\n");
> > > + else
> > > + imx_rproc_free_mbox(rproc);
> > >
> > > return ret;
> > > }
> > > @@ -592,6 +600,22 @@ static void imx_rproc_kick(struct rproc *rproc,
> > > int vqid)
> > >
> > > static int imx_rproc_attach(struct rproc *rproc) {
> > > + return imx_rproc_xtr_mbox_init(rproc); }
> > > +
> > > +static int imx_rproc_detach(struct rproc *rproc) {
> > > + struct imx_rproc *priv = rproc->priv;
> > > + const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > > +
> > > + if (dcfg->method != IMX_RPROC_SCU_API)
> > > + return -EOPNOTSUPP;
> > > +
> > > + if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
> > > + return -EOPNOTSUPP;
> > > +
> > > + imx_rproc_free_mbox(rproc);
> > > +
> > > return 0;
> > > }
> > >
> > > @@ -610,6 +634,7 @@ static struct resource_table
> > > *imx_rproc_get_loaded_rsc_table(struct rproc *rproc static const struct
> > rproc_ops imx_rproc_ops = {
> > > .prepare = imx_rproc_prepare,
> > > .attach = imx_rproc_attach,
> > > + .detach = imx_rproc_detach,
> > > .start = imx_rproc_start,
> > > .stop = imx_rproc_stop,
> > > .kick = imx_rproc_kick,
> > > @@ -720,6 +745,9 @@ static int imx_rproc_xtr_mbox_init(struct rproc
> > *rproc)
> > > struct device *dev = priv->dev;
> > > struct mbox_client *cl;
> > >
> > > + if (priv->tx_ch && priv->rx_ch)
> > > + return 0;
> > > +
> >
> > You did exactly the same things as in V6. I asked you why this is needed and
> > all you did is point me to the code in _probe(), which I can read on my own.
> >
>
> Sorry for not wrote down clear.
>
> > Again - why is this needed when we know it will be done in start() and
> > attach()?
>
> start() and attach() not able to handle mbox defer probe. So I add

We are finally at the heart of the problem. I had to go look at the
implementation of imx_rproc_xtr_mbox_init() to understand that it can return
-EPROBE_DEFER. Had there been a comment in the code to highlight _why_ the if()
condition is needed, I would have understood right away and all this waste of
time avoided.

> the mbox requesting in probe to handle mbox defer probe, and add
> a check when requesting mbox channel in start/attach. During first
> time attach/start remote core, the imx_rproc_xtr_mbox_init just
> return, because channel requested in probe flow.
>
> Since mbox requested in probe, why still add it in start() and attach()?
> It is to support runtime stop and start(M4 is under control of Linux),
> to support runtime detach(only for i.MX8QM/QXP attach recovery,
> m4 out of control from linux) and attach.
>
> Thanks,
> Peng.
> >
> >
> > > if (!of_get_property(dev->of_node, "mbox-names", NULL))
> > > return 0;
> > >
> > > @@ -749,8 +777,15 @@ static void imx_rproc_free_mbox(struct rproc
> > > *rproc) {
> > > struct imx_rproc *priv = rproc->priv;
> > >
> > > - mbox_free_channel(priv->tx_ch);
> > > - mbox_free_channel(priv->rx_ch);
> > > + if (priv->tx_ch) {
> > > + mbox_free_channel(priv->tx_ch);
> > > + priv->tx_ch = NULL;
> > > + }
> > > +
> > > + if (priv->rx_ch) {
> > > + mbox_free_channel(priv->rx_ch);
> > > + priv->rx_ch = NULL;
> > > + }
> > > }
> > >
> > > static void imx_rproc_put_scu(struct rproc *rproc)
> > > --
> > > 2.37.1
> > >

2022-10-18 07:11:56

by Peng Fan

[permalink] [raw]
Subject: RE: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel later

> Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox channel
> later
>
> On Mon, Oct 17, 2022 at 03:13:16AM +0000, Peng Fan wrote:
> > Hi Mathieu,
> >
> > > Subject: Re: [PATCH V7 6/7] remoteproc: imx_rproc: request mbox
> > > channel later
> > >
> > > On Fri, Oct 14, 2022 at 11:10:36AM +0800, Peng Fan (OSS) wrote:
> > > > From: Peng Fan <[email protected]>
> > > >
> > > > It is possible that when remote processor crash, the communication
> > > > channel will be broken with garbage value in mailbox, such as when
> > > > Linux is issuing a message through mailbox, remote processor
> > > > crashes, we need free & rebuild the mailbox channels to make sure
> > > > no garbage value in mailbox channels.
> > > >
> > > > So move the request/free to start/stop for managing remote
> > > > procesosr in Linux, move to attach/detach for remote processor is
> > > > out of control of Linux.
> > > >
> > > > Previous, we just request mbox when attach for CM4 boot early
> > > > before Linux, but if mbox defer probe, remoteproc core will do
> > > > resource cleanup and corrupt resource table for later probe.
> > > >
> > > > So move request mbox ealier and still keep mbox request when
> > > > attach for self recovery case, but keep a check when request/free
> mbox.
> > > >
> > > > Signed-off-by: Peng Fan <[email protected]>
> > > > ---
> > > > drivers/remoteproc/imx_rproc.c | 39
> > > > ++++++++++++++++++++++++++++++++--
> > > > 1 file changed, 37 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/drivers/remoteproc/imx_rproc.c
> > > > b/drivers/remoteproc/imx_rproc.c index
> 917e6db39572..1183de84a4c0
> > > > 100644
> > > > --- a/drivers/remoteproc/imx_rproc.c
> > > > +++ b/drivers/remoteproc/imx_rproc.c
> > > > @@ -84,6 +84,8 @@ struct imx_rproc_mem {
> > > > #define ATT_CORE_MASK 0xffff
> > > > #define ATT_CORE(I) BIT((I))
> > > >
> > > > +static int imx_rproc_xtr_mbox_init(struct rproc *rproc); static
> > > > +void imx_rproc_free_mbox(struct rproc *rproc);
> > > > static int imx_rproc_detach_pd(struct rproc *rproc);
> > > >
> > > > struct imx_rproc {
> > > > @@ -357,6 +359,10 @@ static int imx_rproc_start(struct rproc *rproc)
> > > > struct arm_smccc_res res;
> > > > int ret;
> > > >
> > > > + ret = imx_rproc_xtr_mbox_init(rproc);
> > > > + if (ret)
> > > > + return ret;
> > > > +
> > > > switch (dcfg->method) {
> > > > case IMX_RPROC_MMIO:
> > > > ret = regmap_update_bits(priv->regmap, dcfg->src_reg,
> > > > dcfg->src_mask, @@ -407,6 +413,8 @@ static int
> > > > dcfg->imx_rproc_stop(struct
> > > > rproc *rproc)
> > > >
> > > > if (ret)
> > > > dev_err(dev, "Failed to stop remote core\n");
> > > > + else
> > > > + imx_rproc_free_mbox(rproc);
> > > >
> > > > return ret;
> > > > }
> > > > @@ -592,6 +600,22 @@ static void imx_rproc_kick(struct rproc
> > > > *rproc, int vqid)
> > > >
> > > > static int imx_rproc_attach(struct rproc *rproc) {
> > > > + return imx_rproc_xtr_mbox_init(rproc); }
> > > > +
> > > > +static int imx_rproc_detach(struct rproc *rproc) {
> > > > + struct imx_rproc *priv = rproc->priv;
> > > > + const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> > > > +
> > > > + if (dcfg->method != IMX_RPROC_SCU_API)
> > > > + return -EOPNOTSUPP;
> > > > +
> > > > + if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id))
> > > > + return -EOPNOTSUPP;
> > > > +
> > > > + imx_rproc_free_mbox(rproc);
> > > > +
> > > > return 0;
> > > > }
> > > >
> > > > @@ -610,6 +634,7 @@ static struct resource_table
> > > > *imx_rproc_get_loaded_rsc_table(struct rproc *rproc static const
> > > > struct
> > > rproc_ops imx_rproc_ops = {
> > > > .prepare = imx_rproc_prepare,
> > > > .attach = imx_rproc_attach,
> > > > + .detach = imx_rproc_detach,
> > > > .start = imx_rproc_start,
> > > > .stop = imx_rproc_stop,
> > > > .kick = imx_rproc_kick,
> > > > @@ -720,6 +745,9 @@ static int imx_rproc_xtr_mbox_init(struct
> > > > rproc
> > > *rproc)
> > > > struct device *dev = priv->dev;
> > > > struct mbox_client *cl;
> > > >
> > > > + if (priv->tx_ch && priv->rx_ch)
> > > > + return 0;
> > > > +
> > >
> > > You did exactly the same things as in V6. I asked you why this is
> > > needed and all you did is point me to the code in _probe(), which I can
> read on my own.
> > >
> >
> > Sorry for not wrote down clear.
> >
> > > Again - why is this needed when we know it will be done in start()
> > > and attach()?
> >
> > start() and attach() not able to handle mbox defer probe. So I add
>
> We are finally at the heart of the problem. I had to go look at the
> implementation of imx_rproc_xtr_mbox_init() to understand that it can
> return -EPROBE_DEFER. Had there been a comment in the code to highlight
> _why_ the if() condition is needed, I would have understood right away and
> all this waste of time avoided.

My bad. I could add comment in V8 if no major comments after you review.
Thanks for your time.

Thanks,
Peng.
>
> > the mbox requesting in probe to handle mbox defer probe, and add a
> > check when requesting mbox channel in start/attach. During first time
> > attach/start remote core, the imx_rproc_xtr_mbox_init just return,
> > because channel requested in probe flow.
> >
> > Since mbox requested in probe, why still add it in start() and attach()?
> > It is to support runtime stop and start(M4 is under control of Linux),
> > to support runtime detach(only for i.MX8QM/QXP attach recovery,
> > m4 out of control from linux) and attach.
> >
> > Thanks,
> > Peng.
> > >
> > >
> > > > if (!of_get_property(dev->of_node, "mbox-names", NULL))
> > > > return 0;
> > > >
> > > > @@ -749,8 +777,15 @@ static void imx_rproc_free_mbox(struct rproc
> > > > *rproc) {
> > > > struct imx_rproc *priv = rproc->priv;
> > > >
> > > > - mbox_free_channel(priv->tx_ch);
> > > > - mbox_free_channel(priv->rx_ch);
> > > > + if (priv->tx_ch) {
> > > > + mbox_free_channel(priv->tx_ch);
> > > > + priv->tx_ch = NULL;
> > > > + }
> > > > +
> > > > + if (priv->rx_ch) {
> > > > + mbox_free_channel(priv->rx_ch);
> > > > + priv->rx_ch = NULL;
> > > > + }
> > > > }
> > > >
> > > > static void imx_rproc_put_scu(struct rproc *rproc)
> > > > --
> > > > 2.37.1
> > > >