Patchwork qemu 0.15.0 testing, usb redirection, and libusb_get_device_speed()

login
register
mail settings
Submitter Hans Petter Selasky
Date Aug. 16, 2011, 7:37 a.m.
Message ID <201108160937.39168.hselasky@c2i.net>
Download mbox | patch
Permalink /patch/110154/
State New
Headers show

Comments

Hans Petter Selasky - Aug. 16, 2011, 7:37 a.m.
On Monday 15 August 2011 22:26:56 Juergen Lock wrote:
> Hi!
> 
>  I just prepared a preliminary update of the emulators/qemu-devel
> port to 0.15.0 [1], and among other things it now also has a
> usb network redirection feature using usbredir [2], which uses
> libusb 1.0 and a function that is missing in our version,
> libusb_get_device_speed().  I added a stub to the code that
> always returns LIBUSB_SPEED_UNKNOWN
> (files/patch-usbredirhost-usbredirhost.c in the usbredir port [2]),
> question for Hans (I guess), would there be an easy way to make a
> `proper' implementation?
> 
>  If anyone wants to help me test qemu 0.15.0, thanx!

Please try the attached patch to libusb in /usr/src/lib/libusb .

You only need to rebuild libusb: make all install clean

>         FETCHENTRY: entry at 22C5484 is of type 2 which is not supported
> yet processing error - resetting ehci HC

Try my patch first. EHCI needs to know device speed.

--HPS
Juergen Lock - Aug. 16, 2011, 7:54 p.m.
On Tue, Aug 16, 2011 at 09:37:39AM +0200, Hans Petter Selasky wrote:
> On Monday 15 August 2011 22:26:56 Juergen Lock wrote:
> > Hi!
> > 
> >  I just prepared a preliminary update of the emulators/qemu-devel
> > port to 0.15.0 [1], and among other things it now also has a
> > usb network redirection feature using usbredir [2], which uses
> > libusb 1.0 and a function that is missing in our version,
> > libusb_get_device_speed().  I added a stub to the code that
> > always returns LIBUSB_SPEED_UNKNOWN
> > (files/patch-usbredirhost-usbredirhost.c in the usbredir port [2]),
> > question for Hans (I guess), would there be an easy way to make a
> > `proper' implementation?
> > 
> >  If anyone wants to help me test qemu 0.15.0, thanx!
> 
> Please try the attached patch to libusb in /usr/src/lib/libusb .
> 
> You only need to rebuild libusb: make all install clean
> 
> >         FETCHENTRY: entry at 22C5484 is of type 2 which is not supported
> > yet processing error - resetting ehci HC
> 
> Try my patch first. EHCI needs to know device speed.

Thanx, tho it turns out:

a) the FETCHENTRY:.. crash also happens without any device redirection
   with FreeBSD 8.2 (at least) guests and ehci enabled (-readconfig
   docs/ich9-ehci-uhci.cfg), and

b) if I test this with your patch (working libusb_get_device_speed()
   that doesn't just always return LIBUSB_SPEED_UNKNOWN) and redirecting
   an usb 2.0 device with ehci enabled using usbredir then qemu
   complains like:

	qemu: Warning: speed mismatch trying to attach usb device USB Redirectio
n Device to bus usb.0

   and ignores the redirected device.  So for now I have added a
   #define IGNORE_LIBUSB_GET_DEVICE_SPEED to the (updated) preliminary
   usbredir FreeBSD port,

	http://people.freebsd.org/~nox/qemu/usbredir.shar

   so that usbredirhost_open() now always works with:

	device_connect.speed = usb_redir_speed_unknown;

 Question: do people also see this problem on Linux?  This post has
an usage example:

	http://thread.gmane.org/gmane.comp.emulators.qemu/110176/focus=110183

 Or is the problem just that with the example usage,

	sudo usbredirserver 045e:0772
	...
	qemu ... \
	    -readconfig docs/ich9-ehci-uhci.cfg \
	    -chardev socket,id=usbredirchardev,host=localhost,port=4000 \
	    -device usb-redir,chardev=usbredirchardev,id=usbredirdev

qemu 0.15.0 tries to attach the redirected usb 2.0 device to the
uhci bus instead of to the ehci one and if yes, how can I fix that?

 Thanx! :)
	Juergen
