From nobody Mon Feb 9 23:38:49 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1559111803; cv=none; d=zoho.com; s=zohoarc; b=S+XdIZbjY+AE3XaTTASDRRhwp7a2/M2zeqX5wjHraxKaj4e7eSx+953Pb4B/L9FLpKeZjNLGJLC7+GtEqGOZpnRxgr423kKHP9er789bRJohvVUWCMt38ojkANIns2j9tSlAYQWALu9YyBCGPFMyQX1OiaMUqBNnYV05f+7xmq0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1559111803; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Cqoi6F75DLxcpH6QWu68MPXD7JKtH7QVqDY6LNNy8dA=; b=SsCrGBqpvGfR9/HYI+MCskc/eUHh8Ts3Q3pmQZo5H1reObMG298CVHBAuNNJGrKXgd8poCL108aHZV4rAfZbD7sYlxb19tqSNece7gWkqP1BblMlogg4n7EXycSQCS8uw0Ck/fILvfY6Bkch0Cy+LUaN6HW+pUIiUzpHnGadVD0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1559111803835512.4106666294997; Tue, 28 May 2019 23:36:43 -0700 (PDT) Received: from localhost ([127.0.0.1]:48130 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVsBv-0005XU-0O for importer@patchew.org; Wed, 29 May 2019 02:36:03 -0400 Received: from eggs.gnu.org ([209.51.188.92]:42038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hVs4o-0000an-Ay for qemu-devel@nongnu.org; Wed, 29 May 2019 02:28:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hVs4m-0004ez-0R for qemu-devel@nongnu.org; Wed, 29 May 2019 02:28:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hVs4l-0004dp-FM for qemu-devel@nongnu.org; Wed, 29 May 2019 02:28:39 -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 533533179177; Wed, 29 May 2019 06:28:38 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA9E769193; Wed, 29 May 2019 06:28:37 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 3188E17532; Wed, 29 May 2019 08:28:33 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 29 May 2019 08:28:29 +0200 Message-Id: <20190529062832.26483-7-kraxel@redhat.com> In-Reply-To: <20190529062832.26483-1-kraxel@redhat.com> References: <20190529062832.26483-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.41]); Wed, 29 May 2019 06:28:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 6/9] usb-hub: add helpers to update port state 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: Eduardo Habkost , Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add usb_hub_port_set() and usb_hub_port_clear() helpers which care about updating the change bits (port->wPortChange) properly, so we don't need to have that logic sprinkled all over the place ;) Signed-off-by: Gerd Hoffmann Message-id: 20190524070310.4952-4-kraxel@redhat.com --- hw/usb/dev-hub.c | 84 ++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c index 4f700c8f92b5..1cc92a5f9abe 100644 --- a/hw/usb/dev-hub.c +++ b/hw/usb/dev-hub.c @@ -159,18 +159,46 @@ static const uint8_t qemu_hub_hub_descriptor[] =3D /* DeviceRemovable and PortPwrCtrlMask patched in later */ }; =20 +static bool usb_hub_port_change(USBHubPort *port, uint16_t status) +{ + bool notify =3D false; + + if (status & 0x1f) { + port->wPortChange |=3D status; + notify =3D true; + } + return notify; +} + +static bool usb_hub_port_set(USBHubPort *port, uint16_t status) +{ + if (port->wPortStatus & status) { + return false; + } + port->wPortStatus |=3D status; + return usb_hub_port_change(port, status); +} + +static bool usb_hub_port_clear(USBHubPort *port, uint16_t status) +{ + if (!(port->wPortStatus & status)) { + return false; + } + port->wPortStatus &=3D ~status; + return usb_hub_port_change(port, status); +} + static void usb_hub_attach(USBPort *port1) { USBHubState *s =3D port1->opaque; USBHubPort *port =3D &s->ports[port1->index]; =20 trace_usb_hub_attach(s->dev.addr, port1->index + 1); - port->wPortStatus |=3D PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; + usb_hub_port_set(port, PORT_STAT_CONNECTION); if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->wPortStatus |=3D PORT_STAT_LOW_SPEED; + usb_hub_port_set(port, PORT_STAT_LOW_SPEED); } else { - port->wPortStatus &=3D ~PORT_STAT_LOW_SPEED; + usb_hub_port_clear(port, PORT_STAT_LOW_SPEED); } usb_wakeup(s->intr, 0); } @@ -186,16 +214,9 @@ static void usb_hub_detach(USBPort *port1) /* Let upstream know the device on this port is gone */ s->dev.port->ops->child_detach(s->dev.port, port1->dev); =20 - port->wPortStatus &=3D ~PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; - if (port->wPortStatus & PORT_STAT_ENABLE) { - port->wPortStatus &=3D ~PORT_STAT_ENABLE; - port->wPortChange |=3D PORT_STAT_C_ENABLE; - } - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - port->wPortChange |=3D PORT_STAT_C_SUSPEND; - } + usb_hub_port_clear(port, PORT_STAT_CONNECTION); + usb_hub_port_clear(port, PORT_STAT_ENABLE); + usb_hub_port_clear(port, PORT_STAT_SUSPEND); usb_wakeup(s->intr, 0); } =20 @@ -212,9 +233,7 @@ static void usb_hub_wakeup(USBPort *port1) USBHubState *s =3D port1->opaque; USBHubPort *port =3D &s->ports[port1->index]; =20 - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - port->wPortChange |=3D PORT_STAT_C_SUSPEND; + if (usb_hub_port_clear(port, PORT_STAT_SUSPEND)) { usb_wakeup(s->intr, 0); } } @@ -265,13 +284,13 @@ static void usb_hub_handle_reset(USBDevice *dev) trace_usb_hub_reset(s->dev.addr); for (i =3D 0; i < s->num_ports; i++) { port =3D s->ports + i; - port->wPortStatus =3D PORT_STAT_POWER; + port->wPortStatus =3D 0; port->wPortChange =3D 0; + usb_hub_port_set(port, PORT_STAT_POWER); if (port->port.dev && port->port.dev->attached) { - port->wPortStatus |=3D PORT_STAT_CONNECTION; - port->wPortChange |=3D PORT_STAT_C_CONNECTION; + usb_hub_port_set(port, PORT_STAT_CONNECTION); if (port->port.dev->speed =3D=3D USB_SPEED_LOW) { - port->wPortStatus |=3D PORT_STAT_LOW_SPEED; + usb_hub_port_set(port, PORT_STAT_LOW_SPEED); } } } @@ -372,13 +391,13 @@ static void usb_hub_handle_control(USBDevice *dev, US= BPacket *p, port->wPortStatus |=3D PORT_STAT_SUSPEND; break; case PORT_RESET: + usb_hub_port_set(port, PORT_STAT_RESET); + usb_hub_port_clear(port, PORT_STAT_RESET); if (dev && dev->attached) { usb_device_reset(dev); - port->wPortChange |=3D PORT_STAT_C_RESET; - /* set enable bit */ - port->wPortStatus |=3D PORT_STAT_ENABLE; - usb_wakeup(s->intr, 0); + usb_hub_port_set(port, PORT_STAT_ENABLE); } + usb_wakeup(s->intr, 0); break; case PORT_POWER: break; @@ -407,20 +426,7 @@ static void usb_hub_handle_control(USBDevice *dev, USB= Packet *p, port->wPortChange &=3D ~PORT_STAT_C_ENABLE; break; case PORT_SUSPEND: - if (port->wPortStatus & PORT_STAT_SUSPEND) { - port->wPortStatus &=3D ~PORT_STAT_SUSPEND; - - /* - * USB Spec rev2.0 11.24.2.7.2.3 C_PORT_SUSPEND - * "This bit is set on the following transitions: - * - On transition from the Resuming state to the - * SendEOP [sic] state" - * - * Note that this includes both remote wake-up and - * explicit ClearPortFeature(PORT_SUSPEND). - */ - port->wPortChange |=3D PORT_STAT_C_SUSPEND; - } + usb_hub_port_clear(port, PORT_STAT_SUSPEND); break; case PORT_C_SUSPEND: port->wPortChange &=3D ~PORT_STAT_C_SUSPEND; --=20 2.18.1