1 From 702de2c21eed04c67cefaaedc248ef16e5f6b293 Mon Sep 17 00:00:00 2001
2 From: Biju Das <biju.das.jz@bp.renesas.com>
3 Date: Tue, 25 Oct 2022 16:56:55 +0100
4 Subject: can: rcar_canfd: rcar_canfd_handle_global_receive(): fix IRQ storm on global FIFO receive
6 From: Biju Das <biju.das.jz@bp.renesas.com>
8 commit 702de2c21eed04c67cefaaedc248ef16e5f6b293 upstream.
10 We are seeing an IRQ storm on the global receive IRQ line under heavy
11 CAN bus load conditions with both CAN channels enabled.
15 The global receive IRQ line is shared between can0 and can1, either of
16 the channels can trigger interrupt while the other channel's IRQ line
19 When global a receive IRQ interrupt occurs, we mask the interrupt in
20 the IRQ handler. Clearing and unmasking of the interrupt is happening
21 in rx_poll(). There is a race condition where rx_poll() unmasks the
22 interrupt, but the next IRQ handler does not mask the IRQ due to
23 NAPIF_STATE_MISSED flag (e.g.: can0 RX FIFO interrupt is disabled and
24 can1 is triggering RX interrupt, the delay in rx_poll() processing
25 results in setting NAPIF_STATE_MISSED flag) leading to an IRQ storm.
27 This patch fixes the issue by checking IRQ active and enabled before
28 handling the IRQ on a particular channel.
30 Fixes: dd3bd23eb438 ("can: rcar_canfd: Add Renesas R-Car CAN FD driver")
31 Suggested-by: Marc Kleine-Budde <mkl@pengutronix.de>
32 Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
33 Link: https://lore.kernel.org/all/20221025155657.1426948-2-biju.das.jz@bp.renesas.com
34 Cc: stable@vger.kernel.org
35 [mkl: adjust commit message]
36 Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
37 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39 drivers/net/can/rcar/rcar_canfd.c | 6 ++++--
40 1 file changed, 4 insertions(+), 2 deletions(-)
42 --- a/drivers/net/can/rcar/rcar_canfd.c
43 +++ b/drivers/net/can/rcar/rcar_canfd.c
44 @@ -1157,11 +1157,13 @@ static void rcar_canfd_handle_global_rec
46 struct rcar_canfd_channel *priv = gpriv->ch[ch];
47 u32 ridx = ch + RCANFD_RFFIFO_IDX;
51 /* Handle Rx interrupts */
52 sts = rcar_canfd_read(priv->base, RCANFD_RFSTS(gpriv, ridx));
53 - if (likely(sts & RCANFD_RFSTS_RFIF)) {
54 + cc = rcar_canfd_read(priv->base, RCANFD_RFCC(gpriv, ridx));
55 + if (likely(sts & RCANFD_RFSTS_RFIF &&
56 + cc & RCANFD_RFCC_RFIE)) {
57 if (napi_schedule_prep(&priv->napi)) {
58 /* Disable Rx FIFO interrupts */
59 rcar_canfd_clear_bit(priv->base,