]> xenbits.xensource.com Git - people/andrewcoop/seabios.git/commitdiff
xhci: Move set_address code from xhci_control to xhci_alloc_pipe.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 28 Dec 2013 00:25:46 +0000 (19:25 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Wed, 29 Jan 2014 17:57:01 +0000 (12:57 -0500)
It's easier to run the set_address from xhci_alloc_pipe as there is
more information available there.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/hw/usb-xhci.c
src/hw/usb.c

index d55a2cf7cf910a3bd8b740a50088d5b24f2b59de..cda0214d94b7f1e5f6ad55c82a649bb7530151a3 100644 (file)
@@ -917,7 +917,37 @@ xhci_alloc_pipe(struct usbdevice_s *usbdev
 
     dprintf(3, "%s: usbdev %p, ring %p, slotid %d, epid %d\n", __func__,
             usbdev, &pipe->reqs, pipe->dev->slotid, pipe->epid);
-    if (pipe->epid > 1 && pipe->dev->slotid) {
+    if (pipe->epid == 1) {
+        // Enable slot and send set_address command.
+        int slotid = xhci_cmd_enable_slot(xhci);
+        if (slotid < 0) {
+            dprintf(1, "%s: enable slot: failed\n", __func__);
+            goto fail;
+        }
+        dprintf(3, "%s: enable slot: got slotid %d\n", __func__, slotid);
+        pipe->dev->slotid = slotid;
+        xhci->devs[slotid].ptr_low = (u32)&pipe->dev->devctx;
+        xhci->devs[slotid].ptr_high = 0;
+
+        struct xhci_inctx *in = xhci_alloc_inctx(pipe);
+        in->add |= (1 << 1);
+
+        in->ep[0].ctx[0]   |= (3 << 16); // interval: 1ms
+        in->ep[0].ctx[1]   |= (4 << 3);  // control pipe
+        in->ep[0].ctx[1]   |= (speed_to_ctlsize[pipe->dev->usbdev->speed] << 16);
+
+        in->ep[0].deq_low  = (u32)&pipe->reqs.ring[0];
+        in->ep[0].deq_low  |= 1;         // dcs
+        in->ep[0].deq_high = 0;
+        in->ep[0].length   = 8;
+
+        int cc = xhci_cmd_address_device(pipe->dev, in);
+        free(in);
+        if (cc != CC_SUCCESS) {
+            dprintf(1, "%s: address device: failed (cc %d)\n", __func__, cc);
+            goto fail;
+        }
+    } else {
         struct xhci_inctx *in = xhci_alloc_inctx(pipe);
         if (!in)
             goto fail;
@@ -991,46 +1021,17 @@ xhci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
     const struct usb_ctrlrequest *req = cmd;
     struct xhci_pipe *pipe = container_of(p, struct xhci_pipe, pipe);
     struct usb_xhci_s *xhci = pipe->dev->xhci;
-    int cc;
 
-    if (req->bRequest == USB_REQ_SET_ADDRESS) {
-        int slotid = xhci_cmd_enable_slot(xhci);
-        if (slotid < 0) {
-            dprintf(1, "%s: enable slot: failed\n", __func__);
-            return -1;
-        }
-        dprintf(3, "%s: enable slot: got slotid %d\n", __func__, slotid);
-        pipe->dev->slotid = slotid;
-        xhci->devs[slotid].ptr_low = (u32)&pipe->dev->devctx;
-        xhci->devs[slotid].ptr_high = 0;
-
-        struct xhci_inctx *in = xhci_alloc_inctx(pipe);
-        in->add |= (1 << 1);
-
-        in->ep[0].ctx[0]   |= (3 << 16); // interval: 1ms
-        in->ep[0].ctx[1]   |= (4 << 3);  // control pipe
-        in->ep[0].ctx[1]   |= (speed_to_ctlsize[pipe->dev->usbdev->speed] << 16);
-
-        in->ep[0].deq_low  = (u32)&pipe->reqs.ring[0];
-        in->ep[0].deq_low  |= 1;         // dcs
-        in->ep[0].deq_high = 0;
-        in->ep[0].length   = 8;
-
-        cc = xhci_cmd_address_device(pipe->dev, in);
-        free(in);
-        if (cc != CC_SUCCESS) {
-            dprintf(1, "%s: address device: failed (cc %d)\n", __func__, cc);
-            return -1;
-        }
+    if (req->bRequest == USB_REQ_SET_ADDRESS)
+        // Set address command sent during xhci_alloc_pipe.
         return 0;
-    }
 
     xhci_xfer_setup(pipe, req, dir, datalen);
     if (datalen)
         xhci_xfer_data(pipe, dir, data, datalen);
     xhci_xfer_status(pipe, dir, datalen);
 
-    cc = xhci_event_wait(xhci, &pipe->reqs, 1000);
+    int cc = xhci_event_wait(xhci, &pipe->reqs, 1000);
     if (cc != CC_SUCCESS) {
         dprintf(1, "%s: control xfer failed (cc %d)\n", __func__, cc);
         return -1;
index 8430e50baf5e833c8c223b747ad93bef0022d25b..e1356f97142092d0f90e1ec637b0846e49968bde 100644 (file)
@@ -263,6 +263,8 @@ usb_set_address(struct usbdevice_s *usbdev)
     if (cntl->maxaddr >= USB_MAXADDR)
         return -1;
 
+    msleep(USB_TIME_RSTRCY);
+
     // Create a pipe for the default address.
     struct usb_endpoint_descriptor epdesc = {
         .wMaxPacketSize = 8,
@@ -272,8 +274,6 @@ usb_set_address(struct usbdevice_s *usbdev)
     if (!usbdev->defpipe)
         return -1;
 
-    msleep(USB_TIME_RSTRCY);
-
     // Send set_address command.
     struct usb_ctrlrequest req;
     req.bRequestType = USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE;