netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
@ 2011-12-12 15:09 Wolfgang Grandegger
  2011-12-12 15:31 ` Marc Kleine-Budde
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-12 15:09 UTC (permalink / raw)
  To: netdev; +Cc: linux-can, Reuben Dowle, Lothar Waßmann

As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
to avoid interrupt flooding, at least for the Flexcan on i.MX28
SOCs. Furthermore, the interrupts are only cleared, if really one
of those interrupt sources are pending (which is not the case for
rx and tx done).

CC: Reuben Dowle <Reuben.Dowle@navico.com>
CC: Lothar Waßmann <LW@KARO-electronics.de>
Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
---
 drivers/net/can/flexcan.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
index 165a4c7..111f154 100644
--- a/drivers/net/can/flexcan.c
+++ b/drivers/net/can/flexcan.c
@@ -118,6 +118,9 @@
 	(FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | FLEXCAN_ESR_BOFF_INT)
 #define FLEXCAN_ESR_ERR_ALL \
 	(FLEXCAN_ESR_ERR_BUS | FLEXCAN_ESR_ERR_STATE)
+#define FLEXCAN_ESR_ALL_INT \
+	(FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | \
+	 FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT)
 
 /* FLEXCAN interrupt flag register (IFLAG) bits */
 #define FLEXCAN_TX_BUF_ID		8
@@ -577,7 +580,9 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
 
 	reg_iflag1 = flexcan_read(&regs->iflag1);
 	reg_esr = flexcan_read(&regs->esr);
-	flexcan_write(FLEXCAN_ESR_ERR_INT, &regs->esr);	/* ACK err IRQ */
+	/* ACK all bus error and state change IRQ sources */
+	if (reg_esr & FLEXCAN_ESR_ALL_INT)
+		flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
 
 	/*
 	 * schedule NAPI in case of:
-- 
1.7.4.1


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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-12 15:09 [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources Wolfgang Grandegger
@ 2011-12-12 15:31 ` Marc Kleine-Budde
  2011-12-12 15:44   ` Wolfgang Grandegger
  0 siblings, 1 reply; 9+ messages in thread
From: Marc Kleine-Budde @ 2011-12-12 15:31 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

[-- Attachment #1: Type: text/plain, Size: 2133 bytes --]

On 12/12/2011 04:09 PM, Wolfgang Grandegger wrote:
> As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
> RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
> to avoid interrupt flooding, at least for the Flexcan on i.MX28
> SOCs. Furthermore, the interrupts are only cleared, if really one
> of those interrupt sources are pending (which is not the case for
> rx and tx done).
> 
> CC: Reuben Dowle <Reuben.Dowle@navico.com>
> CC: Lothar Waßmann <LW@KARO-electronics.de>
> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>

Have you tested on mx25/mx35, does it have any negative side effects?
My schedule is full until Friday, sorry cannot test here.

Marc

> ---
>  drivers/net/can/flexcan.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/net/can/flexcan.c b/drivers/net/can/flexcan.c
> index 165a4c7..111f154 100644
> --- a/drivers/net/can/flexcan.c
> +++ b/drivers/net/can/flexcan.c
> @@ -118,6 +118,9 @@
>  	(FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | FLEXCAN_ESR_BOFF_INT)
>  #define FLEXCAN_ESR_ERR_ALL \
>  	(FLEXCAN_ESR_ERR_BUS | FLEXCAN_ESR_ERR_STATE)
> +#define FLEXCAN_ESR_ALL_INT \
> +	(FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | \
> +	 FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT)
>  
>  /* FLEXCAN interrupt flag register (IFLAG) bits */
>  #define FLEXCAN_TX_BUF_ID		8
> @@ -577,7 +580,9 @@ static irqreturn_t flexcan_irq(int irq, void *dev_id)
>  
>  	reg_iflag1 = flexcan_read(&regs->iflag1);
>  	reg_esr = flexcan_read(&regs->esr);
> -	flexcan_write(FLEXCAN_ESR_ERR_INT, &regs->esr);	/* ACK err IRQ */
> +	/* ACK all bus error and state change IRQ sources */
> +	if (reg_esr & FLEXCAN_ESR_ALL_INT)
> +		flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
>  
>  	/*
>  	 * schedule NAPI in case of:


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


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

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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-12 15:31 ` Marc Kleine-Budde
@ 2011-12-12 15:44   ` Wolfgang Grandegger
  2011-12-13 12:13     ` Wolfgang Grandegger
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-12 15:44 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

On 12/12/2011 04:31 PM, Marc Kleine-Budde wrote:
> On 12/12/2011 04:09 PM, Wolfgang Grandegger wrote:
>> As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
>> RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
>> to avoid interrupt flooding, at least for the Flexcan on i.MX28
>> SOCs. Furthermore, the interrupts are only cleared, if really one
>> of those interrupt sources are pending (which is not the case for
>> rx and tx done).
>>
>> CC: Reuben Dowle <Reuben.Dowle@navico.com>
>> CC: Lothar Waßmann <LW@KARO-electronics.de>
>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
> 
> Have you tested on mx25/mx35, does it have any negative side effects?
> My schedule is full until Friday, sorry cannot test here.

Not yet. But it's not critical. Only the pending interrupt flags are
cleared. Maybe somebody else out there could do some testing... before I
get hold of a MX35PDK board.

Wolfgang.

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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-12 15:44   ` Wolfgang Grandegger
@ 2011-12-13 12:13     ` Wolfgang Grandegger
  2011-12-13 12:53       ` Marc Kleine-Budde
  2011-12-13 12:53       ` Wolfgang Grandegger
  0 siblings, 2 replies; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-13 12:13 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

On 12/12/2011 04:44 PM, Wolfgang Grandegger wrote:
> On 12/12/2011 04:31 PM, Marc Kleine-Budde wrote:
>> On 12/12/2011 04:09 PM, Wolfgang Grandegger wrote:
>>> As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
>>> RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
>>> to avoid interrupt flooding, at least for the Flexcan on i.MX28
>>> SOCs. Furthermore, the interrupts are only cleared, if really one
>>> of those interrupt sources are pending (which is not the case for
>>> rx and tx done).
>>>
>>> CC: Reuben Dowle <Reuben.Dowle@navico.com>
>>> CC: Lothar Waßmann <LW@KARO-electronics.de>
>>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
>>
>> Have you tested on mx25/mx35, does it have any negative side effects?
>> My schedule is full until Friday, sorry cannot test here.
> 
> Not yet. But it's not critical. Only the pending interrupt flags are
> cleared. Maybe somebody else out there could do some testing... before I
> get hold of a MX35PDK board.

I got my MX35PDK board working and can confirm, that the patch works on
a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
flags do show up once, together with ERR_INT, and then, after clearing,
never again. Obviously a bug in the Flexcan logic. From the feedback we
can say, that only the i.MX28 does behave differently (==correctly). All
other seem to work with the current code:

 Flexcan on
 - i.mx25
 - i.mx35
 - i.mx53
 - P1010/P1020

