Skip to contentSkip to conversation

Enhancements to UART driver for error handling and DMA RX status

PATCH In review Moteen Shah 2 participants 5 messages Jan 12 – Jan 20 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

cover Enhancements to UART driver for error handling and DMA RX status

This series adds support for handling UART error conditions such as overrun and other error conditions before any DMA transaction is issued. It also ensures that the DMA RX running status is cleared only after the DMA termination is fully done to maintain a sync between software and the hardware states.

Moteen Shah (2):
serial: 8250: 8250_omap.c: Add support for handling UART error
conditions
serial: 8250: 8250_omap.c: Clear DMA RX running status only after DMA
termination is done

 drivers/tty/serial/8250/8250_omap.c | 25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 serial: 8250: 8250_omap.c: Add support for handling UART error conditions

The DMA IRQ handler does not accounts for the overrun(OE) or any other errors being reported by the IP before triggering a DMA transaction which leads to the interrupts not being handled resulting into an IRQ storm.

The way to handle OE is to:
1. Reset the RX FIFO.
2. Read the UART_RESUME register, which clears the internal flag

Earlier, the driver issued DMA transations even in case of OE which shouldn't be done according to the OE handling mechanism mentioned above, as we are resetting the FIFO's, refer section: "12.1.6.4.8.1.3.6 Overrun During Receive" [0].

[0] https://www.ti.com/lit/pdf/spruiu1

---
 drivers/tty/serial/8250/8250_omap.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_omap.c +21 -2
index 9e49ef48b851..e26bae0a6488 100644
@@ -100,6 +100,9 @@
 #define OMAP_UART_REV_52 0x0502
 #define OMAP_UART_REV_63 0x0603
 
+/* Resume register */
+#define UART_OMAP_RESUME		0x0B
+
 /* Interrupt Enable Register 2 */
 #define UART_OMAP_IER2			0x1B
 #define UART_OMAP_IER2_RHR_IT_DIS	BIT(2)
@@ -119,7 +122,6 @@
 /* Timeout low and High */
 #define UART_OMAP_TO_L                 0x26
 #define UART_OMAP_TO_H                 0x27
-
 struct omap8250_priv {
 	void __iomem *membase;
 	int line;
@@ -1256,6 +1258,20 @@ static u16 omap_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir, u16 status
 	return status;
 }
 
+static void am654_8250_handle_uart_errors(struct uart_8250_port *up, u8 iir, u16 status)
+{
+	if (status & UART_LSR_OE) {
+		serial8250_clear_and_reinit_fifos(up);
+		serial_in(up, UART_LSR);
+		serial_in(up, UART_OMAP_RESUME);
+	} else {
+		if (status & (UART_LSR_FE | UART_LSR_PE | UART_LSR_BI))
+			serial_in(up, UART_RX);
+		if (iir & UART_IIR_XOFF)
+			serial_in(up, UART_IIR);
+	}
+}
+
 static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
 				     u16 status)
 {
@@ -1266,7 +1282,8 @@ static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
 	 * Queue a new transfer if FIFO has data.
 	 */
 	if ((status & (UART_LSR_DR | UART_LSR_BI)) &&
-	    (up->ier & UART_IER_RDI)) {
+	    (up->ier & UART_IER_RDI) && !(status & UART_LSR_OE)) {
+		am654_8250_handle_uart_errors(up, iir, status);
 		omap_8250_rx_dma(up);
 		serial_out(up, UART_OMAP_EFR2, UART_OMAP_EFR2_TIMEOUT_BEHAVE);
 	} else if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) {
@@ -1282,6 +1299,8 @@ static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
 		serial_out(up, UART_OMAP_EFR2, 0x0);
 		up->ier |= UART_IER_RLSI | UART_IER_RDI;
 		serial_out(up, UART_IER, up->ier);
+	} else {
+		am654_8250_handle_uart_errors(up, iir, status);
 	}
 }
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 1/2] serial: 8250: 8250_omap.c: Add support for handling UART error conditions

please check subject of patch

Quoted 1 line · Moteen Shah

The DMA IRQ handler does not accounts for the overrun(OE) or any other

accounts to account

Quoted 1 line

errors being reported by the IP before triggering a DMA transaction which

transaction, which

Quoted 7 lines

leads to the interrupts not being handled resulting into an IRQ storm.

The way to handle OE is to:
1. Reset the RX FIFO.
2. Read the UART_RESUME register, which clears the internal flag

Earlier, the driver issued DMA transations even in case of OE which shouldn't

transations to transactions

Quoted 2 lines

be done according to the OE handling mechanism mentioned above, as we are resetting the FIFO's, refer section: "12.1.6.4.8.1.3.6 Overrun During

FIFO's to FIFO

Quoted 53 lines

Receive" [0].

[0] https://www.ti.com/lit/pdf/spruiu1

---
  drivers/tty/serial/8250/8250_omap.c | 23 +++++++++++++++++++++--
  1 file changed, 21 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_omap.c +17 -1
index 9e49ef48b851..e26bae0a6488 100644
@@ -100,6 +100,9 @@
  #define OMAP_UART_REV_52 0x0502
  #define OMAP_UART_REV_63 0x0603
 
