Skip to contentSkip to conversation

serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

PATCH RESEND In review Ilpo Järvinen 2 participants 5 messages Sep 1, 2022 – Sep 15, 2022

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

Add uart_xmit_advance() helper to handle circular xmit buffer advancement + accounting of Tx'ed bytes. Use it to fix a few drivers that previously lacked to accounting for DMA Tx.

v2:
- Correct tags

Ilpo Järvinen (3):
serial: Create uart_xmit_advance()
serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting
serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting

 drivers/tty/serial/serial-tegra.c |  5 ++---
 drivers/tty/serial/tegra-tcu.c    |  2 +-
 include/linux/serial_core.h       | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 4 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH RESEND v2 1/3 serial: Create uart_xmit_advance()

A very common pattern in the drivers is to advance xmit tail index and do bookkeeping of Tx'ed characters. Create uart_xmit_advance() to handle it.

---
 include/linux/serial_core.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
include/linux/serial_core.h +17 -0
index aef3145f2032..ffc7b8cb7a7f 100644
@@ -616,6 +616,23 @@ struct uart_state {
 /* number of characters left in xmit buffer before we ask for more */
 #define WAKEUP_CHARS		256
 
+/**
+ * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars
+ * @up: uart_port structure describing the port
+ * @chars: number of characters sent
+ *
+ * This function advances the tail of circular xmit buffer by the number of
+ * @chars transmitted and handles accounting of transmitted bytes (into
+ * @up's icount.tx).
+ */
+static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars)
+{
+	struct circ_buf *xmit = &up->state->xmit;
+
+	xmit->tail = (xmit->tail + chars) & (UART_XMIT_SIZE - 1);
+	up->icount.tx += chars;
+}
+
 struct module;
 struct tty_driver;
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH RESEND v2 2/3 serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting

In reply to Ilpo Järvinen

DMA complete & stop paths did not correctly account Tx'ed characters into icount.tx. Using uart_xmit_advance() fixes the problem.

Cc <[email protected]> # serial: Create uart_xmit_advance()
Fixes e9ea096dd225 ("serial: tegra: add serial driver")
---
 drivers/tty/serial/serial-tegra.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tty/serial/serial-tegra.c +2 -3
index ad4f3567ff90..a5748e41483b 100644
@@ -525,7 +525,7 @@ static void tegra_uart_tx_dma_complete(void *args)
 	count = tup->tx_bytes_requested - state.residue;
 	async_tx_ack(tup->tx_dma_desc);
 	spin_lock_irqsave(&tup->uport.lock, flags);
-	xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
+	uart_xmit_advance(&tup->uport, count);
 	tup->tx_in_progress = 0;
 	if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
 		uart_write_wakeup(&tup->uport);
@@ -613,7 +613,6 @@ static unsigned int tegra_uart_tx_empty(struct uart_port *u)
 static void tegra_uart_stop_tx(struct uart_port *u)
 {
 	struct tegra_uart_port *tup = to_tegra_uport(u);
-	struct circ_buf *xmit = &tup->uport.state->xmit;
 	struct dma_tx_state state;
 	unsigned int count;
 
@@ -624,7 +623,7 @@ static void tegra_uart_stop_tx(struct uart_port *u)
 	dmaengine_tx_status(tup->tx_dma_chan, tup->tx_cookie, &state);
 	count = tup->tx_bytes_requested - state.residue;
 	async_tx_ack(tup->tx_dma_desc);
-	xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
+	uart_xmit_advance(&tup->uport, count);
 	tup->tx_in_progress = 0;
 }
 
Signature · 1 line
2.30.2
#3 lore raw

PATCH RESEND v2 3/3 serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting

In reply to Ilpo Järvinen

Tx'ing does not correctly account Tx'ed characters into icount.tx. Using uart_xmit_advance() fixes the problem.

Cc <[email protected]> # serial: Create uart_xmit_advance()
Fixes 2d908b38d409 ("serial: Add Tegra Combined UART driver")
---
 drivers/tty/serial/tegra-tcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/tegra-tcu.c +1 -1
index 4877c54c613d..889b701ba7c6 100644
@@ -101,7 +101,7 @@ static void tegra_tcu_uart_start_tx(struct uart_port *port)
 			break;
 
 		tegra_tcu_write(tcu, &xmit->buf[xmit->tail], count);
-		xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
+		uart_xmit_advance(port, count);
 	}
 
 	uart_write_wakeup(port);
Signature · 1 line
2.30.2
Acked-by on v2 3/3
#4 lore raw

Re: [PATCH v2 RESEND 3/3] serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting

Quoted 10 lines · Ilpo Järvinen

Tx'ing does not correctly account Tx'ed characters into icount.tx. Using uart_xmit_advance() fixes the problem.

Cc <[email protected]> # serial: Create uart_xmit_advance()
Fixes 2d908b38d409 ("serial: Add Tegra Combined UART driver")
---
 drivers/tty/serial/tegra-tcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Difficult to review without a copy of the first patch in my inbox. I was able to find it on lore, though and this does seem to do the right thing, so: