fix USB driver to compile with ADMH_VERBOSE_DEBUG defined
[openwrt/openwrt.git] / target / linux / adm5120 / files / drivers / usb / host / adm5120-q.c
index 24542d273395f218a44a63e2ef41713a7367ee49..d93f8b9d5d0a38016cdabfb29383a9f004398932 100644 (file)
@@ -38,7 +38,7 @@ __acquires(ahcd->lock)
                        && urb->status == 0) {
                urb->status = -EREMOTEIO;
 #ifdef ADMHC_VERBOSE_DEBUG
-               urb_print(urb, "SHORT", usb_pipeout (urb->pipe));
+               urb_print(ahcd, urb, "SHORT", usb_pipeout(urb->pipe));
 #endif
        }
        spin_unlock(&urb->lock);
@@ -53,7 +53,7 @@ __acquires(ahcd->lock)
        }
 
 #ifdef ADMHC_VERBOSE_DEBUG
-       urb_print(urb, "RET", usb_pipeout (urb->pipe));
+       urb_print(ahcd, urb, "RET", usb_pipeout (urb->pipe));
 #endif
 
        /* urb->complete() can reenter this HCD */
@@ -112,7 +112,7 @@ static void periodic_link (struct admhcd *ahcd, struct ed *ed)
        unsigned        i;
 
        admhc_vdbg (ahcd, "link %sed %p branch %d [%dus.], interval %d\n",
-               (ed->hwINFO & cpu_to_hc32 (ahcd, ED_ISO)) ? "iso " : "",
+               (ed->hwINFO & cpu_to_hc32(ahcd, ED_ISO)) ? "iso " : "",
                ed, ed->branch, ed->load, ed->interval);
 
        for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
@@ -202,7 +202,7 @@ static void periodic_unlink (struct admhcd *ahcd, struct ed *ed)
 
        admhcd_to_hcd(ahcd)->self.bandwidth_allocated -= ed->load / ed->interval;
        admhc_vdbg (ahcd, "unlink %sed %p branch %d [%dus.], interval %d\n",
-               (ed->hwINFO & cpu_to_hc32 (ahcd, ED_ISO)) ? "iso " : "",
+               (ed->hwINFO & cpu_to_hc32(ahcd, ED_ISO)) ? "iso " : "",
                ed, ed->branch, ed->load, ed->interval);
 }
 #endif
@@ -299,6 +299,7 @@ static struct ed *ed_get(struct admhcd *ahcd,       struct usb_host_endpoint *ep,
        unsigned long           flags;
 
        spin_lock_irqsave(&ahcd->lock, flags);
+
        ed = ep->hcpriv;
        if (!ed) {
                u32             info;
@@ -316,6 +317,7 @@ static struct ed *ed_get(struct admhcd *ahcd,       struct usb_host_endpoint *ep,
                if (ed)
                        ep->hcpriv = ed;
        }
+
        spin_unlock_irqrestore(&ahcd->lock, flags);
 
        return ed;
@@ -331,7 +333,7 @@ static struct ed *ed_get(struct admhcd *ahcd,       struct usb_host_endpoint *ep,
  */
 static void start_ed_unlink(struct admhcd *ahcd, struct ed *ed)
 {
-       ed->hwINFO |= cpu_to_hc32 (ahcd, ED_DEQUEUE);
+       ed->hwINFO |= cpu_to_hc32(ahcd, ED_DEQUEUE);
        ed_deschedule(ahcd, ed);
 
        /* add this ED into the remove list */
@@ -430,9 +432,7 @@ static void td_submit_urb(struct admhcd *ahcd, struct urb *urb)
        int             cnt = 0;
        u32             info = 0;
        int             is_out = usb_pipeout(urb->pipe);
-       int             periodic = 0;
        u32             toggle = 0;
-       struct td       *td;
 
        /* OHCI handles the bulk/interrupt data toggles itself.  We just
         * use the device toggle bits for resetting, and rely on the fact
@@ -555,11 +555,14 @@ static void td_submit_urb(struct admhcd *ahcd, struct urb *urb)
 /* calculate transfer length/status and update the urb
  * PRECONDITION:  irqsafe (only for urb->status locking)
  */
-static void td_done(struct admhcd *ahcd, struct urb *urb, struct td *td)
+static int td_done(struct admhcd *ahcd, struct urb *urb, struct td *td)
 {
+       struct urb_priv *urb_priv = urb->hcpriv;
        u32     info = hc32_to_cpup(ahcd, &td->hwINFO);
        int     type = usb_pipetype(urb->pipe);
-       int     cc = TD_CC_NOERROR;
+       int     cc;
+
+       cc = TD_CC_GET(info);
 
        /* ISO ... drivers see per-TD length/status */
        if (type == PIPE_ISOCHRONOUS) {
@@ -600,15 +603,12 @@ static void td_done(struct admhcd *ahcd, struct urb *urb, struct td *td)
                u32     bl = TD_BL_GET(hc32_to_cpup(ahcd, &td->hwCBL));
                u32     tdDBP = hc32_to_cpup(ahcd, &td->hwDBP);
 
-               cc = TD_CC_GET(info);
-
                /* update packet status if needed (short is normally ok) */
                if (cc == TD_CC_DATAUNDERRUN
                                && !(urb->transfer_flags & URB_SHORT_NOT_OK))
                        cc = TD_CC_NOERROR;
 
                if (cc != TD_CC_NOERROR && cc < TD_CC_HCD0) {
-                       admhc_dump_ed(ahcd, "CC ERROR", td->ed, 1);
                        spin_lock(&urb->lock);
                        if (urb->status == -EINPROGRESS)
                                urb->status = cc_to_error[cc];
@@ -629,7 +629,9 @@ static void td_done(struct admhcd *ahcd, struct urb *urb, struct td *td)
        }
 
        list_del(&td->td_list);
+       urb_priv->td_idx++;
 
+       return cc;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -640,15 +642,15 @@ ed_halted(struct admhcd *ahcd, struct td *td, int cc, struct td *rev)
        struct urb              *urb = td->urb;
        struct ed               *ed = td->ed;
        struct list_head        *tmp = td->td_list.next;
-       __hc32                  toggle = ed->hwHeadP & cpu_to_hc32 (ahcd, ED_C);
+       __hc32                  toggle = ed->hwHeadP & cpu_to_hc32(ahcd, ED_C);
 
        admhc_dump_ed(ahcd, "ed halted", td->ed, 1);
        /* clear ed halt; this is the td that caused it, but keep it inactive
         * until its urb->complete() has a chance to clean up.
         */
-       ed->hwINFO |= cpu_to_hc32 (ahcd, ED_SKIP);
-       wmb ();
-       ed->hwHeadP &= ~cpu_to_hc32 (ahcd, ED_H);
+       ed->hwINFO |= cpu_to_hc32(ahcd, ED_SKIP);
+       wmb();
+       ed->hwHeadP &= ~cpu_to_hc32(ahcd, ED_H);
 
        /* put any later tds from this urb onto the donelist, after 'td',
         * order won't matter here: no errors, and nothing was transferred.
@@ -673,9 +675,9 @@ ed_halted(struct admhcd *ahcd, struct td *td, int cc, struct td *rev)
                 */
                info = next->hwINFO;
 #if 0          /* FIXME */
-               info |= cpu_to_hc32 (ahcd, TD_DONE);
-               info &= ~cpu_to_hc32 (ahcd, TD_CC);
+               info |= cpu_to_hc32(ahcd, TD_DONE);
 #endif
+               info &= ~cpu_to_hc32(ahcd, TD_CC);
                next->hwINFO = info;
 
                next->next_dl_td = rev;
@@ -694,7 +696,7 @@ ed_halted(struct admhcd *ahcd, struct td *td, int cc, struct td *rev)
                        break;
                /* fallthrough */
        case TD_CC_STALL:
-               if (usb_pipecontrol (urb->pipe))
+               if (usb_pipecontrol(urb->pipe))
                        break;
                /* fallthrough */
        default:
@@ -734,7 +736,7 @@ skip_ed:
                                continue;
                        }
 
-                       if (!list_empty (&ed->td_list)) {
+                       if (!list_empty(&ed->td_list)) {
                                struct td       *td;
                                u32             head;
 
@@ -768,7 +770,7 @@ skip_ed:
 rescan_this:
                completed = 0;
                prev = &ed->hwHeadP;
-               list_for_each_safe (entry, tmp, &ed->td_list) {
+               list_for_each_safe(entry, tmp, &ed->td_list) {
                        struct td       *td;
                        struct urb      *urb;
                        struct urb_priv *urb_priv;
@@ -791,9 +793,8 @@ rescan_this:
                        *prev = td->hwNextTD | savebits;
 
                        /* HC may have partly processed this TD */
-                       urb_print(urb, "PARTIAL",1);
+                       urb_print(ahcd, urb, "PARTIAL", 1);
                        td_done(ahcd, urb, td);
-                       urb_priv->td_idx++;
 
                        /* if URB is done, clean up */
                        if (urb_priv->td_idx == urb_priv->td_cnt) {
@@ -801,7 +802,7 @@ rescan_this:
                                finish_urb(ahcd, urb);
                        }
                }
-               if (completed && !list_empty (&ed->td_list))
+               if (completed && !list_empty(&ed->td_list))
                        goto rescan_this;
 
                /* ED's now officially unlinked, hc doesn't see */
@@ -809,10 +810,10 @@ rescan_this:
                ed->hwHeadP &= ~cpu_to_hc32(ahcd, ED_H);
                ed->hwNextED = 0;
                wmb ();
-               ed->hwINFO &= ~cpu_to_hc32 (ahcd, ED_SKIP | ED_DEQUEUE);
+               ed->hwINFO &= ~cpu_to_hc32(ahcd, ED_SKIP | ED_DEQUEUE);
 
                /* but if there's work queued, reschedule */
-               if (!list_empty (&ed->td_list)) {
+               if (!list_empty(&ed->td_list)) {
                        if (HC_IS_RUNNING(admhcd_to_hcd(ahcd)->state))
                                ed_schedule(ahcd, ed);
                }
@@ -832,23 +833,71 @@ rescan_this:
  * scanning the (re-reversed) donelist as this does.
  */
 
+static void ed_unhalt(struct admhcd *ahcd, struct ed *ed, struct urb *urb)
+{
+       struct list_head *entry,*tmp;
+       __hc32 toggle = ed->hwHeadP & cpu_to_hc32(ahcd, ED_C);
+
+#ifdef ADMHC_VERBOSE_DEBUG
+       admhc_dump_ed(ahcd, "UNHALT", ed, 0);
+#endif
+       /* clear ed halt; this is the td that caused it, but keep it inactive
+        * until its urb->complete() has a chance to clean up.
+        */
+       ed->hwINFO |= cpu_to_hc32(ahcd, ED_SKIP);
+       wmb();
+       ed->hwHeadP &= ~cpu_to_hc32(ahcd, ED_H);
+
+       list_for_each_safe(entry, tmp, &ed->td_list) {
+               struct td *td = list_entry(entry, struct td, td_list);
+               __hc32 info;
+
+               if (td->urb != urb)
+                       break;
+
+               info = td->hwINFO;
+               info &= ~cpu_to_hc32(ahcd, TD_CC | TD_OWN);
+               td->hwINFO = info;
+
+               ed->hwHeadP = td->hwNextTD | toggle;
+               wmb();
+       }
+
+}
+
+static inline int is_ed_halted(struct admhcd *ahcd, struct ed *ed)
+{
+       return ((hc32_to_cpup(ahcd, &ed->hwHeadP) & ED_H) == ED_H);
+}
+
+static inline int is_td_halted(struct admhcd *ahcd, struct ed *ed,
+               struct td *td)
+{
+       return ((hc32_to_cpup(ahcd, &ed->hwHeadP) & TD_MASK) ==
+               (hc32_to_cpup(ahcd, &td->hwNextTD) & TD_MASK));
+}
+
 static void ed_update(struct admhcd *ahcd, struct ed *ed)
 {
        struct list_head *entry,*tmp;
 
-       admhc_dump_ed(ahcd, "ed update", ed, 1);
+#ifdef ADMHC_VERBOSE_DEBUG
+       admhc_dump_ed(ahcd, "UPDATE", ed, 0);
+#endif
 
        list_for_each_safe(entry, tmp, &ed->td_list) {
                struct td *td = list_entry(entry, struct td, td_list);
                struct urb *urb = td->urb;
                struct urb_priv *urb_priv = urb->hcpriv;
+               int cc;
 
                if (hc32_to_cpup(ahcd, &td->hwINFO) & TD_OWN)
                        break;
 
                /* update URB's length and status from TD */
-               td_done(ahcd, urb, td);
-               urb_priv->td_idx++;
+               cc = td_done(ahcd, urb, td);
+               if (is_ed_halted(ahcd, ed) && is_td_halted(ahcd, ed, td))
+                       ed_unhalt(ahcd, ed, urb);
 
                /* If all this urb's TDs are done, call complete() */
                if (urb_priv->td_idx == urb_priv->td_cnt)
@@ -860,13 +909,13 @@ static void ed_update(struct admhcd *ahcd, struct ed *ed)
                                start_ed_unlink(ahcd, ed);
 
                /* ... reenabling halted EDs only after fault cleanup */
-               } else if ((ed->hwINFO & cpu_to_hc32 (ahcd,
+               } else if ((ed->hwINFO & cpu_to_hc32(ahcd,
                                                ED_SKIP | ED_DEQUEUE))
-                                       == cpu_to_hc32 (ahcd, ED_SKIP)) {
+                                       == cpu_to_hc32(ahcd, ED_SKIP)) {
                        td = list_entry(ed->td_list.next, struct td, td_list);
 #if 0
-                       if (!(td->hwINFO & cpu_to_hc32 (ahcd, TD_DONE))) {
-                               ed->hwINFO &= ~cpu_to_hc32 (ahcd, ED_SKIP);
+                       if (!(td->hwINFO & cpu_to_hc32(ahcd, TD_DONE))) {
+                               ed->hwINFO &= ~cpu_to_hc32(ahcd, ED_SKIP);
                                /* ... hc may need waking-up */
                                switch (ed->type) {
                                case PIPE_CONTROL:
@@ -888,11 +937,6 @@ static void ed_update(struct admhcd *ahcd, struct ed *ed)
        }
 }
 
-static void ed_halt(struct admhcd *ahcd, struct ed *ed)
-{
-       admhc_dump_ed(ahcd, "ed_halt", ed, 1);
-}
-
 /* there are some tds completed; called in_irq(), with HCD locked */
 static void admhc_td_complete(struct admhcd *ahcd)
 {
@@ -902,14 +946,6 @@ static void admhc_td_complete(struct admhcd *ahcd)
                if (ed->state != ED_OPER)
                        continue;
 
-               if (hc32_to_cpup(ahcd, &ed->hwINFO) & ED_SKIP)
-                       continue;
-
-               if (hc32_to_cpup(ahcd, &ed->hwHeadP) & ED_H) {
-                       ed_halt(ahcd, ed);
-                       continue;
-               }
-
                ed_update(ahcd, ed);
        }
 }