]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/usb/host/ehci-sched.c
USB: ehci-orion: the Orion EHCI root hub does have a Transaction Translator
[karo-tx-linux.git] / drivers / usb / host / ehci-sched.c
index 1c771045ccaa8e3e7bfc2ca08e56a87944c9b4de..be575e46eac3132a661479a9138fcf64ea3a73ae 100644 (file)
@@ -119,7 +119,8 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
                        q = &q->fstn->fstn_next;
                        break;
                case Q_TYPE_ITD:
-                       usecs += q->itd->usecs [uframe];
+                       if (q->itd->hw_transaction[uframe])
+                               usecs += q->itd->stream->usecs;
                        hw_p = &q->itd->hw_next;
                        q = &q->itd->itd_next;
                        break;
@@ -439,11 +440,10 @@ static int enable_periodic (struct ehci_hcd *ehci)
        /* did clearing PSE did take effect yet?
         * takes effect only at frame boundaries...
         */
-       status = handshake(ehci, &ehci->regs->status, STS_PSS, 0, 9 * 125);
-       if (status != 0) {
-               ehci_to_hcd(ehci)->state = HC_STATE_HALT;
+       status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
+                                            STS_PSS, 0, 9 * 125);
+       if (status)
                return status;
-       }
 
        cmd = ehci_readl(ehci, &ehci->regs->command) | CMD_PSE;
        ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -464,11 +464,10 @@ static int disable_periodic (struct ehci_hcd *ehci)
        /* did setting PSE not take effect yet?
         * takes effect only at frame boundaries...
         */
-       status = handshake(ehci, &ehci->regs->status, STS_PSS, STS_PSS, 9 * 125);
-       if (status != 0) {
-               ehci_to_hcd(ehci)->state = HC_STATE_HALT;
+       status = handshake_on_error_set_halt(ehci, &ehci->regs->status,
+                                            STS_PSS, STS_PSS, 9 * 125);
+       if (status)
                return status;
-       }
 
        cmd = ehci_readl(ehci, &ehci->regs->command) & ~CMD_PSE;
        ehci_writel(ehci, cmd, &ehci->regs->command);
@@ -1182,21 +1181,18 @@ itd_urb_transaction (
                                        struct ehci_itd, itd_list);
                        list_del (&itd->itd_list);
                        itd_dma = itd->itd_dma;
-               } else
-                       itd = NULL;
-
-               if (!itd) {
+               } else {
                        spin_unlock_irqrestore (&ehci->lock, flags);
                        itd = dma_pool_alloc (ehci->itd_pool, mem_flags,
                                        &itd_dma);
                        spin_lock_irqsave (&ehci->lock, flags);
+                       if (!itd) {
+                               iso_sched_free(stream, sched);
+                               spin_unlock_irqrestore(&ehci->lock, flags);
+                               return -ENOMEM;
+                       }
                }
 
-               if (unlikely (NULL == itd)) {
-                       iso_sched_free (stream, sched);
-                       spin_unlock_irqrestore (&ehci->lock, flags);
-                       return -ENOMEM;
-               }
                memset (itd, 0, sizeof *itd);
                itd->itd_dma = itd_dma;
                list_add (&itd->itd_list, &sched->td_list);
@@ -1536,7 +1532,6 @@ itd_link_urb (
                uframe = next_uframe & 0x07;
                frame = next_uframe >> 3;
 
-               itd->usecs [uframe] = stream->usecs;
                itd_patch(ehci, itd, iso_sched, packet, uframe);
 
                next_uframe += stream->interval;
@@ -1630,16 +1625,12 @@ itd_complete (
                BUG_ON (itd->urb == urb);
         */
 
-       /* give urb back to the driver ... can be out-of-order */
+       /* give urb back to the driver; completion often (re)submits */
        dev = urb->dev;
        ehci_urb_done(ehci, urb, 0);
        retval = true;
        urb = NULL;
-
-       /* defer stopping schedule; completion can submit */
        ehci->periodic_sched--;
-       if (unlikely (!ehci->periodic_sched))
-               (void) disable_periodic (ehci);
        ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
 
        if (unlikely (list_empty (&stream->td_list))) {
@@ -1686,7 +1677,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
 #ifdef EHCI_URB_TRACE
        ehci_dbg (ehci,
                "%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n",
-               __FUNCTION__, urb->dev->devpath, urb,
+               __func__, urb->dev->devpath, urb,
                usb_pipeendpoint (urb->pipe),
                usb_pipein (urb->pipe) ? "in" : "out",
                urb->transfer_buffer_length,
@@ -1725,8 +1716,6 @@ done:
        return status;
 }
 
-#ifdef CONFIG_USB_EHCI_SPLIT_ISO
-
 /*-------------------------------------------------------------------------*/
 
 /*
@@ -1822,21 +1811,18 @@ sitd_urb_transaction (
                                         struct ehci_sitd, sitd_list);
                        list_del (&sitd->sitd_list);
                        sitd_dma = sitd->sitd_dma;
-               } else
-                       sitd = NULL;
-
-               if (!sitd) {
+               } else {
                        spin_unlock_irqrestore (&ehci->lock, flags);
                        sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags,
                                        &sitd_dma);
                        spin_lock_irqsave (&ehci->lock, flags);
+                       if (!sitd) {
+                               iso_sched_free(stream, iso_sched);
+                               spin_unlock_irqrestore(&ehci->lock, flags);
+                               return -ENOMEM;
+                       }
                }
 
-               if (!sitd) {
-                       iso_sched_free (stream, iso_sched);
-                       spin_unlock_irqrestore (&ehci->lock, flags);
-                       return -ENOMEM;
-               }
                memset (sitd, 0, sizeof *sitd);
                sitd->sitd_dma = sitd_dma;
                list_add (&sitd->sitd_list, &iso_sched->td_list);
@@ -2016,16 +2002,12 @@ sitd_complete (
                BUG_ON (sitd->urb == urb);
         */
 
-       /* give urb back to the driver */
+       /* give urb back to the driver; completion often (re)submits */
        dev = urb->dev;
        ehci_urb_done(ehci, urb, 0);
        retval = true;
        urb = NULL;
-
-       /* defer stopping schedule; completion can submit */
        ehci->periodic_sched--;
-       if (!ehci->periodic_sched)
-               (void) disable_periodic (ehci);
        ehci_to_hcd(ehci)->self.bandwidth_isoc_reqs--;
 
        if (list_empty (&stream->td_list)) {
@@ -2108,26 +2090,6 @@ done:
        return status;
 }
 
-#else
-
-static inline int
-sitd_submit (struct ehci_hcd *ehci, struct urb *urb, gfp_t mem_flags)
-{
-       ehci_dbg (ehci, "split iso support is disabled\n");
-       return -ENOSYS;
-}
-
-static inline unsigned
-sitd_complete (
-       struct ehci_hcd         *ehci,
-       struct ehci_sitd        *sitd
-) {
-       ehci_err (ehci, "sitd_complete %p?\n", sitd);
-       return 0;
-}
-
-#endif /* USB_EHCI_SPLIT_ISO */
-
 /*-------------------------------------------------------------------------*/
 
 static void
@@ -2153,17 +2115,9 @@ scan_periodic (struct ehci_hcd *ehci)
        for (;;) {
                union ehci_shadow       q, *q_p;
                __hc32                  type, *hw_p;
-               unsigned                uframes;
+               unsigned                incomplete = false;
 
-               /* don't scan past the live uframe */
                frame = now_uframe >> 3;
-               if (frame == (clock >> 3))
-                       uframes = now_uframe & 0x07;
-               else {
-                       /* safe to scan the whole frame at once */
-                       now_uframe |= 0x07;
-                       uframes = 8;
-               }
 
 restart:
                /* scan each element in frame's queue for completions */
@@ -2201,12 +2155,15 @@ restart:
                                q = q.fstn->fstn_next;
                                break;
                        case Q_TYPE_ITD:
-                               /* skip itds for later in the frame */
+                               /* If this ITD is still active, leave it for
+                                * later processing ... check the next entry.
+                                */
                                rmb ();
-                               for (uf = live ? uframes : 8; uf < 8; uf++) {
+                               for (uf = 0; uf < 8 && live; uf++) {
                                        if (0 == (q.itd->hw_transaction [uf]
                                                        & ITD_ACTIVE(ehci)))
                                                continue;
+                                       incomplete = true;
                                        q_p = &q.itd->itd_next;
                                        hw_p = &q.itd->hw_next;
                                        type = Q_NEXT_TYPE(ehci,
@@ -2214,10 +2171,12 @@ restart:
                                        q = *q_p;
                                        break;
                                }
-                               if (uf != 8)
+                               if (uf < 8 && live)
                                        break;
 
-                               /* this one's ready ... HC won't cache the
+                               /* Take finished ITDs out of the schedule
+                                * and process them:  recycle, maybe report
+                                * URB completion.  HC won't cache the
                                 * pointer for much longer, if at all.
                                 */
                                *q_p = q.itd->itd_next;
@@ -2228,8 +2187,12 @@ restart:
                                q = *q_p;
                                break;
                        case Q_TYPE_SITD:
+                               /* If this SITD is still active, leave it for
+                                * later processing ... check the next entry.
+                                */
                                if ((q.sitd->hw_results & SITD_ACTIVE(ehci))
                                                && live) {
+                                       incomplete = true;
                                        q_p = &q.sitd->sitd_next;
                                        hw_p = &q.sitd->hw_next;
                                        type = Q_NEXT_TYPE(ehci,
@@ -2237,6 +2200,11 @@ restart:
                                        q = *q_p;
                                        break;
                                }
+
+                               /* Take finished SITDs out of the schedule
+                                * and process them:  recycle, maybe report
+                                * URB completion.
+                                */
                                *q_p = q.sitd->sitd_next;
                                *hw_p = q.sitd->hw_next;
                                type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
@@ -2252,11 +2220,24 @@ restart:
                        }
 
                        /* assume completion callbacks modify the queue */
-                       if (unlikely (modified))
-                               goto restart;
+                       if (unlikely (modified)) {
+                               if (likely(ehci->periodic_sched > 0))
+                                       goto restart;
+                               /* maybe we can short-circuit this scan! */
+                               disable_periodic(ehci);
+                               now_uframe = clock;
+                               break;
+                       }
                }
 
-               /* stop when we catch up to the HC */
+               /* If we can tell we caught up to the hardware, stop now.
+                * We can't advance our scan without collecting the ISO
+                * transfers that are still pending in this frame.
+                */
+               if (incomplete && HC_IS_RUNNING(ehci_to_hcd(ehci)->state)) {
+                       ehci->next_uframe = now_uframe;
+                       break;
+               }
 
                // FIXME:  this assumes we won't get lapped when
                // latencies climb; that should be rare, but...
@@ -2269,7 +2250,8 @@ restart:
                if (now_uframe == clock) {
                        unsigned        now;
 
-                       if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state))
+                       if (!HC_IS_RUNNING (ehci_to_hcd(ehci)->state)
+                                       || ehci->periodic_sched == 0)
                                break;
                        ehci->next_uframe = now_uframe;
                        now = ehci_readl(ehci, &ehci->regs->frame_index) % mod;