All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v4 14/32] usb: move remote wakeup handling to common code
Date: Wed, 12 Jan 2011 12:19:56 +0100	[thread overview]
Message-ID: <1294831214-4499-15-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1294831214-4499-1-git-send-email-kraxel@redhat.com>

This patch moves setting and clearing the remote_wakeup feature
bit (via USB_REQ_{SET,CLEAR}_FEATURE) to common code.  Also
USB_REQ_GET_STATUS handling is moved to common code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-bt.c     |   21 +++------------------
 hw/usb-desc.c   |   26 ++++++++++++++++++++++++++
 hw/usb-hid.c    |   22 ----------------------
 hw/usb-hub.c    |   22 ----------------------
 hw/usb-msd.c    |   23 -----------------------
 hw/usb-net.c    |   25 -------------------------
 hw/usb-serial.c |   22 ----------------------
 hw/usb-wacom.c  |   23 -----------------------
 trace-events    |    2 ++
 9 files changed, 31 insertions(+), 155 deletions(-)

diff --git a/hw/usb-bt.c b/hw/usb-bt.c
index 36c90a3..22e6845 100644
--- a/hw/usb-bt.c
+++ b/hw/usb-bt.c
@@ -396,33 +396,18 @@ static int usb_bt_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch (request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
     case InterfaceRequest | USB_REQ_GET_STATUS:
     case EndpointRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
+        data[0] = 0x00;
         data[1] = 0x00;
         ret = 2;
         break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
     case InterfaceOutRequest | USB_REQ_CLEAR_FEATURE:
     case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
+        goto fail;
     case InterfaceOutRequest | USB_REQ_SET_FEATURE:
     case EndpointOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
+        goto fail;
         break;
     case InterfaceRequest | USB_REQ_GET_INTERFACE:
         if (value != 0 || (index & ~1) || length != 1)
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 14c9e11..56ef734 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -299,6 +299,32 @@ int usb_desc_handle_control(USBDevice *dev, int request, int value,
         }
         trace_usb_set_config(dev->addr, value, ret);
         break;
+
+    case DeviceRequest | USB_REQ_GET_STATUS:
+        data[0] = 0;
+        if (dev->config->bmAttributes & 0x40) {
+            data[0] |= 1 << USB_DEVICE_SELF_POWERED;
+        }
+        if (dev->remote_wakeup) {
+            data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;
+        }
+        data[1] = 0x00;
+        ret = 2;
+        break;
+    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
+        if (value == USB_DEVICE_REMOTE_WAKEUP) {
+            dev->remote_wakeup = 0;
+            ret = 0;
+        }
+        trace_usb_clear_device_feature(dev->addr, value, ret);
+        break;
+    case DeviceOutRequest | USB_REQ_SET_FEATURE:
+        if (value == USB_DEVICE_REMOTE_WAKEUP) {
+            dev->remote_wakeup = 1;
+            ret = 0;
+        }
+        trace_usb_set_device_feature(dev->addr, value, ret);
+        break;
     }
     return ret;
 }
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 21c0c72..1c35960 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -673,28 +673,6 @@ static int usb_hid_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch(request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_INTERFACE:
         data[0] = 0;
         ret = 1;
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index fc0b94b..3c7c3ee 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -269,34 +269,12 @@ static int usb_hub_handle_control(USBDevice *dev, int request, int value,
     }
 
     switch(request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
         if (value == 0 && index != 0x81) { /* clear ep halt */
             goto fail;
         }
         ret = 0;
         break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_INTERFACE:
         data[0] = 0;
         ret = 1;
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 56c6f3d..74e657e 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -239,28 +239,6 @@ static int usb_msd_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch (request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_INTERFACE:
         data[0] = 0;
         ret = 1;
@@ -285,7 +263,6 @@ static int usb_msd_handle_control(USBDevice *dev, int request, int value,
         ret = 1;
         break;
     default:
-    fail:
         ret = USB_RET_STALL;
         break;
     }
diff --git a/hw/usb-net.c b/hw/usb-net.c
index f123045..bf51bb3 100644
--- a/hw/usb-net.c
+++ b/hw/usb-net.c
@@ -1055,31 +1055,6 @@ static int usb_net_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch(request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-                (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-
     case ClassInterfaceOutRequest | USB_CDC_SEND_ENCAPSULATED_COMMAND:
         if (!is_rndis(s) || value || index != 0) {
             goto fail;
diff --git a/hw/usb-serial.c b/hw/usb-serial.c
index 2bdb10b..6763d52 100644
--- a/hw/usb-serial.c
+++ b/hw/usb-serial.c
@@ -232,28 +232,6 @@ static int usb_serial_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch (request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (0 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_INTERFACE:
         data[0] = 0;
         ret = 1;
diff --git a/hw/usb-wacom.c b/hw/usb-wacom.c
index 3a98e80..16be7a2 100644
--- a/hw/usb-wacom.c
+++ b/hw/usb-wacom.c
@@ -262,28 +262,6 @@ static int usb_wacom_handle_control(USBDevice *dev, int request, int value,
 
     ret = 0;
     switch (request) {
-    case DeviceRequest | USB_REQ_GET_STATUS:
-        data[0] = (1 << USB_DEVICE_SELF_POWERED) |
-            (dev->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);
-        data[1] = 0x00;
-        ret = 2;
-        break;
-    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 0;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
-    case DeviceOutRequest | USB_REQ_SET_FEATURE:
-        if (value == USB_DEVICE_REMOTE_WAKEUP) {
-            dev->remote_wakeup = 1;
-        } else {
-            goto fail;
-        }
-        ret = 0;
-        break;
     case DeviceRequest | USB_REQ_GET_INTERFACE:
         data[0] = 0;
         ret = 1;
@@ -320,7 +298,6 @@ static int usb_wacom_handle_control(USBDevice *dev, int request, int value,
         ret = 0;
         break;
     default:
-    fail:
         ret = USB_RET_STALL;
         break;
     }
diff --git a/trace-events b/trace-events
index 9ef8474..45e7582 100644
--- a/trace-events
+++ b/trace-events
@@ -196,6 +196,8 @@ disable usb_desc_config(int addr, int index, int len, int ret) "dev %d query con
 disable usb_desc_string(int addr, int index, int len, int ret) "dev %d query string %d, len %d, ret %d"
 disable usb_set_addr(int addr) "dev %d"
 disable usb_set_config(int addr, int config, int ret) "dev %d, config %d, ret %d"
+disable usb_clear_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
+disable usb_set_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
 
 # vl.c
 disable vm_state_notify(int running, int reason) "running %d reason %d"
-- 
1.7.1

  parent reply	other threads:[~2011-01-12 11:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-12 11:19 [Qemu-devel] [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 01/32] usb: update MAINTAINERS Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 02/32] usb: data structs and helpers for usb descriptors Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 03/32] usb hid: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 04/32] usb serial: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 05/32] usb storage: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 06/32] usb wacom: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 07/32] usb bluetooth: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 08/32] usb hub: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 09/32] usb descriptors: add settable strings Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 10/32] usb storage: serial number support Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 11/32] usb network: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 12/32] usb: move USB_REQ_SET_ADDRESS handling to common code Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 13/32] usb: move USB_REQ_{GET, SET}_CONFIGURATION " Gerd Hoffmann
2011-01-12 11:19 ` Gerd Hoffmann [this message]
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 15/32] usb: create USBPortOps, move attach there Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 16/32] usb: rework attach/detach workflow Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 17/32] usb: add usb_wakeup() + wakeup callback to port ops Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 18/32] usb: uhci: remote wakeup support Gerd Hoffmann
2011-01-12 12:25   ` Stefan Hajnoczi
2011-01-14 11:56     ` Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 19/32] usb: hub: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 20/32] usb: hid: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 21/32] usb: hid: change serial number to "42" Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 22/32] usb: add speed mask to ports Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 23/32] usb: add attach callback Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 24/32] usb: add usb_desc_attach Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 25/32] usb: add device qualifier support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 26/32] usb storage: high speed support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 27/32] usb storage: fix status reporting Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 28/32] usb storage: handle long responses Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 29/32] usb: keep track of physical port address Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 30/32] usb: add port property Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 31/32] usb: rewrite fw path, fix numbering Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 32/32] usb: zap pdev from usbport Gerd Hoffmann
2011-01-21 15:00 ` [Qemu-devel] Re: [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-21 17:04   ` Aurelien Jarno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1294831214-4499-15-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.