include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / usb / host / ohci-q.c
index 889c072..83094d0 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include <linux/irq.h>
+#include <linux/slab.h>
 
 static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
 {
@@ -36,33 +37,25 @@ static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
  * PRECONDITION:  ohci lock held, irqs blocked.
  */
 static void
-finish_urb (struct ohci_hcd *ohci, struct urb *urb)
+finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
 __releases(ohci->lock)
 __acquires(ohci->lock)
 {
        // ASSERT (urb->hcpriv != 0);
 
        urb_free_priv (ohci, urb->hcpriv);
-       urb->hcpriv = NULL;
-
-       spin_lock (&urb->lock);
-       if (likely (urb->status == -EINPROGRESS))
-               urb->status = 0;
-       /* report short control reads right even though the data TD always
-        * has TD_R set.  (much simpler, but creates the 1-td limit.)
-        */
-       if (unlikely (urb->transfer_flags & URB_SHORT_NOT_OK)
-                       && unlikely (usb_pipecontrol (urb->pipe))
-                       && urb->actual_length < urb->transfer_buffer_length
-                       && usb_pipein (urb->pipe)
-                       && urb->status == 0) {
-               urb->status = -EREMOTEIO;
-       }
-       spin_unlock (&urb->lock);
+       if (likely(status == -EINPROGRESS))
+               status = 0;
 
        switch (usb_pipetype (urb->pipe)) {
        case PIPE_ISOCHRONOUS:
                ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--;
+               if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
+                       if (quirk_amdiso(ohci))
+                               quirk_amd_pll(1);
+                       if (quirk_amdprefetch(ohci))
+                               sb800_prefetch(ohci, 0);
+               }
                break;
        case PIPE_INTERRUPT:
                ohci_to_hcd(ohci)->self.bandwidth_int_reqs--;
@@ -70,13 +63,13 @@ __acquires(ohci->lock)
        }
 
 #ifdef OHCI_VERBOSE_DEBUG
-       urb_print (urb, "RET", usb_pipeout (urb->pipe));
+       urb_print(urb, "RET", usb_pipeout (urb->pipe), status);
 #endif
 
        /* urb->complete() can reenter this HCD */
        usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb);
        spin_unlock (&ohci->lock);
-       usb_hcd_giveback_urb (ohci_to_hcd(ohci), urb);
+       usb_hcd_giveback_urb(ohci_to_hcd(ohci), urb, status);
        spin_lock (&ohci->lock);
 
        /* stop periodic dma if it's not needed */
@@ -173,9 +166,6 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
 {
        int     branch;
 
-       if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING)
-               return -EAGAIN;
-
        ed->state = ED_OPER;
        ed->ed_prev = NULL;
        ed->ed_next = NULL;
@@ -183,7 +173,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
        if (quirk_zfmicro(ohci)
                        && (ed->type == PIPE_INTERRUPT)
                        && !(ohci->eds_scheduled++))
-               mod_timer(&ohci->unlink_watchdog, round_jiffies_relative(HZ));
+               mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
        wmb ();
 
        /* we care about rm_list when setting CLE/BLE in case the HC was at
@@ -432,7 +422,7 @@ static struct ed *ed_get (
                is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN);
 
                /* FIXME usbcore changes dev->devnum before SET_ADDRESS
-                * suceeds ... otherwise we wouldn't need "pipe".
+                * succeeds ... otherwise we wouldn't need "pipe".
                 */
                info = usb_pipedevice (pipe);
                ed->type = usb_pipetype(pipe);
@@ -694,6 +684,12 @@ static void td_submit_urb (
                                data + urb->iso_frame_desc [cnt].offset,
                                urb->iso_frame_desc [cnt].length, urb, cnt);
                }
+               if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
+                       if (quirk_amdiso(ohci))
+                               quirk_amd_pll(0);
+                       if (quirk_amdprefetch(ohci))
+                               sb800_prefetch(ohci, 1);
+               }
                periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0
                        && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0;
                break;
@@ -713,19 +709,18 @@ static void td_submit_urb (
  * Done List handling functions
  *-------------------------------------------------------------------------*/
 
-/* calculate transfer length/status and update the urb
- * PRECONDITION:  irqsafe (only for urb->status locking)
- */
-static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
+/* calculate transfer length/status and update the urb */
+static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td)
 {
        u32     tdINFO = hc32_to_cpup (ohci, &td->hwINFO);
        int     cc = 0;
+       int     status = -EINPROGRESS;
 
        list_del (&td->td_list);
 
        /* ISO ... drivers see per-TD length/status */
        if (tdINFO & TD_ISO) {
-               u16     tdPSW = ohci_hwPSW (ohci, td, 0);
+               u16     tdPSW = ohci_hwPSW(ohci, td, 0);
                int     dlen = 0;
 
                /* NOTE:  assumes FC in tdINFO == 0, and that
@@ -734,7 +729,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
 
                cc = (tdPSW >> 12) & 0xF;
                if (tdINFO & TD_CC)     /* hc didn't touch? */
-                       return;
+                       return status;
 
                if (usb_pipeout (urb->pipe))
                        dlen = urb->iso_frame_desc [td->index].length;
@@ -767,12 +762,8 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
                if (cc == TD_DATAUNDERRUN
                                && !(urb->transfer_flags & URB_SHORT_NOT_OK))
                        cc = TD_CC_NOERROR;
-               if (cc != TD_CC_NOERROR && cc < 0x0E) {
-                       spin_lock (&urb->lock);
-                       if (urb->status == -EINPROGRESS)
-                               urb->status = cc_to_error [cc];
-                       spin_unlock (&urb->lock);
-               }
+               if (cc != TD_CC_NOERROR && cc < 0x0E)
+                       status = cc_to_error[cc];
 
                /* count all non-empty packets except control SETUP packet */
                if ((type != PIPE_CONTROL || td->index != 0) && tdBE != 0) {
@@ -791,14 +782,15 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
                                urb->actual_length,
                                urb->transfer_buffer_length);
        }
+       return status;
 }
 
 /*-------------------------------------------------------------------------*/
 
-static inline struct td *
-ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
+static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc)
 {
        struct urb              *urb = td->urb;
+       urb_priv_t              *urb_priv = urb->hcpriv;
        struct ed               *ed = td->ed;
        struct list_head        *tmp = td->td_list.next;
        __hc32                  toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
@@ -810,13 +802,12 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
        wmb ();
        ed->hwHeadP &= ~cpu_to_hc32 (ohci, 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.
-        * also patch the ed so it looks as if those tds completed normally.
+       /* Get rid of all later tds from this urb.  We don't have
+        * to be careful: no errors and nothing was transferred.
+        * Also patch the ed so it looks as if those tds completed normally.
         */
        while (tmp != &ed->td_list) {
                struct td       *next;
-               __hc32          info;
 
                next = list_entry (tmp, struct td, td_list);
                tmp = next->td_list.next;
@@ -831,14 +822,9 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
                 * then we need to leave the control STATUS packet queued
                 * and clear ED_SKIP.
                 */
-               info = next->hwINFO;
-               info |= cpu_to_hc32 (ohci, TD_DONE);
-               info &= ~cpu_to_hc32 (ohci, TD_CC);
-               next->hwINFO = info;
-
-               next->next_dl_td = rev;
-               rev = next;
 
+               list_del(&next->td_list);
+               urb_priv->td_cnt++;
                ed->hwHeadP = next->hwNextTD | toggle;
        }
 
@@ -864,8 +850,6 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
                        hc32_to_cpu (ohci, td->hwINFO),
                        cc, cc_to_error [cc]);
        }
-
-       return rev;
 }
 
 /* replies to the request have to be on a FIFO basis so
@@ -902,7 +886,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
                 */
                if (cc != TD_CC_NOERROR
                                && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
-                       td_rev = ed_halted (ohci, td, cc, td_rev);
+                       ed_halted(ohci, td, cc);
 
                td->next_dl_td = td_rev;
                td_rev = td;
@@ -978,12 +962,13 @@ rescan_this:
                        struct urb      *urb;
                        urb_priv_t      *urb_priv;
                        __hc32          savebits;
+                       u32             tdINFO;
 
                        td = list_entry (entry, struct td, td_list);
                        urb = td->urb;
                        urb_priv = td->urb->hcpriv;
 
-                       if (urb->status == -EINPROGRESS) {
+                       if (!urb->unlinked) {
                                prev = &td->hwNextTD;
                                continue;
                        }
@@ -992,6 +977,17 @@ rescan_this:
                        savebits = *prev & ~cpu_to_hc32 (ohci, TD_MASK);
                        *prev = td->hwNextTD | savebits;
 
+                       /* If this was unlinked, the TD may not have been
+                        * retired ... so manually save the data toggle.
+                        * The controller ignores the value we save for
+                        * control and ISO endpoints.
+                        */
+                       tdINFO = hc32_to_cpup(ohci, &td->hwINFO);
+                       if ((tdINFO & TD_T) == TD_T_DATA0)
+                               ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_C);
+                       else if ((tdINFO & TD_T) == TD_T_DATA1)
+                               ed->hwHeadP |= cpu_to_hc32(ohci, ED_C);
+
                        /* HC may have partly processed this TD */
                        td_done (ohci, urb, td);
                        urb_priv->td_cnt++;
@@ -999,7 +995,7 @@ rescan_this:
                        /* if URB is done, clean up */
                        if (urb_priv->td_cnt == urb_priv->length) {
                                modified = completed = 1;
-                               finish_urb (ohci, urb);
+                               finish_urb(ohci, urb, 0);
                        }
                }
                if (completed && !list_empty (&ed->td_list))
@@ -1082,14 +1078,15 @@ static void takeback_td(struct ohci_hcd *ohci, struct td *td)
        struct urb      *urb = td->urb;
        urb_priv_t      *urb_priv = urb->hcpriv;
        struct ed       *ed = td->ed;
+       int             status;
 
        /* update URB's length and status from TD */
-       td_done(ohci, urb, td);
+       status = td_done(ohci, urb, td);
        urb_priv->td_cnt++;
 
        /* If all this urb's TDs are done, call complete() */
        if (urb_priv->td_cnt == urb_priv->length)
-               finish_urb(ohci, urb);
+               finish_urb(ohci, urb, status);
 
        /* clean schedule:  unlink EDs that are no longer busy */
        if (list_empty(&ed->td_list)) {