From: Diogo Ivo <diogo.ivo.sx@renesas.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-renesas-soc@vger.kernel.org,
Biju Das <biju.das.jz@bp.renesas.com>,
Au Dang <au.dang.jx@renesas.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>,
Thierry Bultel <thierry.bultel.yh@bp.renesas.com>,
stable@vger.kernel.org, Diogo Ivo <diogo.ivo.sx@renesas.com>
Subject: [PATCH v5 2/7] serial: sh-sci: Keep TX enabled on TEI while data is pending
Date: Tue, 17 Nov 2026 23:40:32 +0000 [thread overview]
Message-ID: <20261117-g2ul_sci-v5-2-30b58ea18923@renesas.com> (raw)
In-Reply-To: <20261117-g2ul_sci-v5-0-30b58ea18923@renesas.com>
From: Biju Das <biju.das.jz@bp.renesas.com>
sci_tx_end_interrupt() clears TE and TEIE unconditionally on SCI and
RSCI ports. If new data was queued or transmission restarted before the
TEI handler runs, disabling the transmitter stalls or truncates output.
To fix truncations, verify that poll_sent_bits are set, and address
stalls by checking for pending data (while the port is not suspended)
before clearing TE and TEIE. The existing TE/TEIE teardown path only
runs once nothing is left to send and we are sure that we are not still
sending data.
While at it, make sure to also stop TX when the port is stopped with data
queued.
Fixes: d61ae331d6f3 ("tty: serial: sh-sci: Add support for tx end interrupt handling")
Cc: stable@vger.kernel.org
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Co-developed-by: Diogo Ivo <diogo.ivo.sx@renesas.com>
Signed-off-by: Diogo Ivo <diogo.ivo.sx@renesas.com>
---
Changes in v5:
- Make the commit message more succinct.
- Drop unused tie and teie initializers from sci_scif_port_params_bits.
- Enable SCSCR.TEIE in sci_stop_tx() on PORT_SCI and call
sci_stop_tx() in sci_transmit_chars() when empty or stopped.
- Check poll_sent_bits in sci_tx_end_interrupt() before acting on TEI.
- Prevent sci_tx_end_interrupt() from restarting TX during suspend.
---
drivers/tty/serial/rsci.c | 4 +++-
drivers/tty/serial/sh-sci-common.h | 2 ++
drivers/tty/serial/sh-sci.c | 45 ++++++++++++++++++++++++++++----------
3 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/drivers/tty/serial/rsci.c b/drivers/tty/serial/rsci.c
index 40db9daa4272..0391111db8ae 100644
--- a/drivers/tty/serial/rsci.c
+++ b/drivers/tty/serial/rsci.c
@@ -465,7 +465,7 @@ static void rsci_transmit_chars(struct uart_port *port)
if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
uart_write_wakeup(port);
- if (kfifo_is_empty(&tport->xmit_fifo)) {
+ if (kfifo_is_empty(&tport->xmit_fifo) || stopped) {
ctrl = rsci_serial_in(port, CCR0);
ctrl &= ~CCR0_TIE;
ctrl |= CCR0_TEIE;
@@ -627,6 +627,8 @@ static const struct sci_port_params_bits rsci_port_param_bits = {
.rxtx_enable = CCR0_RE | CCR0_TE,
.te_clear = CCR0_TE | CCR0_TEIE,
.poll_sent_bits = CSR_TDRE | CSR_TEND,
+ .tie = CCR0_TIE,
+ .teie = CCR0_TEIE
};
static const struct sci_port_params rsci_rzg3e_port_params = {
diff --git a/drivers/tty/serial/sh-sci-common.h b/drivers/tty/serial/sh-sci-common.h
index 01ff9fced803..273856fbc20b 100644
--- a/drivers/tty/serial/sh-sci-common.h
+++ b/drivers/tty/serial/sh-sci-common.h
@@ -56,6 +56,8 @@ struct sci_port_params_bits {
unsigned int rxtx_enable;
unsigned int te_clear;
unsigned int poll_sent_bits;
+ unsigned int tie;
+ unsigned int teie;
};
struct sci_common_regs {
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 9eb297dbc901..c2de7e7faab6 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -261,7 +261,9 @@ static bool sci_uart_earlycon_dev_probing;
static const struct sci_port_params_bits sci_sci_port_params_bits = {
.rxtx_enable = SCSCR_RE | SCSCR_TE,
.te_clear = SCSCR_TE | SCSCR_TEIE,
- .poll_sent_bits = SCI_TDRE | SCI_TEND
+ .poll_sent_bits = SCI_TDRE | SCI_TEND,
+ .tie = SCSCR_TIE,
+ .teie = SCSCR_TEIE
};
static const struct sci_port_params_bits sci_scif_port_params_bits = {
@@ -810,6 +812,9 @@ static void sci_stop_tx(struct uart_port *port)
ctrl &= ~SCSCR_TIE;
+ if (s->type == PORT_SCI && (ctrl & SCSCR_TE))
+ ctrl |= SCSCR_TEIE;
+
sci_serial_out(port, SCSCR, ctrl);
#ifdef CONFIG_SERIAL_SH_SCI_DMA
@@ -1049,16 +1054,9 @@ static void sci_transmit_chars(struct uart_port *port)
if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
uart_write_wakeup(port);
- if (kfifo_is_empty(&tport->xmit_fifo)) {
- if (s->type == PORT_SCI) {
- ctrl = sci_serial_in(port, SCSCR);
- ctrl &= ~SCSCR_TIE;
- ctrl |= SCSCR_TEIE;
- sci_serial_out(port, SCSCR, ctrl);
- }
+ if (kfifo_is_empty(&tport->xmit_fifo) || stopped)
sci_stop_tx(port);
- }
}
static void sci_receive_chars(struct uart_port *port)
@@ -2012,17 +2010,40 @@ static irqreturn_t sci_tx_end_interrupt(int irq, void *ptr)
{
struct uart_port *port = ptr;
struct sci_port *s = to_sci_port(port);
+ struct tty_port *tport = &port->state->port;
+ const struct sci_port_params_bits *bits = s->params->param_bits;
const struct sci_common_regs *regs = s->params->common_regs;
unsigned long flags;
- u32 ctrl;
+ u32 ctrl, status;
if (s->type != PORT_SCI && !sci_is_rsci_type(s->type))
return sci_tx_interrupt(irq, ptr);
uart_port_lock_irqsave(port, &flags);
- ctrl = s->ops->read_reg(port, regs->control) &
- ~(s->params->param_bits->te_clear);
+
+ /*
+ * We may be sending data while we service this TEI. If so,
+ * bail out so we don't stop an ongoing TX.
+ */
+ status = s->ops->read_reg(port, regs->status);
+ if ((status & bits->poll_sent_bits) != bits->poll_sent_bits)
+ goto out_unlock;
+
+ ctrl = s->ops->read_reg(port, regs->control);
+
+ if (!port->suspended &&
+ (port->x_char ||
+ (!kfifo_is_empty(&tport->xmit_fifo) && !uart_tx_stopped(port)))) {
+ ctrl &= ~bits->teie;
+ ctrl |= bits->tie;
+ s->ops->write_reg(port, regs->control, ctrl);
+ s->ops->transmit_chars(port);
+ goto out_unlock;
+ }
+
+ ctrl &= ~bits->te_clear;
s->ops->write_reg(port, regs->control, ctrl);
+out_unlock:
uart_port_unlock_irqrestore(port, flags);
return IRQ_HANDLED;
--
2.56.1
next prev parent reply other threads:[~2026-11-17 23:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 23:40 [PATCH v5 0/7] Fix transmit handling on SCI/RSCI ports Diogo Ivo
2026-11-17 23:40 ` [PATCH v5 1/7] serial: sh-sci: Drop TE disable at end of transmission on SCI Diogo Ivo
2026-11-17 23:40 ` Diogo Ivo [this message]
2026-11-17 23:40 ` [PATCH v5 3/7] serial: rsci: Enable transmit end interrupt in rsci_stop_tx() Diogo Ivo
2026-11-17 23:40 ` [PATCH v5 4/7] serial: sh-sci: Do not kick TX from sci_er_interrupt() on RSCI Diogo Ivo
2026-11-17 23:40 ` [PATCH v5 5/7] serial: sh-sci: Skip TDxE clear when hardware clears it automatically Diogo Ivo
2026-11-17 23:40 ` [PATCH v5 6/7] serial: sh-sci: Toggle TE when restoring SCSCR in console write on SCI Diogo Ivo
2026-11-17 23:40 ` [PATCH v5 7/7] serial: rsci: Simplify rsci_transmit_chars() Diogo Ivo
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=20261117-g2ul_sci-v5-2-30b58ea18923@renesas.com \
--to=diogo.ivo.sx@renesas.com \
--cc=au.dang.jx@renesas.com \
--cc=biju.das.jz@bp.renesas.com \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=stable@vger.kernel.org \
--cc=thierry.bultel.yh@bp.renesas.com \
--cc=wsa+renesas@sang-engineering.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
all inboxes | Powered by JetHome®