From: Mateusz Sikora <ms1qaz@gmail.com>
To: Johan Hovold <johan@kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Mateusz Sikora <ms1qaz@gmail.com>
Subject: [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds
Date: Sun, 6 Dec 2026 01:18:42 +0100 [thread overview]
Message-ID: <20261206001844.14858-1-ms1qaz@gmail.com> (raw)
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)
next reply other threads:[~2026-12-06 0:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-06 0:18 Mateusz Sikora [this message]
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
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=20261206001844.14858-1-ms1qaz@gmail.com \
--to=ms1qaz@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/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®