Wolfgang.


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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-13 12:13     ` Wolfgang Grandegger
@ 2011-12-13 12:53       ` Marc Kleine-Budde
  2011-12-13 12:53       ` Wolfgang Grandegger
  1 sibling, 0 replies; 9+ messages in thread
From: Marc Kleine-Budde @ 2011-12-13 12:53 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

[-- Attachment #1: Type: text/plain, Size: 2072 bytes --]

On 12/13/2011 01:13 PM, Wolfgang Grandegger wrote:
> On 12/12/2011 04:44 PM, Wolfgang Grandegger wrote:
>> On 12/12/2011 04:31 PM, Marc Kleine-Budde wrote:
>>> On 12/12/2011 04:09 PM, Wolfgang Grandegger wrote:
>>>> As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
>>>> RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
>>>> to avoid interrupt flooding, at least for the Flexcan on i.MX28
>>>> SOCs. Furthermore, the interrupts are only cleared, if really one
>>>> of those interrupt sources are pending (which is not the case for
>>>> rx and tx done).
>>>>
>>>> CC: Reuben Dowle <Reuben.Dowle@navico.com>
>>>> CC: Lothar Waßmann <LW@KARO-electronics.de>
>>>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
>>>
>>> Have you tested on mx25/mx35, does it have any negative side effects?
>>> My schedule is full until Friday, sorry cannot test here.
>>
>> Not yet. But it's not critical. Only the pending interrupt flags are
>> cleared. Maybe somebody else out there could do some testing... before I
>> get hold of a MX35PDK board.
> 
> I got my MX35PDK board working and can confirm, that the patch works on
> a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
> RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
> flags do show up once, together with ERR_INT, and then, after clearing,
> never again. Obviously a bug in the Flexcan logic. From the feedback we
> can say, that only the i.MX28 does behave differently (==correctly). All
> other seem to work with the current code:
> 
>  Flexcan on
>  - i.mx25
>  - i.mx35
>  - i.mx53
>  - P1010/P1020

I'm adding the patch to linux-can. I think this is a stable candidate
for v2.6.39 and newer (mx28 suport was added in 2.6.39).

Marc

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


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

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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-13 12:13     ` Wolfgang Grandegger
  2011-12-13 12:53       ` Marc Kleine-Budde
@ 2011-12-13 12:53       ` Wolfgang Grandegger
  2011-12-13 12:59         ` Marc Kleine-Budde
  1 sibling, 1 reply; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-13 12:53 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

On 12/13/2011 01:13 PM, Wolfgang Grandegger wrote:
> On 12/12/2011 04:44 PM, Wolfgang Grandegger wrote:
>> On 12/12/2011 04:31 PM, Marc Kleine-Budde wrote:
>>> On 12/12/2011 04:09 PM, Wolfgang Grandegger wrote:
>>>> As pointed out by Reuben Dowle and Lothar Waßmann, the TWRN_INT,
>>>> RWRN_INT, BOFF_INT interrupt sources need to be cleared as well
>>>> to avoid interrupt flooding, at least for the Flexcan on i.MX28
>>>> SOCs. Furthermore, the interrupts are only cleared, if really one
>>>> of those interrupt sources are pending (which is not the case for
>>>> rx and tx done).
>>>>
>>>> CC: Reuben Dowle <Reuben.Dowle@navico.com>
>>>> CC: Lothar Waßmann <LW@KARO-electronics.de>
>>>> Signed-off-by: Wolfgang Grandegger <wg@grandegger.com>
>>>
>>> Have you tested on mx25/mx35, does it have any negative side effects?
>>> My schedule is full until Friday, sorry cannot test here.
>>
>> Not yet. But it's not critical. Only the pending interrupt flags are
>> cleared. Maybe somebody else out there could do some testing... before I
>> get hold of a MX35PDK board.
> 
> I got my MX35PDK board working and can confirm, that the patch works on
> a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
> RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
> flags do show up once, together with ERR_INT, and then, after clearing,
> never again. Obviously a bug in the Flexcan logic. From the feedback we
> can say, that only the i.MX28 does behave differently (==correctly). All
> other seem to work with the current code:
> 
>  Flexcan on
>  - i.mx25
>  - i.mx35
>  - i.mx53
>  - P1010/P1020

But unfortunately, state change reporting looks different with this patch :)

Wolfgang.

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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-13 12:53       ` Wolfgang Grandegger
@ 2011-12-13 12:59         ` Marc Kleine-Budde
  2011-12-13 16:22           ` Wolfgang Grandegger
  0 siblings, 1 reply; 9+ messages in thread
From: Marc Kleine-Budde @ 2011-12-13 12:59 UTC (permalink / raw)
  To: Wolfgang Grandegger; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

On 12/13/2011 01:53 PM, Wolfgang Grandegger wrote:
>> I got my MX35PDK board working and can confirm, that the patch works on
>> a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
>> RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
>> flags do show up once, together with ERR_INT, and then, after clearing,
>> never again. Obviously a bug in the Flexcan logic. From the feedback we
>> can say, that only the i.MX28 does behave differently (==correctly). All
>> other seem to work with the current code:
>>
>>  Flexcan on
>>  - i.mx25
>>  - i.mx35
>>  - i.mx53
>>  - P1010/P1020
> 
> But unfortunately, state change reporting looks different with this patch :)

Hmm - so not schedule for stable. What about your buf-off-handling, will
this change the reporting again?

