Lines Matching full:ohci

3  * OHCI HCD (Host Controller Driver) for USB.
38 * PRECONDITION: ohci lock held, irqs blocked.
41 finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status) in finish_urb() argument
42 __releases(ohci->lock) in finish_urb()
43 __acquires(ohci->lock) in finish_urb()
45 struct device *dev = ohci_to_hcd(ohci)->self.controller; in finish_urb()
52 urb_free_priv (ohci, urb->hcpriv); in finish_urb()
59 ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs--; in finish_urb()
60 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { in finish_urb()
61 if (quirk_amdiso(ohci)) in finish_urb()
63 if (quirk_amdprefetch(ohci)) in finish_urb()
68 ohci_to_hcd(ohci)->self.bandwidth_int_reqs--; in finish_urb()
73 usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb); in finish_urb()
74 spin_unlock (&ohci->lock); in finish_urb()
75 usb_hcd_giveback_urb(ohci_to_hcd(ohci), urb, status); in finish_urb()
76 spin_lock (&ohci->lock); in finish_urb()
79 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0 in finish_urb()
80 && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0) { in finish_urb()
81 ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE); in finish_urb()
82 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in finish_urb()
109 static int balance (struct ohci_hcd *ohci, int interval, int load) in balance() argument
121 if (branch < 0 || ohci->load [branch] > ohci->load [i]) { in balance()
126 if ((ohci->load [j] + load) > 900) in balance()
143 static void periodic_link (struct ohci_hcd *ohci, struct ed *ed) in periodic_link() argument
147 ohci_dbg(ohci, "link %sed %p branch %d [%dus.], interval %d\n", in periodic_link()
148 (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", in periodic_link()
152 struct ed **prev = &ohci->periodic [i]; in periodic_link()
153 __hc32 *prev_p = &ohci->hcca->int_table [i]; in periodic_link()
173 *prev_p = cpu_to_hc32(ohci, ed->dma); in periodic_link()
176 ohci->load [i] += ed->load; in periodic_link()
178 ohci_to_hcd(ohci)->self.bandwidth_allocated += ed->load / ed->interval; in periodic_link()
183 static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed) in ed_schedule() argument
198 * periodic schedule encodes a tree like figure 3-5 in the ohci in ed_schedule()
204 if (ohci->ed_controltail == NULL) { in ed_schedule()
205 WARN_ON (ohci->hc_control & OHCI_CTRL_CLE); in ed_schedule()
206 ohci_writel (ohci, ed->dma, in ed_schedule()
207 &ohci->regs->ed_controlhead); in ed_schedule()
209 ohci->ed_controltail->ed_next = ed; in ed_schedule()
210 ohci->ed_controltail->hwNextED = cpu_to_hc32 (ohci, in ed_schedule()
213 ed->ed_prev = ohci->ed_controltail; in ed_schedule()
214 if (!ohci->ed_controltail && !ohci->ed_rm_list) { in ed_schedule()
216 ohci->hc_control |= OHCI_CTRL_CLE; in ed_schedule()
217 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent); in ed_schedule()
218 ohci_writel (ohci, ohci->hc_control, in ed_schedule()
219 &ohci->regs->control); in ed_schedule()
221 ohci->ed_controltail = ed; in ed_schedule()
225 if (ohci->ed_bulktail == NULL) { in ed_schedule()
226 WARN_ON (ohci->hc_control & OHCI_CTRL_BLE); in ed_schedule()
227 ohci_writel (ohci, ed->dma, &ohci->regs->ed_bulkhead); in ed_schedule()
229 ohci->ed_bulktail->ed_next = ed; in ed_schedule()
230 ohci->ed_bulktail->hwNextED = cpu_to_hc32 (ohci, in ed_schedule()
233 ed->ed_prev = ohci->ed_bulktail; in ed_schedule()
234 if (!ohci->ed_bulktail && !ohci->ed_rm_list) { in ed_schedule()
236 ohci->hc_control |= OHCI_CTRL_BLE; in ed_schedule()
237 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent); in ed_schedule()
238 ohci_writel (ohci, ohci->hc_control, in ed_schedule()
239 &ohci->regs->control); in ed_schedule()
241 ohci->ed_bulktail = ed; in ed_schedule()
247 branch = balance (ohci, ed->interval, ed->load); in ed_schedule()
249 ohci_dbg (ohci, in ed_schedule()
256 periodic_link (ohci, ed); in ed_schedule()
270 static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed) in periodic_unlink() argument
276 struct ed **prev = &ohci->periodic [i]; in periodic_unlink()
277 __hc32 *prev_p = &ohci->hcca->int_table [i]; in periodic_unlink()
287 ohci->load [i] -= ed->load; in periodic_unlink()
289 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval; in periodic_unlink()
291 ohci_dbg(ohci, "unlink %sed %p branch %d [%dus.], interval %d\n", in periodic_unlink()
292 (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "", in periodic_unlink()
317 static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed) in ed_deschedule() argument
319 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); in ed_deschedule()
338 ohci->hc_control &= ~OHCI_CTRL_CLE; in ed_deschedule()
339 ohci_writel (ohci, ohci->hc_control, in ed_deschedule()
340 &ohci->regs->control); in ed_deschedule()
343 ohci_writel (ohci, in ed_deschedule()
344 hc32_to_cpup (ohci, &ed->hwNextED), in ed_deschedule()
345 &ohci->regs->ed_controlhead); in ed_deschedule()
351 if (ohci->ed_controltail == ed) { in ed_deschedule()
352 ohci->ed_controltail = ed->ed_prev; in ed_deschedule()
353 if (ohci->ed_controltail) in ed_deschedule()
354 ohci->ed_controltail->ed_next = NULL; in ed_deschedule()
364 ohci->hc_control &= ~OHCI_CTRL_BLE; in ed_deschedule()
365 ohci_writel (ohci, ohci->hc_control, in ed_deschedule()
366 &ohci->regs->control); in ed_deschedule()
369 ohci_writel (ohci, in ed_deschedule()
370 hc32_to_cpup (ohci, &ed->hwNextED), in ed_deschedule()
371 &ohci->regs->ed_bulkhead); in ed_deschedule()
377 if (ohci->ed_bulktail == ed) { in ed_deschedule()
378 ohci->ed_bulktail = ed->ed_prev; in ed_deschedule()
379 if (ohci->ed_bulktail) in ed_deschedule()
380 ohci->ed_bulktail->ed_next = NULL; in ed_deschedule()
389 periodic_unlink (ohci, ed); in ed_deschedule()
401 struct ohci_hcd *ohci, in ed_get() argument
410 spin_lock_irqsave (&ohci->lock, flags); in ed_get()
418 ed = ed_alloc (ohci, GFP_ATOMIC); in ed_get()
425 td = td_alloc (ohci, GFP_ATOMIC); in ed_get()
428 ed_free (ohci, ed); in ed_get()
433 ed->hwTailP = cpu_to_hc32 (ohci, td->td_dma); in ed_get()
466 ed->hwINFO = cpu_to_hc32(ohci, info); in ed_get()
472 spin_unlock_irqrestore (&ohci->lock, flags); in ed_get()
484 static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed) in start_ed_unlink() argument
486 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE); in start_ed_unlink()
487 ed_deschedule (ohci, ed); in start_ed_unlink()
490 ed->ed_next = ohci->ed_rm_list; in start_ed_unlink()
492 ohci->ed_rm_list = ed; in start_ed_unlink()
495 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus); in start_ed_unlink()
496 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable); in start_ed_unlink()
498 (void) ohci_readl (ohci, &ohci->regs->control); in start_ed_unlink()
505 ed->tick = ohci_frame_no(ohci) + 1; in start_ed_unlink()
513 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
516 td_fill (struct ohci_hcd *ohci, u32 info, in td_fill() argument
557 td->hwINFO = cpu_to_hc32 (ohci, info); in td_fill()
559 td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000); in td_fill()
560 *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci, in td_fill()
563 td->hwCBP = cpu_to_hc32 (ohci, data); in td_fill()
566 td->hwBE = cpu_to_hc32 (ohci, data + len - 1); in td_fill()
569 td->hwNextTD = cpu_to_hc32 (ohci, td_pt->td_dma); in td_fill()
576 td->td_hash = ohci->td_hash [hash]; in td_fill()
577 ohci->td_hash [hash] = td; in td_fill()
592 struct ohci_hcd *ohci, in td_submit_urb() argument
596 struct device *dev = ohci_to_hcd(ohci)->self.controller; in td_submit_urb()
606 /* OHCI handles the bulk/interrupt data toggles itself. We just in td_submit_urb()
613 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C); in td_submit_urb()
616 list_add (&urb_priv->pending, &ohci->pending); in td_submit_urb()
648 periodic = ohci_to_hcd(ohci)->self.bandwidth_int_reqs++ == 0 in td_submit_urb()
649 && ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0; in td_submit_urb()
664 td_fill(ohci, info, data, n, urb, cnt); in td_submit_urb()
681 td_fill (ohci, info, 0, 0, urb, cnt); in td_submit_urb()
687 ohci_writel (ohci, OHCI_BLF, &ohci->regs->cmdstatus); in td_submit_urb()
696 td_fill (ohci, info, urb->setup_dma, 8, urb, cnt++); in td_submit_urb()
701 td_fill (ohci, info, data, data_len, urb, cnt++); in td_submit_urb()
706 td_fill (ohci, info, data, 0, urb, cnt++); in td_submit_urb()
709 ohci_writel (ohci, OHCI_CLF, &ohci->regs->cmdstatus); in td_submit_urb()
722 // roll-around ... exotic case (and OHCI has in td_submit_urb()
726 td_fill (ohci, TD_CC | TD_ISO | frame, in td_submit_urb()
730 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) { in td_submit_urb()
731 if (quirk_amdiso(ohci)) in td_submit_urb()
733 if (quirk_amdprefetch(ohci)) in td_submit_urb()
736 periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0 in td_submit_urb()
737 && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0; in td_submit_urb()
744 ohci->hc_control |= OHCI_CTRL_PLE|OHCI_CTRL_IE; in td_submit_urb()
745 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control); in td_submit_urb()
756 static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td) in td_done() argument
758 u32 tdINFO = hc32_to_cpup (ohci, &td->hwINFO); in td_done()
766 u16 tdPSW = ohci_hwPSW(ohci, td, 0); in td_done()
790 ohci_dbg(ohci, in td_done()
800 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE); in td_done()
817 hc32_to_cpup (ohci, &td->hwCBP) in td_done()
822 ohci_dbg(ohci, in td_done()
833 static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc) in ed_halted() argument
839 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C); in ed_halted()
844 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP); in ed_halted()
846 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H); in ed_halted()
888 ohci_dbg (ohci, in ed_halted()
893 hc32_to_cpu (ohci, td->hwINFO), in ed_halted()
899 static void add_to_done_list(struct ohci_hcd *ohci, struct td *td) in add_to_done_list() argument
917 if (ohci->dl_end) in add_to_done_list()
918 ohci->dl_end->next_dl_td = td_prev; in add_to_done_list()
920 ohci->dl_start = td_prev; in add_to_done_list()
926 ohci->dl_end = td->next_dl_td = td; in add_to_done_list()
935 static void update_done_list(struct ohci_hcd *ohci) in update_done_list() argument
940 td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head); in update_done_list()
941 ohci->hcca->done_head = 0; in update_done_list()
950 td = dma_to_td (ohci, td_dma); in update_done_list()
952 ohci_err (ohci, "bad entry %8x\n", td_dma); in update_done_list()
956 td->hwINFO |= cpu_to_hc32 (ohci, TD_DONE); in update_done_list()
957 cc = TD_CC_GET (hc32_to_cpup (ohci, &td->hwINFO)); in update_done_list()
964 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H))) in update_done_list()
965 ed_halted(ohci, td, cc); in update_done_list()
967 td_dma = hc32_to_cpup (ohci, &td->hwNextTD); in update_done_list()
968 add_to_done_list(ohci, td); in update_done_list()
975 static void finish_unlinks(struct ohci_hcd *ohci) in finish_unlinks() argument
977 unsigned tick = ohci_frame_no(ohci); in finish_unlinks()
981 for (last = &ohci->ed_rm_list, ed = *last; ed != NULL; ed = *last) { in finish_unlinks()
989 if (likely(ohci->rh_state == OHCI_RH_RUNNING) && in finish_unlinks()
1002 head = hc32_to_cpu(ohci, ed->hwHeadP) & TD_MASK; in finish_unlinks()
1004 ohci->rh_state == OHCI_RH_RUNNING) in finish_unlinks()
1013 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H); in finish_unlinks()
1016 ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE); in finish_unlinks()
1054 savebits = *prev & ~cpu_to_hc32 (ohci, TD_MASK); in finish_unlinks()
1062 tdINFO = hc32_to_cpup(ohci, &td->hwINFO); in finish_unlinks()
1064 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_C); in finish_unlinks()
1066 ed->hwHeadP |= cpu_to_hc32(ohci, ED_C); in finish_unlinks()
1069 td_done (ohci, urb, td); in finish_unlinks()
1075 finish_urb(ohci, urb, 0); in finish_unlinks()
1090 } else if (ohci->rh_state == OHCI_RH_RUNNING) { in finish_unlinks()
1091 ed_schedule(ohci, ed); in finish_unlinks()
1093 ed->ed_next = ohci->ed_rm_list; in finish_unlinks()
1094 ohci->ed_rm_list = ed; in finish_unlinks()
1096 if (last == &ohci->ed_rm_list) in finish_unlinks()
1105 if (ohci->rh_state == OHCI_RH_RUNNING && !ohci->ed_rm_list) { in finish_unlinks()
1108 if (ohci->ed_controltail) { in finish_unlinks()
1110 if (quirk_zfmicro(ohci)) in finish_unlinks()
1112 if (!(ohci->hc_control & OHCI_CTRL_CLE)) { in finish_unlinks()
1114 ohci_writel (ohci, 0, in finish_unlinks()
1115 &ohci->regs->ed_controlcurrent); in finish_unlinks()
1118 if (ohci->ed_bulktail) { in finish_unlinks()
1120 if (quirk_zfmicro(ohci)) in finish_unlinks()
1122 if (!(ohci->hc_control & OHCI_CTRL_BLE)) { in finish_unlinks()
1124 ohci_writel (ohci, 0, in finish_unlinks()
1125 &ohci->regs->ed_bulkcurrent); in finish_unlinks()
1131 ohci->hc_control |= control; in finish_unlinks()
1132 if (quirk_zfmicro(ohci)) in finish_unlinks()
1134 ohci_writel (ohci, ohci->hc_control, in finish_unlinks()
1135 &ohci->regs->control); in finish_unlinks()
1138 if (quirk_zfmicro(ohci)) in finish_unlinks()
1140 ohci_writel (ohci, command, &ohci->regs->cmdstatus); in finish_unlinks()
1150 static void takeback_td(struct ohci_hcd *ohci, struct td *td) in takeback_td() argument
1158 status = td_done(ohci, urb, td); in takeback_td()
1163 finish_urb(ohci, urb, status); in takeback_td()
1168 start_ed_unlink(ohci, ed); in takeback_td()
1171 } else if ((ed->hwINFO & cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE)) in takeback_td()
1172 == cpu_to_hc32(ohci, ED_SKIP)) { in takeback_td()
1174 if (!(td->hwINFO & cpu_to_hc32(ohci, TD_DONE))) { in takeback_td()
1175 ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP); in takeback_td()
1179 ohci_writel(ohci, OHCI_CLF, in takeback_td()
1180 &ohci->regs->cmdstatus); in takeback_td()
1183 ohci_writel(ohci, OHCI_BLF, in takeback_td()
1184 &ohci->regs->cmdstatus); in takeback_td()
1198 static void process_done_list(struct ohci_hcd *ohci) in process_done_list() argument
1202 while (ohci->dl_start) { in process_done_list()
1203 td = ohci->dl_start; in process_done_list()
1204 if (td == ohci->dl_end) in process_done_list()
1205 ohci->dl_start = ohci->dl_end = NULL; in process_done_list()
1207 ohci->dl_start = td->next_dl_td; in process_done_list()
1209 takeback_td(ohci, td); in process_done_list()
1217 static void ohci_work(struct ohci_hcd *ohci) in ohci_work() argument
1219 if (ohci->working) { in ohci_work()
1220 ohci->restart_work = 1; in ohci_work()
1223 ohci->working = 1; in ohci_work()
1226 process_done_list(ohci); in ohci_work()
1227 if (ohci->ed_rm_list) in ohci_work()
1228 finish_unlinks(ohci); in ohci_work()
1230 if (ohci->restart_work) { in ohci_work()
1231 ohci->restart_work = 0; in ohci_work()
1234 ohci->working = 0; in ohci_work()