Skip to contentSkip to conversation

8250: DMA Fixes

PATCH Superseded Ilpo Järvinen 2 participants 11 messages Nov 7, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Ilpo Järvinen

author maintainer
#0 lore raw

cover 8250: DMA Fixes

Here are a number of 8250 DMA related fixes. The last one seems the most serious problem able to corrupt the payload ordering.

Ilpo Järvinen (4):
serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs
serial: 8250_lpss: Configure DMA also w/o DMA filter
serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
serial: 8250: Flush DMA Rx on RLSI

 drivers/tty/serial/8250/8250_lpss.c | 18 +++++++++++++-----
 drivers/tty/serial/8250/8250_port.c |  7 +++++--
 2 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 1/4 serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs

DW UART sometimes triggers IIR_RDI during DMA Rx when IIR_RX_TIMEOUT should have been triggered instead. Since IIR_RDI has higher priority than IIR_RX_TIMEOUT, this causes the Rx to hang into interrupt loop. The problem seems to occur at least with some combinations of small-sized transfers (I've reproduced the problem on Elkhart Lake PSE UARTs).

If there's already an on-going Rx DMA and IIR_RDI triggers, fall graciously back to non-DMA Rx. That is, behave as if IIR_RX_TIMEOUT had occurred.

8250_omap already considers IIR_RDI similar to this change so its nothing unheard of.

Fixes 75df022b5f89 ("serial: 8250_dma: Fix RX handling")
---
 drivers/tty/serial/8250/8250_port.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/8250/8250_port.c +4 -0
index fe8662cd9402..92dd18716169 100644
@@ -1897,6 +1897,10 @@ EXPORT_SYMBOL_GPL(serial8250_modem_status);
 static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir)
 {
 	switch (iir & 0x3f) {
+	case UART_IIR_RDI:
+		if (!up->dma->rx_running)
+			break;
+		fallthrough;
 	case UART_IIR_RX_TIMEOUT:
 		serial8250_rx_dma_flush(up);
 		fallthrough;
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 2/4 serial: 8250_lpss: Configure DMA also w/o DMA filter

In reply to Ilpo Järvinen

If the platform doesn't use DMA device filter (as is the case with Elkhart Lake), whole lpss8250_dma_setup() setup is skipped. This results in skipping also *_maxburst setup which is undesirable. Refactor lpss8250_dma_setup() to configure DMA even if filter is not setup.

---
 drivers/tty/serial/8250/8250_lpss.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_lpss.c +11 -5
index 44cc755b1a29..ed281445a97d 100644
@@ -277,8 +277,10 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
 	struct dw_dma_slave *rx_param, *tx_param;
 	struct device *dev = port->port.dev;
 
-	if (!lpss->dma_param.dma_dev)
-		return 0;
+	if (!lpss->dma_param.dma_dev) {
+		dma = port->dma;
+		goto confonly;
+	}
 
 	rx_param = devm_kzalloc(dev, sizeof(*rx_param), GFP_KERNEL);
 	if (!rx_param)
@@ -289,16 +291,20 @@ static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port
 		return -ENOMEM;
 
 	*rx_param = lpss->dma_param;
-	dma->rxconf.src_maxburst = lpss->dma_maxburst;
-
 	*tx_param = lpss->dma_param;
-	dma->txconf.dst_maxburst = lpss->dma_maxburst;
 
 	dma->fn = lpss8250_dma_filter;
 	dma->rx_param = rx_param;
 	dma->tx_param = tx_param;
 
 	port->dma = dma;
+
+confonly:
+	if (dma) {
+		dma->rxconf.src_maxburst = lpss->dma_maxburst;
+		dma->txconf.dst_maxburst = lpss->dma_maxburst;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.30.2
#3 lore raw

Re: [PATCH 2/4] serial: 8250_lpss: Configure DMA also w/o DMA filter

Quoted 5 lines · Ilpo Järvinen

If the platform doesn't use DMA device filter (as is the case with Elkhart Lake), whole lpss8250_dma_setup() setup is skipped. This results in skipping also *_maxburst setup which is undesirable. Refactor lpss8250_dma_setup() to configure DMA even if filter is not setup.

...

drivers/tty/serial/8250/8250_lpss.c static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port · line 282

Quoted 3 lines
drivers/tty/serial/8250/8250_lpss.c +3 -0
+	if (!lpss->dma_param.dma_dev) {
+		dma = port->dma;
+		goto confonly;

Perhaps

		if (dma)
			goto out_configuration_only;

		return 0;

(note the label naming as well).

Quoted 1 line
(quoted diff) +1 -0
+	}

...

drivers/tty/serial/8250/8250_lpss.c static int lpss8250_dma_setup(struct lpss8250 *lpss, struct uart_8250_port *port

Quoted 3 lines
drivers/tty/serial/8250/8250_lpss.c +2 -0
+confonly:
 
+	if (dma) {

But you know that previous code has dma != NULL. See above.

Quoted 3 lines
drivers/tty/serial/8250/8250_lpss.c +3 -0
+		dma->rxconf.src_maxburst = lpss->dma_maxburst;
+		dma->txconf.dst_maxburst = lpss->dma_maxburst;
+	}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#4 lore raw

PATCH 3/4 serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake

In reply to Ilpo Järvinen

Configure DMA to use 16B burst size with Elkhart Lake. This makes the bus use more efficient and works around an issue which occurs with the previously used 1B.

Fixes 0a9410b981e9 ("serial: 8250_lpss: Enable DMA on Intel Elkhart Lake")
Cc <[email protected]> # serial: 8250_lpss: Configure DMA also w/o DMA filter

---
I know the list of Co-dev-bys & Sob seems a bit odd for a oneliner. The reason is that I cleaned up this from a more complex patch using the earlier change that I authored myself so only this oneliner remained in this patch.

---
 drivers/tty/serial/8250/8250_lpss.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/tty/serial/8250/8250_lpss.c +2 -0
index ed281445a97d..e0b4e1446eac 100644
@@ -174,6 +174,8 @@ static int ehl_serial_setup(struct lpss8250 *lpss, struct uart_port *port)
 	 */
 	up->dma = dma;
 
+	lpss->dma_maxburst = 16;
+
 	port->set_termios = dw8250_do_set_termios;
 
 	return 0;
Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH 3/4] serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake

Quoted 13 lines · Ilpo Järvinen

Configure DMA to use 16B burst size with Elkhart Lake. This makes the bus use more efficient and works around an issue which occurs with the previously used 1B.

Fixes 0a9410b981e9 ("serial: 8250_lpss: Enable DMA on Intel Elkhart Lake")
Cc <[email protected]> # serial: 8250_lpss: Configure DMA also w/o DMA filter
Quoted 5 lines

---
I know the list of Co-dev-bys & Sob seems a bit odd for a oneliner. The reason is that I cleaned up this from a more complex patch using the earlier change that I authored myself so only this oneliner remained in this patch.

If you changed more than 70% of the code, I would suggest to drop the rest of (Co)authors and if you want to pay a credit, just mention them in the commit message in a free form.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#6 lore raw

PATCH 4/4 serial: 8250: Flush DMA Rx on RLSI

In reply to Ilpo Järvinen

Returning true from handle_rx_dma() without flushing DMA first creates a data ordering hazard. If DMA Rx has handled any character at the point when RLSI occurs, the non-DMA path handles any pending characters jumping them ahead of those characters that are pending under DMA.

Fixes 75df022b5f89 ("serial: 8250_dma: Fix RX handling")

---
Cc: Gilles BULOZ <[email protected]>

 drivers/tty/serial/8250/8250_port.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/serial/8250/8250_port.c +1 -2
index 92dd18716169..388172289627 100644
@@ -1901,10 +1901,9 @@ static bool handle_rx_dma(struct uart_8250_port *up, unsigned int iir)
 		if (!up->dma->rx_running)
 			break;
 		fallthrough;
+	case UART_IIR_RLSI:
 	case UART_IIR_RX_TIMEOUT:
 		serial8250_rx_dma_flush(up);
-		fallthrough;
-	case UART_IIR_RLSI:
 		return true;
 	}
 	return up->dma->rx_dma(up);
Signature · 1 line
2.30.2
#7 lore raw

Re: [PATCH 4/4] serial: 8250: Flush DMA Rx on RLSI

Quoted 10 lines · Ilpo Järvinen

Returning true from handle_rx_dma() without flushing DMA first creates a data ordering hazard. If DMA Rx has handled any character at the point when RLSI occurs, the non-DMA path handles any pending characters jumping them ahead of those characters that are pending under DMA.

Fixes 75df022b5f89 ("serial: 8250_dma: Fix RX handling")

---
Cc: Gilles BULOZ <[email protected]>

Maybe instead you can do --cc Guilles ... for entire series (and drop from other commit messages)?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw
In reply to Ilpo Järvinen
Quoted 5 lines · Ilpo Järvinen

Here are a number of 8250 DMA related fixes. The last one seems the most serious problem able to corrupt the payload ordering.

Ilpo Järvinen (4):
serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs

8250_port?

Quoted 3 lines

serial: 8250_lpss: Configure DMA also w/o DMA filter
serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
serial: 8250: Flush DMA Rx on RLSI

8250_port?

Quoted 4 lines
 drivers/tty/serial/8250/8250_lpss.c | 18 +++++++++++++-----
 drivers/tty/serial/8250/8250_port.c |  7 +++++--
 2 files changed, 18 insertions(+), 7 deletions(-)
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#9 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Ilpo Järvinen

Here are a number of 8250 DMA related fixes. The last one seems the most serious problem able to corrupt the payload ordering.

Ilpo Järvinen (4):
serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs

Quoted 7 lines

8250_port?

Quoted 3 lines

serial: 8250_lpss: Configure DMA also w/o DMA filter
serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
serial: 8250: Flush DMA Rx on RLSI

8250_port?

Why?

To me this 8250_core/port split is still integral part of the same 8250 even if they're in the end technically loaded into different modules or the code is in a different file. There's even some trickery to access internals of the other part to workaround the circular module dependency logic that would otherwise prevent the split (like we learned not so long time ago with that setup_irq change).

I can start to use 8250_port if you insist but it seems pointless 5 extra characters out from a resource that is scarse to begin with, IMHO (the summary line is not that long).

Signature · 1 line
 i.
#10 lore raw
Quoted 26 lines · Ilpo J�rvinen
Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Ilpo J�rvinen

Here are a number of 8250 DMA related fixes. The last one seems the most serious problem able to corrupt the payload ordering.

Ilpo J�rvinen (4):
serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs

Quoted 7 lines

8250_port?

Quoted 3 lines

serial: 8250_lpss: Configure DMA also w/o DMA filter
serial: 8250_lpss: Use 16B DMA burst with Elkhart Lake
serial: 8250: Flush DMA Rx on RLSI

8250_port?

Why?

To me this 8250_core/port split is still integral part of the same 8250 even if they're in the end technically loaded into different modules or the code is in a different file. There's even some trickery to access internals of the other part to workaround the circular module dependency logic that would otherwise prevent the split (like we learned not so long time ago with that setup_irq change).

Quoted 3 lines

I can start to use 8250_port if you insist but it seems pointless 5 extra characters out from a resource that is scarse to begin with, IMHO (the summary line is not that long).

No strong opinion here, I just follow (in my patches) the following logic:
- if it touches a single file, I use full prefix,
- otherwise I use 8250

Signature · 2 lines
With Best Regards,
Andy Shevchenko