public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-serial@vger.kernel.org, Stephen Warren <swarren@nvidia.com>,
	Alan Cox <alan@linux.intel.com>,
	Laxman Dewangan <ldewangan@nvidia.com>,
	Thierry Reding <treding@nvidia.com>,
	linux-kernel@vger.kernel.org
Cc: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 1/3] serial: Create uart_xmit_advance()
Date: Thu, 25 Aug 2022 12:17:05 +0300	[thread overview]
Message-ID: <20220825091707.8112-2-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20220825091707.8112-1-ilpo.jarvinen@linux.intel.com>

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


  reply	other threads:[~2022-08-25  9:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-25  9:17 [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Ilpo Järvinen
2022-08-25  9:17 ` Ilpo Järvinen [this message]
2022-08-30 12:27   ` [PATCH 1/3] serial: Create uart_xmit_advance() Greg Kroah-Hartman
2022-08-30 12:38     ` Andy Shevchenko
2022-08-30 12:48       ` Greg Kroah-Hartman
2022-08-30 12:53         ` Andy Shevchenko
2022-08-25  9:17 ` [PATCH 2/3] serial: tegra: Use uart_xmit_advance(), fixes icount.tx accounting Ilpo Järvinen
2022-08-25  9:17 ` [PATCH 3/3] serial: tegra-tcu: " Ilpo Järvinen
2022-08-26 16:03 ` [PATCH 0/3] serial: Add uart_xmit_advance() + fixes part (of a larger patch series) Andy Shevchenko
2022-08-29  7:23 ` Jiri Slaby
2022-08-29  7:41   ` Ilpo Järvinen
2022-08-29  7:50     ` Jiri Slaby
2022-08-29  7:54       ` Ilpo Järvinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220825091707.8112-2-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=alan@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jirislaby@kernel.org \
    --cc=ldewangan@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=swarren@nvidia.com \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox