All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] usb: selective endpoint initialization
@ 2012-07-02 16:16 Gerd Hoffmann
  2012-07-03  7:47 ` Jan Kiszka
  2012-07-04  8:09 ` Erik Rull
  0 siblings, 2 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2012-07-02 16:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: jan.kiszka, Gerd Hoffmann, erik.rull

Add support for (re-)initializing endpoints which belong to a specific
interface only.  Use this in usb-host when changing altsetting for an
interface, so other interfaces are not disturbed.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb.h            |    2 +-
 hw/usb/bus.c        |    2 +-
 hw/usb/core.c       |   48 +++++++++++++++++++++++++++---------------------
 hw/usb/desc.c       |    2 +-
 hw/usb/host-linux.c |   16 ++++++++--------
 hw/usb/redirect.c   |    2 +-
 6 files changed, 39 insertions(+), 33 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index a5623d3..b6d7052 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -362,7 +362,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p);
 void usb_packet_complete(USBDevice *dev, USBPacket *p);
 void usb_cancel_packet(USBPacket * p);
 
-void usb_ep_init(USBDevice *dev);
+void usb_ep_init(USBDevice *dev, int interface);
 void usb_ep_dump(USBDevice *dev);
 struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep);
 uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep);
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index b649360..ad1daaf 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -190,7 +190,7 @@ static int usb_qdev_init(DeviceState *qdev)
             usb_device_get_product_desc(dev));
     dev->auto_attach = 1;
     QLIST_INIT(&dev->strings);
-    usb_ep_init(dev);
+    usb_ep_init(dev, 0);
     rc = usb_claim_port(dev);
     if (rc != 0) {
         return rc;
diff --git a/hw/usb/core.c b/hw/usb/core.c
index 0e02da7..94c3c1a 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -550,31 +550,37 @@ void usb_packet_cleanup(USBPacket *p)
     qemu_iovec_destroy(&p->iov);
 }
 
-void usb_ep_init(USBDevice *dev)
+void usb_ep_init(USBDevice *dev, int interface)
 {
     int ep;
 
-    dev->ep_ctl.nr = 0;
-    dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL;
-    dev->ep_ctl.ifnum = 0;
-    dev->ep_ctl.dev = dev;
-    dev->ep_ctl.pipeline = false;
-    QTAILQ_INIT(&dev->ep_ctl.queue);
+    if (interface == 0) {
+        dev->ep_ctl.nr = 0;
+        dev->ep_ctl.type = USB_ENDPOINT_XFER_CONTROL;
+        dev->ep_ctl.ifnum = 0;
+        dev->ep_ctl.dev = dev;
+        dev->ep_ctl.pipeline = false;
+        QTAILQ_INIT(&dev->ep_ctl.queue);
+    }
     for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
-        dev->ep_in[ep].nr = ep + 1;
-        dev->ep_out[ep].nr = ep + 1;
-        dev->ep_in[ep].pid = USB_TOKEN_IN;
-        dev->ep_out[ep].pid = USB_TOKEN_OUT;
-        dev->ep_in[ep].type = USB_ENDPOINT_XFER_INVALID;
-        dev->ep_out[ep].type = USB_ENDPOINT_XFER_INVALID;
-        dev->ep_in[ep].ifnum = 0;
-        dev->ep_out[ep].ifnum = 0;
-        dev->ep_in[ep].dev = dev;
-        dev->ep_out[ep].dev = dev;
-        dev->ep_in[ep].pipeline = false;
-        dev->ep_out[ep].pipeline = false;
-        QTAILQ_INIT(&dev->ep_in[ep].queue);
-        QTAILQ_INIT(&dev->ep_out[ep].queue);
+        if (interface == 0 || interface == dev->ep_in[ep].ifnum) {
+            dev->ep_in[ep].nr = ep + 1;
+            dev->ep_in[ep].pid = USB_TOKEN_IN;
+            dev->ep_in[ep].type = USB_ENDPOINT_XFER_INVALID;
+            dev->ep_in[ep].ifnum = 0;
+            dev->ep_in[ep].dev = dev;
+            dev->ep_in[ep].pipeline = false;
+            QTAILQ_INIT(&dev->ep_in[ep].queue);
+        }
+        if (interface == 0 || interface == dev->ep_out[ep].ifnum) {
+            dev->ep_out[ep].nr = ep + 1;
+            dev->ep_out[ep].pid = USB_TOKEN_OUT;
+            dev->ep_out[ep].type = USB_ENDPOINT_XFER_INVALID;
+            dev->ep_out[ep].ifnum = 0;
+            dev->ep_out[ep].dev = dev;
+            dev->ep_out[ep].pipeline = false;
+            QTAILQ_INIT(&dev->ep_out[ep].queue);
+        }
     }
 }
 
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index 0a9d3c9..f010755 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -246,7 +246,7 @@ static void usb_desc_ep_init(USBDevice *dev)
     const USBDescIface *iface;
     int i, e, pid, ep;
 
-    usb_ep_init(dev);
+    usb_ep_init(dev, 0);
     for (i = 0; i < dev->ninterfaces; i++) {
         iface = dev->ifaces[i];
         if (iface == NULL) {
diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index 5479fb5..8e5d1be 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -135,7 +135,7 @@ static int parse_filter(const char *spec, struct USBAutoFilter *f);
 static void usb_host_auto_check(void *unused);
 static int usb_host_read_file(char *line, size_t line_size,
                             const char *device_file, const char *device_name);
-static int usb_linux_update_endp_table(USBHostDevice *s);
+static int usb_linux_update_endp_table(USBHostDevice *s, int ifnum);
 
 static int usb_host_usbfs_type(USBHostDevice *s, USBPacket *p)
 {
@@ -648,7 +648,7 @@ static void usb_host_handle_reset(USBDevice *dev)
     usb_host_do_reset(s);;
 
     usb_host_claim_interfaces(s, 0);
-    usb_linux_update_endp_table(s);
+    usb_linux_update_endp_table(s, 0);
 }
 
 static void usb_host_handle_destroy(USBDevice *dev)
@@ -988,7 +988,7 @@ again:
         return ctrl_error();
     }
     usb_host_claim_interfaces(s, config);
-    usb_linux_update_endp_table(s);
+    usb_linux_update_endp_table(s, 0);
     return 0;
 }
 
@@ -1024,7 +1024,7 @@ static int usb_host_set_interface(USBHostDevice *s, int iface, int alt)
     }
 
     s->dev.altsetting[iface] = alt;
-    usb_linux_update_endp_table(s);
+    usb_linux_update_endp_table(s, iface);
     return 0;
 }
 
@@ -1120,7 +1120,7 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p,
 }
 
 /* returns 1 on problem encountered or 0 for success */
-static int usb_linux_update_endp_table(USBHostDevice *s)
+static int usb_linux_update_endp_table(USBHostDevice *s, int ifnum)
 {
     static const char *tname[] = {
         [USB_ENDPOINT_XFER_CONTROL] = "control",
@@ -1136,7 +1136,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     USBDescriptor *d;
     bool active = false;
 
-    usb_ep_init(&s->dev);
+    usb_ep_init(&s->dev, ifnum);
 
     for (i = 0;; i += d->bLength) {
         if (i+2 >= s->descr_len) {
@@ -1239,7 +1239,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     return 0;
 
 error:
-    usb_ep_init(&s->dev);
+    usb_ep_init(&s->dev, 0);
     return 1;
 }
 
@@ -1326,7 +1326,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
         goto fail;
     }
 
-    ret = usb_linux_update_endp_table(dev);
+    ret = usb_linux_update_endp_table(dev, 0);
     if (ret) {
         goto fail;
     }
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index d949f04..4afa9c2 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1136,7 +1136,7 @@ static void usbredir_device_disconnect(void *priv)
     for (i = 0; i < MAX_ENDPOINTS; i++) {
         QTAILQ_INIT(&dev->endpoint[i].bufpq);
     }
-    usb_ep_init(&dev->dev);
+    usb_ep_init(&dev->dev, 0);
     dev->interface_info.interface_count = NO_INTERFACE_INFO;
     dev->dev.addr = 0;
     dev->dev.speed = 0;
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-02 16:16 [Qemu-devel] [PATCH] usb: selective endpoint initialization Gerd Hoffmann
@ 2012-07-03  7:47 ` Jan Kiszka
  2012-07-03  8:21   ` Gerd Hoffmann
  2012-07-04  8:09 ` Erik Rull
  1 sibling, 1 reply; 13+ messages in thread
From: Jan Kiszka @ 2012-07-03  7:47 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: erik.rull, qemu-devel

On 2012-07-02 18:16, Gerd Hoffmann wrote:
> Add support for (re-)initializing endpoints which belong to a specific
> interface only.  Use this in usb-host when changing altsetting for an
> interface, so other interfaces are not disturbed.
> 

qemu-system-x86_64: /data/qemu/hw/usb/host-linux.c:1220:
usb_linux_update_endp_table: Assertion `usb_ep_get_type(&s->dev, pid,
ep) == 255' failed.

Do you need a trace again?

Thanks,
Jan

PS: The device used here is this one:

Bus 001 Device 060: ID 047f:c247 Plantronics, Inc.
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0         8
  idVendor           0x047f Plantronics, Inc.
  idProduct          0xc247
  bcdDevice            0.27
  iManufacturer           1 Plantronics
  iProduct                2 HW121N-USB
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          286
    bNumInterfaces          4
    bConfigurationValue     1
    iConfiguration          3 v18M6
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      1 Control Device
      bInterfaceProtocol      0
      iInterface              0
      AudioControl Interface Descriptor:
        bLength                10
        bDescriptorType        36
        bDescriptorSubtype      1 (HEADER)
        bcdADC               1.00
        wTotalLength          115
        bInCollection           2
        baInterfaceNr( 0)       1
        baInterfaceNr( 1)       2
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            13
        wTerminalType      0x0201 Microphone
        bAssocTerminal          0
        bNrChannels             1
        wChannelConfig     0x0000
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 6
        bSourceID              13
        bControlSize            1
        bmaControls( 0)      0x03
          Mute Control
          Volume Control
        bmaControls( 1)      0x00
        iFeature                0
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            12
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      4 (MIXER_UNIT)
        bUnitID                 9
        bNrInPins               2
        baSourceID( 0)         12
        baSourceID( 1)          6
        bNrChannels             2
        wChannelConfig     0x0003
          Left Front (L)
          Right Front (R)
        iChannelNames           0
        bmControls         0x00
        iMixer                  0
      AudioControl Interface Descriptor:
        bLength                13
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 1
        bSourceID               9
        bControlSize            2
        bmaControls( 0)      0x15
        bmaControls( 0)      0x00
          Mute Control
          Bass Control
          Treble Control
        bmaControls( 1)      0x02
        bmaControls( 1)      0x00
          Volume Control
        bmaControls( 2)      0x02
        bmaControls( 2)      0x00
          Volume Control
        iFeature                0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID            14
        wTerminalType      0x0301 Speaker
        bAssocTerminal         11
        bSourceID               1
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                12
        bDescriptorType        36
        bDescriptorSubtype      2 (INPUT_TERMINAL)
        bTerminalID            11
        wTerminalType      0x0201 Microphone
        bAssocTerminal         14
        bNrChannels             1
        wChannelConfig     0x0000
        iChannelNames           0
        iTerminal               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      6 (FEATURE_UNIT)
        bUnitID                 2
        bSourceID              11
        bControlSize            1
        bmaControls( 0)      0x03
          Mute Control
          Volume Control
        bmaControls( 1)      0x00
        iFeature                0
      AudioControl Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      5 (SELECTOR_UNIT)
        bUnitID                 8
        bNrInPins               1
        baSource( 0)            2
        iSelector               0
      AudioControl Interface Descriptor:
        bLength                 9
        bDescriptorType        36
        bDescriptorSubtype      3 (OUTPUT_TERMINAL)
        bTerminalID            10
        wTerminalType      0x0101 USB Streaming
        bAssocTerminal          0
        bSourceID               8
        iTerminal               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink          12
        bDelay                  0 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                23
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             2
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            5 Discrete
        tSamFreq[ 0]         8000
        tSamFreq[ 1]        16000
        tSamFreq[ 2]        32000
        tSamFreq[ 3]        44100
        tSamFreq[ 4]        48000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes           13
          Transfer Type            Isochronous
          Synch Type               Synchronous
          Usage Type               Data
        wMaxPacketSize     0x00c0  1x 192 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay              1 Decoded PCM samples
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        2
      bAlternateSetting       1
      bNumEndpoints           1
      bInterfaceClass         1 Audio
      bInterfaceSubClass      2 Streaming
      bInterfaceProtocol      0
      iInterface              0
      AudioStreaming Interface Descriptor:
        bLength                 7
        bDescriptorType        36
        bDescriptorSubtype      1 (AS_GENERAL)
        bTerminalLink          10
        bDelay                  0 frames
        wFormatTag              1 PCM
      AudioStreaming Interface Descriptor:
        bLength                23
        bDescriptorType        36
        bDescriptorSubtype      2 (FORMAT_TYPE)
        bFormatType             1 (FORMAT_TYPE_I)
        bNrChannels             1
        bSubframeSize           2
        bBitResolution         16
        bSamFreqType            5 Discrete
        tSamFreq[ 0]         8000
        tSamFreq[ 1]        16000
        tSamFreq[ 2]        32000
        tSamFreq[ 3]        44100
        tSamFreq[ 4]        48000
      Endpoint Descriptor:
        bLength                 9
        bDescriptorType         5
        bEndpointAddress     0x84  EP 4 IN
        bmAttributes           13
          Transfer Type            Isochronous
          Synch Type               Synchronous
          Usage Type               Data
        wMaxPacketSize     0x0060  1x 96 bytes
        bInterval               1
        bRefresh                0
        bSynchAddress           0
        AudioControl Endpoint Descriptor:
          bLength                 7
          bDescriptorType        37
          bDescriptorSubtype      1 (EP_GENERAL)
          bmAttributes         0x01
            Sampling Frequency
          bLockDelayUnits         2 Decoded PCM samples
          wLockDelay              1 Decoded PCM samples
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        3
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         3 Human Interface Device
      bInterfaceSubClass      0 No Subclass
      bInterfaceProtocol      0 None
      iInterface              0
        HID Device Descriptor:
          bLength                 9
          bDescriptorType        33
          bcdHID               1.00
          bCountryCode            0 Not supported
          bNumDescriptors         1
          bDescriptorType        34 Report
          wDescriptorLength     115
          Report Descriptor: (length is 115)
            Item(Global): Logical Minimum, data= [ 0x00 ] 0
            Item(Global): Logical Maximum, data= [ 0x01 ] 1
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Global): Usage Page, data= [ 0x0c ] 12
                            Consumer
            Item(Local ): Usage, data= [ 0x01 ] 1
                            Consumer Control
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Report ID, data= [ 0x01 ] 1
            Item(Global): Report Count, data= [ 0x06 ] 6
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0xea ] 234
                            Volume Decrement
            Item(Local ): Usage, data= [ 0xe9 ] 233
                            Volume Increment
            Item(Global): Report Count, data= [ 0x02 ] 2
            Item(Main  ): Input, data= [ 0x06 ] 6
                            Data Variable Relative No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0xa0 0xff ] 65440
                            (null)
            Item(Global): Report ID, data= [ 0x10 ] 16
            Item(Global): Report Count, data= [ 0x01 ] 1
            Item(Local ): Usage, data= [ 0x98 ] 152
                            (null)
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Main  ): Output, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x07 ] 7
            Item(Main  ): Output, data= [ 0x01 ] 1
                            Constant Array Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
            Item(Global): Usage Page, data= [ 0x0b ] 11
                            Telephony
            Item(Local ): Usage, data= [ 0x05 ] 5
                            Headset
            Item(Main  ): Collection, data= [ 0x01 ] 1
                            Application
            Item(Global): Report ID, data= [ 0x02 ] 2
            Item(Global): Report Size, data= [ 0x01 ] 1
            Item(Global): Report Count, data= [ 0x03 ] 3
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x2f ] 47
                            Phone Mute
            Item(Global): Report Count, data= [ 0x01 ] 1
            Item(Main  ): Input, data= [ 0x02 ] 2
                            Data Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x21 ] 33
                            Flash
            Item(Main  ): Input, data= [ 0x06 ] 6
                            Data Variable Relative No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Local ): Usage, data= [ 0x20 ] 32
                            Hook Switch
            Item(Main  ): Input, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report Count, data= [ 0x0a ] 10
            Item(Main  ): Input, data= [ 0x03 ] 3
                            Constant Variable Absolute No_Wrap Linear
                            Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Usage Page, data= [ 0x08 ] 8
                            LEDs
            Item(Global): Report ID, data= [ 0x18 ] 24
            Item(Local ): Usage, data= [ 0x18 ] 24
                            Ring
            Item(Global): Report Count, data= [ 0x08 ] 8
            Item(Main  ): Output, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x17 ] 23
            Item(Local ): Usage, data= [ 0x17 ] 23
                            Off-Hook
            Item(Main  ): Output, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x1e ] 30
            Item(Local ): Usage, data= [ 0x1e ] 30
                            Speaker
            Item(Main  ): Output, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x09 ] 9
            Item(Local ): Usage, data= [ 0x09 ] 9
                            Mute
            Item(Main  ): Output, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Global): Report ID, data= [ 0x2a ] 42
            Item(Local ): Usage, data= [ 0x2a ] 42
                            On-Line
            Item(Main  ): Output, data= [ 0x22 ] 34
                            Data Variable Absolute No_Wrap Linear
                            No_Preferred_State No_Null_Position
Non_Volatile Bitfield
            Item(Main  ): End Collection, data=none
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x83  EP 3 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0003  1x 3 bytes
        bInterval               2
Device Status:     0x0000
  (Bus Powered)

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03  7:47 ` Jan Kiszka
@ 2012-07-03  8:21   ` Gerd Hoffmann
  2012-07-03  8:43     ` Jan Kiszka
  0 siblings, 1 reply; 13+ messages in thread
From: Gerd Hoffmann @ 2012-07-03  8:21 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: erik.rull, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 781 bytes --]

On 07/03/12 09:47, Jan Kiszka wrote:
> On 2012-07-02 18:16, Gerd Hoffmann wrote:
>> Add support for (re-)initializing endpoints which belong to a specific
>> interface only.  Use this in usb-host when changing altsetting for an
>> interface, so other interfaces are not disturbed.
>>
> 
> qemu-system-x86_64: /data/qemu/hw/usb/host-linux.c:1220:
> usb_linux_update_endp_table: Assertion `usb_ep_get_type(&s->dev, pid,
> ep) == 255' failed.
> 
> Do you need a trace again?

Don't think so.  Alternative fix attached.

>     Interface Descriptor:
>       bInterfaceNumber        3
>       bInterfaceClass         3 Human Interface Device

This interface is the one the packet comes from, guess the headset has
some button(s) which this HID interface is intended for.

cheers,
  Gerd

[-- Attachment #2: 0001-usb-split-endpoint-init-and-reset.patch --]
[-- Type: text/plain, Size: 2911 bytes --]

>From 7d00f8996f7981bb118b6986813ce407b31f2b70 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Tue, 3 Jul 2012 10:11:21 +0200
Subject: [PATCH] usb: split endpoint init and reset

Create a new usb_ep_reset() function to reset endpoint state, without
re-initialiting the queues, so we don't unlink in-flight packets just
because usb-host has to re-parse the descriptor tables.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb.h            |    1 +
 hw/usb/core.c       |   13 +++++++++++--
 hw/usb/host-linux.c |    5 +++--
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/hw/usb.h b/hw/usb.h
index a5623d3..9cd2f89 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -363,6 +363,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p);
 void usb_cancel_packet(USBPacket * p);
 
 void usb_ep_init(USBDevice *dev);
+void usb_ep_reset(USBDevice *dev);
 void usb_ep_dump(USBDevice *dev);
 struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep);
 uint8_t usb_ep_get_type(USBDevice *dev, int pid, int ep);
diff --git a/hw/usb/core.c b/hw/usb/core.c
index 0e02da7..fe15be0 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -550,7 +550,7 @@ void usb_packet_cleanup(USBPacket *p)
     qemu_iovec_destroy(&p->iov);
 }
 
