Skip to content

Commit 801ad2f

Browse files
JakeHamby-TDYmarckleinebudde
authored andcommitted
can: m_can: enable NAPI before enabling interrupts
If an interrupt (RX-complete or error flag) is set when bringing up the CAN device, e.g. due to CAN bus traffic before initializing the device, when m_can_start() is called and interrupts are enabled, m_can_isr() is called immediately, which disables all CAN interrupts and calls napi_schedule(). Because napi_enable() isn't called until later in m_can_open(), the call to napi_schedule() never schedules the m_can_poll() callback and the device is left with interrupts disabled and can't receive any CAN packets until rebooted. This can be verified by running "cansend" from another device before setting the bitrate and calling "ip link set up can0" on the test device. Adding debug lines to m_can_isr() shows it's called with flags (IR_EP | IR_EW | IR_CRCE), which calls m_can_disable_all_interrupts() and napi_schedule(), and then m_can_poll() is never called. Move the call to napi_enable() above the call to m_can_start() to enable any initial interrupt flags to be handled by m_can_poll() so that interrupts are reenabled. Add a call to napi_disable() in the error handling section of m_can_open(), to handle the case where later functions return errors. Also, in m_can_close(), move the call to napi_disable() below the call to m_can_stop() to ensure all interrupts are handled when bringing down the device. This race condition is much less likely to occur. Tested on a Microchip SAMA7G54 MPU. The fix should be applicable to any SoC with a Bosch M_CAN controller. Signed-off-by: Jake Hamby <[email protected]> Fixes: e0d1f48 ("can: m_can: add Bosch M_CAN controller support") Link: https://patch.msgid.link/[email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent d0fa064 commit 801ad2f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/net/can/m_can/m_can.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,9 +1763,6 @@ static int m_can_close(struct net_device *dev)
17631763

17641764
netif_stop_queue(dev);
17651765

1766-
if (!cdev->is_peripheral)
1767-
napi_disable(&cdev->napi);
1768-
17691766
m_can_stop(dev);
17701767
m_can_clk_stop(cdev);
17711768
free_irq(dev->irq, dev);
@@ -1776,6 +1773,8 @@ static int m_can_close(struct net_device *dev)
17761773
destroy_workqueue(cdev->tx_wq);
17771774
cdev->tx_wq = NULL;
17781775
can_rx_offload_disable(&cdev->offload);
1776+
} else {
1777+
napi_disable(&cdev->napi);
17791778
}
17801779

17811780
close_candev(dev);
@@ -2030,6 +2029,8 @@ static int m_can_open(struct net_device *dev)
20302029

20312030
if (cdev->is_peripheral)
20322031
can_rx_offload_enable(&cdev->offload);
2032+
else
2033+
napi_enable(&cdev->napi);
20332034

20342035
/* register interrupt handler */
20352036
if (cdev->is_peripheral) {
@@ -2063,9 +2064,6 @@ static int m_can_open(struct net_device *dev)
20632064
if (err)
20642065
goto exit_start_fail;
20652066

2066-
if (!cdev->is_peripheral)
2067-
napi_enable(&cdev->napi);
2068-
20692067
netif_start_queue(dev);
20702068

20712069
return 0;
@@ -2079,6 +2077,8 @@ static int m_can_open(struct net_device *dev)
20792077
out_wq_fail:
20802078
if (cdev->is_peripheral)
20812079
can_rx_offload_disable(&cdev->offload);
2080+
else
2081+
napi_disable(&cdev->napi);
20822082
close_candev(dev);
20832083
exit_disable_clks:
20842084
m_can_clk_stop(cdev);

0 commit comments

Comments
 (0)