Marc

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


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

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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-13 12:59         ` Marc Kleine-Budde
@ 2011-12-13 16:22           ` Wolfgang Grandegger
  2011-12-14 13:21             ` Wolfgang Grandegger
  0 siblings, 1 reply; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-13 16:22 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

On 12/13/2011 01:59 PM, Marc Kleine-Budde wrote:
> On 12/13/2011 01:53 PM, Wolfgang Grandegger wrote:
>>> I got my MX35PDK board working and can confirm, that the patch works on
>>> a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
>>> RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
>>> flags do show up once, together with ERR_INT, and then, after clearing,
>>> never again. Obviously a bug in the Flexcan logic. From the feedback we
>>> can say, that only the i.MX28 does behave differently (==correctly). All
>>> other seem to work with the current code:
>>>
>>>  Flexcan on
>>>  - i.mx25
>>>  - i.mx35
>>>  - i.mx53
>>>  - P1010/P1020
>>
>> But unfortunately, state change reporting looks different with this patch :)
> 
> Hmm - so not schedule for stable. What about your buf-off-handling, will
> this change the reporting again?

Well, as it is a serious problem on i.MX28, I would schedule this patch
for stable as well. The error and state change reporting is bogus on the
Flexcan anyhow. Without this patch, I get "active->warning->passive" if
I send a message with cable disconnect (no ack). With patch just
"active->warning". That's the same behaviour
as on the i.MX28, also with my new state and bus-off handling. See:

https://gitorious.org/~wgrandegger/linux-can/wg-linux-can-next/commit/bd3acb12dbb9551541d28ae8766c154d3cf6ed57

Wolfgang.


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

* Re: [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources
  2011-12-13 16:22           ` Wolfgang Grandegger
@ 2011-12-14 13:21             ` Wolfgang Grandegger
  0 siblings, 0 replies; 9+ messages in thread
From: Wolfgang Grandegger @ 2011-12-14 13:21 UTC (permalink / raw)
  To: Marc Kleine-Budde; +Cc: netdev, linux-can, Reuben Dowle, Lothar Waßmann

Hi Marc,

On 12/13/2011 05:22 PM, Wolfgang Grandegger wrote:
> On 12/13/2011 01:59 PM, Marc Kleine-Budde wrote:
>> On 12/13/2011 01:53 PM, Wolfgang Grandegger wrote:
>>>> I got my MX35PDK board working and can confirm, that the patch works on
>>>> a i.mx35 as well. My testing also confirms, that the ESR TWRN_INT,
>>>> RWRN_INT, FLEXCAN_ESR_BOFF_INT do not function as documented. These
>>>> flags do show up once, together with ERR_INT, and then, after clearing,
>>>> never again. Obviously a bug in the Flexcan logic. From the feedback we
>>>> can say, that only the i.MX28 does behave differently (==correctly). All
>>>> other seem to work with the current code:
>>>>
>>>>  Flexcan on
>>>>  - i.mx25
>>>>  - i.mx35
>>>>  - i.mx53
>>>>  - P1010/P1020
>>>
>>> But unfortunately, state change reporting looks different with this patch :)
>>
>> Hmm - so not schedule for stable. What about your buf-off-handling, will
>> this change the reporting again?
> 
> Well, as it is a serious problem on i.MX28, I would schedule this patch
> for stable as well. The error and state change reporting is bogus on the
> Flexcan anyhow. Without this patch, I get "active->warning->passive" if
> I send a message with cable disconnect (no ack). With patch just
> "active->warning". That's the same behaviour
> as on the i.MX28, also with my new state and bus-off handling. See:

I now understand the difference. I "flexcan_irq" we have:

	/*
	 * schedule NAPI in case of:
	 * - rx IRQ
	 * - state change IRQ
	 * - bus error IRQ and bus error reporting is activated
	 */
	if ((reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) ||
	    (reg_esr & FLEXCAN_ESR_ERR_STATE) ||
	    flexcan_has_and_handle_berr(priv, reg_esr)) {

Without this patch, "reg_esr & FLEXCAN_ESR_ERR_STATE" is *always* true
because the RWRN_INT is never cleared. This means, *any* message is
scheduled. As a nice side effect, this patch fixes this bug a well.

Only because any message is scheduled, the state change to error passive
is recognized in flexcan_poll(). The state change to error passive is
not signaled by an extra interrupt and is therefore only visible
together with RX, TX done or bus-error events.

Wolfgang.


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

end of thread, other threads:[~2011-12-14 13:21 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12 15:09 [PATCH] can: flexcan: fix irq flooding by clearing all interrupt sources Wolfgang Grandegger
2011-12-12 15:31 ` Marc Kleine-Budde
2011-12-12 15:44   ` Wolfgang Grandegger
2011-12-13 12:13     ` Wolfgang Grandegger
2011-12-13 12:53       ` Marc Kleine-Budde
2011-12-13 12:53       ` Wolfgang Grandegger
2011-12-13 12:59         ` Marc Kleine-Budde
2011-12-13 16:22           ` Wolfgang Grandegger
2011-12-14 13:21             ` Wolfgang Grandegger

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).