+/* Resume register */
+#define UART_OMAP_RESUME		0x0B
+
  /* Interrupt Enable Register 2 */
  #define UART_OMAP_IER2			0x1B
  #define UART_OMAP_IER2_RHR_IT_DIS	BIT(2)
@@ -119,7 +122,6 @@
  /* Timeout low and High */
  #define UART_OMAP_TO_L                 0x26
  #define UART_OMAP_TO_H                 0x27
-
  struct omap8250_priv {
  	void __iomem *membase;
  	int line;
@@ -1256,6 +1258,20 @@ static u16 omap_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir, u16 status
  	return status;
  }
 
+static void am654_8250_handle_uart_errors(struct uart_8250_port *up, u8 iir, u16 status)
+{
+	if (status & UART_LSR_OE) {
+		serial8250_clear_and_reinit_fifos(up);
+		serial_in(up, UART_LSR);
+		serial_in(up, UART_OMAP_RESUME);
+	} else {
+		if (status & (UART_LSR_FE | UART_LSR_PE | UART_LSR_BI))
+			serial_in(up, UART_RX);
+		if (iir & UART_IIR_XOFF)
+			serial_in(up, UART_IIR);
+	}
+}
+
  static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
  				     u16 status)
  {

drivers/tty/serial/8250/8250_omap.c static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir, · line 1286

Quoted 6 lines
drivers/tty/serial/8250/8250_omap.c +2 -1
@@ -1266,7 +1282,8 @@ static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
  	 * Queue a new transfer if FIFO has data.
  	 */
  	if ((status & (UART_LSR_DR | UART_LSR_BI)) &&
-	    (up->ier & UART_IER_RDI)) {
+	    (up->ier & UART_IER_RDI) && !(status & UART_LSR_OE)) {
+		am654_8250_handle_uart_errors(up, iir, status);

may be you can think of splitting error handing into 2 functions ie handle BI or so and OE error.

when you call above function am654_8250_handle_uart_errors, first condition will be always false.

drivers/tty/serial/8250/8250_omap.c static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir, · line 1303

Quoted 9 lines
drivers/tty/serial/8250/8250_omap.c +2 -0
  		omap_8250_rx_dma(up);
  		serial_out(up, UART_OMAP_EFR2, UART_OMAP_EFR2_TIMEOUT_BEHAVE);
  	} else if ((iir & 0x3f) == UART_IIR_RX_TIMEOUT) {
@@ -1282,6 +1299,8 @@ static void am654_8250_handle_rx_dma(struct uart_8250_port *up, u8 iir,
  		serial_out(up, UART_OMAP_EFR2, 0x0);
  		up->ier |= UART_IER_RLSI | UART_IER_RDI;
  		serial_out(up, UART_IER, up->ier);
+	} else {
+		am654_8250_handle_uart_errors(up, iir, status);

I assume , you will hit this else only case of OE ? , if yes then do you think, call to error handling should be conditional ?

Quoted 3 lines
drivers/tty/serial/8250/8250_omap.c +0 -0
  	}
  }
 
#3 lore raw

PATCH 2/2 serial: 8250: 8250_omap.c: Clear DMA RX running status only after DMA termination is done

In reply to Moteen Shah

Clear rx_running flag only after DMA teardown polling completes. In the previous implementation the flag was being cleared while hardware teardown was still in progress, creating a mismatch between software state (flag = 0, "ready") and hardware state (still terminating).

---
 drivers/tty/serial/8250/8250_omap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_omap.c +1 -1
index e26bae0a6488..272bc07c9a6b 100644
@@ -931,7 +931,6 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 		goto out;
 
 	cookie = dma->rx_cookie;
-	dma->rx_running = 0;
 
 	/* Re-enable RX FIFO interrupt now that transfer is complete */
 	if (priv->habit & UART_HAS_RHR_IT_DIS) {
@@ -965,6 +964,7 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
 		goto out;
 	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
+	dma->rx_running = 0;
 	p->port.icount.rx += ret;
 	p->port.icount.buf_overrun += count - ret;
 out:
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 2/2] serial: 8250: 8250_omap.c: Clear DMA RX running status only after DMA termination is done

Please check subject

git log drivers/tty/serial/8250/8250_omap.c

serial: 8250_omap: ....

Quoted 2 lines · Moteen Shah

Clear rx_running flag only after DMA teardown polling completes. In the previous implementation the flag was being cleared while hardware teardown

hardware to DMA please,

Quoted 28 lines

was still in progress, creating a mismatch between software state (flag = 0, "ready") and hardware state (still terminating).

---
  drivers/tty/serial/8250/8250_omap.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_omap.c +1 -1
index e26bae0a6488..272bc07c9a6b 100644
@@ -931,7 +931,6 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
  		goto out;
 
  	cookie = dma->rx_cookie;
-	dma->rx_running = 0;
 
  	/* Re-enable RX FIFO interrupt now that transfer is complete */
  	if (priv->habit & UART_HAS_RHR_IT_DIS) {
@@ -965,6 +964,7 @@ static void __dma_rx_do_complete(struct uart_8250_port *p)
  		goto out;
  	ret = tty_insert_flip_string(tty_port, dma->rx_buf, count);
 
+	dma->rx_running = 0;
  	p->port.icount.rx += ret;
  	p->port.icount.buf_overrun += count - ret;
  out: