Skip to content

Commit

Permalink
dwc_otg: fiq_fsm: Make high-speed isochronous strided transfers work …
Browse files Browse the repository at this point in the history
…properly

Certain low-bandwidth high-speed USB devices (specialist audio devices,
compressed-frame webcams) have packet intervals > 1 microframe.

Stride these transfers in the FIQ by using the start-of-frame interrupt
to restart the channel at the right time.
  • Loading branch information
P33M authored and P33M committed Aug 4, 2015
1 parent 2a2dc4e commit 1f236e7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
17 changes: 13 additions & 4 deletions drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -615,16 +615,19 @@ static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_chan
break;

case FIQ_HS_ISOC_SLEEPING:
state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
fiq_fsm_restart_channel(state, n, 0);
/* Is it time to wake this channel yet? */
if (--state->channel[n].uframe_sleeps == 0) {
state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
fiq_fsm_restart_channel(state, n, 0);
}
break;

case FIQ_PER_SSPLIT_QUEUED:
if ((hfnum.b.frnum & 0x7) == 5)
break;
if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
if (!fiq_fsm_too_late(state, n)) {
fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
fiq_print(FIQDBG_INT, state, "SOF GO %01d", n);
fiq_fsm_restart_channel(state, n, 0);
state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
} else {
Expand Down Expand Up @@ -1069,8 +1072,14 @@ static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_c
if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
/* more transactions to come */
handled = 1;
restart = 1;
fiq_print(FIQDBG_INT, state, "HSISO M ");
/* For strided transfers, put ourselves to sleep */
if (st->hs_isoc_info.stride > 1) {
st->uframe_sleeps = st->hs_isoc_info.stride - 1;
st->fsm = FIQ_HS_ISOC_SLEEPING;
} else {
restart = 1;
}
} else {
st->fsm = FIQ_HS_ISOC_DONE;
fiq_print(FIQDBG_INT, state, "HSISO F ");
Expand Down
5 changes: 4 additions & 1 deletion drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ struct fiq_dma_blob {
* @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
* @nrframes: Total length of iso_frame_desc array
* @index: Current index (FIQ-maintained)
*
* @stride: Interval in uframes between HS isoc transactions
*/
struct fiq_hs_isoc_info {
struct dwc_otg_hcd_iso_packet_desc *iso_desc;
unsigned int nrframes;
unsigned int index;
unsigned int stride;
};

/**
Expand Down Expand Up @@ -296,6 +297,8 @@ struct fiq_channel_state {
/* Hardware bug workaround: sometimes channel halt interrupts are
* delayed until the next SOF. Keep track of when we expected to get interrupted. */
unsigned int expected_uframe;
/* number of uframes remaining (for interval > 1 HS isoc transfers) before next transfer */
unsigned int uframe_sleeps;
/* in/out for communicating number of dma buffers used, or number of ISOC to do */
unsigned int nrpackets;
struct fiq_dma_info dma_info;
Expand Down
7 changes: 6 additions & 1 deletion drivers/usb/host/dwc_otg/dwc_otg_hcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,9 @@ int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
}
}

st->hs_isoc_info.stride = qh->interval;
st->uframe_sleeps = 0;

fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
Expand All @@ -1692,9 +1695,11 @@ int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
/* Prevent queueing near EOF1. Bad things happen if a periodic
* split transaction is queued very close to EOF.
* split transaction is queued very close to EOF. SOF interrupt handler
* will wake this channel at the next interrupt.
*/
st->fsm = FIQ_HS_ISOC_SLEEPING;
st->uframe_sleeps = 1;
} else {
st->fsm = FIQ_HS_ISOC_TURBO;
st->hcchar_copy.b.chen = 1;
Expand Down
6 changes: 4 additions & 2 deletions drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2297,10 +2297,10 @@ void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd
dwc_urb->error_count++;
}
}
qh->sched_frame = dwc_frame_num_inc(qh->sched_frame, qh->interval * (nr_frames - 1));

//printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
// __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
}

/**
Expand Down Expand Up @@ -2543,6 +2543,8 @@ void dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
* fail.
*/
dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
break;

case FIQ_PER_SPLIT_LS_ABORTED:
Expand Down

0 comments on commit 1f236e7

Please sign in to comment.