-void usb_ep_init(USBDevice *dev)
+void usb_ep_reset(USBDevice *dev)
 {
     int ep;
 
@@ -559,7 +559,6 @@ void usb_ep_init(USBDevice *dev)
     dev->ep_ctl.ifnum = 0;
     dev->ep_ctl.dev = dev;
     dev->ep_ctl.pipeline = false;
-    QTAILQ_INIT(&dev->ep_ctl.queue);
     for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
         dev->ep_in[ep].nr = ep + 1;
         dev->ep_out[ep].nr = ep + 1;
@@ -573,6 +572,16 @@ void usb_ep_init(USBDevice *dev)
         dev->ep_out[ep].dev = dev;
         dev->ep_in[ep].pipeline = false;
         dev->ep_out[ep].pipeline = false;
+    }
+}
+
+void usb_ep_init(USBDevice *dev)
+{
+    int ep;
+
+    usb_ep_reset(dev);
+    QTAILQ_INIT(&dev->ep_ctl.queue);
+    for (ep = 0; ep < USB_MAX_ENDPOINTS; ep++) {
         QTAILQ_INIT(&dev->ep_in[ep].queue);
         QTAILQ_INIT(&dev->ep_out[ep].queue);
     }
diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index 5479fb5..9ba8925 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -1136,7 +1136,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     USBDescriptor *d;
     bool active = false;
 
-    usb_ep_init(&s->dev);
+    usb_ep_reset(&s->dev);
 
     for (i = 0;; i += d->bLength) {
         if (i+2 >= s->descr_len) {
@@ -1239,7 +1239,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
     return 0;
 
 error:
-    usb_ep_init(&s->dev);
+    usb_ep_reset(&s->dev);
     return 1;
 }
 
@@ -1326,6 +1326,7 @@ static int usb_host_open(USBHostDevice *dev, int bus_num,
         goto fail;
     }
 
+    usb_ep_init(&dev->dev);
     ret = usb_linux_update_endp_table(dev);
     if (ret) {
         goto fail;
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03  8:21   ` Gerd Hoffmann
@ 2012-07-03  8:43     ` Jan Kiszka
  2012-07-03  8:51       ` Jan Kiszka
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kiszka @ 2012-07-03  8:43 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: erik.rull, qemu-devel

On 2012-07-03 10:21, Gerd Hoffmann wrote:
> On 07/03/12 09:47, Jan Kiszka wrote:
>> On 2012-07-02 18:16, Gerd Hoffmann wrote:
>>> Add support for (re-)initializing endpoints which belong to a specific
>>> interface only.  Use this in usb-host when changing altsetting for an
>>> interface, so other interfaces are not disturbed.
>>>
>>
>> qemu-system-x86_64: /data/qemu/hw/usb/host-linux.c:1220:
>> usb_linux_update_endp_table: Assertion `usb_ep_get_type(&s->dev, pid,
>> ep) == 255' failed.
>>
>> Do you need a trace again?
> 
> Don't think so.  Alternative fix attached.

Looks good here. No crashes so far, sound is playing.

> 
>>     Interface Descriptor:
>>       bInterfaceNumber        3
>>       bInterfaceClass         3 Human Interface Device
> 
> This interface is the one the packet comes from, guess the headset has
> some button(s) which this HID interface is intended for.

Yes, there are several buttons.

Thanks,
Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03  8:43     ` Jan Kiszka
@ 2012-07-03  8:51       ` Jan Kiszka
  2012-07-03  9:17         ` Gerd Hoffmann
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kiszka @ 2012-07-03  8:51 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: erik.rull, qemu-devel

On 2012-07-03 10:43, Jan Kiszka wrote:
> On 2012-07-03 10:21, Gerd Hoffmann wrote:
>> On 07/03/12 09:47, Jan Kiszka wrote:
>>> On 2012-07-02 18:16, Gerd Hoffmann wrote:
>>>> Add support for (re-)initializing endpoints which belong to a specific
>>>> interface only.  Use this in usb-host when changing altsetting for an
>>>> interface, so other interfaces are not disturbed.
>>>>
>>>
>>> qemu-system-x86_64: /data/qemu/hw/usb/host-linux.c:1220:
>>> usb_linux_update_endp_table: Assertion `usb_ep_get_type(&s->dev, pid,
>>> ep) == 255' failed.
>>>
>>> Do you need a trace again?
>>
>> Don't think so.  Alternative fix attached.
> 
> Looks good here. No crashes so far, sound is playing.
> 

BTW, there are still plenty of "husb: out of buffers for iso stream"
messages. Can we do anything about it, or does the the guest selects too
few buffers here (for a virtualized setup)?

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03  8:51       ` Jan Kiszka
@ 2012-07-03  9:17         ` Gerd Hoffmann
  2012-07-03 11:39           ` Jan Kiszka
  0 siblings, 1 reply; 13+ messages in thread
From: Gerd Hoffmann @ 2012-07-03  9:17 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: erik.rull, qemu-devel

  Hi,

> BTW, there are still plenty of "husb: out of buffers for iso stream"
> messages. Can we do anything about it, or does the the guest selects too
> few buffers here (for a virtualized setup)?

Try increase isobufs (usb-host property, default is 4).

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03  9:17         ` Gerd Hoffmann
@ 2012-07-03 11:39           ` Jan Kiszka
  2012-07-03 11:55             ` Gerd Hoffmann
  0 siblings, 1 reply; 13+ messages in thread
From: Jan Kiszka @ 2012-07-03 11:39 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: erik.rull, qemu-devel

On 2012-07-03 11:17, Gerd Hoffmann wrote:
>   Hi,
> 
>> BTW, there are still plenty of "husb: out of buffers for iso stream"
>> messages. Can we do anything about it, or does the the guest selects too
>> few buffers here (for a virtualized setup)?
> 
> Try increase isobufs (usb-host property, default is 4).

I gave up at isobufs=10000 - it apparently has no influence on this issue.

Rather, it looks like it is triggered when some sound effect played by
Windows ends (e.g. the feedback on volume changes).

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-03 11:39           ` Jan Kiszka
@ 2012-07-03 11:55             ` Gerd Hoffmann
  0 siblings, 0 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2012-07-03 11:55 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: erik.rull, qemu-devel

On 07/03/12 13:39, Jan Kiszka wrote:
> On 2012-07-03 11:17, Gerd Hoffmann wrote:
>>   Hi,
>>
>>> BTW, there are still plenty of "husb: out of buffers for iso stream"
>>> messages. Can we do anything about it, or does the the guest selects too
>>> few buffers here (for a virtualized setup)?
>>
>> Try increase isobufs (usb-host property, default is 4).
> 
> I gave up at isobufs=10000 - it apparently has no influence on this issue.
>
> Rather, it looks like it is triggered when some sound effect played by
> Windows ends (e.g. the feedback on volume changes).

Makes sense.  /me should probably turn those messages into
usb_host_iso_* tracepoints so usb-host is quiet by default.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-02 16:16 [Qemu-devel] [PATCH] usb: selective endpoint initialization Gerd Hoffmann
  2012-07-03  7:47 ` Jan Kiszka
@ 2012-07-04  8:09 ` Erik Rull
  2012-07-10 18:57   ` Erik Rull
  1 sibling, 1 reply; 13+ messages in thread
From: Erik Rull @ 2012-07-04  8:09 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: jan.kiszka, qemu-devel

Gerd Hoffmann wrote:
> Add support for (re-)initializing endpoints which belong to a specific
> interface only.  Use this in usb-host when changing altsetting for an
> interface, so other interfaces are not disturbed.
>

Hi Gerd,

I tested it on my AMD test system where the issue didn't appear with the 
same USB hardware (also before this patch!) - so the final test on my Intel 
test system is pending until next week where it happened.

Best regards,

Erik

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-04  8:09 ` Erik Rull
@ 2012-07-10 18:57   ` Erik Rull
  2012-08-09  8:59     ` Gerd Hoffmann
  0 siblings, 1 reply; 13+ messages in thread
From: Erik Rull @ 2012-07-10 18:57 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: jan.kiszka, qemu-devel

Erik Rull wrote:
> Gerd Hoffmann wrote:
>> Add support for (re-)initializing endpoints which belong to a specific
>> interface only.  Use this in usb-host when changing altsetting for an
>> interface, so other interfaces are not disturbed.
>>
>
> Hi Gerd,
>
> I tested it on my AMD test system where the issue didn't appear with the
> same USB hardware (also before this patch!) - so the final test on my Intel
> test system is pending until next week where it happened.
>
> Best regards,
>
> Erik
>
>

Hi Gerd,

sorry for the delays, I tested the latest pulled patch queue and it's now 
fine on my Intel board, too. The dongle gets detected again without 
assertions. Thanks for your work.

Still remaining are the multiple usb resets on host side before the dongle 
gets finally detected / usable on the guest.

Best regards,

Erik

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-07-10 18:57   ` Erik Rull
@ 2012-08-09  8:59     ` Gerd Hoffmann
  2012-08-13 13:36       ` Erik Rull
  2012-08-24 10:11       ` Erik Rull
  0 siblings, 2 replies; 13+ messages in thread
From: Gerd Hoffmann @ 2012-08-09  8:59 UTC (permalink / raw)
  To: Erik Rull; +Cc: jan.kiszka, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 394 bytes --]

> Hi Gerd,
> 
> sorry for the delays, I tested the latest pulled patch queue and it's
> now fine on my Intel board, too. The dongle gets detected again without
> assertions. Thanks for your work.
> 
> Still remaining are the multiple usb resets on host side before the
> dongle gets finally detected / usable on the guest.

Can you try if the attached patch makes a difference?

thanks,
  Gerd

[-- Attachment #2: 0001-async-control-xfer-fixup.patch --]
[-- Type: text/plain, Size: 1195 bytes --]

>From d51ea0d80009eb58a09e8e571a7eca5da562becc Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 9 Aug 2012 10:57:32 +0200
Subject: [PATCH] async control xfer fixup

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/core.c       |    1 +
 hw/usb/host-linux.c |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/hw/usb/core.c b/hw/usb/core.c
index 01a7622..c7e5bc0 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -107,6 +107,7 @@ static int do_token_setup(USBDevice *s, USBPacket *p)
     }
 
     usb_packet_copy(p, s->setup_buf, p->iov.size);
+    p->result = 0;
     s->setup_len   = (s->setup_buf[7] << 8) | s->setup_buf[6];
     s->setup_index = 0;
 
diff --git a/hw/usb/host-linux.c b/hw/usb/host-linux.c
index d55be87..8df9207 100644
--- a/hw/usb/host-linux.c
+++ b/hw/usb/host-linux.c
@@ -1045,6 +1045,7 @@ static int usb_host_handle_control(USBDevice *dev, USBPacket *p,
 
     /* Note request is (bRequestType << 8) | bRequest */
     trace_usb_host_req_control(s->bus_num, s->addr, p, request, value, index);
+    assert(p->result == 0);
 
     switch (request) {
     case DeviceOutRequest | USB_REQ_SET_ADDRESS:
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-08-09  8:59     ` Gerd Hoffmann
@ 2012-08-13 13:36       ` Erik Rull
  2012-08-24 10:11       ` Erik Rull
  1 sibling, 0 replies; 13+ messages in thread
From: Erik Rull @ 2012-08-13 13:36 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: jan.kiszka, qemu-devel


On August 9, 2012 at 10:59 AM Gerd Hoffmann <kraxel@redhat.com> wrote:
> > Hi Gerd,
> >
> > sorry for the delays, I tested the latest pulled patch queue and it's
> > now fine on my Intel board, too. The dongle gets detected again without
> > assertions. Thanks for your work.
> >
> > Still remaining are the multiple usb resets on host side before the
> > dongle gets finally detected / usable on the guest.
>
> Can you try if the attached patch makes a difference?
>
> thanks,
>   Gerd

Hi Gerd,

sorry, no difference. Still the same behavior.

Best regards,

Erik

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Qemu-devel] [PATCH] usb: selective endpoint initialization
  2012-08-09  8:59     ` Gerd Hoffmann
  2012-08-13 13:36       ` Erik Rull
@ 2012-08-24 10:11       ` Erik Rull
  1 sibling, 0 replies; 13+ messages in thread
From: Erik Rull @ 2012-08-24 10:11 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: jan.kiszka, qemu-devel

On August 9, 2012 at 10:59 AM Gerd Hoffmann <kraxel@redhat.com> wrote:

> > Hi Gerd,
> >
> > sorry for the delays, I tested the latest pulled patch queue and it's
> > now fine on my Intel board, too. The dongle gets detected again without
> > assertions. Thanks for your work.
> >
> > Still remaining are the multiple usb resets on host side before the
> > dongle gets finally detected / usable on the guest.
>
> Can you try if the attached patch makes a difference?
>
> thanks,
>   Gerd

Hi Gerd,

it still has a lot of USB host resets with the latest QEMU master.

Any ideas how to proceed?

Best regards,

Erik

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2012-08-24 10:11 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-02 16:16 [Qemu-devel] [PATCH] usb: selective endpoint initialization Gerd Hoffmann
2012-07-03  7:47 ` Jan Kiszka
2012-07-03  8:21   ` Gerd Hoffmann
2012-07-03  8:43     ` Jan Kiszka
2012-07-03  8:51       ` Jan Kiszka
2012-07-03  9:17         ` Gerd Hoffmann
2012-07-03 11:39           ` Jan Kiszka
2012-07-03 11:55             ` Gerd Hoffmann
2012-07-04  8:09 ` Erik Rull
2012-07-10 18:57   ` Erik Rull
2012-08-09  8:59     ` Gerd Hoffmann
2012-08-13 13:36       ` Erik Rull
2012-08-24 10:11       ` Erik Rull

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.