1
2
3
4
5
6
7
8
9
10#include <linux/irq.h>
11#include <linux/slab.h>
12
13static void urb_free_priv (struct ohci_hcd *hc, urb_priv_t *urb_priv)
14{
15 int last = urb_priv->length - 1;
16
17 if (last >= 0) {
18 int i;
19 struct td *td;
20
21 for (i = 0; i <= last; i++) {
22 td = urb_priv->td [i];
23 if (td)
24 td_free (hc, td);
25 }
26 }
27
28 list_del (&urb_priv->pending);
29 kfree (urb_priv);
30}
31
32
33
34
35
36
37
38
39static void
40finish_urb(struct ohci_hcd *ohci, struct urb *urb, int status)
41__releases(ohci->lock)
42__acquires(ohci->lock)
43{
44
45
46 urb_free_priv (ohci, urb->hcpriv);
47 if (likely(status == -EINPROGRESS))
48 status = 0;
49
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))
55 usb_amd_quirk_pll_enable();
56 if (quirk_amdprefetch(ohci))
57 sb800_prefetch(ohci, 0);
58 }
59 break;
60 case PIPE_INTERRUPT:
61 ohci_to_hcd(ohci)->self.bandwidth_int_reqs--;
62 break;
63 }
64
65#ifdef OHCI_VERBOSE_DEBUG
66 urb_print(urb, "RET", usb_pipeout (urb->pipe), status);
67#endif
68
69
70 usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb);
71 spin_unlock (&ohci->lock);
72 usb_hcd_giveback_urb(ohci_to_hcd(ohci), urb, status);
73 spin_lock (&ohci->lock);
74
75
76 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0
77 && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0) {
78 ohci->hc_control &= ~(OHCI_CTRL_PLE|OHCI_CTRL_IE);
79 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
80 }
81}
82
83
84
85
86
87
88
89
90
91static int balance (struct ohci_hcd *ohci, int interval, int load)
92{
93 int i, branch = -ENOSPC;
94
95
96 if (interval > NUM_INTS)
97 interval = NUM_INTS;
98
99
100
101
102 for (i = 0; i < interval ; i++) {
103 if (branch < 0 || ohci->load [branch] > ohci->load [i]) {
104 int j;
105
106
107 for (j = i; j < NUM_INTS; j += interval) {
108 if ((ohci->load [j] + load) > 900)
109 break;
110 }
111 if (j < NUM_INTS)
112 continue;
113 branch = i;
114 }
115 }
116 return branch;
117}
118
119
120
121
122
123
124
125static void periodic_link (struct ohci_hcd *ohci, struct ed *ed)
126{
127 unsigned i;
128
129 ohci_vdbg (ohci, "link %sed %p branch %d [%dus.], interval %d\n",
130 (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "",
131 ed, ed->branch, ed->load, ed->interval);
132
133 for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
134 struct ed **prev = &ohci->periodic [i];
135 __hc32 *prev_p = &ohci->hcca->int_table [i];
136 struct ed *here = *prev;
137
138
139
140
141
142 while (here && ed != here) {
143 if (ed->interval > here->interval)
144 break;
145 prev = &here->ed_next;
146 prev_p = &here->hwNextED;
147 here = *prev;
148 }
149 if (ed != here) {
150 ed->ed_next = here;
151 if (here)
152 ed->hwNextED = *prev_p;
153 wmb ();
154 *prev = ed;
155 *prev_p = cpu_to_hc32(ohci, ed->dma);
156 wmb();
157 }
158 ohci->load [i] += ed->load;
159 }
160 ohci_to_hcd(ohci)->self.bandwidth_allocated += ed->load / ed->interval;
161}
162
163
164
165static int ed_schedule (struct ohci_hcd *ohci, struct ed *ed)
166{
167 int branch;
168
169 ed->state = ED_OPER;
170 ed->ed_prev = NULL;
171 ed->ed_next = NULL;
172 ed->hwNextED = 0;
173 if (quirk_zfmicro(ohci)
174 && (ed->type == PIPE_INTERRUPT)
175 && !(ohci->eds_scheduled++))
176 mod_timer(&ohci->unlink_watchdog, round_jiffies(jiffies + HZ));
177 wmb ();
178
179
180
181
182
183
184
185
186
187
188
189 switch (ed->type) {
190 case PIPE_CONTROL:
191 if (ohci->ed_controltail == NULL) {
192 WARN_ON (ohci->hc_control & OHCI_CTRL_CLE);
193 ohci_writel (ohci, ed->dma,
194 &ohci->regs->ed_controlhead);
195 } else {
196 ohci->ed_controltail->ed_next = ed;
197 ohci->ed_controltail->hwNextED = cpu_to_hc32 (ohci,
198 ed->dma);
199 }
200 ed->ed_prev = ohci->ed_controltail;
201 if (!ohci->ed_controltail && !ohci->ed_rm_list) {
202 wmb();
203 ohci->hc_control |= OHCI_CTRL_CLE;
204 ohci_writel (ohci, 0, &ohci->regs->ed_controlcurrent);
205 ohci_writel (ohci, ohci->hc_control,
206 &ohci->regs->control);
207 }
208 ohci->ed_controltail = ed;
209 break;
210
211 case PIPE_BULK:
212 if (ohci->ed_bulktail == NULL) {
213 WARN_ON (ohci->hc_control & OHCI_CTRL_BLE);
214 ohci_writel (ohci, ed->dma, &ohci->regs->ed_bulkhead);
215 } else {
216 ohci->ed_bulktail->ed_next = ed;
217 ohci->ed_bulktail->hwNextED = cpu_to_hc32 (ohci,
218 ed->dma);
219 }
220 ed->ed_prev = ohci->ed_bulktail;
221 if (!ohci->ed_bulktail && !ohci->ed_rm_list) {
222 wmb();
223 ohci->hc_control |= OHCI_CTRL_BLE;
224 ohci_writel (ohci, 0, &ohci->regs->ed_bulkcurrent);
225 ohci_writel (ohci, ohci->hc_control,
226 &ohci->regs->control);
227 }
228 ohci->ed_bulktail = ed;
229 break;
230
231
232
233 default:
234 branch = balance (ohci, ed->interval, ed->load);
235 if (branch < 0) {
236 ohci_dbg (ohci,
237 "ERR %d, interval %d msecs, load %d\n",
238 branch, ed->interval, ed->load);
239
240 return branch;
241 }
242 ed->branch = branch;
243 periodic_link (ohci, ed);
244 }
245
246
247
248
249 return 0;
250}
251
252
253
254
255static void periodic_unlink (struct ohci_hcd *ohci, struct ed *ed)
256{
257 int i;
258
259 for (i = ed->branch; i < NUM_INTS; i += ed->interval) {
260 struct ed *temp;
261 struct ed **prev = &ohci->periodic [i];
262 __hc32 *prev_p = &ohci->hcca->int_table [i];
263
264 while (*prev && (temp = *prev) != ed) {
265 prev_p = &temp->hwNextED;
266 prev = &temp->ed_next;
267 }
268 if (*prev) {
269 *prev_p = ed->hwNextED;
270 *prev = ed->ed_next;
271 }
272 ohci->load [i] -= ed->load;
273 }
274 ohci_to_hcd(ohci)->self.bandwidth_allocated -= ed->load / ed->interval;
275
276 ohci_vdbg (ohci, "unlink %sed %p branch %d [%dus.], interval %d\n",
277 (ed->hwINFO & cpu_to_hc32 (ohci, ED_ISO)) ? "iso " : "",
278 ed, ed->branch, ed->load, ed->interval);
279}
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303static void ed_deschedule (struct ohci_hcd *ohci, struct ed *ed)
304{
305 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
306 wmb ();
307 ed->state = ED_UNLINK;
308
309
310
311
312
313
314
315
316
317
318
319 switch (ed->type) {
320 case PIPE_CONTROL:
321
322 if (ed->ed_prev == NULL) {
323 if (!ed->hwNextED) {
324 ohci->hc_control &= ~OHCI_CTRL_CLE;
325 ohci_writel (ohci, ohci->hc_control,
326 &ohci->regs->control);
327
328 } else
329 ohci_writel (ohci,
330 hc32_to_cpup (ohci, &ed->hwNextED),
331 &ohci->regs->ed_controlhead);
332 } else {
333 ed->ed_prev->ed_next = ed->ed_next;
334 ed->ed_prev->hwNextED = ed->hwNextED;
335 }
336
337 if (ohci->ed_controltail == ed) {
338 ohci->ed_controltail = ed->ed_prev;
339 if (ohci->ed_controltail)
340 ohci->ed_controltail->ed_next = NULL;
341 } else if (ed->ed_next) {
342 ed->ed_next->ed_prev = ed->ed_prev;
343 }
344 break;
345
346 case PIPE_BULK:
347
348 if (ed->ed_prev == NULL) {
349 if (!ed->hwNextED) {
350 ohci->hc_control &= ~OHCI_CTRL_BLE;
351 ohci_writel (ohci, ohci->hc_control,
352 &ohci->regs->control);
353
354 } else
355 ohci_writel (ohci,
356 hc32_to_cpup (ohci, &ed->hwNextED),
357 &ohci->regs->ed_bulkhead);
358 } else {
359 ed->ed_prev->ed_next = ed->ed_next;
360 ed->ed_prev->hwNextED = ed->hwNextED;
361 }
362
363 if (ohci->ed_bulktail == ed) {
364 ohci->ed_bulktail = ed->ed_prev;
365 if (ohci->ed_bulktail)
366 ohci->ed_bulktail->ed_next = NULL;
367 } else if (ed->ed_next) {
368 ed->ed_next->ed_prev = ed->ed_prev;
369 }
370 break;
371
372
373
374 default:
375 periodic_unlink (ohci, ed);
376 break;
377 }
378}
379
380
381
382
383
384
385
386static struct ed *ed_get (
387 struct ohci_hcd *ohci,
388 struct usb_host_endpoint *ep,
389 struct usb_device *udev,
390 unsigned int pipe,
391 int interval
392) {
393 struct ed *ed;
394 unsigned long flags;
395
396 spin_lock_irqsave (&ohci->lock, flags);
397
398 if (!(ed = ep->hcpriv)) {
399 struct td *td;
400 int is_out;
401 u32 info;
402
403 ed = ed_alloc (ohci, GFP_ATOMIC);
404 if (!ed) {
405
406 goto done;
407 }
408
409
410 td = td_alloc (ohci, GFP_ATOMIC);
411 if (!td) {
412
413 ed_free (ohci, ed);
414 ed = NULL;
415 goto done;
416 }
417 ed->dummy = td;
418 ed->hwTailP = cpu_to_hc32 (ohci, td->td_dma);
419 ed->hwHeadP = ed->hwTailP;
420 ed->state = ED_IDLE;
421
422 is_out = !(ep->desc.bEndpointAddress & USB_DIR_IN);
423
424
425
426
427 info = usb_pipedevice (pipe);
428 ed->type = usb_pipetype(pipe);
429
430 info |= (ep->desc.bEndpointAddress & ~USB_DIR_IN) << 7;
431 info |= usb_endpoint_maxp(&ep->desc) << 16;
432 if (udev->speed == USB_SPEED_LOW)
433 info |= ED_LOWSPEED;
434
435 if (ed->type != PIPE_CONTROL) {
436 info |= is_out ? ED_OUT : ED_IN;
437 if (ed->type != PIPE_BULK) {
438
439 if (ed->type == PIPE_ISOCHRONOUS)
440 info |= ED_ISO;
441 else if (interval > 32)
442 interval = 32;
443 ed->interval = interval;
444 ed->load = usb_calc_bus_time (
445 udev->speed, !is_out,
446 ed->type == PIPE_ISOCHRONOUS,
447 usb_endpoint_maxp(&ep->desc))
448 / 1000;
449 }
450 }
451 ed->hwINFO = cpu_to_hc32(ohci, info);
452
453 ep->hcpriv = ed;
454 }
455
456done:
457 spin_unlock_irqrestore (&ohci->lock, flags);
458 return ed;
459}
460
461
462
463
464
465
466
467
468
469static void start_ed_unlink (struct ohci_hcd *ohci, struct ed *ed)
470{
471 ed->hwINFO |= cpu_to_hc32 (ohci, ED_DEQUEUE);
472 ed_deschedule (ohci, ed);
473
474
475 ed->ed_next = ohci->ed_rm_list;
476 ed->ed_prev = NULL;
477 ohci->ed_rm_list = ed;
478
479
480 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrstatus);
481 ohci_writel (ohci, OHCI_INTR_SF, &ohci->regs->intrenable);
482
483 (void) ohci_readl (ohci, &ohci->regs->control);
484
485
486
487
488
489
490 ed->tick = ohci_frame_no(ohci) + 1;
491
492}
493
494
495
496
497
498
499
500static void
501td_fill (struct ohci_hcd *ohci, u32 info,
502 dma_addr_t data, int len,
503 struct urb *urb, int index)
504{
505 struct td *td, *td_pt;
506 struct urb_priv *urb_priv = urb->hcpriv;
507 int is_iso = info & TD_ISO;
508 int hash;
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523 if (index != (urb_priv->length - 1)
524 || (urb->transfer_flags & URB_NO_INTERRUPT))
525 info |= TD_DI_SET (6);
526
527
528 td_pt = urb_priv->td [index];
529
530
531 td = urb_priv->td [index] = urb_priv->ed->dummy;
532 urb_priv->ed->dummy = td_pt;
533
534 td->ed = urb_priv->ed;
535 td->next_dl_td = NULL;
536 td->index = index;
537 td->urb = urb;
538 td->data_dma = data;
539 if (!len)
540 data = 0;
541
542 td->hwINFO = cpu_to_hc32 (ohci, info);
543 if (is_iso) {
544 td->hwCBP = cpu_to_hc32 (ohci, data & 0xFFFFF000);
545 *ohci_hwPSWp(ohci, td, 0) = cpu_to_hc16 (ohci,
546 (data & 0x0FFF) | 0xE000);
547 td->ed->last_iso = info & 0xffff;
548 } else {
549 td->hwCBP = cpu_to_hc32 (ohci, data);
550 }
551 if (data)
552 td->hwBE = cpu_to_hc32 (ohci, data + len - 1);
553 else
554 td->hwBE = 0;
555 td->hwNextTD = cpu_to_hc32 (ohci, td_pt->td_dma);
556
557
558 list_add_tail (&td->td_list, &td->ed->td_list);
559
560
561 hash = TD_HASH_FUNC (td->td_dma);
562 td->td_hash = ohci->td_hash [hash];
563 ohci->td_hash [hash] = td;
564
565
566 wmb ();
567 td->ed->hwTailP = td->hwNextTD;
568}
569
570
571
572
573
574
575
576
577static void td_submit_urb (
578 struct ohci_hcd *ohci,
579 struct urb *urb
580) {
581 struct urb_priv *urb_priv = urb->hcpriv;
582 dma_addr_t data;
583 int data_len = urb->transfer_buffer_length;
584 int cnt = 0;
585 u32 info = 0;
586 int is_out = usb_pipeout (urb->pipe);
587 int periodic = 0;
588
589
590
591
592
593 if (!usb_gettoggle (urb->dev, usb_pipeendpoint (urb->pipe), is_out)) {
594 usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
595 is_out, 1);
596 urb_priv->ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_C);
597 }
598
599 urb_priv->td_cnt = 0;
600 list_add (&urb_priv->pending, &ohci->pending);
601
602 if (data_len)
603 data = urb->transfer_dma;
604 else
605 data = 0;
606
607
608
609
610
611 switch (urb_priv->ed->type) {
612
613
614
615
616 case PIPE_INTERRUPT:
617
618 periodic = ohci_to_hcd(ohci)->self.bandwidth_int_reqs++ == 0
619 && ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0;
620
621 case PIPE_BULK:
622 info = is_out
623 ? TD_T_TOGGLE | TD_CC | TD_DP_OUT
624 : TD_T_TOGGLE | TD_CC | TD_DP_IN;
625
626 while (data_len > 4096) {
627 td_fill (ohci, info, data, 4096, urb, cnt);
628 data += 4096;
629 data_len -= 4096;
630 cnt++;
631 }
632
633 if (!(urb->transfer_flags & URB_SHORT_NOT_OK))
634 info |= TD_R;
635 td_fill (ohci, info, data, data_len, urb, cnt);
636 cnt++;
637 if ((urb->transfer_flags & URB_ZERO_PACKET)
638 && cnt < urb_priv->length) {
639 td_fill (ohci, info, 0, 0, urb, cnt);
640 cnt++;
641 }
642
643 if (urb_priv->ed->type == PIPE_BULK) {
644 wmb ();
645 ohci_writel (ohci, OHCI_BLF, &ohci->regs->cmdstatus);
646 }
647 break;
648
649
650
651
652 case PIPE_CONTROL:
653 info = TD_CC | TD_DP_SETUP | TD_T_DATA0;
654 td_fill (ohci, info, urb->setup_dma, 8, urb, cnt++);
655 if (data_len > 0) {
656 info = TD_CC | TD_R | TD_T_DATA1;
657 info |= is_out ? TD_DP_OUT : TD_DP_IN;
658
659 td_fill (ohci, info, data, data_len, urb, cnt++);
660 }
661 info = (is_out || data_len == 0)
662 ? TD_CC | TD_DP_IN | TD_T_DATA1
663 : TD_CC | TD_DP_OUT | TD_T_DATA1;
664 td_fill (ohci, info, data, 0, urb, cnt++);
665
666 wmb ();
667 ohci_writel (ohci, OHCI_CLF, &ohci->regs->cmdstatus);
668 break;
669
670
671
672
673
674 case PIPE_ISOCHRONOUS:
675 for (cnt = 0; cnt < urb->number_of_packets; cnt++) {
676 int frame = urb->start_frame;
677
678
679
680
681 frame += cnt * urb->interval;
682 frame &= 0xffff;
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);
686 }
687 if (ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs == 0) {
688 if (quirk_amdiso(ohci))
689 usb_amd_quirk_pll_disable();
690 if (quirk_amdprefetch(ohci))
691 sb800_prefetch(ohci, 1);
692 }
693 periodic = ohci_to_hcd(ohci)->self.bandwidth_isoc_reqs++ == 0
694 && ohci_to_hcd(ohci)->self.bandwidth_int_reqs == 0;
695 break;
696 }
697
698
699 if (periodic) {
700 wmb ();
701 ohci->hc_control |= OHCI_CTRL_PLE|OHCI_CTRL_IE;
702 ohci_writel (ohci, ohci->hc_control, &ohci->regs->control);
703 }
704
705
706}
707
708
709
710
711
712
713static int td_done(struct ohci_hcd *ohci, struct urb *urb, struct td *td)
714{
715 u32 tdINFO = hc32_to_cpup (ohci, &td->hwINFO);
716 int cc = 0;
717 int status = -EINPROGRESS;
718
719 list_del (&td->td_list);
720
721
722 if (tdINFO & TD_ISO) {
723 u16 tdPSW = ohci_hwPSW(ohci, td, 0);
724 int dlen = 0;
725
726
727
728
729
730 cc = (tdPSW >> 12) & 0xF;
731 if (tdINFO & TD_CC)
732 return status;
733
734 if (usb_pipeout (urb->pipe))
735 dlen = urb->iso_frame_desc [td->index].length;
736 else {
737
738 if (cc == TD_DATAUNDERRUN)
739 cc = TD_CC_NOERROR;
740 dlen = tdPSW & 0x3ff;
741 }
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];
745
746 if (cc != TD_CC_NOERROR)
747 ohci_vdbg (ohci,
748 "urb %p iso td %p (%d) len %d cc %d\n",
749 urb, td, 1 + td->index, dlen, cc);
750
751
752
753
754
755 } else {
756 int type = usb_pipetype (urb->pipe);
757 u32 tdBE = hc32_to_cpup (ohci, &td->hwBE);
758
759 cc = TD_CC_GET (tdINFO);
760
761
762 if (cc == TD_DATAUNDERRUN
763 && !(urb->transfer_flags & URB_SHORT_NOT_OK))
764 cc = TD_CC_NOERROR;
765 if (cc != TD_CC_NOERROR && cc < 0x0E)
766 status = cc_to_error[cc];
767
768
769 if ((type != PIPE_CONTROL || td->index != 0) && tdBE != 0) {
770 if (td->hwCBP == 0)
771 urb->actual_length += tdBE - td->data_dma + 1;
772 else
773 urb->actual_length +=
774 hc32_to_cpup (ohci, &td->hwCBP)
775 - td->data_dma;
776 }
777
778 if (cc != TD_CC_NOERROR && cc < 0x0E)
779 ohci_vdbg (ohci,
780 "urb %p td %p (%d) cc %d, len=%d/%d\n",
781 urb, td, 1 + td->index, cc,
782 urb->actual_length,
783 urb->transfer_buffer_length);
784 }
785 return status;
786}
787
788
789
790static void ed_halted(struct ohci_hcd *ohci, struct td *td, int cc)
791{
792 struct urb *urb = td->urb;
793 urb_priv_t *urb_priv = urb->hcpriv;
794 struct ed *ed = td->ed;
795 struct list_head *tmp = td->td_list.next;
796 __hc32 toggle = ed->hwHeadP & cpu_to_hc32 (ohci, ED_C);
797
798
799
800
801 ed->hwINFO |= cpu_to_hc32 (ohci, ED_SKIP);
802 wmb ();
803 ed->hwHeadP &= ~cpu_to_hc32 (ohci, ED_H);
804
805
806
807
808
809 while (tmp != &ed->td_list) {
810 struct td *next;
811
812 next = list_entry (tmp, struct td, td_list);
813 tmp = next->td_list.next;
814
815 if (next->urb != urb)
816 break;
817
818
819
820
821
822
823
824
825
826 list_del(&next->td_list);
827 urb_priv->td_cnt++;
828 ed->hwHeadP = next->hwNextTD | toggle;
829 }
830
831
832
833
834
835 switch (cc) {
836 case TD_DATAUNDERRUN:
837 if ((urb->transfer_flags & URB_SHORT_NOT_OK) == 0)
838 break;
839
840 case TD_CC_STALL:
841 if (usb_pipecontrol (urb->pipe))
842 break;
843
844 default:
845 ohci_dbg (ohci,
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",
850 hc32_to_cpu (ohci, td->hwINFO),
851 cc, cc_to_error [cc]);
852 }
853}
854
855
856
857
858static struct td *dl_reverse_done_list (struct ohci_hcd *ohci)
859{
860 u32 td_dma;
861 struct td *td_rev = NULL;
862 struct td *td = NULL;
863
864 td_dma = hc32_to_cpup (ohci, &ohci->hcca->done_head);
865 ohci->hcca->done_head = 0;
866 wmb();
867
868
869
870
871 while (td_dma) {
872 int cc;
873
874 td = dma_to_td (ohci, td_dma);
875 if (!td) {
876 ohci_err (ohci, "bad entry %8x\n", td_dma);
877 break;
878 }
879
880 td->hwINFO |= cpu_to_hc32 (ohci, TD_DONE);
881 cc = TD_CC_GET (hc32_to_cpup (ohci, &td->hwINFO));
882
883
884
885
886
887 if (cc != TD_CC_NOERROR
888 && (td->ed->hwHeadP & cpu_to_hc32 (ohci, ED_H)))
889 ed_halted(ohci, td, cc);
890
891 td->next_dl_td = td_rev;
892 td_rev = td;
893 td_dma = hc32_to_cpup (ohci, &td->hwNextTD);
894 }
895 return td_rev;
896}
897
898
899
900
901static void
902finish_unlinks (struct ohci_hcd *ohci, u16 tick)
903{
904 struct ed *ed, **last;
905
906rescan_all:
907 for (last = &ohci->ed_rm_list, ed = *last; ed != NULL; ed = *last) {
908 struct list_head *entry, *tmp;
909 int completed, modified;
910 __hc32 *prev;
911
912
913
914
915 if (likely(ohci->rh_state == OHCI_RH_RUNNING)) {
916 if (tick_before (tick, ed->tick)) {
917skip_ed:
918 last = &ed->ed_next;
919 continue;
920 }
921
922 if (!list_empty (&ed->td_list)) {
923 struct td *td;
924 u32 head;
925
926 td = list_entry (ed->td_list.next, struct td,
927 td_list);
928 head = hc32_to_cpu (ohci, ed->hwHeadP) &
929 TD_MASK;
930
931
932 if (td->td_dma != head) {
933 if (ed == ohci->ed_to_check)
934 ohci->ed_to_check = NULL;
935 else
936 goto skip_ed;
937 }
938 }
939 }
940
941
942
943
944
945 *last = ed->ed_next;
946 ed->ed_next = NULL;
947 modified = 0;
948
949
950
951
952
953
954
955
956
957rescan_this:
958 completed = 0;
959 prev = &ed->hwHeadP;
960 list_for_each_safe (entry, tmp, &ed->td_list) {
961 struct td *td;
962 struct urb *urb;
963 urb_priv_t *urb_priv;
964 __hc32 savebits;
965 u32 tdINFO;
966
967 td = list_entry (entry, struct td, td_list);
968 urb = td->urb;
969 urb_priv = td->urb->hcpriv;
970
971 if (!urb->unlinked) {
972 prev = &td->hwNextTD;
973 continue;
974 }
975
976
977 savebits = *prev & ~cpu_to_hc32 (ohci, TD_MASK);
978 *prev = td->hwNextTD | savebits;
979
980
981
982
983
984
985 tdINFO = hc32_to_cpup(ohci, &td->hwINFO);
986 if ((tdINFO & TD_T) == TD_T_DATA0)
987 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_C);
988 else if ((tdINFO & TD_T) == TD_T_DATA1)
989 ed->hwHeadP |= cpu_to_hc32(ohci, ED_C);
990
991
992 td_done (ohci, urb, td);
993 urb_priv->td_cnt++;
994
995
996 if (urb_priv->td_cnt == urb_priv->length) {
997 modified = completed = 1;
998 finish_urb(ohci, urb, 0);
999 }
1000 }
1001 if (completed && !list_empty (&ed->td_list))
1002 goto rescan_this;
1003
1004
1005 ed->state = ED_IDLE;
1006 if (quirk_zfmicro(ohci) && ed->type == PIPE_INTERRUPT)
1007 ohci->eds_scheduled--;
1008 ed->hwHeadP &= ~cpu_to_hc32(ohci, ED_H);
1009 ed->hwNextED = 0;
1010 wmb ();
1011 ed->hwINFO &= ~cpu_to_hc32 (ohci, ED_SKIP | ED_DEQUEUE);
1012
1013
1014 if (!list_empty (&ed->td_list)) {
1015 if (ohci->rh_state == OHCI_RH_RUNNING)
1016 ed_schedule (ohci, ed);
1017 }
1018
1019 if (modified)
1020 goto rescan_all;
1021 }
1022
1023
1024 if (ohci->rh_state == OHCI_RH_RUNNING && !ohci->ed_rm_list) {
1025 u32 command = 0, control = 0;
1026
1027 if (ohci->ed_controltail) {
1028 command |= OHCI_CLF;
1029 if (quirk_zfmicro(ohci))
1030 mdelay(1);
1031 if (!(ohci->hc_control & OHCI_CTRL_CLE)) {
1032 control |= OHCI_CTRL_CLE;
1033 ohci_writel (ohci, 0,
1034 &ohci->regs->ed_controlcurrent);
1035 }
1036 }
1037 if (ohci->ed_bulktail) {
1038 command |= OHCI_BLF;
1039 if (quirk_zfmicro(ohci))
1040 mdelay(1);
1041 if (!(ohci->hc_control & OHCI_CTRL_BLE)) {
1042 control |= OHCI_CTRL_BLE;
1043 ohci_writel (ohci, 0,
1044 &ohci->regs->ed_bulkcurrent);
1045 }
1046 }
1047
1048
1049 if (control) {
1050 ohci->hc_control |= control;
1051 if (quirk_zfmicro(ohci))
1052 mdelay(1);
1053 ohci_writel (ohci, ohci->hc_control,
1054 &ohci->regs->control);
1055 }
1056 if (command) {
1057 if (quirk_zfmicro(ohci))
1058 mdelay(1);
1059 ohci_writel (ohci, command, &ohci->regs->cmdstatus);
1060 }
1061 }
1062}
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074static void takeback_td(struct ohci_hcd *ohci, struct td *td)
1075{
1076 struct urb *urb = td->urb;
1077 urb_priv_t *urb_priv = urb->hcpriv;
1078 struct ed *ed = td->ed;
1079 int status;
1080
1081
1082 status = td_done(ohci, urb, td);
1083 urb_priv->td_cnt++;
1084
1085
1086 if (urb_priv->td_cnt == urb_priv->length)
1087 finish_urb(ohci, urb, status);
1088
1089
1090 if (list_empty(&ed->td_list)) {
1091 if (ed->state == ED_OPER)
1092 start_ed_unlink(ohci, ed);
1093
1094
1095 } else if ((ed->hwINFO & cpu_to_hc32(ohci, ED_SKIP | ED_DEQUEUE))
1096 == cpu_to_hc32(ohci, ED_SKIP)) {
1097 td = list_entry(ed->td_list.next, struct td, td_list);
1098 if (!(td->hwINFO & cpu_to_hc32(ohci, TD_DONE))) {
1099 ed->hwINFO &= ~cpu_to_hc32(ohci, ED_SKIP);
1100
1101 switch (ed->type) {
1102 case PIPE_CONTROL:
1103 ohci_writel(ohci, OHCI_CLF,
1104 &ohci->regs->cmdstatus);
1105 break;
1106 case PIPE_BULK:
1107 ohci_writel(ohci, OHCI_BLF,
1108 &ohci->regs->cmdstatus);
1109 break;
1110 }
1111 }
1112 }
1113}
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124static void
1125dl_done_list (struct ohci_hcd *ohci)
1126{
1127 struct td *td = dl_reverse_done_list (ohci);
1128
1129 while (td) {
1130 struct td *td_next = td->next_dl_td;
1131 takeback_td(ohci, td);
1132 td = td_next;
1133 }
1134}
1135