Skip to contentSkip to conversation

can: m_can: m_can_rx_handler(): fix RX in periphs being blocked by error handling

PATCH In review Torin Cooper-Bennun 2 participants 6 messages Mar 4, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 3752520a7d4b..3ec42e613ca1 100644
@@ -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
#1 lore raw
Quoted 2 lines · Torin Cooper-Bennun

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

Quoted 42 lines

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
index 3752520a7d4b..3ec42e613ca1 100644
@@ -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 |
#2 lore raw
Quoted 5 lines · Marc Kleine-Budde
Quoted 2 lines

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

#3 lore raw
Quoted 9 lines · Torin Cooper-Bennun
Quoted 5 lines · Marc Kleine-Budde
Quoted 2 lines

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.

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 |
#4 lore raw
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

#5 lore raw
In reply to Marc Kleine-Budde
Quoted 2 lines · Marc Kleine-Budde

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