From nobody Wed Nov 5 12:03:24 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 1498060262463727.9464024896972; Wed, 21 Jun 2017 08:51:02 -0700 (PDT) Received: from localhost ([::1]:54779 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhuG-0006cG-4t for importer@patchew.org; Wed, 21 Jun 2017 11:51:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhnO-0007fg-H6 for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNhnN-0003fX-3T for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:43:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33754) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dNhnM-0003ek-R3 for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:43:53 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFA727DCF0; Wed, 21 Jun 2017 15:43:51 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-226.ams2.redhat.com [10.36.117.226]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5520060601; Wed, 21 Jun 2017 15:43:43 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id CEA3631E61; Wed, 21 Jun 2017 17:43:47 +0200 (CEST) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BFA727DCF0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kraxel@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BFA727DCF0 From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 21 Jun 2017 17:43:47 +0200 Message-Id: <20170621154347.32084-2-kraxel@redhat.com> In-Reply-To: <20170621154347.32084-1-kraxel@redhat.com> References: <20170621154347.32084-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 21 Jun 2017 15:43:51 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] usb-host: support devices with sparse/non-sequential USB interfaces 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: Samuel Brian , Gerd Hoffmann 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: Samuel Brian Some USB devices have sparse interface numbering which is not able to be passthroughed. For example, the Sierra Wireless MC7455/MC7430: # lsusb -D /dev/bus/usb/003/003 | egrep '1199|9071|bNumInterfaces|bInter= faceNumber' Device: ID 1199:9071 Sierra Wireless, Inc. idVendor 0x1199 Sierra Wireless, Inc. idProduct 0x9071 bNumInterfaces 5 bInterfaceNumber 0 bInterfaceNumber 2 bInterfaceNumber 3 bInterfaceNumber 8 bInterfaceNumber 10 In this case, the interface numbers are 0, 2, 3, 8, 10 and not the 0, 1, 2, 3, 4 that QEMU tries to claim. This change allows sparse USB interface numbering. Instead of only claiming the interfaces in the range reported by the USB device through bNumInterfaces, QEMU attempts to claim all possible interfaces. v2 to fix broken v1 patch formatting. v3 to fix indentation. Signed-off-by: Samuel Brian Message-id: 20170613234039.27201-1-sam.brian@accelerated.com Signed-off-by: Gerd Hoffmann --- hw/usb/host-libusb.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index f9c8eafe06..1b0be071cc 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -1107,7 +1107,7 @@ static void usb_host_detach_kernel(USBHostDevice *s) if (rc !=3D 0) { return; } - for (i =3D 0; i < conf->bNumInterfaces; i++) { + for (i =3D 0; i < USB_MAX_INTERFACES; i++) { rc =3D libusb_kernel_driver_active(s->dh, i); usb_host_libusb_error("libusb_kernel_driver_active", rc); if (rc !=3D 1) { @@ -1130,7 +1130,7 @@ static void usb_host_attach_kernel(USBHostDevice *s) if (rc !=3D 0) { return; } - for (i =3D 0; i < conf->bNumInterfaces; i++) { + for (i =3D 0; i < USB_MAX_INTERFACES; i++) { if (!s->ifs[i].detached) { continue; } @@ -1145,7 +1145,7 @@ static int usb_host_claim_interfaces(USBHostDevice *s= , int configuration) { USBDevice *udev =3D USB_DEVICE(s); struct libusb_config_descriptor *conf; - int rc, i; + int rc, i, claimed; =20 for (i =3D 0; i < USB_MAX_INTERFACES; i++) { udev->altsetting[i] =3D 0; @@ -1164,14 +1164,19 @@ static int usb_host_claim_interfaces(USBHostDevice = *s, int configuration) return USB_RET_STALL; } =20 - for (i =3D 0; i < conf->bNumInterfaces; i++) { + claimed =3D 0; + for (i =3D 0; i < USB_MAX_INTERFACES; i++) { trace_usb_host_claim_interface(s->bus_num, s->addr, configuration,= i); rc =3D libusb_claim_interface(s->dh, i); - usb_host_libusb_error("libusb_claim_interface", rc); - if (rc !=3D 0) { - return USB_RET_STALL; + if (rc =3D=3D 0) { + s->ifs[i].claimed =3D true; + if (++claimed =3D=3D conf->bNumInterfaces) { + break; + } } - s->ifs[i].claimed =3D true; + } + if (claimed !=3D conf->bNumInterfaces) { + return USB_RET_STALL; } =20 udev->ninterfaces =3D conf->bNumInterfaces; @@ -1183,10 +1188,9 @@ static int usb_host_claim_interfaces(USBHostDevice *= s, int configuration) =20 static void usb_host_release_interfaces(USBHostDevice *s) { - USBDevice *udev =3D USB_DEVICE(s); int i, rc; =20 - for (i =3D 0; i < udev->ninterfaces; i++) { + for (i =3D 0; i < USB_MAX_INTERFACES; i++) { if (!s->ifs[i].claimed) { continue; } --=20 2.9.3