diff mbox series

[V6,7/7] remoteproc: imx_rproc: Enable attach recovery for i.MX8QM/QXP

Message ID 20220929061704.1571746-8-peng.fan@oss.nxp.com (mailing list archive)
State New, archived
Headers show
Series remoteproc: imx_rproc: support i.MX8QM/QXP | expand

Commit Message

Peng Fan (OSS) Sept. 29, 2022, 6:17 a.m. UTC
From: Peng Fan <peng.fan@nxp.com>

i.MX8QM/QXP M4 could recover without help from Linux, so to support it:
 - enable feature RPROC_FEAT_ATTACH_ON_RECOVERY
 - add detach hook
 - Since we have detach callback, we could move the free mbox operation
 from partition reset notify to detach callback.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/remoteproc/imx_rproc.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

Comments

Peng Fan (OSS) Sept. 29, 2022, 11:20 p.m. UTC | #1
Hi Mathieu,

This patch is an incremental patch that could ignored, if you not have 
time or think this patch is not in good shape. Patch 1-6 is
to achieve same as V5 patchset [1].

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

Thanks,
Peng.
On 9/29/2022 2:17 PM, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> i.MX8QM/QXP M4 could recover without help from Linux, so to support it:
>   - enable feature RPROC_FEAT_ATTACH_ON_RECOVERY
>   - add detach hook
>   - Since we have detach callback, we could move the free mbox operation
>   from partition reset notify to detach callback.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>   drivers/remoteproc/imx_rproc.c | 22 +++++++++++++++++++---
>   1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index bece44b46719..4057d6f33813 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -603,6 +603,22 @@ 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;
> +}
> +
>   static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz)
>   {
>   	struct imx_rproc *priv = rproc->priv;
> @@ -618,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,
> @@ -797,8 +814,6 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
>   	if (!((event & BIT(priv->rproc_pt)) && (*(u8 *)group == IMX_SC_IRQ_GROUP_REBOOTED)))
>   		return 0;
>   
> -	imx_rproc_free_mbox(priv->rproc);
> -
>   	rproc_report_crash(priv->rproc, RPROC_WATCHDOG);
>   
>   	pr_info("Partition%d reset!\n", priv->rproc_pt);
> @@ -916,7 +931,8 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
>   		}
>   
>   		priv->rproc->state = RPROC_DETACHED;
> -		priv->rproc->recovery_disabled = true;
> +		priv->rproc->recovery_disabled = false;
> +		rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
>   
>   		/* Get partition id and enable irq in SCFW */
>   		ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
Mathieu Poirier Oct. 12, 2022, 10:32 p.m. UTC | #2
On Thu, Sep 29, 2022 at 02:17:04PM +0800, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> i.MX8QM/QXP M4 could recover without help from Linux, so to support it:
>  - enable feature RPROC_FEAT_ATTACH_ON_RECOVERY
>  - add detach hook
>  - Since we have detach callback, we could move the free mbox operation
>  from partition reset notify to detach callback.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  drivers/remoteproc/imx_rproc.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index bece44b46719..4057d6f33813 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -603,6 +603,22 @@ 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);

Which is exactly what you did here.

I really don't understand what you did in patch 6/7...  Anyways, I suggest to
add support for the detached scenario and then fix the mailbox corruption
problem.

I am done reviewing this set.

