Convert ehci_wait_qh to ehci_wait_pipe to mirror the similar change made to the uhci code.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/usb-ehci.c | 61 +++++++++++++++++++++++++++---------------------------- 1 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/src/usb-ehci.c b/src/usb-ehci.c index a60c607..8ce68ba 100644 --- a/src/usb-ehci.c +++ b/src/usb-ehci.c @@ -303,22 +303,12 @@ ehci_init(struct pci_device *pci, int busid, struct pci_device *comppci) * End point communication ****************************************************************/
-static int -ehci_wait_qh(struct usb_ehci_s *cntl, struct ehci_qh *qh) -{ - // XXX - 500ms just a guess - u64 end = calc_future_tsc(500); - for (;;) { - if (qh->qtd_next & EHCI_PTR_TERM) - // XXX - confirm - return 0; - if (check_tsc(end)) { - warn_timeout(); - return -1; - } - yield(); - } -} +struct ehci_pipe { + struct ehci_qh qh; + struct ehci_qtd *next_td, *tds; + void *data; + struct usb_pipe pipe; +};
// Wait for next USB async frame to start - for ensuring safe memory release. static void @@ -362,12 +352,29 @@ ehci_waittick(struct usb_ehci_s *cntl) writel(&cntl->regs->usbsts, STS_IAA); }
-struct ehci_pipe { - struct ehci_qh qh; - struct ehci_qtd *next_td, *tds; - void *data; - struct usb_pipe pipe; -}; +static int +ehci_wait_pipe(struct ehci_pipe *pipe, int timeout) +{ + u64 end = calc_future_tsc(timeout); + for (;;) { + u32 el_link = GET_FLATPTR(pipe->qh.qtd_next); + if (el_link & EHCI_PTR_TERM) + // XXX - confirm + return 0; + if (check_tsc(end)) { + warn_timeout(); + SET_FLATPTR(pipe->qh.token, QTD_STS_HALT); + SET_FLATPTR(pipe->qh.qtd_next, EHCI_PTR_TERM); + SET_FLATPTR(pipe->qh.alt_next, EHCI_PTR_TERM); + // XXX - halt qh? + struct usb_ehci_s *cntl = container_of( + GET_FLATPTR(pipe->pipe.cntl), struct usb_ehci_s, usb); + ehci_waittick(cntl); + return -1; + } + yield(); + } +}
void ehci_free_pipe(struct usb_pipe *p) @@ -462,8 +469,6 @@ ehci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize return -1; } struct ehci_pipe *pipe = container_of(p, struct ehci_pipe, pipe); - struct usb_ehci_s *cntl = container_of( - pipe->pipe.cntl, struct usb_ehci_s, usb);
u16 maxpacket = pipe->pipe.maxpacket; int speed = pipe->pipe.speed; @@ -515,13 +520,7 @@ ehci_control(struct usb_pipe *p, int dir, const void *cmd, int cmdsize pipe->qh.qtd_next = (u32)tds; barrier(); pipe->qh.token = 0; - int ret = ehci_wait_qh(cntl, &pipe->qh); - pipe->qh.token = QTD_STS_HALT; - if (ret) { - pipe->qh.qtd_next = pipe->qh.alt_next = EHCI_PTR_TERM; - // XXX - halt qh? - ehci_waittick(cntl); - } + int ret = ehci_wait_pipe(pipe, 500); free(tds); return ret; }