All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: George Dunlap <George.Dunlap@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Chunyan Liu <cyliu@suse.com>,
	"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>,
	Jim Fehlig <jfehlig@suse.com>, Simon Cao <caobosimon@gmail.com>
Subject: Re: [PATCH V4 3/7] libxl: add pvusb API
Date: Tue, 16 Jun 2015 12:51:21 +0200	[thread overview]
Message-ID: <557FFFA9.2070002@suse.com> (raw)
In-Reply-To: <CAFLBxZYL4yBMmGOFRPJZ4+dZQUW=V4wN=OJZuqk7-AH+DmjvOg@mail.gmail.com>

On 06/16/2015 12:30 PM, George Dunlap wrote:
> On Mon, Jun 15, 2015 at 7:26 PM, Juergen Gross <jgross@suse.com> wrote:
>> On 06/15/2015 04:34 PM, George Dunlap wrote:
>>>
>>> On Mon, Jun 15, 2015 at 3:25 PM, Jürgen Groß <jgross@suse.com> wrote:
>>>>
>>>> On 06/15/2015 04:17 PM, George Dunlap wrote:
>>>>>
>>>>>
>>>>> On Wed, Jun 10, 2015 at 4:20 AM, Chunyan Liu <cyliu@suse.com> wrote:
>>>>>>
>>>>>>
>>>>>> diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl
>>>>>> index 23f27d4..4561e1b 100644
>>>>>> --- a/tools/libxl/libxl_types.idl
>>>>>> +++ b/tools/libxl/libxl_types.idl
>>>>>> @@ -541,6 +541,29 @@ libxl_device_pci = Struct("device_pci", [
>>>>>>         ("seize", bool),
>>>>>>         ])
>>>>>>
>>>>>> +libxl_usb_protocol = Enumeration("usb_protocol", [
>>>>>> +    (0, "AUTO"),
>>>>>> +    (1, "PV"),
>>>>>> +    (2, "QEMU"),
>>>>>> +    ])
>>>>>> +
>>>>>> +libxl_device_usbctrl = Struct("device_usbctrl", [
>>>>>> +    ("protocol", libxl_usb_protocol),
>>>>>> +    ("devid", libxl_devid),
>>>>>> +    ("version", integer),
>>>>>> +    ("ports", integer),
>>>>>> +    ("backend_domid", libxl_domid),
>>>>>> +    ("backend_domname", string),
>>>>>> +   ])
>>>>>> +
>>>>>> +libxl_device_usb = Struct("device_usb", [
>>>>>> +    ("ctrl", libxl_devid),
>>>>>> +    ("port", integer),
>>>>>> +    ("busid", string),
>>>>>> +    ("hostbus",   integer),
>>>>>> +    ("hostaddr",  integer),
>>>>>> +    ])
>>>>>
>>>>>
>>>>>
>>>>> Ian / Ian / Wei / Jim:
>>>>>
>>>>> Question about the design of the interface here.
>>>>>
>>>>> The way that most systems in Linux specify particular USB devices is
>>>>> with the bus:addr format.  It's the output you get when you run tools
>>>>> like lsusb, for example, and it's the interface that qemu (and thus
>>>>> KVM) uses when talking about host devices to assign.  bus:addr might
>>>>> look like "002:006".
>>>>>
>>>>> But the bus:addr is a "public api" for Linux; internally, it has a
>>>>> more structured format, which contains more about the USB topology.
>>>>> Chunyan is calling this "busid".  An example is something like this:
>>>>> "2-3.1.1:1.0".
>>>>>
>>>>> Internally, pvusb needs "busid" in order to find the right sysfs
>>>>> files.  qemu, on the other hand, does not take busid; so the
>>>>> devicemodel / HVM implementation of USB would need bus:addr
>>>>> internally.
>>>>
>>>>
>>>>
>>>> A patch for qemu to support the busid is trivial, as the structures
>>>> already contain the necessary elements:
>>>>
>>>> --- a/hw/usb/host-legacy.c
>>>> +++ b/hw/usb/host-legacy.c
>>>> @@ -53,11 +53,6 @@ static int parse_filter(const char *spec, struct
>>>> USBAutoFilter *f)
>>>>        const char *p = spec;
>>>>        int i;
>>>>
>>>> -    f->bus_num    = 0;
>>>> -    f->addr       = 0;
>>>> -    f->vendor_id  = 0;
>>>> -    f->product_id = 0;
>>>> -
>>>>        for (i = BUS; i < DONE; i++) {
>>>>            p = strpbrk(p, ":.");
>>>>            if (!p) {
>>>> @@ -100,32 +95,47 @@ USBDevice *usb_host_device_open(USBBus *bus, const
>>>> char
>>>> *devname)
>>>>
>>>>        dev = usb_create(bus, "usb-host");
>>>>
>>>> +    memset(&filter, 0, sizeof(filter));
>>>> +
>>>>        if (strstr(devname, "auto:")) {
>>>>            if (parse_filter(devname, &filter) < 0) {
>>>>                goto fail;
>>>>            }
>>>> -    } else {
>>>> -        p = strchr(devname, '.');
>>>> -        if (p) {
>>>> -            filter.bus_num    = strtoul(devname, NULL, 0);
>>>> -            filter.addr       = strtoul(p + 1, NULL, 0);
>>>> -            filter.vendor_id  = 0;
>>>> -            filter.product_id = 0;
>>>> -        } else {
>>>> -            p = strchr(devname, ':');
>>>> -            if (p) {
>>>> -                filter.bus_num    = 0;
>>>> -                filter.addr       = 0;
>>>> -                filter.vendor_id  = strtoul(devname, NULL, 16);
>>>> -                filter.product_id = strtoul(p + 1, NULL, 16);
>>>> -            } else {
>>>> -                goto fail;
>>>> -            }
>>>> -        }
>>>> +        goto out;
>>>>        }
>>>>
>>>> +    /* Check for <bus>-<port> specification. */
>>>> +    p = strchr(devname, '-');
>>>> +    if (p && p != devname) {
>>>> +        filter.bus_num    = strtoul(devname, NULL, 0);
>>>> +        filter.port       = p + 1;
>>>> +        goto out;
>>>> +    }
>>>
>>>
>>>
>>> On my system bus:addr for my mouse is 002:005, while the "busid" (the
>>> corresponding directory in sysfs) is 2-3.3.
>>>
>>> This code doesn't appear to me to parse the above properly; or did I
>>> miss something?
>>
>>
>> Filling filter.bus_num and filter.port is enough. This was the only part
>> missing in qemu, finding the device via libusb using bus_num and port is
>> already existing. At least it is working for me. :-)
>
> Well, one of us is completely wrong.
>
> Let's follow the example above:
>
> $ ls /sys/bus/usb/devices/2-3*
> /sys/bus/usb/devices/2-3@
> /sys/bus/usb/devices/2-3.1@
> /sys/bus/usb/devices/2-3:1.0@
> /sys/bus/usb/devices/2-3.1.1@
> /sys/bus/usb/devices/2-3.1:1.0@
> /sys/bus/usb/devices/2-3.1.1:1.0@
> /sys/bus/usb/devices/2-3.1.2@
> /sys/bus/usb/devices/2-3.1.2:1.0@
> /sys/bus/usb/devices/2-3.1.2:1.1@
> /sys/bus/usb/devices/2-3.2@
> /sys/bus/usb/devices/2-3.2:1.0@
> /sys/bus/usb/devices/2-3.3@
> /sys/bus/usb/devices/2-3.3:1.0@
>
> $ for i in /sys/bus/usb/devices/2-3*/; do grep . $i/{bus,dev}num ; done
> /sys/bus/usb/devices/2-3//busnum:2
> /sys/bus/usb/devices/2-3//devnum:2
> /sys/bus/usb/devices/2-3.1//busnum:2
> /sys/bus/usb/devices/2-3.1//devnum:3
> /sys/bus/usb/devices/2-3.1.1//busnum:2
> /sys/bus/usb/devices/2-3.1.1//devnum:6
> /sys/bus/usb/devices/2-3.1.2//busnum:2
> /sys/bus/usb/devices/2-3.1.2//devnum:10
> /sys/bus/usb/devices/2-3.2//busnum:2
> /sys/bus/usb/devices/2-3.2//devnum:4
> /sys/bus/usb/devices/2-3.3//busnum:2
> /sys/bus/usb/devices/2-3.3//devnum:5
>
> $ lsusb | grep "Bus 002"
> Bus 002 Device 005: ID 046d:c016 Logitech, Inc. Optical Wheel Mouse
> Bus 002 Device 004: ID f617:0905
> Bus 002 Device 010: ID 1050:0111 Yubico.com
> Bus 002 Device 006: ID 0424:4060 Standard Microsystems Corp. Ultra
> Fast Media Reader
> Bus 002 Device 003: ID 0424:2640 Standard Microsystems Corp. USB 2.0 Hub
> Bus 002 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub
> Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
>
> In other words, there are 6 distinct devices that correspond to "bus 2
> port 3".  I don't know what it was you were passing through, but
> giving qemu (or libusb) only "2-3" is absolutely not enough for it to
> distinquish between my mouse (002:005, at 2-3.3) and my yubikey
> (002:010 at 2-3.1.2).  That's why the bus:addr convention was invented
> in the first place, I presume -- to abstract away the topology of the
> USB hubs for the user.
>
> The "busid" interface that Chunyan is describing requires the caller
> to find out that long name -- 2-3.1.2 -- rather than the traditional
> short name (002:010).  Just accepting "2-3" is not sufficient.

qemu with my patch will find the device only if the long name is used.
So the "port" in qemu would be "3.1.2" in your example above.

BTW: be careful with the syntax: x:y is used by qemu to specify a device
by vendorId:productId, you should write "002.010" to use the short name
above.


Juergen

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  reply	other threads:[~2015-06-16 10:51 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10  3:20 [PATCH V4 0/7] xen pvusb toolstack work Chunyan Liu
2015-06-10  3:20 ` [PATCH V4 1/7] libxl: export some functions for pvusb use Chunyan Liu
2015-06-11 16:08   ` Ian Jackson
2015-06-11 16:28     ` Wei Liu
2015-06-12 15:14       ` Ian Jackson
2015-06-10  3:20 ` [PATCH V4 2/7] libxl_read_file_contents: add new entry to read sysfs file Chunyan Liu
2015-06-11 16:16   ` Ian Jackson
2015-06-12  7:00     ` Chun Yan Liu
2015-06-12 15:11       ` Ian Jackson
2015-06-10  3:20 ` [PATCH V4 3/7] libxl: add pvusb API Chunyan Liu
2015-06-11 15:00   ` Juergen Gross
2015-06-11 16:07     ` Ian Jackson
2015-06-11 16:42   ` Ian Jackson
2015-06-12  7:39     ` Chun Yan Liu
2015-06-12  8:06       ` Chun Yan Liu
2015-06-12 11:22       ` Ian Jackson
2015-06-15 14:17   ` George Dunlap
2015-06-15 14:25     ` Jürgen Groß
2015-06-15 14:34       ` George Dunlap
2015-06-15 18:26         ` Juergen Gross
2015-06-16 10:30           ` George Dunlap
2015-06-16 10:51             ` Juergen Gross [this message]
2015-06-16 11:11               ` George Dunlap
2015-06-16 11:19                 ` Juergen Gross
2015-06-16 11:23                   ` George Dunlap
2015-06-16 11:44                     ` Ian Jackson
2015-06-17 11:24                       ` Ian Campbell
2015-06-18 11:50                         ` George Dunlap
2015-06-18 12:08                         ` George Dunlap
2015-06-18 13:03                           ` Juergen Gross
2015-06-22 13:29                           ` Proposed plan for libxl USB interface (was Re: [PATCH V4 3/7] libxl: add pvusb API) George Dunlap
2015-06-22 14:14                             ` Juergen Gross
2015-06-22 14:22                             ` Ian Jackson
2015-06-23  2:42                             ` Chun Yan Liu
2015-06-23  2:43                             ` Chun Yan Liu
2015-06-23  2:44                             ` Chun Yan Liu
2015-06-16 10:41     ` [PATCH V4 3/7] libxl: add pvusb API Ian Jackson
2015-06-16 10:56       ` Jürgen Groß
2015-06-16 11:03         ` George Dunlap
2015-06-16 11:10         ` Ian Jackson
2015-06-16 11:25           ` Juergen Gross
2015-06-16 11:45             ` George Dunlap
2015-06-16 12:02               ` Ian Jackson
2015-06-16 13:19                 ` George Dunlap
2015-06-16 13:32                   ` Juergen Gross
2015-06-16 13:37                   ` [PATCH V4 3/7] libxl: add pvusb API [and 1 more messages] Ian Jackson
2015-06-16 14:41                     ` George Dunlap
2015-06-16 15:58                       ` Sander Eikelenboom
2015-06-16 15:59                       ` Ian Jackson
2015-06-16 16:34                         ` George Dunlap
2015-06-17  3:59                           ` Juergen Gross
2015-06-17 10:27                             ` George Dunlap
2015-06-18  6:24                               ` Chun Yan Liu
2015-06-16 11:45             ` [PATCH V4 3/7] libxl: add pvusb API Ian Jackson
2015-06-16 13:06               ` Juergen Gross
2015-06-16 13:09                 ` George Dunlap
2015-06-16 13:23                   ` Juergen Gross
2015-06-16 13:29                     ` George Dunlap
2015-06-16 13:49                       ` Juergen Gross
2015-06-16 14:06                         ` George Dunlap
2015-06-16 14:20                           ` Juergen Gross
2015-06-16 14:37                             ` George Dunlap
2015-06-17 11:34                             ` Ian Campbell
2015-06-17 11:40                               ` Juergen Gross
2015-06-18  6:20                               ` Chun Yan Liu
2015-06-18  7:02                                 ` Juergen Gross
2015-06-18  8:50                                   ` Ian Campbell
2015-06-18 13:02                                     ` Juergen Gross
2015-06-16 15:38             ` George Dunlap
2015-06-16 11:01       ` George Dunlap
2015-06-16 11:12         ` Ian Jackson
2015-06-16 11:21           ` George Dunlap
2015-06-16 16:32             ` Ian Jackson
2015-06-16 16:39               ` George Dunlap
2015-06-16 16:51                 ` Ross Philipson
2015-06-17  4:03                   ` Jürgen Groß
2015-06-17 13:48                     ` Ross Philipson
2015-06-15 17:47   ` George Dunlap
2015-06-23 10:18     ` Chun Yan Liu
2015-06-23 11:29       ` George Dunlap
2015-06-24  2:26         ` Chun Yan Liu
2015-06-10  3:20 ` [PATCH V4 4/7] libxl: add libxl_device_usb_assignable_list API Chunyan Liu
2015-06-10  3:20 ` [PATCH V4 5/7] xl: add pvusb commands Chunyan Liu
2015-06-12  7:37   ` Juergen Gross
2015-06-12  8:03     ` Chun Yan Liu
2015-06-12  8:22       ` Juergen Gross
2015-06-10  3:20 ` [PATCH V4 6/7] xl: add usb-assignable-list command Chunyan Liu
2015-06-10  3:20 ` [PATCH V4 7/7] domcreate: support pvusb in configuration file Chunyan Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=557FFFA9.2070002@suse.com \
    --to=jgross@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=caobosimon@gmail.com \
    --cc=cyliu@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=jfehlig@suse.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.