[Qemu-devel] [PATCH v2 4/5] usb-hub: add usb_hub_port_update()

Gerd Hoffmann posted 5 patches 6 years, 8 months ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>
[Qemu-devel] [PATCH v2 4/5] usb-hub: add usb_hub_port_update()
Posted by Gerd Hoffmann 6 years, 8 months ago
Helper function to update port status bits which depends on the
connected device.  We need the same logic for device attach and
port reset, so factor it out.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb/dev-hub.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index 1cc92a5f9abe..29f4d6723e26 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -188,18 +188,28 @@ static bool usb_hub_port_clear(USBHubPort *port, uint16_t status)
     return usb_hub_port_change(port, status);
 }
 
+static bool usb_hub_port_update(USBHubPort *port)
+{
+    bool notify = false;
+
+    if (port->port.dev && port->port.dev->attached) {
+        notify = usb_hub_port_set(port, PORT_STAT_CONNECTION);
+        if (port->port.dev->speed == USB_SPEED_LOW) {
+            usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
+        } else {
+            usb_hub_port_clear(port, PORT_STAT_LOW_SPEED);
+        }
+    }
+    return notify;
+}
+
 static void usb_hub_attach(USBPort *port1)
 {
     USBHubState *s = port1->opaque;
     USBHubPort *port = &s->ports[port1->index];
 
     trace_usb_hub_attach(s->dev.addr, port1->index + 1);
-    usb_hub_port_set(port, PORT_STAT_CONNECTION);
-    if (port->port.dev->speed == USB_SPEED_LOW) {
-        usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
-    } else {
-        usb_hub_port_clear(port, PORT_STAT_LOW_SPEED);
-    }
+    usb_hub_port_update(port);
     usb_wakeup(s->intr, 0);
 }
 
@@ -287,12 +297,7 @@ static void usb_hub_handle_reset(USBDevice *dev)
         port->wPortStatus = 0;
         port->wPortChange = 0;
         usb_hub_port_set(port, PORT_STAT_POWER);
-        if (port->port.dev && port->port.dev->attached) {
-            usb_hub_port_set(port, PORT_STAT_CONNECTION);
-            if (port->port.dev->speed == USB_SPEED_LOW) {
-                usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
-            }
-        }
+        usb_hub_port_update(port);
     }
 }
 
-- 
2.18.1


Re: [Qemu-devel] [PATCH v2 4/5] usb-hub: add usb_hub_port_update()
Posted by Philippe Mathieu-Daudé 6 years, 8 months ago
On 5/24/19 9:03 AM, Gerd Hoffmann wrote:
> Helper function to update port status bits which depends on the
> connected device.  We need the same logic for device attach and
> port reset, so factor it out.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  hw/usb/dev-hub.c | 29 +++++++++++++++++------------
>  1 file changed, 17 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
> index 1cc92a5f9abe..29f4d6723e26 100644
> --- a/hw/usb/dev-hub.c
> +++ b/hw/usb/dev-hub.c
> @@ -188,18 +188,28 @@ static bool usb_hub_port_clear(USBHubPort *port, uint16_t status)
>      return usb_hub_port_change(port, status);
>  }
>  
> +static bool usb_hub_port_update(USBHubPort *port)
> +{
> +    bool notify = false;
> +
> +    if (port->port.dev && port->port.dev->attached) {
> +        notify = usb_hub_port_set(port, PORT_STAT_CONNECTION);
> +        if (port->port.dev->speed == USB_SPEED_LOW) {
> +            usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
> +        } else {
> +            usb_hub_port_clear(port, PORT_STAT_LOW_SPEED);
> +        }
> +    }
> +    return notify;
> +}
> +
>  static void usb_hub_attach(USBPort *port1)
>  {
>      USBHubState *s = port1->opaque;
>      USBHubPort *port = &s->ports[port1->index];
>  
>      trace_usb_hub_attach(s->dev.addr, port1->index + 1);
> -    usb_hub_port_set(port, PORT_STAT_CONNECTION);
> -    if (port->port.dev->speed == USB_SPEED_LOW) {
> -        usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
> -    } else {
> -        usb_hub_port_clear(port, PORT_STAT_LOW_SPEED);
> -    }
> +    usb_hub_port_update(port);
>      usb_wakeup(s->intr, 0);
>  }
>  
> @@ -287,12 +297,7 @@ static void usb_hub_handle_reset(USBDevice *dev)
>          port->wPortStatus = 0;
>          port->wPortChange = 0;
>          usb_hub_port_set(port, PORT_STAT_POWER);
> -        if (port->port.dev && port->port.dev->attached) {
> -            usb_hub_port_set(port, PORT_STAT_CONNECTION);
> -            if (port->port.dev->speed == USB_SPEED_LOW) {
> -                usb_hub_port_set(port, PORT_STAT_LOW_SPEED);
> -            }
> -        }
> +        usb_hub_port_update(port);
>      }
>  }
>  
> 

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com>