Linux Serial subsystem development
 help / color / mirror / Atom feed
* [PATCH 0/3] serial: max310x: transmit path fixes
@ 2026-11-16  9:57 Tapio Reijonen
  2026-11-16  9:57 ` [PATCH 1/3] serial: max310x: do not advance the TX fifo past a flush Tapio Reijonen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Tapio Reijonen @ 2026-11-16  9:57 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-serial, linux-kernel, Hugo Villeneuve, Tapio Reijonen,
	stable

Three fixes for the MAX310x transmit path, found while stress testing
the software-timed RS-485 delays that are new in v7.4.

Patch 1 fixes a race between the transmit work and a flush. The work
advances the fifo after the SPI transfer without the port lock; since
the kfifo conversion in v6.10 a uart_flush_buffer() during the transfer
leaves the fifo length wrapped to about 4G. tcdrain() then never
returns and stale data is sent until the port is closed. It carries
Cc stable, but does not apply to v7.3 and older as it is: the context
is the v7.4 driver. I will send backports for 6.12.y and later.

Patches 2 and 3 fix commit 33632215e1bb ("serial: max310x: drive RTS in
software when hardware delays are too short"), which is in v7.4-rc1.
With patch 2, data written while an envelope is closing no longer
leaves after RTS has been released. With patch 3, a late TX-empty
interrupt of the previous envelope no longer pushes the head of the
next write out before RTS is up. Both lose data silently on an RS-485
bus, so it would be good to have them in v7.4.

Tested on a MAX14830 behind a single-core i.MX6SX, on v7.4-rc3:

- flush during transmission on all four ports, five minutes: the fifo
  length stays within 4096;
- 20 unbinds with a tcdrain() blocked on a slow port: no task is left
  sleeping;
- RS-485 loopback with data verification on three ports, 57600 baud,
  25-byte writes every 20 ms, 20 ms before-send delay, ten minutes:
  no byte lost or misframed. The numbers without patches 2 and 3 are
  in their commit messages;
- baud rate changes at random moments under traffic, each one moving
  the port between chip-timed and driver-timed RTS: 7672 changes in
  ten minutes, no stall, every byte sent;
- TIOCSERGETLSR and tcdrain() polled after every write, 12500 writes:
  the port is never reported idle with data unsent;
- xmit_fifo_size raised to 256 with TIOCSSERIAL: 570000 bytes per
  port, all sent, nothing in the log;
- output stopped with TCOOFF, data queued, baud rate changed: nothing
  is sent while stopped, everything after TCOON;
- TIOCSRS485 repeated every few milliseconds while a second block is
  written at the end of the first, with and without CPU load, 50
  minutes on v7.4-rc2 and v7.4-rc3: 30900 block pairs verified through
  the loopback, none lost.

The envelope timing was checked on a logic analyser with an earlier
version of the three patches, on v7.3-rc7.

Not addressed here, all older than this series:

- an x_char is written without regard to the RTS envelope;
- a reconfigure while stopped output has data queued asserts RTS for
  about one character time;
- by the code, a TIOCSRS485 applied at the very end of an envelope can
  arm the after-send hold while a new write is being pushed, and RTS
  then drops under that write. Patch 2 closes this window for the
  transmit work, not for the work item that applies the ioctl. I could
  not provoke it: see the last test above.
- sc16is7xx advances the transmit fifo after a sleeping write without
  the port lock in the same way; patch 1's race should apply there
  too. I have not looked at that driver further.

I will send the max310x ones separately.

Tool use: Claude Code (Anthropic) was used throughout. It drafted the
code and the commit messages, wrote the test scripts and the hardware
test plans, and analysed the function traces. An LLM review of an
earlier version found two faults, in patches 1 and 3; both were
reproduced on hardware and are fixed in what is posted here. I decided
the approach of each fix, reviewed every change against the code, and
ran the hardware tests. The code and the messages are mine to defend.

Signed-off-by: Tapio Reijonen <tapio.reijonen@vaisala.com>
---
Tapio Reijonen (3):
      serial: max310x: do not advance the TX fifo past a flush
      serial: max310x: re-check the TX queue before the after-send hold
      serial: max310x: hold TX data until the software RTS send phase

 drivers/tty/serial/max310x.c | 122 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 96 insertions(+), 26 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261112-max310x-tx-fixes-eba3803195ae

Best regards,
-- 
Tapio Reijonen <tapio.reijonen@vaisala.com>


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

end of thread, other threads:[~2026-11-16 10:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  9:57 [PATCH 0/3] serial: max310x: transmit path fixes Tapio Reijonen
2026-11-16  9:57 ` [PATCH 1/3] serial: max310x: do not advance the TX fifo past a flush Tapio Reijonen
2026-11-16 10:18   ` sashiko-bot
2026-11-16  9:57 ` [PATCH 2/3] serial: max310x: re-check the TX queue before the after-send hold Tapio Reijonen
2026-11-16 10:12   ` sashiko-bot
2026-11-16  9:57 ` [PATCH 3/3] serial: max310x: hold TX data until the software RTS send phase Tapio Reijonen
2026-11-16 10:34   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox