mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds
@ 2026-12-06  0:18 Mateusz Sikora
  2026-12-06  0:18 ` [PATCH 1/2] USB: serial: allow drivers to use more read urbs Mateusz Sikora
  2026-12-06  0:18 ` [PATCH 2/2] USB: serial: ch341: " Mateusz Sikora
  0 siblings, 2 replies; 4+ messages in thread
From: Mateusz Sikora @ 2026-12-06  0:18 UTC (permalink / raw)
  To: Johan Hovold; +Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Mateusz Sikora

The CH340 has 32-byte bulk endpoints and with the two read urbs used by
the generic implementation it loses characters at 921600 baud as soon as
completion of the read urbs is delayed by more than about 0.7 ms. Two
endpoint-sized urbs, 64 bytes, are far less than what other drivers keep
queued: 1 KiB or more for cdc-acm, 1 KiB for ftdi_sio and 512 bytes for
cp210x and pl2303.

Willy's earlier fix, which used 512-byte buffers, had to be reverted as
these devices do not send zero-length packets [1]. This series instead
lets drivers use more read urbs and makes ch341 use 32 endpoint-sized
ones, 1 KiB in all, each still completing with every packet. WCH's own
out-of-tree driver [2] also reads in endpoint-sized urbs, four of them.

I found this on a Raspberry Pi 4 (6.18.50) recording ESP32 boards at
921600 baud, and reproduced it on an x86 laptop (Ubuntu's 7.0 kernel),
both with the in-tree xhci-hcd, by creating and removing Docker networks
and containers in a loop; on x86 the largest gaps correspond to about
7 ms of data. Lines lost by a CH340 receiving 24-byte lines, per run
(about 220 seconds on the Pi, with two CH340 devices in each run and two
runs with 32 urbs, and 180 seconds on x86):

                    stock      16 urbs    32 urbs
  RPi 4, 921600     392, 398   -          0, 0 / 0, 0
  x86, 921600       436, 335   13, 6      0, 0
  x86, 1500000      703, 681   237, 279   0, 0, 0

With continuous iperf3 traffic through the bridge instead, x86 at
1500000 baud lost 74 to 127 lines per run with the stock driver and
nothing in three runs with 32 urbs. 1 KiB lasts about 7 ms at that rate,
so there is little margin left there. No read urb completed with -EPIPE
in these runs, so this is unrelated to the stalls reported in [3].

Bursts of 32 to 128 bytes followed by a pause were held back for 200 to
800 ms with 512-byte buffers, while this series delivered every burst as
quickly as the stock driver.

Hardware flow control is no option on these boards either: the CH340 is
soldered on, and its RTS output drives the ESP32's reset through the
auto-reset circuit, so with CRTSCTS set on a LOLIN32 the board was held
in reset.

The series is built on top of usb-next with W=1 for x86_64 and i386
without warnings, and the tests ran with the same changes applied to the
6.18 and 7.0 kernels. I can share the test firmware and scripts if that
helps.

I used an AI assistant (Claude) to help track the problem down and to
draft the patches and descriptions. I've reviewed and tested them
myself.

[1] https://lore.kernel.org/all/20210824121926.19311-1-johan@kernel.org/
[2] https://github.com/WCHSoftGroup/ch341ser_linux
[3] https://lore.kernel.org/all/CA+ycdsQ-k3ZnN9t9x4AeVRPgmT2eFWkOzHVChbaPY0ogJEcO6A@mail.gmail.com/

Mateusz

Mateusz Sikora (2):
  USB: serial: allow drivers to use more read urbs
  USB: serial: ch341: use more read urbs

 drivers/usb/serial/ch341.c      |  1 +
 drivers/usb/serial/usb-serial.c | 13 ++++++++++++-
 include/linux/usb/serial.h      | 10 ++++++++--
 3 files changed, 21 insertions(+), 3 deletions(-)

-- 
2.54.0 (Apple Git-157)


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

end of thread, other threads:[~2026-12-06 10:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06  0:18 [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds Mateusz Sikora
2026-12-06  0:18 ` [PATCH 1/2] USB: serial: allow drivers to use more read urbs Mateusz Sikora
2026-12-06  0:18 ` [PATCH 2/2] USB: serial: ch341: " Mateusz Sikora
     [not found]   ` <sashiko-outbox-252017@kernel.org>
2026-12-06 10:23     ` Mateusz Sikora

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®