linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 RESEND 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)
@ 2022-09-01 14:39 Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance() Ilpo Järvinen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-09-01 14:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, Andy Shevchenko
  Cc: linux-kernel, Ilpo Järvinen

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(-)

-- 
2.30.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance()
  2022-09-01 14:39 [PATCH v2 RESEND 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Ilpo Järvinen
@ 2022-09-01 14:39 ` Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 3/3] serial: tegra-tcu: " Ilpo Järvinen
  2 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-09-01 14:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, Andy Shevchenko,
	linux-kernel
  Cc: Ilpo Järvinen, Andy Shevchenko

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.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 include/linux/serial_core.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index aef3145f2032..ffc7b8cb7a7f 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -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;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 RESEND 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting
  2022-09-01 14:39 [PATCH v2 RESEND 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance() Ilpo Järvinen
@ 2022-09-01 14:39 ` Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 3/3] serial: tegra-tcu: " Ilpo Järvinen
  2 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2022-09-01 14:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, Andy Shevchenko,
	Laxman Dewangan, Thierry Reding, Jonathan Hunter, Stephen Warren,
	Alan Cox, linux-tegra, linux-kernel
  Cc: Ilpo Järvinen, stable, Andy Shevchenko

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

Cc: <stable@vger.kernel.org> # serial: Create uart_xmit_advance()
Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/serial-tegra.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
index ad4f3567ff90..a5748e41483b 100644
--- a/drivers/tty/serial/serial-tegra.c
+++ b/drivers/tty/serial/serial-tegra.c
@@ -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;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 RESEND 3/3] serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting
  2022-09-01 14:39 [PATCH v2 RESEND 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance() Ilpo Järvinen
  2022-09-01 14:39 ` [PATCH v2 RESEND 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting Ilpo Järvinen
@ 2022-09-01 14:39 ` Ilpo Järvinen
  2022-09-15 12:26   ` Thierry Reding
  2 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2022-09-01 14:39 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, linux-serial, Andy Shevchenko,
	Thierry Reding, Jonathan Hunter, linux-tegra, linux-kernel
  Cc: Ilpo Järvinen, stable, Andy Shevchenko

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

Cc: <stable@vger.kernel.org> # serial: Create uart_xmit_advance()
Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/tty/serial/tegra-tcu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/tegra-tcu.c b/drivers/tty/serial/tegra-tcu.c
index 4877c54c613d..889b701ba7c6 100644
--- a/drivers/tty/serial/tegra-tcu.c
+++ b/drivers/tty/serial/tegra-tcu.c
@@ -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);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 RESEND 3/3] serial: tegra-tcu: Use uart_xmit_advance(), fixes icount.tx accounting
  2022-09-01 14:39 ` [PATCH v2 RESEND 3/3] serial: tegra-tcu: " Ilpo Järvinen
@ 2022-09-15 12:26   ` Thierry Reding
  0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2022-09-15 12:26 UTC (permalink / raw)
  To: Ilpo Järvinen
  Cc: Greg Kroah-Hartman, Jiri Slaby, linux-serial, Andy Shevchenko,
	Jonathan Hunter, linux-tegra, linux-kernel, stable,
	Andy Shevchenko

[-- Attachment #1: Type: text/plain, Size: 751 bytes --]

On Thu, Sep 01, 2022 at 05:39:34PM +0300, Ilpo Järvinen wrote:
> Tx'ing does not correctly account Tx'ed characters into icount.tx.
> Using uart_xmit_advance() fixes the problem.
> 
> Cc: <stable@vger.kernel.org> # serial: Create uart_xmit_advance()
> Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>  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:

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-09-15 12:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-01 14:39 [PATCH v2 RESEND 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Ilpo Järvinen
2022-09-01 14:39 ` [PATCH v2 RESEND 1/3] serial: Create uart_xmit_advance() Ilpo Järvinen
2022-09-01 14:39 ` [PATCH v2 RESEND 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting Ilpo Järvinen
2022-09-01 14:39 ` [PATCH v2 RESEND 3/3] serial: tegra-tcu: " Ilpo Järvinen
2022-09-15 12:26   ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).