2 * OHCI HCD (Host Controller Driver) for USB.
4 * (C) Copyright 1999 Roman Weissgaerber <weissg@vienna.at>
5 * (C) Copyright 2000-2002 David Brownell <dbrownell@users.sourceforge.net>
7 * This file is licenced under the GPL.
10 #include <linux/irq.h>
12 /*-------------------------------------------------------------------------*/
15 * URB goes back to driver, and isn't reissued.
16 * It's completely gone from HC data structures.
17 * PRECONDITION: ahcd lock held, irqs blocked.
20 finish_urb(struct admhcd
*ahcd
, struct urb
*urb
)
21 __releases(ahcd
->lock
)
22 __acquires(ahcd
->lock
)
24 urb_priv_free(ahcd
, urb
->hcpriv
);
27 spin_lock(&urb
->lock
);
28 if (likely(urb
->status
== -EINPROGRESS
))
31 /* report short control reads right even though the data TD always
32 * has TD_R set. (much simpler, but creates the 1-td limit.)
34 if (unlikely(urb
->transfer_flags
& URB_SHORT_NOT_OK
)
35 && unlikely(usb_pipecontrol(urb
->pipe
))
36 && urb
->actual_length
< urb
->transfer_buffer_length
37 && usb_pipein(urb
->pipe
)
38 && urb
->status
== 0) {
39 urb
->status
= -EREMOTEIO
;
40 #ifdef ADMHC_VERBOSE_DEBUG
41 urb_print(urb
, "SHORT", usb_pipeout (urb
->pipe
));
44 spin_unlock(&urb
->lock
);
46 switch (usb_pipetype(urb
->pipe
)) {
47 case PIPE_ISOCHRONOUS
:
48 admhcd_to_hcd(ahcd
)->self
.bandwidth_isoc_reqs
--;
51 admhcd_to_hcd(ahcd
)->self
.bandwidth_int_reqs
--;
55 #ifdef ADMHC_VERBOSE_DEBUG
56 urb_print(urb
, "RET", usb_pipeout (urb
->pipe
));
59 /* urb->complete() can reenter this HCD */
60 spin_unlock(&ahcd
->lock
);
61 usb_hcd_giveback_urb(admhcd_to_hcd(ahcd
), urb
);
62 spin_lock(&ahcd
->lock
);
66 /*-------------------------------------------------------------------------*
67 * ED handling functions
68 *-------------------------------------------------------------------------*/
71 /* search for the right schedule branch to use for a periodic ed.
72 * does some load balancing; returns the branch, or negative errno.
74 static int balance(struct admhcd
*ahcd
, int interval
, int load
)
76 int i
, branch
= -ENOSPC
;
78 /* iso periods can be huge; iso tds specify frame numbers */
79 if (interval
> NUM_INTS
)
82 /* search for the least loaded schedule branch of that period
83 * that has enough bandwidth left unreserved.
85 for (i
= 0; i
< interval
; i
++) {
86 if (branch
< 0 || ahcd
->load
[branch
] > ahcd
->load
[i
]) {
89 /* usb 1.1 says 90% of one frame */
90 for (j
= i
; j
< NUM_INTS
; j
+= interval
) {
91 if ((ahcd
->load
[j
] + load
) > 900)
103 /*-------------------------------------------------------------------------*/
106 /* both iso and interrupt requests have periods; this routine puts them
107 * into the schedule tree in the apppropriate place. most iso devices use
108 * 1msec periods, but that's not required.
110 static void periodic_link (struct admhcd
*ahcd
, struct ed
*ed
)
114 admhc_vdbg (ahcd
, "link %sed %p branch %d [%dus.], interval %d\n",
115 (ed
->hwINFO
& cpu_to_hc32 (ahcd
, ED_ISO
)) ? "iso " : "",
116 ed
, ed
->branch
, ed
->load
, ed
->interval
);
118 for (i
= ed
->branch
; i
< NUM_INTS
; i
+= ed
->interval
) {
119 struct ed
**prev
= &ahcd
->periodic
[i
];
120 __hc32
*prev_p
= &ahcd
->hcca
->int_table
[i
];
121 struct ed
*here
= *prev
;
123 /* sorting each branch by period (slow before fast)
124 * lets us share the faster parts of the tree.
125 * (plus maybe: put interrupt eds before iso)
127 while (here
&& ed
!= here
) {
128 if (ed
->interval
> here
->interval
)
130 prev
= &here
->ed_next
;
131 prev_p
= &here
->hwNextED
;
137 ed
->hwNextED
= *prev_p
;
140 *prev_p
= cpu_to_hc32(ahcd
, ed
->dma
);
143 ahcd
->load
[i
] += ed
->load
;
145 admhcd_to_hcd(ahcd
)->self
.bandwidth_allocated
+= ed
->load
/ ed
->interval
;
149 /* link an ed into the HC chain */
151 static int ed_schedule(struct admhcd
*ahcd
, struct ed
*ed
)
155 if (admhcd_to_hcd(ahcd
)->state
== HC_STATE_QUIESCING
)
160 old_tail
= ahcd
->ed_tails
[ed
->type
];
162 ed
->ed_next
= old_tail
->ed_next
;
164 ed
->ed_next
->ed_prev
= ed
;
165 ed
->hwNextED
= cpu_to_hc32(ahcd
, ed
->ed_next
->dma
);
167 ed
->ed_prev
= old_tail
;
169 old_tail
->ed_next
= ed
;
170 old_tail
->hwNextED
= cpu_to_hc32(ahcd
, ed
->dma
);
172 ahcd
->ed_tails
[ed
->type
] = ed
;
174 admhc_dma_enable(ahcd
);
179 /*-------------------------------------------------------------------------*/
182 /* scan the periodic table to find and unlink this ED */
183 static void periodic_unlink (struct admhcd
*ahcd
, struct ed
*ed
)
187 for (i
= ed
->branch
; i
< NUM_INTS
; i
+= ed
->interval
) {
189 struct ed
**prev
= &ahcd
->periodic
[i
];
190 __hc32
*prev_p
= &ahcd
->hcca
->int_table
[i
];
192 while (*prev
&& (temp
= *prev
) != ed
) {
193 prev_p
= &temp
->hwNextED
;
194 prev
= &temp
->ed_next
;
197 *prev_p
= ed
->hwNextED
;
200 ahcd
->load
[i
] -= ed
->load
;
203 admhcd_to_hcd(ahcd
)->self
.bandwidth_allocated
-= ed
->load
/ ed
->interval
;
204 admhc_vdbg (ahcd
, "unlink %sed %p branch %d [%dus.], interval %d\n",
205 (ed
->hwINFO
& cpu_to_hc32 (ahcd
, ED_ISO
)) ? "iso " : "",
206 ed
, ed
->branch
, ed
->load
, ed
->interval
);
210 /* unlink an ed from the HC chain.
211 * just the link to the ed is unlinked.
212 * the link from the ed still points to another operational ed or 0
213 * so the HC can eventually finish the processing of the unlinked ed
214 * (assuming it already started that, which needn't be true).
216 * ED_UNLINK is a transient state: the HC may still see this ED, but soon
217 * it won't. ED_SKIP means the HC will finish its current transaction,
218 * but won't start anything new. The TD queue may still grow; device
219 * drivers don't know about this HCD-internal state.
221 * When the HC can't see the ED, something changes ED_UNLINK to one of:
223 * - ED_OPER: when there's any request queued, the ED gets rescheduled
224 * immediately. HC should be working on them.
226 * - ED_IDLE: when there's no TD queue. there's no reason for the HC
227 * to care about this ED; safe to disable the endpoint.
229 * When finish_unlinks() runs later, after SOF interrupt, it will often
230 * complete one or more URB unlinks before making that state change.
232 static void ed_deschedule(struct admhcd
*ahcd
, struct ed
*ed
)
234 ed
->hwINFO
|= cpu_to_hc32(ahcd
, ED_SKIP
);
236 ed
->state
= ED_UNLINK
;
238 /* remove this ED from the HC list */
239 ed
->ed_prev
->hwNextED
= ed
->hwNextED
;
241 /* and remove it from our list also */
242 ed
->ed_prev
->ed_next
= ed
->ed_next
;
245 ed
->ed_next
->ed_prev
= ed
->ed_prev
;
247 if (ahcd
->ed_tails
[ed
->type
] == ed
)
248 ahcd
->ed_tails
[ed
->type
] = ed
->ed_prev
;
251 /*-------------------------------------------------------------------------*/
253 static struct ed
*ed_create(struct admhcd
*ahcd
, unsigned int type
, u32 info
)
258 ed
= ed_alloc(ahcd
, GFP_ATOMIC
);
262 /* dummy td; end of td list for this ed */
263 td
= td_alloc(ahcd
, GFP_ATOMIC
);
271 case PIPE_ISOCHRONOUS
:
280 ed
->hwINFO
= cpu_to_hc32(ahcd
, info
);
281 ed
->hwTailP
= cpu_to_hc32(ahcd
, td
->td_dma
);
282 ed
->hwHeadP
= ed
->hwTailP
; /* ED_C, ED_H zeroed */
292 /* get and maybe (re)init an endpoint. init _should_ be done only as part
293 * of enumeration, usb_set_configuration() or usb_set_interface().
295 static struct ed
*ed_get(struct admhcd
*ahcd
, struct usb_host_endpoint
*ep
,
296 struct usb_device
*udev
, unsigned int pipe
, int interval
)
301 spin_lock_irqsave(&ahcd
->lock
, flags
);
306 /* FIXME: usbcore changes dev->devnum before SET_ADDRESS
307 * suceeds ... otherwise we wouldn't need "pipe".
309 info
= usb_pipedevice(pipe
);
310 info
|= (ep
->desc
.bEndpointAddress
& ~USB_DIR_IN
) << ED_EN_SHIFT
;
311 info
|= le16_to_cpu(ep
->desc
.wMaxPacketSize
) << ED_MPS_SHIFT
;
312 if (udev
->speed
== USB_SPEED_FULL
)
313 info
|= ED_SPEED_FULL
;
315 ed
= ed_create(ahcd
, usb_pipetype(pipe
), info
);
319 spin_unlock_irqrestore(&ahcd
->lock
, flags
);
324 /*-------------------------------------------------------------------------*/
326 /* request unlinking of an endpoint from an operational HC.
327 * put the ep on the rm_list
328 * real work is done at the next start frame (SOFI) hardware interrupt
329 * caller guarantees HCD is running, so hardware access is safe,
330 * and that ed->state is ED_OPER
332 static void start_ed_unlink(struct admhcd
*ahcd
, struct ed
*ed
)
334 ed
->hwINFO
|= cpu_to_hc32 (ahcd
, ED_DEQUEUE
);
335 ed_deschedule(ahcd
, ed
);
337 /* add this ED into the remove list */
338 ed
->ed_rm_next
= ahcd
->ed_rm_list
;
339 ahcd
->ed_rm_list
= ed
;
341 /* enable SOF interrupt */
342 admhc_intr_ack(ahcd
, ADMHC_INTR_SOFI
);
343 admhc_intr_enable(ahcd
, ADMHC_INTR_SOFI
);
344 /* flush those writes */
345 admhc_writel_flush(ahcd
);
347 /* SOF interrupt might get delayed; record the frame counter value that
348 * indicates when the HC isn't looking at it, so concurrent unlinks
349 * behave. frame_no wraps every 2^16 msec, and changes right before
352 ed
->tick
= admhc_frame_no(ahcd
) + 1;
355 /*-------------------------------------------------------------------------*
356 * TD handling functions
357 *-------------------------------------------------------------------------*/
359 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
362 td_fill(struct admhcd
*ahcd
, u32 info
, dma_addr_t data
, int len
,
363 struct urb
*urb
, int index
)
365 struct td
*td
, *td_pt
;
366 struct urb_priv
*urb_priv
= urb
->hcpriv
;
371 if (index
== (urb_priv
->td_cnt
- 1) &&
372 ((urb
->transfer_flags
& URB_NO_INTERRUPT
) == 0))
375 if (index
== (urb_priv
->td_cnt
- 1))
379 /* use this td as the next dummy */
380 td_pt
= urb_priv
->td
[index
];
382 /* fill the old dummy TD */
383 td
= urb_priv
->td
[index
] = urb_priv
->ed
->dummy
;
384 urb_priv
->ed
->dummy
= td_pt
;
386 td
->ed
= urb_priv
->ed
;
387 td
->next_dl_td
= NULL
;
395 cbl
|= (len
& TD_BL_MASK
);
399 /* setup hardware specific fields */
400 td
->hwINFO
= cpu_to_hc32(ahcd
, info
);
401 td
->hwDBP
= cpu_to_hc32(ahcd
, data
);
402 td
->hwCBL
= cpu_to_hc32(ahcd
, cbl
);
403 td
->hwNextTD
= cpu_to_hc32(ahcd
, td_pt
->td_dma
);
405 /* append to queue */
406 list_add_tail(&td
->td_list
, &td
->ed
->td_list
);
408 /* hash it for later reverse mapping */
409 hash
= TD_HASH_FUNC(td
->td_dma
);
410 td
->td_hash
= ahcd
->td_hash
[hash
];
411 ahcd
->td_hash
[hash
] = td
;
413 /* HC might read the TD (or cachelines) right away ... */
415 td
->ed
->hwTailP
= td
->hwNextTD
;
418 /*-------------------------------------------------------------------------*/
420 /* Prepare all TDs of a transfer, and queue them onto the ED.
421 * Caller guarantees HC is active.
422 * Usually the ED is already on the schedule, so TDs might be
423 * processed as soon as they're queued.
425 static void td_submit_urb(struct admhcd
*ahcd
, struct urb
*urb
)
427 struct urb_priv
*urb_priv
= urb
->hcpriv
;
429 int data_len
= urb
->transfer_buffer_length
;
432 int is_out
= usb_pipeout(urb
->pipe
);
437 /* OHCI handles the bulk/interrupt data toggles itself. We just
438 * use the device toggle bits for resetting, and rely on the fact
439 * that resetting toggle is meaningless if the endpoint is active.
442 if (usb_gettoggle(urb
->dev
, usb_pipeendpoint(urb
->pipe
), is_out
)) {
446 usb_settoggle(urb
->dev
, usb_pipeendpoint (urb
->pipe
),
450 urb_priv
->td_idx
= 0;
451 list_add(&urb_priv
->pending
, &ahcd
->pending
);
454 data
= urb
->transfer_dma
;
458 /* NOTE: TD_CC is set so we can tell which TDs the HC processed by
459 * using TD_CC_GET, as well as by seeing them on the done list.
460 * (CC = NotAccessed ... 0x0F, or 0x0E in PSWs for ISO.)
462 switch (urb_priv
->ed
->type
) {
465 ? TD_T_CARRY
| TD_SCC_NOTACCESSED
| TD_DP_OUT
466 : TD_T_CARRY
| TD_SCC_NOTACCESSED
| TD_DP_IN
;
468 /* setup service interval and starting frame number */
469 info
|= (urb
->start_frame
& TD_FN_MASK
);
470 info
|= (urb
->interval
& TD_ISI_MASK
) << TD_ISI_SHIFT
;
472 td_fill(ahcd
, info
, data
, data_len
, urb
, cnt
);
475 admhcd_to_hcd(ahcd
)->self
.bandwidth_int_reqs
++;
480 ? TD_SCC_NOTACCESSED
| TD_DP_OUT
481 : TD_SCC_NOTACCESSED
| TD_DP_IN
;
483 /* TDs _could_ transfer up to 8K each */
484 while (data_len
> TD_DATALEN_MAX
) {
485 td_fill(ahcd
, info
| ((cnt
) ? TD_T_CARRY
: toggle
),
486 data
, TD_DATALEN_MAX
, urb
, cnt
);
487 data
+= TD_DATALEN_MAX
;
488 data_len
-= TD_DATALEN_MAX
;
492 td_fill(ahcd
, info
| ((cnt
) ? TD_T_CARRY
: toggle
), data
,
496 if ((urb
->transfer_flags
& URB_ZERO_PACKET
)
497 && (cnt
< urb_priv
->td_cnt
)) {
498 td_fill(ahcd
, info
| ((cnt
) ? TD_T_CARRY
: toggle
),
504 /* control manages DATA0/DATA1 toggle per-request; SETUP resets it,
505 * any DATA phase works normally, and the STATUS ack is special.
508 /* fill a TD for the setup */
509 info
= TD_SCC_NOTACCESSED
| TD_DP_SETUP
| TD_T_DATA0
;
510 td_fill(ahcd
, info
, urb
->setup_dma
, 8, urb
, cnt
++);
513 /* fill a TD for the data */
514 info
= TD_SCC_NOTACCESSED
| TD_T_DATA1
;
515 info
|= is_out
? TD_DP_OUT
: TD_DP_IN
;
516 /* NOTE: mishandles transfers >8K, some >4K */
517 td_fill(ahcd
, info
, data
, data_len
, urb
, cnt
++);
520 /* fill a TD for the ACK */
521 info
= (is_out
|| data_len
== 0)
522 ? TD_SCC_NOTACCESSED
| TD_DP_IN
| TD_T_DATA1
523 : TD_SCC_NOTACCESSED
| TD_DP_OUT
| TD_T_DATA1
;
524 td_fill(ahcd
, info
, data
, 0, urb
, cnt
++);
528 /* ISO has no retransmit, so no toggle;
529 * Each TD could handle multiple consecutive frames (interval 1);
530 * we could often reduce the number of TDs here.
532 case PIPE_ISOCHRONOUS
:
533 info
= TD_SCC_NOTACCESSED
;
534 for (cnt
= 0; cnt
< urb
->number_of_packets
; cnt
++) {
535 int frame
= urb
->start_frame
;
537 frame
+= cnt
* urb
->interval
;
539 td_fill(ahcd
, info
| frame
,
540 data
+ urb
->iso_frame_desc
[cnt
].offset
,
541 urb
->iso_frame_desc
[cnt
].length
, urb
, cnt
);
543 admhcd_to_hcd(ahcd
)->self
.bandwidth_isoc_reqs
++;
547 if (urb_priv
->td_cnt
!= cnt
)
548 admhc_err(ahcd
, "bad number of tds created for urb %p\n", urb
);
551 /*-------------------------------------------------------------------------*
552 * Done List handling functions
553 *-------------------------------------------------------------------------*/
555 /* calculate transfer length/status and update the urb
556 * PRECONDITION: irqsafe (only for urb->status locking)
558 static void td_done(struct admhcd
*ahcd
, struct urb
*urb
, struct td
*td
)
560 u32 info
= hc32_to_cpup(ahcd
, &td
->hwINFO
);
561 int type
= usb_pipetype(urb
->pipe
);
562 int cc
= TD_CC_NOERROR
;
564 /* ISO ... drivers see per-TD length/status */
565 if (type
== PIPE_ISOCHRONOUS
) {
570 /* NOTE: assumes FC in tdINFO == 0, and that
571 * only the first of 0..MAXPSW psws is used.
575 if (tdINFO
& TD_CC
) /* hc didn't touch? */
578 if (usb_pipeout (urb
->pipe
))
579 dlen
= urb
->iso_frame_desc
[td
->index
].length
;
581 /* short reads are always OK for ISO */
582 if (cc
== TD_DATAUNDERRUN
)
584 dlen
= tdPSW
& 0x3ff;
586 urb
->actual_length
+= dlen
;
587 urb
->iso_frame_desc
[td
->index
].actual_length
= dlen
;
588 urb
->iso_frame_desc
[td
->index
].status
= cc_to_error
[cc
];
590 if (cc
!= TD_CC_NOERROR
)
592 "urb %p iso td %p (%d) len %d cc %d\n",
593 urb
, td
, 1 + td
->index
, dlen
, cc
);
595 /* BULK, INT, CONTROL ... drivers see aggregate length/status,
596 * except that "setup" bytes aren't counted and "short" transfers
597 * might not be reported as errors.
600 u32 bl
= TD_BL_GET(hc32_to_cpup(ahcd
, &td
->hwCBL
));
601 u32 tdDBP
= hc32_to_cpup(ahcd
, &td
->hwDBP
);
603 cc
= TD_CC_GET(info
);
605 /* update packet status if needed (short is normally ok) */
606 if (cc
== TD_CC_DATAUNDERRUN
607 && !(urb
->transfer_flags
& URB_SHORT_NOT_OK
))
610 if (cc
!= TD_CC_NOERROR
&& cc
< TD_CC_HCD0
) {
611 admhc_dump_ed(ahcd
, "CC ERROR", td
->ed
, 1);
612 spin_lock(&urb
->lock
);
613 if (urb
->status
== -EINPROGRESS
)
614 urb
->status
= cc_to_error
[cc
];
615 spin_unlock(&urb
->lock
);
618 /* count all non-empty packets except control SETUP packet */
619 if ((type
!= PIPE_CONTROL
|| td
->index
!= 0) && tdDBP
!= 0) {
620 urb
->actual_length
+= tdDBP
- td
->data_dma
+ bl
;
623 if (cc
!= TD_CC_NOERROR
&& cc
< TD_CC_HCD0
)
625 "urb %p td %p (%d) cc %d, len=%d/%d\n",
626 urb
, td
, td
->index
, cc
,
628 urb
->transfer_buffer_length
);
631 list_del(&td
->td_list
);
635 /*-------------------------------------------------------------------------*/
637 static inline struct td
*
638 ed_halted(struct admhcd
*ahcd
, struct td
*td
, int cc
, struct td
*rev
)
640 struct urb
*urb
= td
->urb
;
641 struct ed
*ed
= td
->ed
;
642 struct list_head
*tmp
= td
->td_list
.next
;
643 __hc32 toggle
= ed
->hwHeadP
& cpu_to_hc32 (ahcd
, ED_C
);
645 admhc_dump_ed(ahcd
, "ed halted", td
->ed
, 1);
646 /* clear ed halt; this is the td that caused it, but keep it inactive
647 * until its urb->complete() has a chance to clean up.
649 ed
->hwINFO
|= cpu_to_hc32 (ahcd
, ED_SKIP
);
651 ed
->hwHeadP
&= ~cpu_to_hc32 (ahcd
, ED_H
);
653 /* put any later tds from this urb onto the donelist, after 'td',
654 * order won't matter here: no errors, and nothing was transferred.
655 * also patch the ed so it looks as if those tds completed normally.
657 while (tmp
!= &ed
->td_list
) {
661 next
= list_entry(tmp
, struct td
, td_list
);
662 tmp
= next
->td_list
.next
;
664 if (next
->urb
!= urb
)
667 /* NOTE: if multi-td control DATA segments get supported,
668 * this urb had one of them, this td wasn't the last td
669 * in that segment (TD_R clear), this ed halted because
670 * of a short read, _and_ URB_SHORT_NOT_OK is clear ...
671 * then we need to leave the control STATUS packet queued
676 info
|= cpu_to_hc32 (ahcd
, TD_DONE
);
677 info
&= ~cpu_to_hc32 (ahcd
, TD_CC
);
681 next
->next_dl_td
= rev
;
684 ed
->hwHeadP
= next
->hwNextTD
| toggle
;
687 /* help for troubleshooting: report anything that
688 * looks odd ... that doesn't include protocol stalls
689 * (or maybe some other things)
692 case TD_CC_DATAUNDERRUN
:
693 if ((urb
->transfer_flags
& URB_SHORT_NOT_OK
) == 0)
697 if (usb_pipecontrol (urb
->pipe
))
702 "urb %p path %s ep%d%s %08x cc %d --> status %d\n",
703 urb
, urb
->dev
->devpath
,
704 usb_pipeendpoint (urb
->pipe
),
705 usb_pipein (urb
->pipe
) ? "in" : "out",
706 hc32_to_cpu(ahcd
, td
->hwINFO
),
707 cc
, cc_to_error
[cc
]);
713 /*-------------------------------------------------------------------------*/
715 /* there are some urbs/eds to unlink; called in_irq(), with HCD locked */
717 finish_unlinks(struct admhcd
*ahcd
, u16 tick
)
719 struct ed
*ed
, **last
;
722 for (last
= &ahcd
->ed_rm_list
, ed
= *last
; ed
!= NULL
; ed
= *last
) {
723 struct list_head
*entry
, *tmp
;
724 int completed
, modified
;
727 /* only take off EDs that the HC isn't using, accounting for
728 * frame counter wraps and EDs with partially retired TDs
730 if (likely(HC_IS_RUNNING(admhcd_to_hcd(ahcd
)->state
))) {
731 if (tick_before (tick
, ed
->tick
)) {
733 last
= &ed
->ed_rm_next
;
737 if (!list_empty (&ed
->td_list
)) {
741 td
= list_entry(ed
->td_list
.next
, struct td
,
743 head
= hc32_to_cpu(ahcd
, ed
->hwHeadP
) &
746 /* INTR_WDH may need to clean up first */
747 if (td
->td_dma
!= head
)
752 /* reentrancy: if we drop the schedule lock, someone might
753 * have modified this list. normally it's just prepending
754 * entries (which we'd ignore), but paranoia won't hurt.
756 *last
= ed
->ed_rm_next
;
757 ed
->ed_rm_next
= NULL
;
760 /* unlink urbs as requested, but rescan the list after
761 * we call a completion since it might have unlinked
762 * another (earlier) urb
764 * When we get here, the HC doesn't see this ed. But it
765 * must not be rescheduled until all completed URBs have
766 * been given back to the driver.
771 list_for_each_safe (entry
, tmp
, &ed
->td_list
) {
774 struct urb_priv
*urb_priv
;
777 td
= list_entry(entry
, struct td
, td_list
);
779 urb_priv
= td
->urb
->hcpriv
;
781 if (urb
->status
== -EINPROGRESS
) {
782 prev
= &td
->hwNextTD
;
786 if ((urb_priv
) == NULL
)
789 /* patch pointer hc uses */
790 savebits
= *prev
& ~cpu_to_hc32(ahcd
, TD_MASK
);
791 *prev
= td
->hwNextTD
| savebits
;
793 /* HC may have partly processed this TD */
794 urb_print(urb
, "PARTIAL",1);
795 td_done(ahcd
, urb
, td
);
798 /* if URB is done, clean up */
799 if (urb_priv
->td_idx
== urb_priv
->td_cnt
) {
800 modified
= completed
= 1;
801 finish_urb(ahcd
, urb
);
804 if (completed
&& !list_empty (&ed
->td_list
))
807 /* ED's now officially unlinked, hc doesn't see */
809 ed
->hwHeadP
&= ~cpu_to_hc32(ahcd
, ED_H
);
812 ed
->hwINFO
&= ~cpu_to_hc32 (ahcd
, ED_SKIP
| ED_DEQUEUE
);
814 /* but if there's work queued, reschedule */
815 if (!list_empty (&ed
->td_list
)) {
816 if (HC_IS_RUNNING(admhcd_to_hcd(ahcd
)->state
))
817 ed_schedule(ahcd
, ed
);
825 /*-------------------------------------------------------------------------*/
828 * Process normal completions (error or success) and clean the schedules.
830 * This is the main path for handing urbs back to drivers. The only other
831 * path is finish_unlinks(), which unlinks URBs using ed_rm_list, instead of
832 * scanning the (re-reversed) donelist as this does.
835 static void ed_update(struct admhcd
*ahcd
, struct ed
*ed
)
837 struct list_head
*entry
,*tmp
;
839 admhc_dump_ed(ahcd
, "ed update", ed
, 1);
841 list_for_each_safe(entry
, tmp
, &ed
->td_list
) {
842 struct td
*td
= list_entry(entry
, struct td
, td_list
);
843 struct urb
*urb
= td
->urb
;
844 struct urb_priv
*urb_priv
= urb
->hcpriv
;
846 if (hc32_to_cpup(ahcd
, &td
->hwINFO
) & TD_OWN
)
849 /* update URB's length and status from TD */
850 td_done(ahcd
, urb
, td
);
853 /* If all this urb's TDs are done, call complete() */
854 if (urb_priv
->td_idx
== urb_priv
->td_cnt
)
855 finish_urb(ahcd
, urb
);
857 /* clean schedule: unlink EDs that are no longer busy */
858 if (list_empty(&ed
->td_list
)) {
859 if (ed
->state
== ED_OPER
)
860 start_ed_unlink(ahcd
, ed
);
862 /* ... reenabling halted EDs only after fault cleanup */
863 } else if ((ed
->hwINFO
& cpu_to_hc32 (ahcd
,
864 ED_SKIP
| ED_DEQUEUE
))
865 == cpu_to_hc32 (ahcd
, ED_SKIP
)) {
866 td
= list_entry(ed
->td_list
.next
, struct td
, td_list
);
868 if (!(td
->hwINFO
& cpu_to_hc32 (ahcd
, TD_DONE
))) {
869 ed
->hwINFO
&= ~cpu_to_hc32 (ahcd
, ED_SKIP
);
870 /* ... hc may need waking-up */
873 admhc_writel (ahcd
, OHCI_CLF
,
874 &ahcd
->regs
->cmdstatus
);
877 admhc_writel (ahcd
, OHCI_BLF
,
878 &ahcd
->regs
->cmdstatus
);
883 if ((td
->hwINFO
& cpu_to_hc32(ahcd
, TD_OWN
)))
884 ed
->hwINFO
&= ~cpu_to_hc32(ahcd
, ED_SKIP
);
891 static void ed_halt(struct admhcd
*ahcd
, struct ed
*ed
)
893 admhc_dump_ed(ahcd
, "ed_halt", ed
, 1);
896 /* there are some tds completed; called in_irq(), with HCD locked */
897 static void admhc_td_complete(struct admhcd
*ahcd
)
901 for (ed
= ahcd
->ed_head
; ed
; ed
= ed
->ed_next
) {
902 if (ed
->state
!= ED_OPER
)
905 if (hc32_to_cpup(ahcd
, &ed
->hwINFO
) & ED_SKIP
)
908 if (hc32_to_cpup(ahcd
, &ed
->hwHeadP
) & ED_H
) {
This page took 0.094563 seconds and 5 git commands to generate.