diff mbox series

[4/4] usb-serial: Fix timeout closing the device

Message ID 20200312125524.7812-5-jandryuk@gmail.com (mailing list archive)
State New, archived
Headers show
Series usb-serial: xHCI and timeout fixes | expand

Commit Message

Jason Andryuk March 12, 2020, 12:55 p.m. UTC
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 <jandryuk@gmail.com>

---
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(-)

Comments

Samuel Thibault March 14, 2020, 9:41 p.m. UTC | #1
Jason Andryuk, le jeu. 12 mars 2020 08:55:23 -0400, a ecrit:
> 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 <jandryuk@gmail.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
> 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 ef33bcd127..5389235f17 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:
> -- 
> 2.24.1
>
diff mbox series

Patch

diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index ef33bcd127..5389235f17 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: