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