* [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
@ 2021-03-03 12:49 Torin Cooper-Bennun
2021-03-03 12:55 ` Marc Kleine-Budde
0 siblings, 1 reply; 6+ messages in thread
From: Torin Cooper-Bennun @ 2021-03-03 12:49 UTC (permalink / raw)
To: linux-can; +Cc: mkl, Torin Cooper-Bennun
In peripherals, m_can_rx_handler is called with quota = 1 from an ISR
context. If the M_CAN reports a high volume of errors, such as message
loss due to heavy bus traffic, then error handling, which is prioritised
in m_can_rx_handler, fills the quota immediately, and RX does not occur.
This has been observed to cause an indefinite blocking of RX.
The patch fixes this by ensuring that in peripherals, m_can_do_rx_poll
is always called with a quota of at least 1, regardless of any errors
handled.
This has been tested with the TCAN4550 under heavy bus traffic; message
loss is still detected correctly.
Signed-off-by: Torin Cooper-Bennun <torin@maxiluxsystems.com>
---
drivers/net/can/m_can/m_can.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 3752520a7d4b..3ec42e613ca1 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -866,8 +866,14 @@ static int m_can_rx_handler(struct net_device *dev, int quota)
if (irqstatus & IR_ERR_BUS_30X)
work_done += m_can_handle_bus_errors(dev, irqstatus, psr);
- if (irqstatus & IR_RF0N)
- work_done += m_can_do_rx_poll(dev, (quota - work_done));
+ if (irqstatus & IR_RF0N) {
+ int rx_quota = quota - work_done;
+
+ if (cdev->is_peripheral && (rx_quota <= 0))
+ rx_quota = 1;
+
+ work_done += m_can_do_rx_poll(dev, rx_quota);
+ }
end:
return work_done;
}
--
2.30.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
2021-03-03 12:49 [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling Torin Cooper-Bennun
@ 2021-03-03 12:55 ` Marc Kleine-Budde
2021-03-03 13:07 ` Torin Cooper-Bennun
2021-03-03 14:36 ` Torin Cooper-Bennun
0 siblings, 2 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 12:55 UTC (permalink / raw)
To: Torin Cooper-Bennun; +Cc: linux-can
[-- Attachment #1: Type: text/plain, Size: 2029 bytes --]
On 03.03.2021 12:49:52, Torin Cooper-Bennun wrote:
> In peripherals, m_can_rx_handler is called with quota = 1 from an ISR
> context.
To be precise, it's a threaded Interrupt. Why not call the rx_handler
with a reasonable quota instead?
Marc
> If the M_CAN reports a high volume of errors, such as message
> loss due to heavy bus traffic, then error handling, which is prioritised
> in m_can_rx_handler, fills the quota immediately, and RX does not occur.
> This has been observed to cause an indefinite blocking of RX.
>
> The patch fixes this by ensuring that in peripherals, m_can_do_rx_poll
> is always called with a quota of at least 1, regardless of any errors
> handled.
>
> This has been tested with the TCAN4550 under heavy bus traffic; message
> loss is still detected correctly.
>
> Signed-off-by: Torin Cooper-Bennun <torin@maxiluxsystems.com>
> ---
> drivers/net/can/m_can/m_can.c | 10 ++++++++--
> 1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
> index 3752520a7d4b..3ec42e613ca1 100644
> --- a/drivers/net/can/m_can/m_can.c
> +++ b/drivers/net/can/m_can/m_can.c
> @@ -866,8 +866,14 @@ static int m_can_rx_handler(struct net_device *dev, int quota)
> if (irqstatus & IR_ERR_BUS_30X)
> work_done += m_can_handle_bus_errors(dev, irqstatus, psr);
>
> - if (irqstatus & IR_RF0N)
> - work_done += m_can_do_rx_poll(dev, (quota - work_done));
> + if (irqstatus & IR_RF0N) {
> + int rx_quota = quota - work_done;
> +
> + if (cdev->is_peripheral && (rx_quota <= 0))
> + rx_quota = 1;
> +
> + work_done += m_can_do_rx_poll(dev, rx_quota);
> + }
> end:
> return work_done;
> }
> --
> 2.30.1
>
>
--
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
2021-03-03 12:55 ` Marc Kleine-Budde
@ 2021-03-03 13:07 ` Torin Cooper-Bennun
2021-03-03 13:11 ` Marc Kleine-Budde
2021-03-03 14:36 ` Torin Cooper-Bennun
1 sibling, 1 reply; 6+ messages in thread
From: Torin Cooper-Bennun @ 2021-03-03 13:07 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
On Wed, Mar 03, 2021 at 01:55:23PM +0100, Marc Kleine-Budde wrote:
> > In peripherals, m_can_rx_handler is called with quota = 1 from an ISR
> > context.
>
> To be precise, it's a threaded Interrupt. Why not call the rx_handler
> with a reasonable quota instead?
I see, thanks. Forgive my ignorance, but how long should a threaded ISR
reasonably block for? Was there ever a good reason for the quota to be 1
here?
--
Regards,
Torin Cooper-Bennun
Software Engineer | maxiluxsystems.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
2021-03-03 13:07 ` Torin Cooper-Bennun
@ 2021-03-03 13:11 ` Marc Kleine-Budde
2021-03-03 13:27 ` Torin Cooper-Bennun
0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2021-03-03 13:11 UTC (permalink / raw)
To: Torin Cooper-Bennun; +Cc: linux-can
[-- Attachment #1: Type: text/plain, Size: 954 bytes --]
On 03.03.2021 13:07:50, Torin Cooper-Bennun wrote:
> On Wed, Mar 03, 2021 at 01:55:23PM +0100, Marc Kleine-Budde wrote:
> > > In peripherals, m_can_rx_handler is called with quota = 1 from an ISR
> > > context.
> >
> > To be precise, it's a threaded Interrupt. Why not call the rx_handler
> > with a reasonable quota instead?
>
> I see, thanks. Forgive my ignorance, but how long should a threaded ISR
> reasonably block for?
It's a IRQ thread, so it's subject to scheduling and priorities can be
configured. The IRQ thread of the mcp251xfd driver runs until all IRQs
are handled.
> Was there ever a good reason for the quota to be 1 here?
Don't know.
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: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
2021-03-03 13:11 ` Marc Kleine-Budde
@ 2021-03-03 13:27 ` Torin Cooper-Bennun
0 siblings, 0 replies; 6+ messages in thread
From: Torin Cooper-Bennun @ 2021-03-03 13:27 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
On Wed, Mar 03, 2021 at 02:11:22PM +0100, Marc Kleine-Budde wrote:
> > I see, thanks. Forgive my ignorance, but how long should a threaded ISR
> > reasonably block for?
>
> It's a IRQ thread, so it's subject to scheduling and priorities can be
> configured. The IRQ thread of the mcp251xfd driver runs until all IRQs
> are handled.
>
> > Was there ever a good reason for the quota to be 1 here?
>
> Don't know.
OK, thanks for the insight. I'll discard this patch and rework the
peripheral interrupt handling logic.
--
Regards,
Torin Cooper-Bennun
Software Engineer | maxiluxsystems.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
2021-03-03 12:55 ` Marc Kleine-Budde
2021-03-03 13:07 ` Torin Cooper-Bennun
@ 2021-03-03 14:36 ` Torin Cooper-Bennun
1 sibling, 0 replies; 6+ messages in thread
From: Torin Cooper-Bennun @ 2021-03-03 14:36 UTC (permalink / raw)
To: Marc Kleine-Budde; +Cc: linux-can
On Wed, Mar 03, 2021 at 01:55:23PM +0100, Marc Kleine-Budde wrote:
> To be precise, it's a threaded Interrupt. Why not call the rx_handler
> with a reasonable quota instead?
After some testing, I've found that this solution works best. I'll send
another patch.
--
Regards,
Torin Cooper-Bennun
Software Engineer | maxiluxsystems.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-03-04 0:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 12:49 [PATCH] can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling Torin Cooper-Bennun
2021-03-03 12:55 ` Marc Kleine-Budde
2021-03-03 13:07 ` Torin Cooper-Bennun
2021-03-03 13:11 ` Marc Kleine-Budde
2021-03-03 13:27 ` Torin Cooper-Bennun
2021-03-03 14:36 ` Torin Cooper-Bennun
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.