From patchwork Mon Mar 16 17:46:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11441149 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA23B14B4 for ; Mon, 16 Mar 2020 18:45:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F61F20674 for ; Mon, 16 Mar 2020 18:45:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="riJ5KKx/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F61F20674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDukG-00071Z-P2 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Mar 2020 14:45:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42734) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtp9-0002uZ-Qm for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDtp8-0001sk-JT for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:47 -0400 Received: from mail-qv1-xf44.google.com ([2607:f8b0:4864:20::f44]:44798) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDtp8-0001nG-C4 for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:46 -0400 Received: by mail-qv1-xf44.google.com with SMTP id w5so9314087qvp.11 for ; Mon, 16 Mar 2020 10:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6huCwRcLnrRmQGGZQ5LTMmE1f5Gb39vHnRRdbzeE9oQ=; b=riJ5KKx/n6cd1x54GENcAF7aQNNiVgjydeEQZNAHeFiosmD7yakWh9dJeuKVXRpZ2c kbjUBlZbUunPMs4xgs63cWG9Ua3Fc9i2wE2LvNhG+hZ4RgNOtnDRMb/JxpPHYY9/IdQX lk02+ZNEr1CJ3u7Mo7di+Y/3U1ww8KUp2YIgmFZqUy3gE2u907olHLJrmK8ikqhM1h9F D9+TCV3f/29h2BqKxyLKyEXhfC2U9WrBqjMHKISe5yvMKZN6DzpjvDULJlI43Bx9En5h YQYGPYnKmCn9VuiwXYyXjDgSUM3X5k442vHYu753gMdzmVjsPLRciGJP+X740TFROs0W Zo7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6huCwRcLnrRmQGGZQ5LTMmE1f5Gb39vHnRRdbzeE9oQ=; b=umL4Hu9pAH+kYliwgS5EhMZvqF/M0guKYMjgzolPeiYqqS69yp0Jdj7QdcUvesAdH8 Il5frmylHquzt3R7d0XfSfOsgI0cyPQgnLWFbS7HSGrgblzdPOg7cvU5NAdCsd/aVJG6 3h1a7+r7mQvnDFwFTtySTqC0bAOIIPBU+AKscCAp8753wm8UT49ZtDK1MEkANp5wgs0s NuvW2miuHJQbDeTlngf2BSHwbYofOJ8zGjtA3iS2M2990T9HzXK4BgXilzfMQvMnIRhz KVJoTi9D1uJrwCG/oSXMXVpLX6NKPrj69xmMAQ5mjRyCZR0jFh8VaFuJm4oSLucDm/4Z 9Pbg== X-Gm-Message-State: ANhLgQ2DDbs34PU5vFu1Q0yrc52GmM5AavkaZiDj2rUyJFKUThUS4zGD 4NsFGY5eZo/eP3INjzgE140= X-Google-Smtp-Source: ADFU+vtN9nk2QWpxiagC7U9vH719Qyp0iS5F2Zllla44w+9M/Geou7UIRG5cALvADIyg2kykZdUW3A== X-Received: by 2002:ad4:45e9:: with SMTP id q9mr910584qvu.199.1584380805774; Mon, 16 Mar 2020 10:46:45 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:7408:9006:8741:9ceb]) by smtp.gmail.com with ESMTPSA id g7sm218422qki.64.2020.03.16.10.46.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 10:46:45 -0700 (PDT) From: Jason Andryuk To: Gerd Hoffmann , Samuel Thibault Subject: [PATCH v2 1/4] usb-serial: Move USB_TOKEN_IN into a helper function Date: Mon, 16 Mar 2020 13:46:07 -0400 Message-Id: <20200316174610.115820-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316174610.115820-1-jandryuk@gmail.com> References: <20200316174610.115820-1-jandryuk@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::f44 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Jason Andryuk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We'll be adding a loop, so move the code into a helper function. breaks are replaced with returns. While making this change, add braces to single line if statements to comply with coding style and keep checkpatch happy. Signed-off-by: Jason Andryuk --- v2: Add braces to single line if statements to comply with coding style. hw/usb/dev-serial.c | 80 ++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index daac75b7ae..d807ce5771 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -358,13 +358,56 @@ static void usb_serial_handle_control(USBDevice *dev, USBPacket *p, } } +static void usb_serial_token_in(USBSerialState *s, USBPacket *p) +{ + int first_len, len; + uint8_t header[2]; + + first_len = RECV_BUF - s->recv_ptr; + len = p->iov.size; + if (len <= 2) { + p->status = USB_RET_NAK; + return; + } + header[0] = usb_get_modem_lines(s) | 1; + /* We do not have the uart details */ + /* handle serial break */ + if (s->event_trigger && s->event_trigger & FTDI_BI) { + s->event_trigger &= ~FTDI_BI; + header[1] = FTDI_BI; + usb_packet_copy(p, header, 2); + return; + } else { + header[1] = 0; + } + len -= 2; + if (len > s->recv_used) { + len = s->recv_used; + } + if (!len) { + p->status = USB_RET_NAK; + return; + } + if (first_len > len) { + first_len = len; + } + usb_packet_copy(p, header, 2); + usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len); + if (len > first_len) { + usb_packet_copy(p, s->recv_buf, len - first_len); + } + s->recv_used -= len; + s->recv_ptr = (s->recv_ptr + len) % RECV_BUF; + + return; +} + static void usb_serial_handle_data(USBDevice *dev, USBPacket *p) { USBSerialState *s = (USBSerialState *)dev; uint8_t devep = p->ep->nr; struct iovec *iov; - uint8_t header[2]; - int i, first_len, len; + int i; switch (p->pid) { case USB_TOKEN_OUT: @@ -382,38 +425,7 @@ static void usb_serial_handle_data(USBDevice *dev, USBPacket *p) case USB_TOKEN_IN: if (devep != 1) goto fail; - first_len = RECV_BUF - s->recv_ptr; - len = p->iov.size; - if (len <= 2) { - p->status = USB_RET_NAK; - break; - } - header[0] = usb_get_modem_lines(s) | 1; - /* We do not have the uart details */ - /* handle serial break */ - if (s->event_trigger && s->event_trigger & FTDI_BI) { - s->event_trigger &= ~FTDI_BI; - header[1] = FTDI_BI; - usb_packet_copy(p, header, 2); - break; - } else { - header[1] = 0; - } - len -= 2; - if (len > s->recv_used) - len = s->recv_used; - if (!len) { - p->status = USB_RET_NAK; - break; - } - if (first_len > len) - first_len = len; - usb_packet_copy(p, header, 2); - usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len); - if (len > first_len) - usb_packet_copy(p, s->recv_buf, len - first_len); - s->recv_used -= len; - s->recv_ptr = (s->recv_ptr + len) % RECV_BUF; + usb_serial_token_in(s, p); break; default: From patchwork Mon Mar 16 17:46:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11441151 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6F9C14B4 for ; Mon, 16 Mar 2020 18:47:34 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CCD62073E for ; Mon, 16 Mar 2020 18:47:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hVCTUILq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CCD62073E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDulx-0002A9-LZ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Mar 2020 14:47:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42829) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtpE-00033c-Cw for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDtpC-0002Ts-5k for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:51 -0400 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]:39180) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDtpB-0002OX-Ve for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:50 -0400 Received: by mail-qt1-x842.google.com with SMTP id f17so13678712qtq.6 for ; Mon, 16 Mar 2020 10:46:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1bhwCIfQKKaw/R08di2pqGOd6dOxABFn7wMHJ0Kn9bo=; b=hVCTUILqyn25cAs18bIpcWe+mUdVZ5fYYw/XvvOARetvrzoNjm0MhDlkyQZXaGQNzH OYCfcVKfL336sVqZQs4cHS+bgUsjjixjjj8Lfkuui4WEY/6boIu6htKc3sfkTlpzFcMG FRYd0yVYZ18ZWauAESESj0W3q3kPn4ecz64E3TougC0kC0pyp6gAtu4rfM51SC0fI1ap 8oCQu/6Gvk/UC4Tv/AQY4Fskww8d3GtZwMXgAJvsHfnaLbYzcndYmZ3Y+rw1Axe1gJR3 pHUpYSPYueEG7WaYg21lbML+Kt4OKMHHIqoEMPrJ4TYTbpJfiK5gPaBDVDaf28b2uyj9 ti6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1bhwCIfQKKaw/R08di2pqGOd6dOxABFn7wMHJ0Kn9bo=; b=Zoh5OIm219yjZlzBXqj3q5sX7i/gvevWDUXnttH35OMyJnGY65FeVD2rjwgh5mRiH0 ltDOSI05im92uMA10VuvyimPYzlVHXWtG6Hn88d7YGIZEoFs7f3I5j0lYjvtdN8FHDFS wa1d+LLGSu1tsfqZ7l6XdX648F++7RQ9n+97CKGB3sCOsNA+2UhLVlf9drGFAFY+yNUq jP8fhMUjva83jhfLlwFXIUOXwRh54X+fRTx5XXaJc/dNMiyPvAk1KRDLN3Eu+/U9PRdO i5tPLm48oADtH8Y3l50FU1l7GpH2S5AVsKUzmCvjhy02YO07CSMXHXGYetesJuhhkd2D YhyA== X-Gm-Message-State: ANhLgQ28mkKzl9cMvmguE25ywaec5YgHUnuWUInLx3wflieQOtfxAG1L o16jyCCtRHjjtBWDwdxXlzs= X-Google-Smtp-Source: ADFU+vvVjtqfF5T5FJ5cYmY30KY+bFjLftrCBgzmVqIlW1PjwnJjjS77swQCKoPB1EWpFwOX4h3ptQ== X-Received: by 2002:ac8:4cce:: with SMTP id l14mr1261605qtv.383.1584380809408; Mon, 16 Mar 2020 10:46:49 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:7408:9006:8741:9ceb]) by smtp.gmail.com with ESMTPSA id g7sm218422qki.64.2020.03.16.10.46.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 10:46:48 -0700 (PDT) From: Jason Andryuk To: Gerd Hoffmann , Samuel Thibault Subject: [PATCH v2 2/4] usb-serial: chunk data to wMaxPacketSize Date: Mon, 16 Mar 2020 13:46:08 -0400 Message-Id: <20200316174610.115820-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316174610.115820-1-jandryuk@gmail.com> References: <20200316174610.115820-1-jandryuk@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::842 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Jason Andryuk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" usb-serial has issues with xHCI controllers where data is lost in the VM. Inspecting the URBs in the guest, EHCI starts every 64 byte boundary (wMaxPacketSize) with a header. EHCI hands packets into usb_serial_token_in() with size 64, so these cannot cross the 64 byte boundary. The xHCI controller has packets of 512 bytes and the usb-serial will just write through the 64 byte boundary. In the guest, this means data bytes are interpreted as header, so data bytes don't make it out the serial interface. Re-work usb_serial_token_in to chunk data into 64 byte units - 2 byte header and 62 bytes data. The Linux driver reads wMaxPacketSize to find the chunk size, so we match that. Real hardware was observed to pass in 512 byte URBs (496 bytes data + 8 * 2 byte headers). Since usb-serial only buffers 384 bytes of data, usb-serial will pass in 6 64 byte blocks and 1 12 byte partial block for 462 bytes max. Signed-off-by: Jason Andryuk --- hw/usb/dev-serial.c | 47 ++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index d807ce5771..ec091b6a36 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -360,15 +360,16 @@ static void usb_serial_handle_control(USBDevice *dev, USBPacket *p, static void usb_serial_token_in(USBSerialState *s, USBPacket *p) { - int first_len, len; + const int max_packet_size = desc_iface0.eps[0].wMaxPacketSize; + int packet_len; uint8_t header[2]; - first_len = RECV_BUF - s->recv_ptr; - len = p->iov.size; - if (len <= 2) { + packet_len = p->iov.size; + if (packet_len <= 2) { p->status = USB_RET_NAK; return; } + header[0] = usb_get_modem_lines(s) | 1; /* We do not have the uart details */ /* handle serial break */ @@ -380,24 +381,34 @@ static void usb_serial_token_in(USBSerialState *s, USBPacket *p) } else { header[1] = 0; } - len -= 2; - if (len > s->recv_used) { - len = s->recv_used; - } - if (!len) { + + if (!s->recv_used) { p->status = USB_RET_NAK; return; } - if (first_len > len) { - first_len = len; - } - usb_packet_copy(p, header, 2); - usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len); - if (len > first_len) { - usb_packet_copy(p, s->recv_buf, len - first_len); + + while (s->recv_used && packet_len > 2) { + int first_len, len; + + len = MIN(packet_len, max_packet_size); + len -= 2; + if (len > s->recv_used) { + len = s->recv_used; + } + + first_len = RECV_BUF - s->recv_ptr; + if (first_len > len) { + first_len = len; + } + usb_packet_copy(p, header, 2); + usb_packet_copy(p, s->recv_buf + s->recv_ptr, first_len); + if (len > first_len) { + usb_packet_copy(p, s->recv_buf, len - first_len); + } + s->recv_used -= len; + s->recv_ptr = (s->recv_ptr + len) % RECV_BUF; + packet_len -= len + 2; } - s->recv_used -= len; - s->recv_ptr = (s->recv_ptr + len) % RECV_BUF; return; } From patchwork Mon Mar 16 17:46:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11441111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A17F13B1 for ; Mon, 16 Mar 2020 18:13:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E4F920674 for ; Mon, 16 Mar 2020 18:13:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d2XyMgnj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E4F920674 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDuEd-0000Df-DZ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Mar 2020 14:13:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42899) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtpL-00038M-Bp for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:47:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDtpJ-0002w7-VL for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:59 -0400 Received: from mail-qk1-x743.google.com ([2607:f8b0:4864:20::743]:36543) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDtpF-0002t5-Na for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:57 -0400 Received: by mail-qk1-x743.google.com with SMTP id u25so27753535qkk.3 for ; Mon, 16 Mar 2020 10:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZWAwQTp/Gfu1n4sLpFLUYHmDggD9ePlAuETyYaPTHZA=; b=d2XyMgnjt8mOPqVAp4gxUl1Y362/lpkF1zYWUCQbziPYVVRT8LeHUAKo2Sffhp7nUO REmy0Tm+Fq3+etN5vTJmn4LXZ2kszMurhramw5MOeiXFaMLBE5jsPnpSD7PfuSsYS/6X AUf+0cWu+SFovSyvqCR0aDhV/5w8p2f1AN+HntkluScF2zfmvUIgn6PhHaj5/wY/yZBn yAvFXT5NHQLqqM/6Il4dieqsTWn/KYlr6U2DVej871pEks5K+8qBFaVFk4oeANEWy6i9 8Mn44DYdG4LYuQDqxdHm5cKXWOlxvg3TIdCJX0fmw5eldVKdntkeZ7iA0QCNXdOADBZz ZtZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZWAwQTp/Gfu1n4sLpFLUYHmDggD9ePlAuETyYaPTHZA=; b=X+pvTMS5r24KQPkallE9Lqkx2GwbFB/tCAReSCq3FtwSQnSTcKsXjAC35NbABbXQiv 9Wo90SwLwXB6p3JaUNUS34EmhV25aWXJe9xt9tUqttd9w/vla8i4MrflGu6l4KBuc8Bu 9Tgjj4FAq1HPp2V0ntAqg+RKA4MNnnIgvhB5fwvjTBVMC1ejudCavaRFNTt+kg54Q48O 0sAjDe4Lw90n1DrUblPZgeIxvkE5c9iJMVH/oPE+FNhlgsw8GKKpyddXXZ5BpbsJRa9k Pk1gyG2ykZo73IgFCWPMqMXittHz5n2e76ksttlLVuhOCBnDBGfr1+RBCPHP+LuNvJkG TJdg== X-Gm-Message-State: ANhLgQ2YbXu9ZJztNCYdrOddCoSYs/vgdYdP2ZktqGMbddMF3RNgJA8Q yAFtZsoivHz/vR3De7AyLZQ= X-Google-Smtp-Source: ADFU+vtTrTxd7Z8X94zj01lsbOzd2fTLwwJjzven7szZu3X2JkayDYD9BQYxAKoZ8CJG0ix5lkXVUA== X-Received: by 2002:a37:8ac3:: with SMTP id m186mr852334qkd.371.1584380812842; Mon, 16 Mar 2020 10:46:52 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:7408:9006:8741:9ceb]) by smtp.gmail.com with ESMTPSA id g7sm218422qki.64.2020.03.16.10.46.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 10:46:52 -0700 (PDT) From: Jason Andryuk To: Gerd Hoffmann , Samuel Thibault Subject: [PATCH v2 3/4] usb-serial: Increase receive buffer to 496 Date: Mon, 16 Mar 2020 13:46:09 -0400 Message-Id: <20200316174610.115820-4-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316174610.115820-1-jandryuk@gmail.com> References: <20200316174610.115820-1-jandryuk@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::743 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Jason Andryuk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" A FTDI USB adapter on an xHCI controller can send 512 byte USB packets. These are 8 * ( 2 bytes header + 62 bytes data). A 384 byte receive buffer is insufficient to fill a 512 byte packet, so bump the receive size to 496 ( 512 - 2 * 8 ). Signed-off-by: Jason Andryuk Reviewed-by: Samuel Thibault --- hw/usb/dev-serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index ec091b6a36..77b964588b 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -29,7 +29,7 @@ do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0) #define DPRINTF(fmt, ...) do {} while(0) #endif -#define RECV_BUF 384 +#define RECV_BUF (512 - (2 * 8)) /* Commands */ #define FTDI_RESET 0 From patchwork Mon Mar 16 17:46:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11441167 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1C5714B4 for ; Mon, 16 Mar 2020 18:54:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9560E20719 for ; Mon, 16 Mar 2020 18:54:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iEMq1ke8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9560E20719 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDusb-00072q-Mn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 16 Mar 2020 14:54:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42898) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDtpL-00038J-Bs for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:47:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDtpK-0002xd-4S for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:59 -0400 Received: from mail-qk1-x741.google.com ([2607:f8b0:4864:20::741]:46846) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jDtpJ-0002vc-Ub for qemu-devel@nongnu.org; Mon, 16 Mar 2020 13:46:58 -0400 Received: by mail-qk1-x741.google.com with SMTP id f28so27692461qkk.13 for ; Mon, 16 Mar 2020 10:46:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vXpqImZ9HhTVPRFT9YH5x3h0Eo+XU4wDDNqk/6QRGAQ=; b=iEMq1ke87oNoziyEUmggvse/h/xHauvq+vOWMRidX/eys/GfmrOk9f79q+A1Hx9tRM M+jgDXyz/iAuBGGYh8RUh9051jkY348AJj2pmlhvq2LdJ60VGX84F7cQVBNb2d8vZas2 ZD+1WgwqTHS4RXUFo6ttQ61Hzz7x9bKBAKap3mLk1cokQ7akQw3jOZ0QNbOMQlLthoan ByMcGHdyTYrY3WFrJNH4+QFkC50478h3LSOzirWEQypiILkG03cKBSMuKj/9nCcPCfHj UfyI5x88JoQ2vtDsT11K/qL/TRlsBl/C362TPYRcnzswAK4UCEoWfV780BKO15HTISiC yH+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vXpqImZ9HhTVPRFT9YH5x3h0Eo+XU4wDDNqk/6QRGAQ=; b=XElN0WnaiNcEMI8dHUc6sYGcHGPbkQ+QXla/cPZF4/Pgp9Re77w8K7DhICrAdsL/nO O7xDc4H9ut3AOhIXL/P5AA+YeR5wD38qGrzH6WejbHcphnsjJ1FfhPZTjh69y4kKJ+zW 9B5mtWiruHMCi4VND3qjF+0cSmlOLXMnETzs/RqJ+Bh7cS/jjQQydsowhxI+h3rGFcPI LyCECutvE71gJt7hIlWGLCmsPBc4rh38HLjBA26b5cCayVxmuYMrAHdAzB5YtBT7vKy1 JxzMMGuAETwpSpjAVLTHBydsrHQyEcyD9hV51Hz+x2n2NdX3Eny0tjMFIubcuK0mnR2j ofzA== X-Gm-Message-State: ANhLgQ3xpJcZuC8Ym3NrkSCfxyu8h5gjza/NlnzynLUa+hInZO9LrKFy U8xF/J9BaZVgjSPci08SwudbvoHC X-Google-Smtp-Source: ADFU+vt4CySAYCuz16d0L5wFeLo+2GcNFJT83nnpBbczZjgPvODSO7oFLevudnqv9c5fRxRJ45yQUg== X-Received: by 2002:a05:620a:1125:: with SMTP id p5mr787196qkk.425.1584380816561; Mon, 16 Mar 2020 10:46:56 -0700 (PDT) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:7408:9006:8741:9ceb]) by smtp.gmail.com with ESMTPSA id g7sm218422qki.64.2020.03.16.10.46.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Mar 2020 10:46:55 -0700 (PDT) From: Jason Andryuk To: Gerd Hoffmann , Samuel Thibault Subject: [PATCH v2 4/4] usb-serial: Fix timeout closing the device Date: Mon, 16 Mar 2020 13:46:10 -0400 Message-Id: <20200316174610.115820-5-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200316174610.115820-1-jandryuk@gmail.com> References: <20200316174610.115820-1-jandryuk@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::741 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Jason Andryuk Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Linux guests wait ~30 seconds when closing the emulated /dev/ttyUSB0. During that time, the kernel driver is sending many control URBs requesting GetModemStat (5). Real hardware returns a status with FTDI_THRE (Transmitter Holding Register) and FTDI_TEMT (Transmitter Empty) set. QEMU leaves them clear, and it seems Linux is waiting for FTDI_TEMT to be set to indicate the tx queue is empty before closing. Set the bits when responding to a GetModemStat query and avoid the shutdown delay. Signed-off-by: Jason Andryuk Reviewed-by: Samuel Thibault --- Looking at a USB dump for a real FTDI USB adapter, I see these bits set in all the bulk URBs where QEMU currently has them clear. --- hw/usb/dev-serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c index 77b964588b..d2c03681b7 100644 --- a/hw/usb/dev-serial.c +++ b/hw/usb/dev-serial.c @@ -332,7 +332,7 @@ static void usb_serial_handle_control(USBDevice *dev, USBPacket *p, break; case DeviceInVendor | FTDI_GET_MDM_ST: data[0] = usb_get_modem_lines(s) | 1; - data[1] = 0; + data[1] = FTDI_THRE | FTDI_TEMT; p->actual_length = 2; break; case DeviceOutVendor | FTDI_SET_EVENT_CHR: