can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
Subsystems (2)
PATCH 1/1 can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling
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.
--- drivers/net/can/m_can/m_can.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/net/can/m_can/m_can.c +8 -2
@@ -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; }
Signature · 1 line
2.30.1
Marc Kleine-Budde
maintainerQuoted 2 lines · Torin Cooper-Bennun
In peripherals,
m_can_rx_handleris 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
Quoted 42 lines
If the
M_CANreports a high volume of errors, such as message loss due to heavy bus traffic, then error handling, which is prioritised inm_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_pollis 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 <[email protected]>--- drivers/net/can/m_can/m_can.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/net/can/m_can/m_can.c +8
-2@@ -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; }Signature · 1 line
2.30.1
Signature · 4 lines
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 |
Quoted 5 lines · Marc Kleine-Budde
Quoted 2 lines
In peripherals,
m_can_rx_handleris called with quota = 1 from an ISR context.To be precise, it's a threaded Interrupt. Why not call the
rx_handlerwith 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
Marc Kleine-Budde
maintainerQuoted 9 lines · Torin Cooper-Bennun
Quoted 5 lines · Marc Kleine-Budde
Quoted 2 lines
In peripherals,
m_can_rx_handleris called with quota = 1 from an ISR context.To be precise, it's a threaded Interrupt. Why not call the
rx_handlerwith 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.
Quoted 1 line
Was there ever a good reason for the quota to be 1 here?
Don't know.
Marc
Signature · 4 lines
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 |
Quoted 10 lines · Marc Kleine-Budde
Quoted 2 lines
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.
Quoted 1 line
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
Quoted 2 lines · Marc Kleine-Budde
To be precise, it's a threaded Interrupt. Why not call the
rx_handlerwith 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