Juergen Lock - Aug. 16, 2011, 8:22 p.m.
On Tue, Aug 16, 2011 at 09:54:23PM +0200, Juergen Lock wrote:
> On Tue, Aug 16, 2011 at 09:37:39AM +0200, Hans Petter Selasky wrote:
> > On Monday 15 August 2011 22:26:56 Juergen Lock wrote:
> > > Hi!
> > > 
> > >  I just prepared a preliminary update of the emulators/qemu-devel
> > > port to 0.15.0 [1], and among other things it now also has a
> > > usb network redirection feature using usbredir [2], which uses
> > > libusb 1.0 and a function that is missing in our version,
> > > libusb_get_device_speed().  I added a stub to the code that
> > > always returns LIBUSB_SPEED_UNKNOWN
> > > (files/patch-usbredirhost-usbredirhost.c in the usbredir port [2]),
> > > question for Hans (I guess), would there be an easy way to make a
> > > `proper' implementation?
> > > 
> > >  If anyone wants to help me test qemu 0.15.0, thanx!
> > 
> > Please try the attached patch to libusb in /usr/src/lib/libusb .
> > 
> > You only need to rebuild libusb: make all install clean
> > 
> > >         FETCHENTRY: entry at 22C5484 is of type 2 which is not supported
> > > yet processing error - resetting ehci HC
> > 
> > Try my patch first. EHCI needs to know device speed.
> 
> Thanx, tho it turns out:
> 
> a) the FETCHENTRY:.. crash also happens without any device redirection
>    with FreeBSD 8.2 (at least) guests and ehci enabled (-readconfig
>    docs/ich9-ehci-uhci.cfg), and
> 
> b) if I test this with your patch (working libusb_get_device_speed()
>    that doesn't just always return LIBUSB_SPEED_UNKNOWN) and redirecting
>    an usb 2.0 device with ehci enabled using usbredir then qemu
>    complains like:
> 
> 	qemu: Warning: speed mismatch trying to attach usb device USB Redirectio
> n Device to bus usb.0
> 
>    and ignores the redirected device.  So for now I have added a
>    #define IGNORE_LIBUSB_GET_DEVICE_SPEED to the (updated) preliminary
>    usbredir FreeBSD port,
> 
> 	http://people.freebsd.org/~nox/qemu/usbredir.shar
> 
>    so that usbredirhost_open() now always works with:
> 
> 	device_connect.speed = usb_redir_speed_unknown;
> 
>  Question: do people also see this problem on Linux?  This post has
> an usage example:
> 
> 	http://thread.gmane.org/gmane.comp.emulators.qemu/110176/focus=110183
> 
>  Or is the problem just that with the example usage,
> 
> 	sudo usbredirserver 045e:0772
> 	...
> 	qemu ... \
> 	    -readconfig docs/ich9-ehci-uhci.cfg \
> 	    -chardev socket,id=usbredirchardev,host=localhost,port=4000 \
> 	    -device usb-redir,chardev=usbredirchardev,id=usbredirdev
> 
> qemu 0.15.0 tries to attach the redirected usb 2.0 device to the
> uhci bus instead of to the ehci one and if yes, how can I fix that?

Nevermind, I didn't actually put the -readconfig parameter first. :(
(It didn't occur to me that the order would matter...)

 But now I found that:

a) seabios hangs at boot when I redirect an usb 2.0 flashkey with
   ehci enabled (at least with -cdrom), and

b) with ehci disabled I still get the speed mismatch warning and
   the device is ignored.  Maybe the speed mismatch check should
   be relaxed if there isn't a bus as fast as the device, and the
   device be attached to the fastest available bus instead?  (i.e.
   also the same is likely to happen with usb 3.0 devices?)

 Thanx,
	Juergen  (who will leave the FreeBSD usbredir port using
usb_redir_speed_unknown for now I guess...)
Gerd Hoffmann - Aug. 17, 2011, 9:14 p.m.
Hi,

> a) the FETCHENTRY:.. crash also happens without any device redirection
>     with FreeBSD 8.2 (at least) guests and ehci enabled (-readconfig
>     docs/ich9-ehci-uhci.cfg), and

That will likely happen with a freebsd guest on a linux host too, looks 
like freebsd asks ehci to do something which isn't (fully) implemented 
in the emulation code.  Will have a look.

> 	qemu ... \
> 	    -readconfig docs/ich9-ehci-uhci.cfg \
> 	    -chardev socket,id=usbredirchardev,host=localhost,port=4000 \
> 	    -device usb-redir,chardev=usbredirchardev,id=usbredirdev
>
> qemu 0.15.0 tries to attach the redirected usb 2.0 device to the
> uhci bus instead of to the ehci one and if yes, how can I fix that?

-device usb-redir,bus=ehci.0,...

HTH,
   Gerd

Patch

=== libusb.h
==================================================================
--- libusb.h	(revision 224768)
+++ libusb.h	(local)
@@ -151,6 +151,14 @@ 
 	LIBUSB_ERROR_OTHER = -99,
 };
 
+enum libusb_speed {
+	LIBUSB_SPEED_UNKNOWN = 0,
+	LIBUSB_SPEED_LOW = 1,
+	LIBUSB_SPEED_FULL = 2,
+	LIBUSB_SPEED_HIGH = 3,
+	LIBUSB_SPEED_SUPER = 4,
+};
+
 enum libusb_transfer_status {
 	LIBUSB_TRANSFER_COMPLETED,
 	LIBUSB_TRANSFER_ERROR,
@@ -304,6 +312,7 @@ 
 void	libusb_free_device_list(libusb_device ** list, int unref_devices);
 uint8_t	libusb_get_bus_number(libusb_device * dev);
 uint8_t	libusb_get_device_address(libusb_device * dev);
+enum libusb_speed libusb_get_device_speed(libusb_device * dev);
 int	libusb_clear_halt(libusb_device_handle *devh, uint8_t endpoint);
 int	libusb_get_max_packet_size(libusb_device * dev, uint8_t endpoint);
 libusb_device *libusb_ref_device(libusb_device * dev);
=== libusb10.c
==================================================================
--- libusb10.c	(revision 224768)
+++ libusb10.c	(local)
@@ -272,6 +272,27 @@ 
 	return (libusb20_dev_get_address(dev->os_priv));
 }
 
+enum libusb_speed
+libusb_get_device_speed(libusb_device *dev)
+{
+	if (dev == NULL)
+		return (0);		/* should not happen */
+
+	switch (libusb20_dev_get_speed(dev->os_priv)) {
+	case LIBUSB20_SPEED_LOW:
+		return (LIBUSB_SPEED_LOW);
+	case LIBUSB20_SPEED_FULL:
+		return (LIBUSB_SPEED_FULL);
+	case LIBUSB20_SPEED_HIGH:
+		return (LIBUSB_SPEED_HIGH);
+	case LIBUSB20_SPEED_SUPER:
+		return (LIBUSB_SPEED_SUPER);
+	default:
+		break;
+	}
+	return (LIBUSB_SPEED_UNKNOWN);
+}
+
 int
 libusb_get_max_packet_size(libusb_device *dev, uint8_t endpoint)
 {