Skip to content

Commit

Permalink
arch/risc-v/src/mpfs/mpfs_fpga_canfd.c: Enable error interrupts only …
Browse files Browse the repository at this point in the history
…when in ERROR_ACTIVE state

Having error interrupts enabled while in ERROR_PASSIVE will cause interrupt storms, for example
bus error would be always asserted if the can is / gets disconnected.

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Mar 15, 2024
1 parent 2797ee2 commit 34fa847
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions arch/risc-v/src/mpfs/mpfs_fpga_canfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,13 +1131,23 @@ static void mpfs_err_interrupt(struct mpfs_driver_s *priv, uint32_t isr)
case CAN_STATE_ERROR_PASSIVE:
priv->can.can_stats.error_passive++;
canwarn("Change to ERROR_PASSIVE error state\n");

/* Mask BERR interrupts */

putreg32(MPFS_CANFD_INT_STAT_ALI | MPFS_CANFD_INT_STAT_BEI,
priv->base + MPFS_CANFD_INT_MASK_SET_OFFSET);
break;
case CAN_STATE_ERROR_WARNING:
priv->can.can_stats.error_warning++;
canwarn("Change to ERROR_WARNING error state\n");
break;
case CAN_STATE_ERROR_ACTIVE:
caninfo("Change to ERROR_ACTIVE error state\n");

/* Unmask BERR interrupts */

putreg32(MPFS_CANFD_INT_STAT_ALI | MPFS_CANFD_INT_STAT_BEI,
priv->base + MPFS_CANFD_INT_MASK_CLR_OFFSET);
return;
default:
canwarn("Unhandled error state %d\n", state);
Expand Down Expand Up @@ -2371,17 +2381,15 @@ static int mpfs_can_controller_start(struct mpfs_driver_s *priv)
MPFS_CANFD_INT_STAT_FCSI |
MPFS_CANFD_INT_STAT_DOI;

int_msk = ~int_ena; /* Initially allow all but errors */

/* Bus error reporting -> Allow Error/Arb.lost interrupts */

if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
{
int_ena |= MPFS_CANFD_INT_STAT_ALI | MPFS_CANFD_INT_STAT_BEI;
}

int_msk = ~int_ena; /* Mask all disabled interrupts */

/* It's after reset, so there is no need to clear anything */

uint32_t mask = 0xffffffff;
putreg32(mask, priv->base + MPFS_CANFD_INT_MASK_CLR_OFFSET);
putreg32(int_msk, priv->base + MPFS_CANFD_INT_MASK_SET_OFFSET);
Expand Down

0 comments on commit 34fa847

Please sign in to comment.