802-can-0026-can-flexcan-fix-deadlock-when-using-self-wakeup.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From 59876225748221d7ebbdb9c892a2086420ddd80d Mon Sep 17 00:00:00 2001
  2. From: Sean Nyekjaer <[email protected]>
  3. Date: Thu, 14 Nov 2019 19:56:28 +0800
  4. Subject: [PATCH] can: flexcan: fix deadlock when using self wakeup
  5. When suspending, when there is still can traffic on the interfaces the
  6. flexcan immediately wakes the platform again. As it should :-). But it
  7. throws this error msg:
  8. [ 3169.378661] PM: noirq suspend of devices failed
  9. On the way down to suspend the interface that throws the error message does
  10. call flexcan_suspend but fails to call flexcan_noirq_suspend. That means the
  11. flexcan_enter_stop_mode is called, but on the way out of suspend the driver
  12. only calls flexcan_resume and skips flexcan_noirq_resume, thus it doesn't call
  13. flexcan_exit_stop_mode. This leaves the flexcan in stop mode, and with the
  14. current driver it can't recover from this even with a soft reboot, it requires
  15. a hard reboot.
  16. This patch can fix deadlock when using self wakeup, it happenes to be
  17. able to fix another issue that frames out-of-order in first IRQ handler
  18. run after wakeup.
  19. In wakeup case, after system resume, frames received out-of-order,the
  20. problem is wakeup latency from frame reception to IRQ handler is much
  21. bigger than the counter overflow. This means it's impossible to sort the
  22. CAN frames by timestamp. The reason is that controller exits stop mode
  23. during noirq resume, then it can receive the frame immediately. If
  24. noirq reusme stage consumes much time, it will extend interrupt response
  25. time.
  26. Fixes: de3578c198c6 ("can: flexcan: add self wakeup support")
  27. Signed-off-by: Sean Nyekjaer <[email protected]>
  28. Signed-off-by: Joakim Zhang <[email protected]>
  29. ---
  30. drivers/net/can/flexcan.c | 9 +++++++--
  31. 1 file changed, 7 insertions(+), 2 deletions(-)
  32. --- a/drivers/net/can/flexcan.c
  33. +++ b/drivers/net/can/flexcan.c
  34. @@ -137,8 +137,7 @@
  35. (FLEXCAN_ESR_ERR_BUS | FLEXCAN_ESR_ERR_STATE)
  36. #define FLEXCAN_ESR_ALL_INT \
  37. (FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | \
  38. - FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT | \
  39. - FLEXCAN_ESR_WAK_INT)
  40. + FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT)
  41. /* FLEXCAN Bit Timing register (CBT) bits */
  42. #define FLEXCAN_CBT_BTF BIT(31)
  43. @@ -1056,6 +1055,12 @@ static irqreturn_t flexcan_irq(int irq,
  44. reg_esr = priv->read(&regs->esr);
  45. + /* ACK wakeup interrupt */
  46. + if (reg_esr & FLEXCAN_ESR_WAK_INT) {
  47. + handled = IRQ_HANDLED;
  48. + priv->write(reg_esr & FLEXCAN_ESR_WAK_INT, &regs->esr);
  49. + }
  50. +
  51. /* ACK all bus error and state change IRQ sources */
  52. if (reg_esr & FLEXCAN_ESR_ALL_INT) {
  53. handled = IRQ_HANDLED;