From nobody Mon Feb 9 09:16:34 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=1558681714; cv=none; d=zoho.com; s=zohoarc; b=P0CWnkSZQY5X2NHIV+FTpxRWxDAAhnndrdDxt/kAYEx7dX9/8WdPRhc3VGFUNAwgg/Tyd/LTvXKxicIGBKXs6qBUbAqYVh+syZbZ5AJ+xsQe21yFrd9uerF0eeoMioxPUAuP6N56K9pw/qw8fQfWyu7ezC4uU49GQV3V2/y4/0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558681714; 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=L36Oe1Kj7rBECOm4cDhNKr0WOaREtbhTTZ5f3h/Q5I0=; b=GrOU4kwJr1Kmx2iIe3xzMlJrPl6xxM7fWn1FdEAfWgM717qD9M+whgM1KTipA4HqdYpE5CGmrNk8WyVUa09/dQUdsBr0T6Flyq64THVs1Sea0N8foVAEipveaNsrEyWA4kYubUeIK6T/kzcp1LvW/XuG03OE+E4Kft5LeDdlxms= 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 1558681714964697.9461189659271; Fri, 24 May 2019 00:08:34 -0700 (PDT) Received: from localhost ([127.0.0.1]:50143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ja-0001Ex-SL for importer@patchew.org; Fri, 24 May 2019 03:08:30 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hU4Ec-0005R1-5D for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hU4Ea-0006Mr-QG for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59042) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hU4EY-0006GJ-Re for qemu-devel@nongnu.org; Fri, 24 May 2019 03:03:19 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B8F1307D854 for ; Fri, 24 May 2019 07:03:14 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-101.ams2.redhat.com [10.36.116.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2D71001DC0; Fri, 24 May 2019 07:03:11 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id D35AB1753A; Fri, 24 May 2019 09:03:10 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 24 May 2019 09:03:08 +0200 Message-Id: <20190524070310.4952-4-kraxel@redhat.com> In-Reply-To: <20190524070310.4952-1-kraxel@redhat.com> References: <20190524070310.4952-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Fri, 24 May 2019 07:03:14 +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] [PATCH v2 3/5] 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: 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 --- 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