From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.218.47 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796516330; b=AlIdB4M/y23Z9jeUhylDsLskCYLfMEtYMS37vF4DDKld3+K7v53POXtBSqOMmZiDr56D JO6NSD29HXWEF8bARTgMNJyR2N1w/iGx7EXTRkk0+7UoaGL/JK/B0tAlWYioWu2wy/XvK +8qZXFR1JAGWUgqwqIJIIUAcNEBIJTWIsZTNIoLGmPE2h+hwZSVKBk+cJoDzZx+pUGOx+ gcd8ZbEad8i6zbBQvTvltv33Zii84bPV0YW22U6x8SuPkMsDYElTss1btC0cQGHamKVb2 qxsc5jICcDcSNe/MqE2eWqO5uqDgD67LFGScwfAxYLO3SW4R85wwijG10iA4mTIzfPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796516330; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=EilV/TMcqjvBlQT88o3qZjTkAySrDu5JMGwpjDbuCRw=; b=diWTDZPdjmJrLuY9By90oqht0YeWGJPFzI9HQX59t/6teui0w3pK3ULsl66OdKlp+nUO i4C5JDAjqx1kYGQ5//puvpU3JMEgZagrPIOF7tswm25lKrwUOu8Kf4MOJS4R/yQiFEHDf qhtdE0nW4Ua23TUEilphUgTg7tKGL1M81K/LbSGPm2FFQmvioQBOezstqer+ig3Z3P2RF FqK8pSFAkskhBfFdZO00xsyswb9t4MwHzeQSe7mOOLfNs8XeKasMkSgcr9BCf4WUCqZFn 1xkOCXIwK0+iSHpTBlW59ALw4rvStjObFwigcJQspbUsFbSJqIML+FjTVxcp0W1YguQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="h/PJ6Pg5"; arc=none smtp.remote-ip=209.85.218.47 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04333606A322 for ; Sun, 6 Dec 2026 00:18:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 04333606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=h/PJ6Pg5 Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-c5255770bf8so392151866b.0 for ; Sat, 05 Dec 2026 16:18:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796516327; x=1797121127; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=EilV/TMcqjvBlQT88o3qZjTkAySrDu5JMGwpjDbuCRw=; b=h/PJ6Pg57TPLY3pXLcWGeDupdvXJmcrENmDQYr/rONvRIF/b7RXaVN1e2FJyFwkW9F y7SIERH34HLPysp/I609f9TGdlfb+JoUUZuNNq2JXFcKCWOJgohq9WEbyGmYV5Y8E4AY IVairvE5lXObVIymeqJe4L2W8w5tbE2CLjD2afhQttVsr+P2v537d3F2Zy85uDsULa/K 0l1rVOj9t8MNfORxYzcrRinvT8/YVk9EunkdPVFjzGS7mHV/tpYG8gbB9xIsXvr9XTqZ 2N3yykoNiV7MvNyjuYKDcEAicjElpfnLBRCHLkVme6nfyMcbZj2OkmGue452VIvE036Q LWFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796516327; x=1797121127; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=EilV/TMcqjvBlQT88o3qZjTkAySrDu5JMGwpjDbuCRw=; b=psvcW3aW4j6I5z5xYlwHSJxN66owPBUfCwA6eLEe2cnG64u6F34a1q4T0b/z348SHb Ukvfw7ND4MwAuopGYvoN9N9cGDRiDy+rdR7yMWkSi+vYtVvMAMh512t1SK1MnHHX1Zl+ 87mjxZZJOeVHaZJN7cvFmPKOIr/oktgXyoa1ImG3TWVnwFZqdWJyjr4NDgBt3tjbT1tD hwvkjgNRDhhpiRRW3ZHOmri/W9z9hOVhAP3BhPBqNUuw9uv7ntT1DG5VJLcO9j0c11kL IIOA3e1+iX2kIat58/jEOJVjut2C6ZbSd4zJ4xfG2ENJyY1JTDCLJlLf1/XxaR/Q3qKU +H0A== X-Forwarded-Encrypted: i=1; AL+hErF5KdnL/mzfs0lJwqmjIUbpzP0cKcdN+QAV3UZIQOXKDALzcVuHpdAaqz0rypaBrSKT+a7qFlr/LNw=@vger.kernel.org X-Gm-Message-State: APuU4Z/RLx7zOVTvaFPogSIQVsZG+OZXeadwc9iSsYJJ70iBEcPmYR4j BMQMTbiPFPGUhb1hT91w4orSSmcD7zFHwGeUp8mbpQc8lWC3k4aHjdHbU45GfVq/DdE= X-Gm-Gg: AZFdTZdBUtGHWjDGbtdZYfUtiCxYaUEqxR+cVzgh7cC6QH49sf7kfxzkHuiWHgxXJZf 5isk5KTPYxdzKHwdolFjvLkxmg0OJdvICEQ6v5gryFrOufgCwn2m2TXJSsoOCNN5ms+GnsZWQuT SmLh4MoItU3ckcEyeVDzNoeZ51cMDWPj+EC0YJvVMqE6bBeiqi1rzvUYbAvrtISQCMqlnGAhRjN axGaL1SJNqhKyGs3pfjgvLOUVS2LH87dKK15bZ439kuj0IO7zdpWqMG0dD+FLnbBcp+B54F51tB uz9hr9bRv3t2OyYYfmxQwhyExEzLAjFBLFfPlccCtcbO4uSQUpqvgHytJjbUc3ATpteNk02AWP1 wNdqJAB/0uy1N4Kwcy/Eiye17RTxHm3axZ2uu/wrCgpu91/hYoQlRqsWJ/Z74CBUjZvgT4yx+M8 Y7Wf0AaNIhPZnhKETFOukT2MCwTE/rtibq8AXQRB5vmt3h8hvLXWSEY+qDTFMJ3hQQZnXr5CEx6 sTyv56+k3DL0ROwGjJttaEPaB8NbgOSsywjXRnvwRz9hhmYA4BUqOQ3k2h8Dp8JGGrFVdDvFSwb oyxaKYjHRYkiXePSHUGVWQQMkdEgkW+x0+m0w5JmMiKi4lIQsjfnTEyItW0nJgM/xCJYf2iVMeg Jxw7n/9xlOp5AJ3KW0EBB3/KUv7IgYoogv1AGo273oiF6fkCSv3jCbkRBZ1GMD5aNGFAsOxdgQ/ Vk15yzLDmyoRNSx2asKqN8c4CAld0j0SSBzQl33MN7dGNMhbhIs5xNKRkjs0boJaKyHw== X-Received: by 2002:a17:907:72ca:b0:c52:51cc:db8a with SMTP id a640c23a62f3a-c52624b6a59mr456987166b.20.1796516327281; Sat, 05 Dec 2026 16:18:47 -0800 (PST) Received: from Mac.localdomain ([188.146.22.246]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c525b3b724esm290077766b.42.2026.12.05.16.18.45 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 05 Dec 2026 16:18:46 -0800 (PST) From: Mateusz Sikora To: Johan Hovold Cc: Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Mateusz Sikora Subject: [PATCH 0/2] USB: serial: ch341: fix character loss at high line speeds Date: Sun, 6 Dec 2026 01:18:42 +0100 Message-ID: <20261206001844.14858-1-ms1qaz@gmail.com> X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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)