Merge to kernel-2.6.20-1.2949.fc6.vs2.2.0.1
[linux-2.6.git] / drivers / usb / host / ohci-q.c
index 4661848..830a3fe 100644 (file)
@@ -1,12 +1,14 @@
 /*
  * OHCI HCD (Host Controller Driver) for USB.
- * 
+ *
  * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
  * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
- * 
+ *
  * This file is licenced under the GPL.
  */
 
+#include <linux/irq.h>
+
 static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
 {
        int             last = urb_priv->length - 1;
@@ -34,7 +36,7 @@ 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, struct pt_regs *regs)
+finish_urb (struct ohci_hcd *ohci, struct urb *urb)
 __releases(ohci->lock)
 __acquires(ohci->lock)
 {
@@ -60,10 +62,10 @@ __acquires(ohci->lock)
 
        switch (usb_pipetype (urb->pipe)) {
        case PIPE_ISOCHRONOUS:
-               hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs--;
+               ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--;
                break;
        case PIPE_INTERRUPT:
-               hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs--;
+               ohci_to_hcd(ohci)->self.bandwidth_int_reqs--;
                break;
        }
 
@@ -73,12 +75,12 @@ __acquires(ohci->lock)
 
        /* urb->complete() can reenter this HCD */
        spin_unlock (&ohci->lock);
-       usb_hcd_giveback_urb (&ohci->hcd, urb, regs);
+       usb_hcd_giveback_urb (ohci_to_hcd(ohci), urb);
        spin_lock (&ohci->lock);
 
        /* stop periodic dma if it's not needed */
-       if (hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs == 0
-                       && hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs == 0) {
+       if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0
+                       && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0) {
                ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
                ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
        }
@@ -87,7 +89,7 @@ __acquires(ohci->lock)
 
 /*-------------------------------------------------------------------------*
  * ED handling functions
- *-------------------------------------------------------------------------*/  
+ *-------------------------------------------------------------------------*/
 
 /* search for the right schedule branch to use for a periodic ed.
  * does some load balancing; returns the branch, or negative errno.
@@ -105,7 +107,6 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
         */
        for (i = 0; i < interval ; i++) {
                if (branch < 0 || ohci->load [branch] > ohci->load [i]) {
-#if 1  /* CONFIG_USB_BANDWIDTH */
                        int     j;
 
                        /* usb 1.1 says 90% of one frame */
@@ -115,8 +116,7 @@ static int balance (struct ohci_hcd *ohci, int interval, int load)
                        }
                        if (j < NUM_INTS)
                                continue;
-#endif
-                       branch = i; 
+                       branch = i;
                }
        }
        return branch;
@@ -163,16 +163,16 @@ static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
                }
                ohci->load [i] += ed->load;
        }
-       hcd_to_bus (&ohci->hcd)->bandwidth_allocated += ed->load / ed->interval;
+       ohci_to_hcd(ohci)->self.bandwidth_allocated += ed->load / ed->interval;
 }
 
 /* link an ed into one of the HC chains */
 
 static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
-{       
+{
        int     branch;
 
-       if (ohci->hcd.state == USB_STATE_QUIESCING)
+       if (ohci_to_hcd(ohci)->state == HC_STATE_QUIESCING)
                return -EAGAIN;
 
        ed->state = ED_OPER;
@@ -246,7 +246,7 @@ static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
                }
                ed->branch = branch;
                periodic_link (ohci, ed);
-       }               
+       }
 
        /* the HC may not see the schedule updates yet, but if it does
         * then they'll be properly ordered.
@@ -275,15 +275,15 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
                        *prev = ed->ed_next;
                }
                ohci->load [i] -= ed->load;
-       }       
-       hcd_to_bus (&ohci->hcd)->bandwidth_allocated -= ed->load / ed->interval;
+       }
+       ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval;
 
        ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
                (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "",
                ed, ed->branch, ed->load, ed->interval);
 }
 
-/* unlink an ed from one of the HC chains. 
+/* unlink an ed from one of the HC chains.
  * just the link to the ed is unlinked.
  * the link from the ed still points to another operational ed or 0
  * so the HC can eventually finish the processing of the unlinked ed
@@ -305,7 +305,7 @@ static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
  * When finish_unlinks() runs later, after SOF interrupt, it will often
  * complete one or more URB unlinks before making that state change.
  */
-static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) 
+static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
 {
        ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
        wmb ();
@@ -386,41 +386,34 @@ static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
 /*-------------------------------------------------------------------------*/
 
 /* get and maybe (re)init an endpoint. init _should_ be done only as part
- * of usb_set_configuration() or usb_set_interface() ... but the USB stack
- * isn't very stateful, so we re-init whenever the HC isn't looking.
+ * of enumeration, usb_set_configuration() or usb_set_interface().
  */
 static struct ed *ed_get (
        struct ohci_hcd         *ohci,
+       struct usb_host_endpoint *ep,
        struct usb_device       *udev,
        unsigned int            pipe,
        int                     interval
 ) {
-       int                     is_out = !usb_pipein (pipe);
-       int                     type = usb_pipetype (pipe);
-       struct hcd_dev          *dev = (struct hcd_dev *) udev->hcpriv;
-       struct ed               *ed; 
-       unsigned                ep;
+       struct ed               *ed;
        unsigned long           flags;
 
-       ep = usb_pipeendpoint (pipe) << 1;
-       if (type != PIPE_CONTROL && is_out)
-               ep |= 1;
-
        spin_lock_irqsave (&ohci->lock, flags);
 
-       if (!(ed = dev->ep [ep])) {
+       if (!(ed = ep->hcpriv)) {
                struct td       *td;
+               int             is_out;
+               u32             info;
 
                ed = ed_alloc (ohci, GFP_ATOMIC);
                if (!ed) {
                        /* out of memory */
                        goto done;
                }
-               dev->ep [ep] = ed;
 
-               /* dummy td; end of td list for ed */
+               /* dummy td; end of td list for ed */
                td = td_alloc (ohci, GFP_ATOMIC);
-               if (!td) {
+               if (!td) {
                        /* out of memory */
                        ed_free (ohci, ed);
                        ed = NULL;
@@ -430,43 +423,44 @@ static struct ed *ed_get (
                ed->hwTailP = cpu_to_hc32 (ohci, td->td_dma);
                ed->hwHeadP = ed->hwTailP;      /* ED_C, ED_H zeroed */
                ed->state = ED_IDLE;
-               ed->type = type;
-       }
 
-       /* NOTE: only ep0 currently needs this "re"init logic, during
-        * enumeration (after set_address).
-        */
-       if (ed->state == ED_IDLE) {
-               u32     info;
+               is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN);
 
+               /* FIXME usbcore changes dev->devnum before SET_ADDRESS
+                * suceeds ... otherwise we wouldn't need "pipe".
+                */
                info = usb_pipedevice (pipe);
-               info |= (ep >> 1) << 7;
-               info |= usb_maxpacket (udev, pipe, is_out) << 16;
+               ed->type = usb_pipetype(pipe);
+
+               info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7;
+               info |= le16_to_cpu(ep->desc.wMaxPacketSize) << 16;
                if (udev->speed == USB_SPEED_LOW)
                        info |= ED_LOWSPEED;
                /* only control transfers store pids in tds */
-               if (type != PIPE_CONTROL) {
+               if (ed->type != PIPE_CONTROL) {
                        info |= is_out ? ED_OUT : ED_IN;
-                       if (type != PIPE_BULK) {
+                       if (ed->type != PIPE_BULK) {
                                /* periodic transfers... */
-                               if (type == PIPE_ISOCHRONOUS)
+                               if (ed->type == PIPE_ISOCHRONOUS)
                                        info |= ED_ISO;
                                else if (interval > 32) /* iso can be bigger */
                                        interval = 32;
                                ed->interval = interval;
                                ed->load = usb_calc_bus_time (
                                        udev->speed, !is_out,
-                                       type == PIPE_ISOCHRONOUS,
-                                       usb_maxpacket (udev, pipe, is_out))
+                                       ed->type == PIPE_ISOCHRONOUS,
+                                       le16_to_cpu(ep->desc.wMaxPacketSize))
                                                / 1000;
                        }
                }
                ed->hwINFO = cpu_to_hc32(ohci, info);
+
+               ep->hcpriv = ed;
        }
 
 done:
        spin_unlock_irqrestore (&ohci->lock, flags);
-       return ed; 
+       return ed;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -478,7 +472,7 @@ done:
  * and that ed->state is ED_OPER
  */
 static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
-{    
+{
        ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE);
        ed_deschedule (ohci, ed);
 
@@ -545,7 +539,7 @@ td_fill (struct ohci_hcd *ohci, u32 info,
        td->ed = urb_priv->ed;
        td->next_dl_td = NULL;
        td->index = index;
-       td->urb = urb; 
+       td->urb = urb;
        td->data_dma = data;
        if (!len)
                data = 0;
@@ -553,11 +547,12 @@ td_fill (struct ohci_hcd *ohci, u32 info,
        td->hwINFO = cpu_to_hc32 (ohci, info);
        if (is_iso) {
                td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000);
-               td->hwPSW [0] = cpu_to_hc16 (ohci, (data & 0x0FFF) | 0xE000);
+               *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
+                                               (data & 0x0FFF) | 0xE000);
                td->ed->last_iso = info & 0xffff;
        } else {
-               td->hwCBP = cpu_to_hc32 (ohci, data); 
-       }                       
+               td->hwCBP = cpu_to_hc32 (ohci, data);
+       }
        if (data)
                td->hwBE = cpu_to_hc32 (ohci, data + len - 1);
        else
@@ -600,7 +595,7 @@ static void td_submit_urb (
         * use the device toggle bits for resetting, and rely on the fact
         * that resetting toggle is meaningless if the endpoint is active.
         */
-       if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
+       if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
                usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
                        is_out, 1);
                urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C);
@@ -625,8 +620,8 @@ static void td_submit_urb (
         */
        case PIPE_INTERRUPT:
                /* ... and periodic urbs have extra accounting */
-               periodic = hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs++ == 0
-                       && hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs == 0;
+               periodic = ohci_to_hcd(ohci)->self.bandwidth_int_reqs++ == 0
+                       && ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0;
                /* FALLTHROUGH */
        case PIPE_BULK:
                info = is_out
@@ -668,7 +663,7 @@ static void td_submit_urb (
                        /* NOTE:  mishandles transfers >8K, some >4K */
                        td_fill (ohci, info, data, data_len, urb, cnt++);
                }
-               info = is_out
+               info = (is_out || data_len == 0)
                        ? TD_CC | TD_DP_IN | TD_T_DATA1
                        : TD_CC | TD_DP_OUT | TD_T_DATA1;
                td_fill (ohci, info, data, 0, urb, cnt++);
@@ -694,8 +689,8 @@ static void td_submit_urb (
                                data + urb->iso_frame_desc [cnt].offset,
                                urb->iso_frame_desc [cnt].length, urb, cnt);
                }
-               periodic = hcd_to_bus (&ohci->hcd)->bandwidth_isoc_reqs++ == 0
-                       && hcd_to_bus (&ohci->hcd)->bandwidth_int_reqs == 0;
+               periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0
+                       && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0;
                break;
        }
 
@@ -724,14 +719,16 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
        list_del (&td->td_list);
 
        /* ISO ... drivers see per-TD length/status */
-       if (tdINFO & TD_ISO) {
-               u16     tdPSW = hc16_to_cpu (ohci, td->hwPSW [0]);
+       if (tdINFO & TD_ISO) {
+               u16     tdPSW = ohci_hwPSW (ohci, td, 0);
                int     dlen = 0;
 
-               /* NOTE:  assumes FC in tdINFO == 0 (and MAXPSW == 1) */
+               /* NOTE:  assumes FC in tdINFO == 0, and that
+                * only the first of 0..MAXPSW psws is used.
+                */
 
-               cc = (tdPSW >> 12) & 0xF;
-               if (tdINFO & TD_CC)     /* hc didn't touch? */
+               cc = (tdPSW >> 12) & 0xF;
+               if (tdINFO & TD_CC)     /* hc didn't touch? */
                        return;
 
                if (usb_pipeout (urb->pipe))
@@ -759,7 +756,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
                int     type = usb_pipetype (urb->pipe);
                u32     tdBE = hc32_to_cpup (ohci, &td->hwBE);
 
-               cc = TD_CC_GET (tdINFO);
+               cc = TD_CC_GET (tdINFO);
 
                /* update packet status if needed (short is normally ok) */
                if (cc == TD_DATAUNDERRUN
@@ -788,7 +785,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
                                urb, td, 1 + td->index, cc,
                                urb->actual_length,
                                urb->transfer_buffer_length);
-       }
+       }
 }
 
 /*-------------------------------------------------------------------------*/
@@ -796,7 +793,7 @@ static void td_done (struct ohci_hcd *ohci, struct urb *urb, struct td *td)
 static inline struct td *
 ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
 {
-       struct urb              *urb = td->urb;
+       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 (ohci, ED_C);
@@ -806,7 +803,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
         */
        ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
        wmb ();
-       ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H); 
+       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.
@@ -834,7 +831,7 @@ ed_halted (struct ohci_hcd *ohci, struct td *td, int cc, struct td *rev)
                info &= ~cpu_to_hc32 (ohci, TD_CC);
                next->hwINFO = info;
 
-               next->next_dl_td = rev; 
+               next->next_dl_td = rev;
                rev = next;
 
                ed->hwHeadP = next->hwNextTD | toggle;
@@ -882,8 +879,8 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
        /* get TD from hc's singly linked list, and
         * prepend to ours.  ed->td_list changes later.
         */
-       while (td_dma) {                
-               int             cc;
+       while (td_dma) {
+               int             cc;
 
                td = dma_to_td (ohci, td_dma);
                if (!td) {
@@ -902,10 +899,10 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
                                && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
                        td_rev = ed_halted (ohci, td, cc, td_rev);
 
-               td->next_dl_td = td_rev;        
+               td->next_dl_td = td_rev;
                td_rev = td;
                td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
-       }       
+       }
        return td_rev;
 }
 
@@ -913,7 +910,7 @@ static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
 
 /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */
 static void
-finish_unlinks (struct ohci_hcd *ohci, u16 tick, struct pt_regs *regs)
+finish_unlinks (struct ohci_hcd *ohci, u16 tick)
 {
        struct ed       *ed, **last;
 
@@ -926,7 +923,7 @@ rescan_all:
                /* only take off EDs that the HC isn't using, accounting for
                 * frame counter wraps and EDs with partially retired TDs
                 */
-               if (likely (regs && HCD_IS_RUNNING(ohci->hcd.state))) {
+               if (likely (HC_IS_RUNNING(ohci_to_hcd(ohci)->state))) {
                        if (tick_before (tick, ed->tick)) {
 skip_ed:
                                last = &ed->ed_next;
@@ -993,7 +990,7 @@ rescan_this:
                        /* if URB is done, clean up */
                        if (urb_priv->td_cnt == urb_priv->length) {
                                modified = completed = 1;
-                               finish_urb (ohci, urb, regs);
+                               finish_urb (ohci, urb);
                        }
                }
                if (completed && !list_empty (&ed->td_list))
@@ -1008,22 +1005,24 @@ rescan_this:
 
                /* but if there's work queued, reschedule */
                if (!list_empty (&ed->td_list)) {
-                       if (HCD_IS_RUNNING(ohci->hcd.state))
+                       if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state))
                                ed_schedule (ohci, ed);
                }
 
                if (modified)
                        goto rescan_all;
-       }
+       }
 
-       /* maybe reenable control and bulk lists */ 
-       if (HCD_IS_RUNNING(ohci->hcd.state)
-                       && ohci->hcd.state != USB_STATE_QUIESCING
+       /* maybe reenable control and bulk lists */
+       if (HC_IS_RUNNING(ohci_to_hcd(ohci)->state)
+                       && ohci_to_hcd(ohci)->state != HC_STATE_QUIESCING
                        && !ohci->ed_rm_list) {
                u32     command = 0, control = 0;
 
                if (ohci->ed_controltail) {
                        command |= OHCI_CLF;
+                       if (ohci->flags & OHCI_QUIRK_ZFMICRO)
+                               mdelay(1);
                        if (!(ohci->hc_control & OHCI_CTRL_CLE)) {
                                control |= OHCI_CTRL_CLE;
                                ohci_writel (ohci, 0,
@@ -1032,22 +1031,29 @@ rescan_this:
                }
                if (ohci->ed_bulktail) {
                        command |= OHCI_BLF;
+                       if (ohci->flags & OHCI_QUIRK_ZFMICRO)
+                               mdelay(1);
                        if (!(ohci->hc_control & OHCI_CTRL_BLE)) {
                                control |= OHCI_CTRL_BLE;
                                ohci_writel (ohci, 0,
                                        &ohci->regs->ed_bulkcurrent);
                        }
                }
-               
+
                /* CLE/BLE to enable, CLF/BLF to (maybe) kickstart */
                if (control) {
                        ohci->hc_control |= control;
-                       ohci_writel (ohci, ohci->hc_control,
-                                       &ohci->regs->control);   
-               }
-               if (command)
-                       ohci_writel (ohci, command, &ohci->regs->cmdstatus);   
-       }
+                       if (ohci->flags & OHCI_QUIRK_ZFMICRO)
+                               mdelay(1);
+                       ohci_writel (ohci, ohci->hc_control,
+                                       &ohci->regs->control);
+               }
+               if (command) {
+                       if (ohci->flags & OHCI_QUIRK_ZFMICRO)
+                               mdelay(1);
+                       ohci_writel (ohci, command, &ohci->regs->cmdstatus);
+               }
+       }
 }
 
 
@@ -1062,23 +1068,23 @@ rescan_this:
  * scanning the (re-reversed) donelist as this does.
  */
 static void
-dl_done_list (struct ohci_hcd *ohci, struct pt_regs *regs)
+dl_done_list (struct ohci_hcd *ohci)
 {
        struct td       *td = dl_reverse_done_list (ohci);
 
-       while (td) {
+       while (td) {
                struct td       *td_next = td->next_dl_td;
                struct urb      *urb = td->urb;
                urb_priv_t      *urb_priv = urb->hcpriv;
                struct ed       *ed = td->ed;
 
                /* update URB's length and status from TD */
-               td_done (ohci, urb, td);
-               urb_priv->td_cnt++;
+               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, regs);
+               if (urb_priv->td_cnt == urb_priv->length)
+                       finish_urb (ohci, urb);
 
                /* clean schedule:  unlink EDs that are no longer busy */
                if (list_empty (&ed->td_list)) {
@@ -1086,25 +1092,26 @@ dl_done_list (struct ohci_hcd *ohci, struct pt_regs *regs)
                                start_ed_unlink (ohci, ed);
 
                /* ... reenabling halted EDs only after fault cleanup */
-               } else if ((ed->hwINFO & cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE))
+               } else if ((ed->hwINFO & cpu_to_hc32 (ohci,
+                                               ED_SKIP | ED_DEQUEUE))
                                        == cpu_to_hc32 (ohci, ED_SKIP)) {
                        td = list_entry (ed->td_list.next, struct td, td_list);
-                       if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
+                       if (!(td->hwINFO & cpu_to_hc32 (ohci, TD_DONE))) {
                                ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP);
                                /* ... hc may need waking-up */
                                switch (ed->type) {
                                case PIPE_CONTROL:
                                        ohci_writel (ohci, OHCI_CLF,
-                                               &ohci->regs->cmdstatus);   
+                                               &ohci->regs->cmdstatus);
                                        break;
                                case PIPE_BULK:
                                        ohci_writel (ohci, OHCI_BLF,
-                                               &ohci->regs->cmdstatus);   
+                                               &ohci->regs->cmdstatus);
                                        break;
                                }
                        }
                }
 
-               td = td_next;
-       }  
+               td = td_next;
+       }
 }