[pve-devel] [PATCH qemu-server] add usb3 option for usb-devices

Dominik Csapak d.csapak at proxmox.com
Wed Feb 10 12:43:18 CET 2016


adding a flag for usb devices (usb3), if this is set to yes,
add an xhci controller and attach the specified devices to it

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuServer.pm | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 047c5a4..d337183 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -730,7 +730,7 @@ my $alldrive_fmt = {
 my $usbdesc = {
     optional => 1,
     type => 'string', format => 'pve-qm-usb-device',
-    typetext => 'host=HOSTUSBDEVICE|spice',
+    typetext => 'host=HOSTUSBDEVICE [,usb3=yes|no]|spice',
     description => <<EODESCR,
 Configure an USB device (n is 0 to 4). This can be used to
 pass-through usb devices to the guest. HOSTUSBDEVICE syntax is:
@@ -744,6 +744,8 @@ Note: This option allows direct access to host hardware. So it is no longer poss
 
 The value 'spice' can be used to add a usb redirection devices for spice.
 
+The 'usb3' option determines whether the device is a USB3 device or not (this does currently not work with spice redirection).
+
 EODESCR
 };
 PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
@@ -1830,6 +1832,8 @@ sub parse_usb_device {
 	} elsif ($v =~ m/^spice$/) {
 	    $found = 1;
 	    $res->{spice} = 1;
+	} elsif ($v =~ m/^usb3=yes$/) {
+	    $res->{usb3} = 1;
 	} else {
 	    return undef;
 	}
@@ -2843,12 +2847,27 @@ sub config_to_command {
         my $use_usb2 = 0;
 	for (my $i = 0; $i < $MAX_USB_DEVICES; $i++)  {
 	    next if !$conf->{"usb$i"};
+	    my $d = parse_usb_device($conf->{"usb$i"});
+	    next if $d->{usb3}; # do not add usb2 controller if we have only usb3 devices
 	    $use_usb2 = 1;
 	}
 	# include usb device config
 	push @$devices, '-readconfig', '/usr/share/qemu-server/pve-usb.cfg' if $use_usb2;
     }
 
+    # add usb3 controller if needed
+
+    my $use_usb3 = 0;
+    for (my $i = 0; $i < $MAX_USB_DEVICES; $i++)  {
+	next if !$conf->{"usb$i"};
+	my $d = parse_usb_device($conf->{"usb$i"});
+	next if !$d->{usb3};
+	$use_usb3 = 1;
+    }
+
+    $pciaddr = print_pci_addr("xhci", $bridges);
+    push @$devices, '-device', "nec-usb-xhci,id=xhci$pciaddr";
+
     my $vga = $conf->{vga};
 
     my $qxlnum = vga_conf_has_spice($vga);
@@ -2927,12 +2946,19 @@ sub config_to_command {
     for (my $i = 0; $i < $MAX_USB_DEVICES; $i++)  {
 	my $d = parse_usb_device($conf->{"usb$i"});
 	next if !$d;
+
+	# if it is a usb3 device, attach it to the xhci controller, else omit the bus option
+	my $usbbus = '';
+	if ($d->{usb3}) {
+	    $usbbus = ',bus=xhci.0';
+	}
+
 	if ($d->{vendorid} && $d->{productid}) {
-	    push @$devices, '-device', "usb-host,vendorid=0x$d->{vendorid},productid=0x$d->{productid}";
+	    push @$devices, '-device', "usb-host$usbbus,vendorid=0x$d->{vendorid},productid=0x$d->{productid}";
 	} elsif (defined($d->{hostbus}) && defined($d->{hostport})) {
-	    push @$devices, '-device', "usb-host,hostbus=$d->{hostbus},hostport=$d->{hostport}";
+	    push @$devices, '-device', "usb-host$usbbus,hostbus=$d->{hostbus},hostport=$d->{hostport}";
 	} elsif ($d->{spice}) {
-	    # usb redir support for spice
+	    # usb redir support for spice, currently no usb3
 	    push @$devices, '-chardev', "spicevmc,id=usbredirchardev$i,name=usbredir";
 	    push @$devices, '-device', "usb-redir,chardev=usbredirchardev$i,id=usbredirdev$i,bus=ehci.0";
 	}
@@ -5045,6 +5071,7 @@ sub print_pci_addr {
 	'net29' => { bus => 1, addr => 24 },
 	'net30' => { bus => 1, addr => 25 },
 	'net31' => { bus => 1, addr => 26 },
+	'xhci' => { bus => 1, addr => 27 },
 	'virtio6' => { bus => 2, addr => 1 },
 	'virtio7' => { bus => 2, addr => 2 },
 	'virtio8' => { bus => 2, addr => 3 },
-- 
2.1.4





More information about the pve-devel mailing list