From nobody Sat Jul 12 15:12:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1486014730756536.9941707689385; Wed, 1 Feb 2017 21:52:10 -0800 (PST) Received: from localhost ([::1]:54399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZAJU-0000v1-JG for importer@patchew.org; Thu, 02 Feb 2017 00:52:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cZ9jp-0007NN-LC for qemu-devel@nongnu.org; Thu, 02 Feb 2017 00:15:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cZ9jl-0003jZ-V5 for qemu-devel@nongnu.org; Thu, 02 Feb 2017 00:15:17 -0500 Received: from ozlabs.org ([103.22.144.67]:55489) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cZ9jl-0003fE-GI; Thu, 02 Feb 2017 00:15:13 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 3vDSqQ4wBqz9s7q; Thu, 2 Feb 2017 16:14:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1486012498; bh=YYdOMvWeh4WBX4m7NFqFSFcN1XT2DXLqAuOp9Xh5ngQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ein6RCXdus302kut7kCHGZlWYiSrjnVw1lBEQgvipSseKZqZdpiln/1hHJtuKVnE+ mLoWzggKyQTEvyzhTznnJ2wXkle5aAhR+4lI4THQgS0YW15kKl0kuW59+2m4lGnDLU AfQENpu34ny5sICSXAStO0ciXpin1c+ELHRu8WHA= From: David Gibson To: peter.maydell@linaro.org Date: Thu, 2 Feb 2017 16:13:29 +1100 Message-Id: <20170202051445.5735-32-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170202051445.5735-1-david@gibson.dropbear.id.au> References: <20170202051445.5735-1-david@gibson.dropbear.id.au> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 103.22.144.67 Subject: [Qemu-devel] [PULL 031/107] hw/ppc/spapr: Fix boot path of usb-host storage devices X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lvivier@redhat.com, thuth@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, agraf@suse.de, aik@ozlabs.ru, qemu-ppc@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Thomas Huth When passing through an USB storage device to a pseries guest, it is currently not possible to automatically boot from the device if the "bootindex" property has been specified, too (e.g. when using "-device nec-usb-xhci -device usb-host,hostbus=3D1,hostaddr=3D2,bootindex= =3D0" at the command line). The problem is that QEMU builds a device tree path like "/pci@800000020000000/usb@0/usb-host@1" and passes it to SLOF in the /chosen/qemu,boot-list property. SLOF, however, probes the USB device, recognizes that it is a storage device and thus changes its name to "storage", and additionally adds a child node for the SCSI LUN, so the correct boot path in SLOF is something like "/pci@800000020000000/usb@0/storage@1/disk@101000000000000" instead. So when we detect an USB mass storage device with SCSI interface, we've got to adjust the firmware boot-device path properly that SLOF can automatically boot from the device. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1354177 Signed-off-by: Thomas Huth Signed-off-by: David Gibson --- hw/ppc/spapr.c | 13 +++++++++++++ hw/usb/host-libusb.c | 29 +++++++++++++++++++++++++++++ hw/usb/host-stub.c | 5 +++++ include/hw/usb.h | 1 + 4 files changed, 48 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 74419f8..f2edbd0 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -2198,6 +2198,19 @@ static char *spapr_get_fw_dev_path(FWPathProvider *p= , BusState *bus, } } =20 + /* + * SLOF probes the USB devices, and if it recognizes that the device i= s a + * storage device, it changes its name to "storage" instead of "usb-ho= st", + * and additionally adds a child node for the SCSI LUN, so the correct + * boot path in SLOF is something like .../storage@1/disk@xxx" instead. + */ + if (strcmp("usb-host", qdev_fw_name(dev)) =3D=3D 0) { + USBDevice *usbdev =3D CAST(USBDevice, dev, TYPE_USB_DEVICE); + if (usb_host_dev_is_scsi_storage(usbdev)) { + return g_strdup_printf("storage@%s/disk", usbdev->port->path); + } + } + if (phb) { /* Replace "pci" with "pci@800000020000000" */ return g_strdup_printf("pci@%"PRIX64, phb->buid); diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index bd81d71..7791c6d 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1707,6 +1707,35 @@ static void usb_host_auto_check(void *unused) timer_mod(usb_auto_timer, qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + 200= 0); } =20 +/** + * Check whether USB host device has a USB mass storage SCSI interface + */ +bool usb_host_dev_is_scsi_storage(USBDevice *ud) +{ + USBHostDevice *uhd =3D USB_HOST_DEVICE(ud); + struct libusb_config_descriptor *conf; + const struct libusb_interface_descriptor *intf; + bool is_scsi_storage =3D false; + int i; + + if (!uhd || libusb_get_active_config_descriptor(uhd->dev, &conf) !=3D = 0) { + return false; + } + + for (i =3D 0; i < conf->bNumInterfaces; i++) { + intf =3D &conf->interface[i].altsetting[ud->altsetting[i]]; + if (intf->bInterfaceClass =3D=3D LIBUSB_CLASS_MASS_STORAGE && + intf->bInterfaceSubClass =3D=3D 6) { /* 6 mean= s SCSI */ + is_scsi_storage =3D true; + break; + } + } + + libusb_free_config_descriptor(conf); + + return is_scsi_storage; +} + void hmp_info_usbhost(Monitor *mon, const QDict *qdict) { libusb_device **devs =3D NULL; diff --git a/hw/usb/host-stub.c b/hw/usb/host-stub.c index 6ba65a1..d0268ba 100644 --- a/hw/usb/host-stub.c +++ b/hw/usb/host-stub.c @@ -46,3 +46,8 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *= devname) { return NULL; } + +bool usb_host_dev_is_scsi_storage(USBDevice *ud) +{ + return false; +} diff --git a/include/hw/usb.h b/include/hw/usb.h index 847c9de..43838c9 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -471,6 +471,7 @@ void usb_generic_async_ctrl_complete(USBDevice *s, USBP= acket *p); /* usb-linux.c */ USBDevice *usb_host_device_open(USBBus *bus, const char *devname); void hmp_info_usbhost(Monitor *mon, const QDict *qdict); +bool usb_host_dev_is_scsi_storage(USBDevice *usbdev); =20 /* usb ports of the VM */ =20 --=20 2.9.3