From: Hugo Villeneuve <hugo@hugovil.com>
To: Paul Mbewe <paultyson.mbewe@ziehl-abegg.de>
Cc: <linux-serial@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<gregkh@linuxfoundation.org>, <jirislaby@kernel.org>,
<hvilleneuve@dimonoff.com>, <stable@vger.kernel.org>,
Tobias Gannert <tobias.gannert@ziehl-abegg.de>,
Joachim Knorr <joachim.knorr@ziehl-abegg.de>
Subject: Re: [PATCH 1/2] serial: sc16is7xx: fix TX gap caused by kfifo circular buffer wrap-around
Date: Thu, 24 Sep 2026 09:53:20 -0400 [thread overview]
Message-ID: <20260924095320.3038105d452dcfbe44cabc60@hugovil.com> (raw)
In-Reply-To: <20260825095741.6dbe87760a2401ba93ed9035@hugovil.com>
On Tue, 25 Aug 2026 09:57:41 -0400
Hugo Villeneuve <hugo@hugovil.com> wrote:
> Hi Paul,
>
> On Tue, 23 Jun 2026 13:22:24 +0200
> Paul Mbewe <paultyson.mbewe@ziehl-abegg.de> wrote:
>
> > kfifo_out_linear_ptr() returns only one contiguous linear segment of the
> > circular kfifo buffer. When transmit data wraps around the end of the
> > buffer, only the first segment (up to the buffer end) is sent. The
> > remaining data at the start of the buffer is not sent until the next TX
> > interrupt fires, resulting in a visible inter-frame gap on the wire.
> >
> > This gap violates the Modbus RTU 1.5 character-time inter-character
> > silence limit. Receivers interpret any silence exceeding 1.5 character
> > times as an end-of-frame marker, splitting a single valid frame into
> > two malformed fragments and corrupting communication on the bus.
> >
> > The incomplete transfer also causes unnecessary TX interrupts: instead
> > of draining the full available FIFO space in one pass, the driver fires
> > an extra interrupt per wrap-around just to send the remaining bytes.
> >
> > The pre-kfifo code handled wrap-around by copying bytes one at a time
> > from the circ_buf into a linear staging buffer. The conversion to kfifo
> > replaced this with a single kfifo_out_linear_ptr() call, losing the
> > wrap-around handling. The max310x driver (a similar SPI UART) correctly
> > handles this with a while loop.
> >
> > Fix this by calling kfifo_out_linear_ptr() in a loop, advancing through
> > all contiguous segments until the available TX FIFO space is exhausted
> > or the kfifo is empty.
> >
> > Tested on SC16IS752 (SPI) driving RS-485 at 115200 baud 8N1 on an
> > i.MX6ULL based board. Oscilloscope confirmed mid-frame breaks at the
> > kfifo wrap-around boundary before the fix; no breaks observed after.
> >
> > Fixes: 1788cf6a91d9 ("tty: serial: switch from circ_buf to kfifo")
> > Cc: stable@vger.kernel.org
> > Reported-by: Tobias Gannert <tobias.gannert@ziehl-abegg.de>
> > Tested-by: Tobias Gannert <tobias.gannert@ziehl-abegg.de>
> > Reviewed-by: Joachim Knorr <joachim.knorr@ziehl-abegg.de>
> > Signed-off-by: Paul Mbewe <paultyson.mbewe@ziehl-abegg.de>
> > ---
> > drivers/tty/serial/sc16is7xx.c | 14 +++++++++++---
> > 1 file changed, 11 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
> > index 1a2c4c14f6aa..395a219280be 100644
> > --- a/drivers/tty/serial/sc16is7xx.c
> > +++ b/drivers/tty/serial/sc16is7xx.c
> > @@ -730,9 +730,17 @@ static void sc16is7xx_handle_tx(struct uart_port *port)
> > txlen = 0;
> > }
> >
> > - txlen = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen);
> > - sc16is7xx_fifo_write(port, tail, txlen);
> > - uart_xmit_advance(port, txlen);
> > + /* Handle circular buffer wrap-around by sending in contiguous segments */
>
> Maybe I would drop "by sending in contiguous segments", because it is
> more confusing than helping for me, because before your patch it was
> already sending one contiguous segment...
> Or maybe change to "... by sending multiple segments"?
>
>
> > + while (txlen > 0 && !kfifo_is_empty(&tport->xmit_fifo)) {
> > + unsigned int to_send;
>
> You can now move this variable here since it is used only in the
> while() scope:
> unsigned char *tail;
>
> > +
> > + to_send = kfifo_out_linear_ptr(&tport->xmit_fifo, &tail, txlen);
> > + if (!to_send)
> > + break;
>
> Insert empty line
>
> > + sc16is7xx_fifo_write(port, tail, to_send);
> > + uart_xmit_advance(port, to_send);
> > + txlen -= to_send;
> > + }
> >
> > uart_port_lock_irqsave(port, &flags);
> > if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
> > --
> > 2.43.0
Hi Paul,
do you still have plans to resubmit that patch (also with my suggestions
above)? If you do, you can probably send it as a standalone patch
independent of this series...
--
Hugo Villeneuve
next prev parent reply other threads:[~2026-09-26 6:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-23 11:22 [PATCH 0/2] serial: sc16is7xx: fix TX inter-frame gaps on SPI UARTs Paul Mbewe
2026-06-23 11:22 ` [PATCH 1/2] serial: sc16is7xx: fix TX gap caused by kfifo circular buffer wrap-around Paul Mbewe
2026-08-25 13:57 ` Hugo Villeneuve
2026-09-24 13:53 ` Hugo Villeneuve [this message]
2026-09-24 16:01 ` Paul Mbewe
2026-06-23 11:22 ` [PATCH 2/2] serial: sc16is7xx: set TX FIFO trigger level to half FIFO to prevent underruns Paul Mbewe
2026-06-23 12:45 ` David Laight
2026-06-23 14:01 ` Paul Mbewe
2026-06-23 15:07 ` David Laight
2026-06-23 17:13 ` Paul Mbewe
2026-06-23 18:42 ` David Laight
2026-06-25 12:59 ` Maarten Brock
2026-07-01 16:40 ` Paul Mbewe
2026-07-01 17:41 ` David Laight
2026-07-02 12:17 ` Maarten Brock
2026-07-02 21:24 ` David Laight
2026-07-03 18:19 ` Paul Mbewe
2026-07-03 20:36 ` David Laight
2026-07-07 15:03 ` Paul Mbewe
2026-07-07 17:50 ` David Laight
2026-07-10 12:43 ` Paul Mbewe
2026-07-11 9:42 ` Maarten Brock
2026-07-10 12:11 ` [PATCH 0/2] serial: sc16is7xx: fix TX inter-frame gaps on SPI UARTs Greg KH
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=20260924095320.3038105d452dcfbe44cabc60@hugovil.com \
--to=hugo@hugovil.com \
--cc=gregkh@linuxfoundation.org \
--cc=hvilleneuve@dimonoff.com \
--cc=jirislaby@kernel.org \
--cc=joachim.knorr@ziehl-abegg.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=paultyson.mbewe@ziehl-abegg.de \
--cc=stable@vger.kernel.org \
--cc=tobias.gannert@ziehl-abegg.de \
/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