[SeaBIOS] [PATCH 5/9] xhci: Merge xhci_send_control with xhci_send_bulk

Kevin O'Connor kevin at koconnor.net
Thu Jan 1 01:57:26 CET 2015


Merge both the control and bulk pipe sending functions into one new
function: xhci_send_pipe().  This makes the xhci interface similar to
the other usb drivers.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/hw/usb-xhci.c | 45 +++++++++++++++------------------------------
 src/hw/usb-xhci.h |  5 ++---
 src/hw/usb.c      |  4 ++--
 3 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/src/hw/usb-xhci.c b/src/hw/usb-xhci.c
index d6caa77..6c7fc13 100644
--- a/src/hw/usb-xhci.c
+++ b/src/hw/usb-xhci.c
@@ -1117,50 +1117,35 @@ xhci_realloc_pipe(struct usbdevice_s *usbdev, struct usb_pipe *upipe
 }
 
 int
-xhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
-                  , void *data, int datalen)
+xhci_send_pipe(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
+               , void *data, int datalen)
 {
     if (!CONFIG_USB_XHCI)
         return -1;
-    const struct usb_ctrlrequest *req = cmd;
     struct xhci_pipe *pipe = container_of(p, struct xhci_pipe, pipe);
     struct usb_xhci_s *xhci = container_of(
         pipe->pipe.cntl, struct usb_xhci_s, usb);
 
-    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);
+    if (cmd) {
+        const struct usb_ctrlrequest *req = cmd;
+        if (req->bRequest == USB_REQ_SET_ADDRESS)
+            // Set address command sent during xhci_alloc_pipe.
+            return 0;
 
-    int cc = xhci_event_wait(xhci, &pipe->reqs, usb_xfer_time(p, datalen));
-    if (cc != CC_SUCCESS) {
-        dprintf(1, "%s: control xfer failed (cc %d)\n", __func__, cc);
-        return -1;
+        xhci_xfer_setup(pipe, req, dir, datalen);
+        if (datalen)
+            xhci_xfer_data(pipe, dir, data, datalen);
+        xhci_xfer_status(pipe, dir, datalen);
+    } else {
+        xhci_xfer_normal(pipe, data, datalen);
     }
 
-    return 0;
-}
-
-int
-xhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datalen)
-{
-    if (!CONFIG_USB_XHCI)
-        return -1;
-
-    struct xhci_pipe *pipe = container_of(p, struct xhci_pipe, pipe);
-    struct usb_xhci_s *xhci = container_of(
-        pipe->pipe.cntl, struct usb_xhci_s, usb);
-
-    xhci_xfer_normal(pipe, data, datalen);
     int cc = xhci_event_wait(xhci, &pipe->reqs, usb_xfer_time(p, datalen));
     if (cc != CC_SUCCESS) {
-        dprintf(1, "%s: bulk xfer failed (cc %d)\n", __func__, cc);
+        dprintf(1, "%s: xfer failed (cc %d)\n", __func__, cc);
         return -1;
     }
+
     return 0;
 }
 
diff --git a/src/hw/usb-xhci.h b/src/hw/usb-xhci.h
index 807d597..fc1bf7f 100644
--- a/src/hw/usb-xhci.h
+++ b/src/hw/usb-xhci.h
@@ -12,9 +12,8 @@ void xhci_setup(void);
 struct usb_pipe *xhci_realloc_pipe(struct usbdevice_s *usbdev
                                    , struct usb_pipe *upipe
                                    , struct usb_endpoint_descriptor *epdesc);
-int xhci_send_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
-                      , void *data, int datasize);
-int xhci_send_bulk(struct usb_pipe *p, int dir, void *data, int datasize);
+int xhci_send_pipe(struct usb_pipe *p, int dir, const void *cmd, int cmdsize
+                   , void *data, int datasize);
 int xhci_poll_intr(struct usb_pipe *p, void *data);
 
 // --------------------------------------------------------------
diff --git a/src/hw/usb.c b/src/hw/usb.c
index 053440c..a262a98 100644
--- a/src/hw/usb.c
+++ b/src/hw/usb.c
@@ -59,7 +59,7 @@ usb_send_control(struct usb_pipe *pipe, int dir, const void *cmd, int cmdsize
     case USB_TYPE_EHCI:
         return ehci_send_pipe(pipe, dir, cmd, cmdsize, data, datasize);
     case USB_TYPE_XHCI:
-        return xhci_send_control(pipe, dir, cmd, cmdsize, data, datasize);
+        return xhci_send_pipe(pipe, dir, cmd, cmdsize, data, datasize);
     }
 }
 
@@ -79,7 +79,7 @@ usb_send_bulk(struct usb_pipe *pipe_fl, int dir, void *data, int datasize)
     case USB_TYPE_XHCI:
         if (MODESEGMENT)
             return -1;
-        return xhci_send_bulk(pipe_fl, dir, data, datasize);
+        return xhci_send_pipe(pipe_fl, dir, NULL, 0, data, datasize);
     }
 }
 
-- 
1.9.3




More information about the SeaBIOS mailing list