From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 08/10] usb: add usb_pick_speed
Date: Mon, 2 Jun 2014 16:42:04 +0200 [thread overview]
Message-ID: <1401720127-32546-9-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1401720127-32546-1-git-send-email-kraxel@redhat.com>
We can pick the usb port speed in generic code, by looking at the port
and device speed masks and looking for the fastest match. So add a
function to do exactly that, and drop the speed setting code from
usb_desc_attach as it isn't needed any more.
This way we can set the device speed before calling port->ops->attach,
which fixes some xhci hotplug issues.
https://bugzilla.redhat.com/show_bug.cgi?id=1046873
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb/core.c | 21 +++++++++++++++++++++
hw/usb/desc.c | 12 ------------
include/hw/usb.h | 1 +
3 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/hw/usb/core.c b/hw/usb/core.c
index 67ba7d6..cf34755 100644
--- a/hw/usb/core.c
+++ b/hw/usb/core.c
@@ -28,6 +28,26 @@
#include "qemu/iov.h"
#include "trace.h"
+void usb_pick_speed(USBPort *port)
+{
+ static const int speeds[] = {
+ USB_SPEED_SUPER,
+ USB_SPEED_HIGH,
+ USB_SPEED_FULL,
+ USB_SPEED_LOW,
+ };
+ USBDevice *udev = port->dev;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(speeds); i++) {
+ if ((udev->speedmask & (1 << speeds[i])) &&
+ (port->speedmask & (1 << speeds[i]))) {
+ udev->speed = speeds[i];
+ return;
+ }
+ }
+}
+
void usb_attach(USBPort *port)
{
USBDevice *dev = port->dev;
@@ -35,6 +55,7 @@ void usb_attach(USBPort *port)
assert(dev != NULL);
assert(dev->attached);
assert(dev->state == USB_STATE_NOTATTACHED);
+ usb_pick_speed(port);
port->ops->attach(port);
dev->state = USB_STATE_ATTACHED;
usb_device_handle_attach(dev);
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
index ab48691..b82c397 100644
--- a/hw/usb/desc.c
+++ b/hw/usb/desc.c
@@ -518,18 +518,6 @@ void usb_desc_init(USBDevice *dev)
void usb_desc_attach(USBDevice *dev)
{
- const USBDesc *desc = usb_device_get_usb_desc(dev);
-
- assert(desc != NULL);
- if (desc->super && (dev->port->speedmask & USB_SPEED_MASK_SUPER)) {
- dev->speed = USB_SPEED_SUPER;
- } else if (desc->high && (dev->port->speedmask & USB_SPEED_MASK_HIGH)) {
- dev->speed = USB_SPEED_HIGH;
- } else if (desc->full && (dev->port->speedmask & USB_SPEED_MASK_FULL)) {
- dev->speed = USB_SPEED_FULL;
- } else {
- return;
- }
usb_desc_setdefaults(dev);
}
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 1919bdc..8bcab48 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -458,6 +458,7 @@ void usb_ep_combine_input_packets(USBEndpoint *ep);
void usb_combined_input_packet_complete(USBDevice *dev, USBPacket *p);
void usb_combined_packet_cancel(USBDevice *dev, USBPacket *p);
+void usb_pick_speed(USBPort *port);
void usb_attach(USBPort *port);
void usb_detach(USBPort *port);
void usb_port_reset(USBPort *port);
--
1.8.3.1
next prev parent reply other threads:[~2014-06-02 14:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-02 14:41 [Qemu-devel] [PULL 00/10] usb patch queu Gerd Hoffmann
2014-06-02 14:41 ` [Qemu-devel] [PULL 01/10] qtest: fix qpci_config_writel Gerd Hoffmann
2014-06-02 14:41 ` [Qemu-devel] [PULL 02/10] usb: move uhci register defines to header file Gerd Hoffmann
2014-06-02 14:41 ` [Qemu-devel] [PULL 03/10] usb: add uhci port status reserved bit Gerd Hoffmann
2014-06-02 14:42 ` [Qemu-devel] [PULL 04/10] usb: move ehci register defines to header file Gerd Hoffmann
2014-06-02 14:42 ` [Qemu-devel] [PULL 05/10] usb: improve ehci/uhci test Gerd Hoffmann
2014-06-02 14:42 ` [Qemu-devel] [PULL 06/10] usb-host: allow attaching usb3 devices to ehci Gerd Hoffmann
2014-06-02 14:42 ` [Qemu-devel] [PULL 07/10] usb-host: add HAVE_STREAMS define Gerd Hoffmann
2014-06-02 14:42 ` Gerd Hoffmann [this message]
2014-06-02 14:42 ` [Qemu-devel] [PULL 09/10] xhci: make port reset trace point more verbose Gerd Hoffmann
2014-06-02 14:42 ` [Qemu-devel] [PULL 10/10] xhci: order superspeed ports first Gerd Hoffmann
2014-06-03 10:58 ` [Qemu-devel] [PULL 00/10] usb patch queu Peter Maydell
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=1401720127-32546-9-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).