[PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

STALE1512d SUPERSEDED

Revision v1 of 3 in this series.

13 messages, 4 authors, 2022-08-30 · open the first message on its own page

[PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-25 09:17:23

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.

Greg,
I've a another series on top this which is tty-next material making the
rest of the drivers to use uart_xmit_advance(). That series obviously
depends on the patch 1/3 of this series so if you end up putting these
3 patches into tty-linus, I'll need it to be merged into tty-next at
some point (I'm not in a big hurry with this so if you choose to delay
the merge, it's not a big deal).

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

[PATCH 1/3] serial: Create uart_xmit_advance()

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-25 09:17:32

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.

Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
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

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

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-25 09:17:36

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

Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
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

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

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-25 09:17:49

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

Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
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

Re: [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Andy Shevchenko <hidden>
Date: 2022-08-26 16:04:34

On Thu, Aug 25, 2022 at 12:19 PM Ilpo Järvinen
[off-list ref] wrote:
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.
For the whole series
Reviewed-by: Andy Shevchenko <redacted>
Thanks for fixing this issue.
Greg,
I've a another series on top this which is tty-next material making the
rest of the drivers to use uart_xmit_advance(). That series obviously
depends on the patch 1/3 of this series so if you end up putting these
3 patches into tty-linus, I'll need it to be merged into tty-next at
some point (I'm not in a big hurry with this so if you choose to delay
the merge, it's not a big deal).

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

-- 
With Best Regards,
Andy Shevchenko

Re: [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2022-08-29 07:23:34

On 25. 08. 22, 11:17, Ilpo Järvinen wrote:
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.

Greg,
I've a another series on top this which is tty-next material making the
rest of the drivers to use uart_xmit_advance(). That series obviously
depends on the patch 1/3 of this series so if you end up putting these
3 patches into tty-linus, I'll need it to be merged into tty-next at
some point (I'm not in a big hurry with this so if you choose to delay
the merge, it's not a big deal).
Hi,
could you hold off with the latter series? I'll send a v2 of TX path cleanup shortly. You'd then need to update much less places (if my series is accepted):
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=2d9ade0412f7e5edacc7f791ebbf773d6481b453
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=fd55062d74a8c137d30388c6e25ebd5c06a04517
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=a1df5129cc0cf174a8cd03e187c6a5e890d313e4

v1 was here (but was doing a call for every character):
https://lore.kernel.org/all/20220411105405.9519-1-jslaby@suse.cz/
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(-)
thanks,
-- 
js
suse labs

Re: [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-29 07:41:20

On Mon, 29 Aug 2022, Jiri Slaby wrote:
On 25. 08. 22, 11:17, Ilpo Järvinen wrote:
quoted
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.

Greg,
I've a another series on top this which is tty-next material making the
rest of the drivers to use uart_xmit_advance(). That series obviously
depends on the patch 1/3 of this series so if you end up putting these
3 patches into tty-linus, I'll need it to be merged into tty-next at
some point (I'm not in a big hurry with this so if you choose to delay
the merge, it's not a big deal).
Hi,
could you hold off with the latter series? I'll send a v2 of TX path cleanup
shortly. You'd then need to update much less places (if my series is
accepted):
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=2d9ade0412f7e5edacc7f791ebbf773d6481b453
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=fd55062d74a8c137d30388c6e25ebd5c06a04517
https://git.kernel.org/pub/scm/linux/kernel/git/jirislaby/linux.git/commit/?h=devel&id=a1df5129cc0cf174a8cd03e187c6a5e890d313e4

v1 was here (but was doing a call for every character):
https://lore.kernel.org/all/20220411105405.9519-1-jslaby@suse.cz/
Sure, I can hold off a while (as long as we're speaking of reasonable 
timescales :-)). Looking into your patches, they also seemed to lack that 
icount.tx++ thing.

-- 
 i.
quoted
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(-)
thanks,

Re: [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Jiri Slaby <jirislaby@kernel.org>
Date: 2022-08-29 07:50:42

On 29. 08. 22, 9:41, Ilpo Järvinen wrote:> Looking into your patches, they also seemed to lack that> icount.tx++ thing.

Perhaps, you only overlooked it?

+	for (; (for_test) && (!tx_ready || tx_ready(port));
+			(for_post), port->icount.tx++) {		

thanks,
-- 
js
suse labs

Re: [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series)

From: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Date: 2022-08-29 07:54:55

On Mon, 29 Aug 2022, Jiri Slaby wrote:
On 29. 08. 22, 9:41, Ilpo Järvinen wrote:> Looking into your patches, they
also seemed to lack that> icount.tx++ thing.

Perhaps, you only overlooked it?

+	for (; (for_test) && (!tx_ready || tx_ready(port));
+			(for_post), port->icount.tx++) {		
Ah, yes, I did (and its placement at the end of a multi-line for() didn't 
help that much either for pick it up :-)).

-- 
 i.

Re: [PATCH 1/3] serial: Create uart_xmit_advance()

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: 2022-08-30 12:27:56

On Thu, Aug 25, 2022 at 12:17:05PM +0300, Ilpo Järvinen wrote:
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.

Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
This commit only adds a new function, it does not "Fix" anything :(

Re: [PATCH 1/3] serial: Create uart_xmit_advance()

From: Andy Shevchenko <hidden>
Date: 2022-08-30 12:39:42

On Tue, Aug 30, 2022 at 3:31 PM Greg Kroah-Hartman
[off-list ref] wrote:
On Thu, Aug 25, 2022 at 12:17:05PM +0300, Ilpo Järvinen wrote:
quoted
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.

Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
This commit only adds a new function, it does not "Fix" anything :(
I'm wondering how to tell stable maintainers about dependencies of
(not yet applied) patches? In practice I saw that contributors use
Fixes tag for the entire chain (for the preparatory patches + the real
fix) when it's not easy / in a nice way to rebase to have a one-patch
fix followed by refactoring, etc.

-- 
With Best Regards,
Andy Shevchenko

Re: [PATCH 1/3] serial: Create uart_xmit_advance()

From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Date: 2022-08-30 12:48:14

On Tue, Aug 30, 2022 at 03:38:27PM +0300, Andy Shevchenko wrote:
On Tue, Aug 30, 2022 at 3:31 PM Greg Kroah-Hartman
[off-list ref] wrote:
quoted
On Thu, Aug 25, 2022 at 12:17:05PM +0300, Ilpo Järvinen wrote:
quoted
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.

Fixes: e9ea096dd225 ("serial: tegra: add serial driver")
Fixes: 2d908b38d409 ("serial: Add Tegra Combined UART driver")
This commit only adds a new function, it does not "Fix" anything :(
I'm wondering how to tell stable maintainers about dependencies of
(not yet applied) patches? In practice I saw that contributors use
Fixes tag for the entire chain (for the preparatory patches + the real
fix) when it's not easy / in a nice way to rebase to have a one-patch
fix followed by refactoring, etc.
It's as if no one has ever had this issue before and wrote it down for
all to read and know what to do in the future.

{sigh}

Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

If you don't know the git id, just use the subject line and it should
work the same.

greg "why even write documentation?" k-h

Re: [PATCH 1/3] serial: Create uart_xmit_advance()

From: Andy Shevchenko <hidden>
Date: 2022-08-30 12:55:42

On Tue, Aug 30, 2022 at 3:48 PM Greg Kroah-Hartman
[off-list ref] wrote:
On Tue, Aug 30, 2022 at 03:38:27PM +0300, Andy Shevchenko wrote:
quoted
On Tue, Aug 30, 2022 at 3:31 PM Greg Kroah-Hartman
[off-list ref] wrote:
quoted
On Thu, Aug 25, 2022 at 12:17:05PM +0300, Ilpo Järvinen wrote:
...
quoted
I'm wondering how to tell stable maintainers about dependencies of
(not yet applied) patches? In practice I saw that contributors use
Fixes tag for the entire chain (for the preparatory patches + the real
fix) when it's not easy / in a nice way to rebase to have a one-patch
fix followed by refactoring, etc.
It's as if no one has ever had this issue before and wrote it down for
all to read and know what to do in the future.

{sigh}

Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

If you don't know the git id, just use the subject line and it should
work the same.

greg "why even write documentation?" k-h
It's good we have it, thanks for writing!
From time to time even experienced developers need to re-read documentation.

-- 
With Best Regards,
Andy Shevchenko
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help