2
0

100-serial8250-on-tegra-hsuart-recover-from-spurious-interrupts-due-to-tegra2-silicon-bug.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From patchwork Fri Jul 13 11:32:42 2018
  2. Content-Type: text/plain; charset="utf-8"
  3. MIME-Version: 1.0
  4. Content-Transfer-Encoding: 7bit
  5. Subject: serial8250 on tegra hsuart: recover from spurious interrupts due to
  6. tegra2 silicon bug
  7. X-Patchwork-Submitter: "David R. Piegdon" <[email protected]>
  8. X-Patchwork-Id: 943440
  9. Message-Id: <[email protected]>
  10. To: [email protected]
  11. Date: Fri, 13 Jul 2018 11:32:42 +0000
  12. From: "David R. Piegdon" <[email protected]>
  13. List-Id: <linux-tegra.vger.kernel.org>
  14. Hi,
  15. a while back I sent a few mails regarding spurious interrupts in the
  16. UARTA (hsuart) block of the Tegra2 SoC, when using the 8250 driver for
  17. it instead of the hsuart driver. After going down a pretty deep
  18. debugging/testing hole, I think I found a patch that fixes the issue. So
  19. far testing in a reboot-cycle suggests that the error frequency dropped
  20. from >3% of all reboots to at least <0.05% of all reboots. Tests
  21. continue to run over the weekend.
  22. The patch below already is a second iteration; the first did not reset
  23. the MCR or contain the lines below '// clear interrupts'. This resulted
  24. in no more spurious interrupts, but in a few % of spurious interrupts
  25. that were recovered the UART block did not receive any characters any
  26. more. So further resetting was required to fully reacquire operational
  27. state of the UART block.
  28. I'd love any comments/suggestions on this!
  29. Cheers,
  30. David
  31. --- a/drivers/tty/serial/8250/8250_core.c
  32. +++ b/drivers/tty/serial/8250/8250_core.c
  33. @@ -134,6 +134,38 @@ static irqreturn_t serial8250_interrupt(
  34. if (l == i->head && pass_counter++ > PASS_LIMIT)
  35. break;
  36. +
  37. +#ifdef CONFIG_ARCH_TEGRA_2x_SOC
  38. + if (!handled && (port->type == PORT_TEGRA)) {
  39. + /*
  40. + * Fix Tegra 2 CPU silicon bug where sometimes
  41. + * "TX holding register empty" interrupts result in a
  42. + * bad (metastable?) state in Tegras HSUART IP core.
  43. + * Only way to recover seems to be to reset all
  44. + * interrupts as well as the TX queue and the MCR.
  45. + * But we don't want to loose any outgoing characters,
  46. + * so only do it if the RX and TX queues are empty.
  47. + */
  48. + unsigned char lsr = port->serial_in(port, UART_LSR);
  49. + const unsigned char fifo_empty_mask =
  50. + (UART_LSR_TEMT | UART_LSR_THRE);
  51. + if (((lsr & (UART_LSR_DR | fifo_empty_mask)) ==
  52. + fifo_empty_mask)) {
  53. + port->serial_out(port, UART_IER, 0);
  54. + port->serial_out(port, UART_MCR, 0);
  55. + serial8250_clear_and_reinit_fifos(up);
  56. + port->serial_out(port, UART_MCR, up->mcr);
  57. + port->serial_out(port, UART_IER, up->ier);
  58. + // clear interrupts
  59. + serial_port_in(port, UART_LSR);
  60. + serial_port_in(port, UART_RX);
  61. + serial_port_in(port, UART_IIR);
  62. + serial_port_in(port, UART_MSR);
  63. + up->lsr_saved_flags = 0;
  64. + up->msr_saved_flags = 0;
  65. + }
  66. + }
  67. +#endif
  68. } while (l != end);
  69. spin_unlock(&i->lock);