> +
> +	return 0;
> +}
> +
>  static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz)
>  {
>  	struct imx_rproc *priv = rproc->priv;
> @@ -618,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,
> @@ -797,8 +814,6 @@ static int imx_rproc_partition_notify(struct notifier_block *nb,
>  	if (!((event & BIT(priv->rproc_pt)) && (*(u8 *)group == IMX_SC_IRQ_GROUP_REBOOTED)))
>  		return 0;
>  
> -	imx_rproc_free_mbox(priv->rproc);
> -
>  	rproc_report_crash(priv->rproc, RPROC_WATCHDOG);
>  
>  	pr_info("Partition%d reset!\n", priv->rproc_pt);
> @@ -916,7 +931,8 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
>  		}
>  
>  		priv->rproc->state = RPROC_DETACHED;
> -		priv->rproc->recovery_disabled = true;
> +		priv->rproc->recovery_disabled = false;
> +		rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
>  
>  		/* Get partition id and enable irq in SCFW */
>  		ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
> -- 
> 2.37.1
>
Peng Fan Oct. 13, 2022, 1:11 p.m. UTC | #3
Hi Mathieu,

> Subject: Re: [PATCH V6 7/7] remoteproc: imx_rproc: Enable attach recovery
> for i.MX8QM/QXP
> 
> On Thu, Sep 29, 2022 at 02:17:04PM +0800, Peng Fan (OSS) wrote:
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > i.MX8QM/QXP M4 could recover without help from Linux, so to support it:
> >  - enable feature RPROC_FEAT_ATTACH_ON_RECOVERY
> >  - add detach hook
> >  - Since we have detach callback, we could move the free mbox
> > operation  from partition reset notify to detach callback.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  drivers/remoteproc/imx_rproc.c | 22 +++++++++++++++++++---
> >  1 file changed, 19 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/remoteproc/imx_rproc.c
> > b/drivers/remoteproc/imx_rproc.c index bece44b46719..4057d6f33813
> > 100644
> > --- a/drivers/remoteproc/imx_rproc.c
> > +++ b/drivers/remoteproc/imx_rproc.c
> > @@ -603,6 +603,22 @@ 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);
> 
> Which is exactly what you did here.
> 
> I really don't understand what you did in patch 6/7...  Anyways, I suggest to
> add support for the detached scenario and then fix the mailbox corruption
> problem.

When CM4 doing attach recovery, the mbox channel needs to be released,
then attach function will request the mbox channel again.

So the flow is 
CM4(attach->request mbox)->CM4 crash notify Linux[1]->Linux got notification
->Linux detach(release mbox)[2]->Linux re-attach(request mbox)

Since patch 7/7 is to support attach recovery, so I move mbox free
from [1] to [2].

> 
> I am done reviewing this set.

Thanks for your time.

Thanks,
Peng.
> 
> > +
> > +	return 0;
> > +}
> > +
> >  static struct resource_table *imx_rproc_get_loaded_rsc_table(struct
> > rproc *rproc, size_t *table_sz)  {
> >  	struct imx_rproc *priv = rproc->priv; @@ -618,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,
> > @@ -797,8 +814,6 @@ static int imx_rproc_partition_notify(struct
> notifier_block *nb,
> >  	if (!((event & BIT(priv->rproc_pt)) && (*(u8 *)group ==
> IMX_SC_IRQ_GROUP_REBOOTED)))
> >  		return 0;
> >
> > -	imx_rproc_free_mbox(priv->rproc);
> > -
> >  	rproc_report_crash(priv->rproc, RPROC_WATCHDOG);
> >
> >  	pr_info("Partition%d reset!\n", priv->rproc_pt); @@ -916,7 +931,8
> @@
> > static int imx_rproc_detect_mode(struct imx_rproc *priv)
> >  		}
> >
> >  		priv->rproc->state = RPROC_DETACHED;
> > -		priv->rproc->recovery_disabled = true;
> > +		priv->rproc->recovery_disabled = false;
> > +		rproc_set_feature(priv->rproc,
> RPROC_FEAT_ATTACH_ON_RECOVERY);
> >
> >  		/* Get partition id and enable irq in SCFW */
> >  		ret = imx_sc_rm_get_resource_owner(priv->ipc_handle,
> priv->rsrc_id,
> > &pt);
> > --
> > 2.37.1
> >
diff mbox series

Patch

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index bece44b46719..4057d6f33813 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -603,6 +603,22 @@  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;
+}
+
 static struct resource_table *imx_rproc_get_loaded_rsc_table(struct rproc *rproc, size_t *table_sz)
 {
 	struct imx_rproc *priv = rproc->priv;
@@ -618,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,
@@ -797,8 +814,6 @@  static int imx_rproc_partition_notify(struct notifier_block *nb,
 	if (!((event & BIT(priv->rproc_pt)) && (*(u8 *)group == IMX_SC_IRQ_GROUP_REBOOTED)))
 		return 0;
 
-	imx_rproc_free_mbox(priv->rproc);
-
 	rproc_report_crash(priv->rproc, RPROC_WATCHDOG);
 
 	pr_info("Partition%d reset!\n", priv->rproc_pt);
@@ -916,7 +931,8 @@  static int imx_rproc_detect_mode(struct imx_rproc *priv)
 		}
 
 		priv->rproc->state = RPROC_DETACHED;
-		priv->rproc->recovery_disabled = true;
+		priv->rproc->recovery_disabled = false;
+		rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
 
 		/* Get partition id and enable irq in SCFW */
 		ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);