From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796516329; b=3aA9vbh00lCEQvtIGDquL1vv60Ie7pYUHNymH47SBz0HsPTmaXYj8x7Hgdms7xQmEaen 7vrF6z9OWVRAY1S90kfBtIMguCvRVcVf44cYxFiCTJZELU4kMMsP2tVIj9DpcJdVwIBl/ DfxXu0OcJjFVkqyOSmdyR8BOfmvXjBDJmVgLhu4z//isGUupsMqUzON4qDZ4OuKidxMQp PCoXTMO6qYTJ0qWcIaVsvr3iz+t9/73KGhPICc5oObSFq7g13gJNI2Xn/ThoZfeS5KYxg EKRlrP5/yQT5hWsOmPR5P8+En0ZYgGf4TJ6zb7V+QYm9afP5LAOPagW25tx4TEyIZEQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796516329; 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=MqY2qAuIc5OMnqFZ8yXgi7GrF2x6xtCxr3i1Ddg9PjKn7mNvTM41UQUKMDU9jflfwcNL Gu6g4GHsNSwqmcBJGLx4fMcvjfYmlD0eHbmg/mbydRZ5RPEjeKyp98KrZJHumjljCMULQ UD6EDh9m62k4CMIo9hg0eXW3AV+RNnY/tnyqib4xoe49C8FhHat+OFQWD1U64Ad22VXxr 8DR75CS/ZxBxKiSXYDq/MhPkpNJ8rNLcpGCc+c/zPT6rXI5ZUTzKVS/0lnMyv2j4lTZvo oSqpvI1ilzMQvukF//jbxxvIdIc6u5pOy8fZYcHXpsxHbgZ1YNBWOfeUce63u3GZziA== 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.208.53 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (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 ECEA5606A31F for ; Sun, 6 Dec 2026 00:18:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ECEA5606A31F 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-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-6b87a1a2babso5195433a12.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=ckKzYYCGvFRN60Fpf8J8MXqrU+E1a2Slb1GYKO4yZnbIEnOPDuvpQX+Opc8zLk+HVX 1cJHSgXDfTM9vIdRRyg6iIik7SzB3zVES6xcgV/aMHX2pknUxuE6Yj7eESLQCElQohEs Iq7VlhN3V776zVH9uBid2pA+W1f3J1/E2/DZaj8YEqVR+YLU2DEdclSr0AmYvwh3E111 Wwzcmmf5yrUHGxrT02Ksz2Qz6hVFzRJp6Lfw3bkq9s6cxGV7S6OaC80+jbFVOLJ0kznb 0/FgglRaTFoYOod/3LN6mo0Fki8PB+OqIwX+TdqANPe9u3fyWmNiToi6N3tBq0N9dpsR USRg== X-Forwarded-Encrypted: i=1; AL+hErEgXt/NHUHRTYRvtecinqekbDWKfYSvnoP5LEWCaouNMao6EFAhG/kFopS/MUm+0u0ZVWb4bGFcO0cX94M=@vger.kernel.org X-Gm-Message-State: APuU4Z9T/ZgveepbCyoqiAUug0sHPMX8LWUYenxb14v7nvuo4ideHOek uwI1RmS85N1D0o0sxmL5xBMUbz54Z0rkfGIEUaiTsHURiIQTjf9UsdiF X-Gm-Gg: AZFdTZcuHP8YJNaRyTEq242uKjfqAAktEI5ugQPPA731nuWxnzy5KYCNxcKWPr98BUd hz0stiBX9v+6bC3nb++S6HwydzYOWg4DAz/MehUgRGKplG2PbeP4nZ99XmnK5tgXCDjQZYi/jvL AuUBAJuc8t6tgU0VamQYfg6SABOb0XpCRJfcN4UdDROdF9wGN21bhLW6yodGJdh+wNrGs4BNPxY kxzVT1Gwwh2BLNclmfXUiiiFd9E6NfCjgug53dgw3DdKz+X4g2UfVGP9yy7GwTbqO3y5Rdqe06v dxZg8OLJWAY7L4xV0F/BnEsCllkeK60ole/P19OdqehnPOMAWUBAhVDhsyt9XL9ROWInHpoOw/3 tdyhrbv/50f62tYS+KxvXx/70STr9PrD6DbW+hPiyYWiQ5nj0neujSFkPSrCUjBCxYdcEUcxHvF r/SGQI3bGjDlS8vgj4yFh+WH7sNifJCc9ayagKNSWHepDwGLHHvk7OOKnuxg76oCLTyt+aqkiqq bWlHUll0xz0L05RlKCJNn0VTy2u4jYt4AocX3m3Mjex2oPHqQXUC3/mqPAe7tMwJAFh8VqaG6BX nhg+XLTSJY4RO5nEzVRYUVmw8v4oOvrx8oc4godKhohAXBJCetNJBakebQsztuNk7bMXdmhdETF EHSwb2/yzLYm/bw6kdxCkW8sDhU50IWhrUwufzvpFb6FnkjU5Ys5ZCzCDkn8ia2tP0Z/pwgB3S6 0bqZg2W9wdyvawgvI8IgWAHlhUD/Lw/uyGd/fdmtHiJKE6X50lO2c/GZoLxG0mQOQYeQ== 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-kernel@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)