Commit 1fb2e055 authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: EHCI: reorganize isochronous scheduler routine

This patch (as1408) rearranges the scheduling code in ehci-hcd, partly
to improve its structure, but mainly to change the way it works.
Whether or not a transfer exceeds the hardware schedule length will
now be determined by looking at the last frame the transfer would use,
instead of the first available frame following the end of the transfer.

The benefit of this change is that it allows the driver to accept
valid URBs which would otherwise be rejected.  For example, suppose
the schedule length is 1024 frames, the endpoint period is 256 frames,
and a four-packet URB is submitted.  The four transfers would occupy
slots that are 0, 256, 512, and 768 frames past the current frame
(plus an extra slop factor).  These don't exceed the 1024-frame limit,
so the URB should be accepted.  But the current code notices that the
next available slot would be 1024 frames (plus slop) in the future,
which is beyond the limit, and so the URB is rejected unnecessarily.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
CC: David Brownell <david-b@pacbell.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent ffda0803
...@@ -1413,13 +1413,6 @@ iso_stream_schedule ( ...@@ -1413,13 +1413,6 @@ iso_stream_schedule (
goto fail; goto fail;
} }
if (stream->depth + span > mod) {
ehci_dbg (ehci, "request %p would overflow (%d+%d>%d)\n",
urb, stream->depth, span, mod);
status = -EFBIG;
goto fail;
}
now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1); now = ehci_readl(ehci, &ehci->regs->frame_index) & (mod - 1);
/* Typical case: reuse current schedule, stream is still active. /* Typical case: reuse current schedule, stream is still active.
...@@ -1428,7 +1421,7 @@ iso_stream_schedule ( ...@@ -1428,7 +1421,7 @@ iso_stream_schedule (
* slot in the schedule, implicitly assuming URB_ISO_ASAP. * slot in the schedule, implicitly assuming URB_ISO_ASAP.
*/ */
if (likely (!list_empty (&stream->td_list))) { if (likely (!list_empty (&stream->td_list))) {
start = stream->next_uframe; u32 excess;
/* For high speed devices, allow scheduling within the /* For high speed devices, allow scheduling within the
* isochronous scheduling threshold. For full speed devices * isochronous scheduling threshold. For full speed devices
...@@ -1440,21 +1433,23 @@ iso_stream_schedule ( ...@@ -1440,21 +1433,23 @@ iso_stream_schedule (
else else
next = now; next = now;
/* Fell behind (by up to twice the slop amount)? */ /* Fell behind (by up to twice the slop amount)?
if (((start - next) & (mod - 1)) >= * We decide based on the time of the last currently-scheduled
mod - 2 * SCHEDULE_SLOP) * slot, not the time of the next available slot.
start += period * DIV_ROUND_UP( */
(next - start) & (mod - 1), excess = (stream->next_uframe - period - next) & (mod - 1);
period); if (excess >= mod - 2 * SCHEDULE_SLOP)
start = next + excess - mod + period *
/* Tried to schedule too far into the future? */ DIV_ROUND_UP(mod - excess, period);
if (unlikely(((start - now) & (mod - 1)) + span else
>= mod - 2 * SCHEDULE_SLOP)) { start = next + excess + period;
if (start - now >= mod) {
ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
urb, start - now - period, period,
mod);
status = -EFBIG; status = -EFBIG;
goto fail; goto fail;
} }
stream->next_uframe = start;
goto ready;
} }
/* need to schedule; when's the next (u)frame we could start? /* need to schedule; when's the next (u)frame we could start?
...@@ -1463,51 +1458,60 @@ iso_stream_schedule ( ...@@ -1463,51 +1458,60 @@ iso_stream_schedule (
* can also help high bandwidth if the dma and irq loads don't * can also help high bandwidth if the dma and irq loads don't
* jump until after the queue is primed. * jump until after the queue is primed.
*/ */
start = SCHEDULE_SLOP + (now & ~0x07); else {
start &= mod - 1; start = SCHEDULE_SLOP + (now & ~0x07);
stream->next_uframe = start;
/* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
/* NOTE: assumes URB_ISO_ASAP, to limit complexity/bugs */
/* find a uframe slot with enough bandwidth */
/* find a uframe slot with enough bandwidth */ next = start + period;
for (; start < (stream->next_uframe + period); start++) { for (; start < next; start++) {
int enough_space;
/* check schedule: enough space? */
/* check schedule: enough space? */ if (stream->highspeed) {
if (stream->highspeed) if (itd_slot_ok(ehci, mod, start,
enough_space = itd_slot_ok (ehci, mod, start, stream->usecs, period))
stream->usecs, period); break;
else { } else {
if ((start % 8) >= 6) if ((start % 8) >= 6)
continue; continue;
enough_space = sitd_slot_ok (ehci, mod, stream, if (sitd_slot_ok(ehci, mod, stream,
start, sched, period); start, sched, period))
break;
}
} }
/* schedule it here if there's enough bandwidth */ /* no room in the schedule */
if (enough_space) { if (start == next) {
stream->next_uframe = start & (mod - 1); ehci_dbg(ehci, "iso resched full %p (now %d max %d)\n",
goto ready; urb, now, now + mod);
status = -ENOSPC;
goto fail;
} }
} }
/* no room in the schedule */ /* Tried to schedule too far into the future? */
ehci_dbg (ehci, "iso %ssched full %p (now %d max %d)\n", if (unlikely(start - now + span - period
list_empty (&stream->td_list) ? "" : "re", >= mod - 2 * SCHEDULE_SLOP)) {
urb, now, now + mod); ehci_dbg(ehci, "request %p would overflow (%d+%d >= %d)\n",
status = -ENOSPC; urb, start - now, span - period,
mod - 2 * SCHEDULE_SLOP);
status = -EFBIG;
goto fail;
}
fail: stream->next_uframe = start & (mod - 1);
iso_sched_free (stream, sched);
urb->hcpriv = NULL;
return status;
ready:
/* report high speed start in uframes; full speed, in frames */ /* report high speed start in uframes; full speed, in frames */
urb->start_frame = stream->next_uframe; urb->start_frame = stream->next_uframe;
if (!stream->highspeed) if (!stream->highspeed)
urb->start_frame >>= 3; urb->start_frame >>= 3;
return 0; return 0;
fail:
iso_sched_free(stream, sched);
urb->hcpriv = NULL;
return status;
} }
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment