11 #include <linux/slab.h>
21 for (i = 0; i <= last; i++) {
22 td = urb_priv->
td [
i];
46 urb_free_priv (
ohci,
urb->hcpriv);
50 switch (usb_pipetype (
urb->pipe)) {
51 case PIPE_ISOCHRONOUS:
52 ohci_to_hcd(
ohci)->self.bandwidth_isoc_reqs--;
53 if (ohci_to_hcd(
ohci)->
self.bandwidth_isoc_reqs == 0) {
54 if (quirk_amdiso(
ohci))
56 if (quirk_amdprefetch(
ohci))
57 sb800_prefetch(
ohci, 0);
61 ohci_to_hcd(
ohci)->self.bandwidth_int_reqs--;
65 #ifdef OHCI_VERBOSE_DEBUG
71 spin_unlock (&
ohci->lock);
73 spin_lock (&
ohci->lock);
76 if (ohci_to_hcd(
ohci)->
self.bandwidth_isoc_reqs == 0
77 && ohci_to_hcd(
ohci)->
self.bandwidth_int_reqs == 0) {
108 if ((ohci->
load [j] + load) > 900)
125 static void periodic_link (
struct ohci_hcd *ohci,
struct ed *
ed)
129 ohci_vdbg (ohci,
"link %sed %p branch %d [%dus.], interval %d\n",
133 for (i = ed->
branch; i < NUM_INTS; i += ed->interval) {
142 while (here && ed != here) {
160 ohci_to_hcd(ohci)->self.bandwidth_allocated += ed->
load / ed->
interval;
165 static int ed_schedule (
struct ohci_hcd *ohci,
struct ed *ed)
173 if (quirk_zfmicro(ohci)
174 && (ed->
type == PIPE_INTERRUPT)
194 &ohci->
regs->ed_controlhead);
206 &ohci->
regs->control);
226 &ohci->
regs->control);
237 "ERR %d, interval %d msecs, load %d\n",
243 periodic_link (ohci, ed);
255 static void periodic_unlink (
struct ohci_hcd *ohci,
struct ed *ed)
259 for (i = ed->
branch; i < NUM_INTS; i += ed->interval) {
264 while (*prev && (temp = *prev) != ed) {
274 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->
load / ed->
interval;
276 ohci_vdbg (ohci,
"unlink %sed %p branch %d [%dus.], interval %d\n",
303 static void ed_deschedule (
struct ohci_hcd *ohci,
struct ed *ed)
326 &ohci->
regs->control);
331 &ohci->
regs->ed_controlhead);
352 &ohci->
regs->control);
357 &ohci->
regs->ed_bulkhead);
375 periodic_unlink (ohci, ed);
386 static struct ed *ed_get (
388 struct usb_host_endpoint *ep,
389 struct usb_device *
udev,
398 if (!(ed = ep->hcpriv)) {
422 is_out = !(ep->desc.bEndpointAddress &
USB_DIR_IN);
427 info = usb_pipedevice (pipe);
428 ed->
type = usb_pipetype(pipe);
430 info |= (ep->desc.bEndpointAddress & ~
USB_DIR_IN) << 7;
431 info |= usb_endpoint_maxp(&ep->desc) << 16;
435 if (ed->
type != PIPE_CONTROL) {
437 if (ed->
type != PIPE_BULK) {
439 if (ed->
type == PIPE_ISOCHRONOUS)
441 else if (interval > 32)
445 udev->speed, !is_out,
446 ed->
type == PIPE_ISOCHRONOUS,
447 usb_endpoint_maxp(&ep->desc))
457 spin_unlock_irqrestore (&ohci->
lock, flags);
469 static void start_ed_unlink (
struct ohci_hcd *ohci,
struct ed *ed)
472 ed_deschedule (ohci, ed);
490 ed->
tick = ohci_frame_no(ohci) + 1;
505 struct td *
td, *td_pt;
506 struct urb_priv *urb_priv = urb->hcpriv;
507 int is_iso = info &
TD_ISO;
523 if (index != (urb_priv->
length - 1)
524 || (urb->transfer_flags & URB_NO_INTERRUPT))
531 td = urb_priv->
td [
index] = urb_priv->
ed->dummy;
532 urb_priv->
ed->dummy = td_pt;
534 td->
ed = urb_priv->
ed;
545 *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
546 (data & 0x0FFF) | 0xE000);
547 td->
ed->last_iso = info & 0xffff;
577 static void td_submit_urb (
581 struct urb_priv *urb_priv = urb->hcpriv;
583 int data_len = urb->transfer_buffer_length;
586 int is_out = usb_pipeout (urb->pipe);
593 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
594 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
603 data = urb->transfer_dma;
611 switch (urb_priv->
ed->type) {
618 periodic = ohci_to_hcd(ohci)->self.bandwidth_int_reqs++ == 0
619 && ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0;
626 while (data_len > 4096) {
627 td_fill (ohci, info, data, 4096, urb, cnt);
633 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
635 td_fill (ohci, info, data, data_len, urb, cnt);
637 if ((urb->transfer_flags & URB_ZERO_PACKET)
638 && cnt < urb_priv->
length) {
639 td_fill (ohci, info, 0, 0, urb, cnt);
643 if (urb_priv->
ed->type == PIPE_BULK) {
654 td_fill (ohci, info, urb->setup_dma, 8, urb, cnt++);
659 td_fill (ohci, info, data, data_len, urb, cnt++);
661 info = (is_out || data_len == 0)
664 td_fill (ohci, info, data, 0, urb, cnt++);
674 case PIPE_ISOCHRONOUS:
675 for (cnt = 0; cnt < urb->number_of_packets; cnt++) {
676 int frame = urb->start_frame;
681 frame += cnt * urb->interval;
683 td_fill (ohci,
TD_CC | TD_ISO | frame,
684 data + urb->iso_frame_desc [cnt].offset,
685 urb->iso_frame_desc [cnt].length, urb, cnt);
687 if (ohci_to_hcd(ohci)->
self.bandwidth_isoc_reqs == 0) {
688 if (quirk_amdiso(ohci))
690 if (quirk_amdprefetch(ohci))
691 sb800_prefetch(ohci, 1);
693 periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0
694 && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0;
713 static int td_done(
struct ohci_hcd *ohci,
struct urb *urb,
struct td *td)
715 u32 tdINFO = hc32_to_cpup (ohci, &td->
hwINFO);
722 if (tdINFO & TD_ISO) {
723 u16 tdPSW = ohci_hwPSW(ohci, td, 0);
730 cc = (tdPSW >> 12) & 0xF;
734 if (usb_pipeout (urb->pipe))
735 dlen = urb->iso_frame_desc [td->
index].length;
740 dlen = tdPSW & 0x3ff;
742 urb->actual_length +=
dlen;
743 urb->iso_frame_desc [td->
index].actual_length =
dlen;
744 urb->iso_frame_desc [td->
index].status = cc_to_error [
cc];
748 "urb %p iso td %p (%d) len %d cc %d\n",
749 urb, td, 1 + td->
index, dlen, cc);
756 int type = usb_pipetype (urb->pipe);
757 u32 tdBE = hc32_to_cpup (ohci, &td->
hwBE);
763 && !(urb->transfer_flags & URB_SHORT_NOT_OK))
766 status = cc_to_error[
cc];
769 if ((type != PIPE_CONTROL || td->
index != 0) && tdBE != 0) {
771 urb->actual_length += tdBE - td->
data_dma + 1;
773 urb->actual_length +=
774 hc32_to_cpup (ohci, &td->
hwCBP)
780 "urb %p td %p (%d) cc %d, len=%d/%d\n",
781 urb, td, 1 + td->
index, cc,
783 urb->transfer_buffer_length);
790 static void ed_halted(
struct ohci_hcd *ohci,
struct td *td,
int cc)
792 struct urb *urb = td->
urb;
794 struct ed *ed = td->
ed;
815 if (next->
urb != urb)
837 if ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)
841 if (usb_pipecontrol (urb->pipe))
846 "urb %p path %s ep%d%s %08x cc %d --> status %d\n",
847 urb, urb->dev->devpath,
848 usb_pipeendpoint (urb->pipe),
849 usb_pipein (urb->pipe) ?
"in" :
"out",
851 cc, cc_to_error [cc]);
858 static struct td *dl_reverse_done_list (
struct ohci_hcd *ohci)
861 struct td *td_rev =
NULL;
862 struct td *td =
NULL;
864 td_dma = hc32_to_cpup (ohci, &ohci->
hcca->done_head);
865 ohci->
hcca->done_head = 0;
874 td = dma_to_td (ohci, td_dma);
876 ohci_err (ohci,
"bad entry %8x\n", td_dma);
889 ed_halted(ohci, td, cc);
893 td_dma = hc32_to_cpup (ohci, &td->
hwNextTD);
904 struct ed *
ed, **last;
907 for (last = &ohci->
ed_rm_list, ed = *last; ed !=
NULL; ed = *last) {
922 if (!list_empty (&ed->
td_list)) {
969 urb_priv = td->
urb->hcpriv;
971 if (!urb->unlinked) {
985 tdINFO = hc32_to_cpup(ohci, &td->
hwINFO);
992 td_done (ohci, urb, td);
997 modified = completed = 1;
998 finish_urb(ohci, urb, 0);
1001 if (completed && !list_empty (&ed->
td_list))
1006 if (quirk_zfmicro(ohci) && ed->
type == PIPE_INTERRUPT)
1014 if (!list_empty (&ed->
td_list)) {
1016 ed_schedule (ohci, ed);
1029 if (quirk_zfmicro(ohci))
1034 &ohci->
regs->ed_controlcurrent);
1039 if (quirk_zfmicro(ohci))
1044 &ohci->
regs->ed_bulkcurrent);
1051 if (quirk_zfmicro(ohci))
1054 &ohci->
regs->control);
1057 if (quirk_zfmicro(ohci))
1074 static void takeback_td(
struct ohci_hcd *ohci,
struct td *td)
1076 struct urb *urb = td->
urb;
1078 struct ed *ed = td->
ed;
1082 status = td_done(ohci, urb, td);
1087 finish_urb(ohci, urb, status);
1090 if (list_empty(&ed->
td_list)) {
1092 start_ed_unlink(ohci, ed);
1104 &ohci->
regs->cmdstatus);
1108 &ohci->
regs->cmdstatus);
1125 dl_done_list (
struct ohci_hcd *ohci)
1127 struct td *td = dl_reverse_done_list (ohci);
1131 struct ed *ed = td->
ed;
1147 takeback_td(ohci, td2);
1150 takeback_td(ohci, td);