linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid
@ 2021-02-02  6:23 Joakim Zhang
  2021-02-02  7:37 ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Joakim Zhang @ 2021-02-02  6:23 UTC (permalink / raw)
  To: mkl, linux-can; +Cc: netdev, linux-imx

RX FIFO enable failed could happen when do system reboot stress test,
one customer reports failure rate is about 50%.

[    0.303958] flexcan 5a8d0000.can: 5a8d0000.can supply xceiver not found, using dummy regulator
[    0.304281] flexcan 5a8d0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
[    0.314640] flexcan 5a8d0000.can: registering netdev failed
[    0.320728] flexcan 5a8e0000.can: 5a8e0000.can supply xceiver not found, using dummy regulator
[    0.320991] flexcan 5a8e0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
[    0.331360] flexcan 5a8e0000.can: registering netdev failed
[    0.337444] flexcan 5a8f0000.can: 5a8f0000.can supply xceiver not found, using dummy regulator
[    0.337716] flexcan 5a8f0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
[    0.348117] flexcan 5a8f0000.can: registering netdev failed

RX FIFO should be enabled after the FRZ/HALT are valid. But the current
code set RX FIFO enable and FRZ/HALT at the same time.

Fixes: e955cead03117 ("CAN: Add Flexcan CAN controller driver")
Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
---
 drivers/net/can/flexcan.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 038fe1036df2..8ee9fa2f4161 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -1803,6 +1803,7 @@ static int register_flexcandev(struct net_device *dev)
 {
 	struct flexcan_priv *priv = netdev_priv(dev);
 	struct flexcan_regs __iomem *regs = priv->regs;
+	unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
 	u32 reg, err;
 
 	err = flexcan_clks_enable(priv);
@@ -1825,10 +1826,19 @@ static int register_flexcandev(struct net_device *dev)
 	if (err)
 		goto out_chip_disable;
 
-	/* set freeze, halt and activate FIFO, restrict register access */
+	/* set freeze, halt and polling the freeze ack */
 	reg = priv->read(&regs->mcr);
-	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
-		FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
+	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
+	priv->write(reg, &regs->mcr);
+
+	while (timeout-- && !(priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
+		udelay(100);
+
+	if (!(priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
+		return -ETIMEDOUT;
+
+	/* Activate FIFO, restrict register access */
+	reg |=  FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
 	priv->write(reg, &regs->mcr);
 
 	/* Currently we only support newer versions of this core
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid
  2021-02-02  6:23 [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid Joakim Zhang
@ 2021-02-02  7:37 ` Marc Kleine-Budde
  2021-02-02  8:02   ` Joakim Zhang
  0 siblings, 1 reply; 4+ messages in thread
From: Marc Kleine-Budde @ 2021-02-02  7:37 UTC (permalink / raw)
  To: Joakim Zhang, linux-can; +Cc: netdev, linux-imx


[-- Attachment #1.1: Type: text/plain, Size: 2822 bytes --]

On 2/2/21 7:23 AM, Joakim Zhang wrote:
> RX FIFO enable failed could happen when do system reboot stress test,
> one customer reports failure rate is about 50%.
> 
> [    0.303958] flexcan 5a8d0000.can: 5a8d0000.can supply xceiver not found, using dummy regulator
> [    0.304281] flexcan 5a8d0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
> [    0.314640] flexcan 5a8d0000.can: registering netdev failed
> [    0.320728] flexcan 5a8e0000.can: 5a8e0000.can supply xceiver not found, using dummy regulator
> [    0.320991] flexcan 5a8e0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
> [    0.331360] flexcan 5a8e0000.can: registering netdev failed
> [    0.337444] flexcan 5a8f0000.can: 5a8f0000.can supply xceiver not found, using dummy regulator
> [    0.337716] flexcan 5a8f0000.can (unnamed net_device) (uninitialized): Could not enable RX FIFO, unsupported core
> [    0.348117] flexcan 5a8f0000.can: registering netdev failed
> 
> RX FIFO should be enabled after the FRZ/HALT are valid. But the current
> code set RX FIFO enable and FRZ/HALT at the same time.
> 
> Fixes: e955cead03117 ("CAN: Add Flexcan CAN controller driver")
> Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
> ---
>  drivers/net/can/flexcan.c | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index 038fe1036df2..8ee9fa2f4161 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -1803,6 +1803,7 @@ static int register_flexcandev(struct net_device *dev)
>  {
>  	struct flexcan_priv *priv = netdev_priv(dev);
>  	struct flexcan_regs __iomem *regs = priv->regs;
> +	unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
>  	u32 reg, err;
>  
>  	err = flexcan_clks_enable(priv);
> @@ -1825,10 +1826,19 @@ static int register_flexcandev(struct net_device *dev)
>  	if (err)
>  		goto out_chip_disable;
>  
> -	/* set freeze, halt and activate FIFO, restrict register access */
> +	/* set freeze, halt and polling the freeze ack */
>  	reg = priv->read(&regs->mcr);
> -	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
> -		FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
> +	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
> +	priv->write(reg, &regs->mcr);
> +
> +	while (timeout-- && !(priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
> +		udelay(100);

Please make use of existing functions like flexcan_chip_freeze().

regards,
Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid
  2021-02-02  7:37 ` Marc Kleine-Budde
@ 2021-02-02  8:02   ` Joakim Zhang
  2021-02-02  8:02     ` Marc Kleine-Budde
  0 siblings, 1 reply; 4+ messages in thread
From: Joakim Zhang @ 2021-02-02  8:02 UTC (permalink / raw)
  To: Marc Kleine-Budde, linux-can; +Cc: netdev, dl-linux-imx


> -----Original Message-----
> From: Marc Kleine-Budde <mkl@pengutronix.de>
> Sent: 2021年2月2日 15:37
> To: Joakim Zhang <qiangqing.zhang@nxp.com>; linux-can@vger.kernel.org
> Cc: netdev@vger.kernel.org; dl-linux-imx <linux-imx@nxp.com>
> Subject: Re: [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT
> valid
> 
> On 2/2/21 7:23 AM, Joakim Zhang wrote:
> > RX FIFO enable failed could happen when do system reboot stress test,
> > one customer reports failure rate is about 50%.
> >
> > [    0.303958] flexcan 5a8d0000.can: 5a8d0000.can supply xceiver not
> found, using dummy regulator
> > [    0.304281] flexcan 5a8d0000.can (unnamed net_device) (uninitialized):
> Could not enable RX FIFO, unsupported core
> > [    0.314640] flexcan 5a8d0000.can: registering netdev failed
> > [    0.320728] flexcan 5a8e0000.can: 5a8e0000.can supply xceiver not
> found, using dummy regulator
> > [    0.320991] flexcan 5a8e0000.can (unnamed net_device) (uninitialized):
> Could not enable RX FIFO, unsupported core
> > [    0.331360] flexcan 5a8e0000.can: registering netdev failed
> > [    0.337444] flexcan 5a8f0000.can: 5a8f0000.can supply xceiver not found,
> using dummy regulator
> > [    0.337716] flexcan 5a8f0000.can (unnamed net_device) (uninitialized):
> Could not enable RX FIFO, unsupported core
> > [    0.348117] flexcan 5a8f0000.can: registering netdev failed
> >
> > RX FIFO should be enabled after the FRZ/HALT are valid. But the
> > current code set RX FIFO enable and FRZ/HALT at the same time.
> >
> > Fixes: e955cead03117 ("CAN: Add Flexcan CAN controller driver")
> > Signed-off-by: Joakim Zhang <qiangqing.zhang@nxp.com>
> > ---
> >  drivers/net/can/flexcan.c | 16 +++++++++++++---
> >  1 file changed, 13 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> > index 038fe1036df2..8ee9fa2f4161 100644
> > --- a/drivers/net/can/flexcan.c
> > +++ b/drivers/net/can/flexcan.c
> > @@ -1803,6 +1803,7 @@ static int register_flexcandev(struct net_device
> > *dev)  {
> >  	struct flexcan_priv *priv = netdev_priv(dev);
> >  	struct flexcan_regs __iomem *regs = priv->regs;
> > +	unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
> >  	u32 reg, err;
> >
> >  	err = flexcan_clks_enable(priv);
> > @@ -1825,10 +1826,19 @@ static int register_flexcandev(struct net_device
> *dev)
> >  	if (err)
> >  		goto out_chip_disable;
> >
> > -	/* set freeze, halt and activate FIFO, restrict register access */
> > +	/* set freeze, halt and polling the freeze ack */
> >  	reg = priv->read(&regs->mcr);
> > -	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
> > -		FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
> > +	reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT;
> > +	priv->write(reg, &regs->mcr);
> > +
> > +	while (timeout-- && !(priv->read(&regs->mcr) &
> FLEXCAN_MCR_FRZ_ACK))
> > +		udelay(100);
> 
> Please make use of existing functions like flexcan_chip_freeze().

OK, will improve it. Marc, I notice this issue also exist in flexcan_chip_start(), should I fix it together? 

Best Regards,
Joakim Zhang
> regards,
> Marc
> 
> --
> Pengutronix e.K.                 | Marc Kleine-Budde           |
> Embedded Linux                   | https://www.pengutronix.de  |
> Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
> Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid
  2021-02-02  8:02   ` Joakim Zhang
@ 2021-02-02  8:02     ` Marc Kleine-Budde
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Kleine-Budde @ 2021-02-02  8:02 UTC (permalink / raw)
  To: Joakim Zhang, linux-can; +Cc: netdev, dl-linux-imx


[-- Attachment #1.1: Type: text/plain, Size: 543 bytes --]

On 2/2/21 9:02 AM, Joakim Zhang wrote:
>> Please make use of existing functions like flexcan_chip_freeze().
> 
> OK, will improve it. Marc, I notice this issue also exist in
> flexcan_chip_start(), should I fix it together?

Make it two seperate patches.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-02  8:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-02  6:23 [PATCH linux-can] can: flexcan: enable RX FIFO after FRZ/HALT valid Joakim Zhang
2021-02-02  7:37 ` Marc Kleine-Budde
2021-02-02  8:02   ` Joakim Zhang
2021-02-02  8:02     ` Marc Kleine-Budde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).