usb: dwc2: host: Fix and speed up all the stuff, especially with splits
Subsystems (3)
v4 cover usb: dwc2: host: Fix and speed up all the stuff, especially with splits
This is a bit of catchall series for all the bug fix and performance patches I've been working on over the last few months. Note that for dwc2 we need to do LOTS in software and need super low interrupt latency, so most performance improvements actually fix real bugs.
Patches are structured to start with no-brainer stuff that could be applied ASAP, especially things I've already gotten Acks for. Things get slightly more RFC / RFT like as we get farther down the series. Anything that can be landed sooner rather than later (especially those Acked long ago) would help in re-posts (I'm not biased, of course).
It's been a few months since my last post of this series. In the meantime I've added a bunch of small bugfixes to the start of it and also TOTALLY REWROTE the microframe scheduler. I'll say up front: I know nothing about USB. I haven't read the whole spec. I'm not terribly familiar with the OHCI, EHCI, and XHCI drivers in the kernel. ...and I'm pretty clueless overall. Nevertheless, I've attempted to write up a fancy scheduler based on the portion of the spec talking about microframe scheduling requirements. This rewritten scheduler does seem to help when I start jamming lots of USB things into a hub, so presumably the code is a reasonably starting point. Given my current understanding of USB the old code was fairly insane, so presumably even if my new patch isn't perfect it's better than what we had.
Anyway, on to the patches:
1. usb: dwc2: rockchip: Make the max_transfer_size automatic
No brainer. Can land any time.
2. usb: dwc2: host: Get aligned DMA in a more supported way
Although this touches a lot of code, it's mostly just deleting stuff. The way this is working is nearly the same as tegra. Biggest objection I expect is that it has too much duplication with tegra and musb. I'd personally prefer to land it now and remove duplication later, but up to others. Speeding up interrupt handler helps with SOF scheduling, so this is not just a dumb optimization.
3. usb: dwc2: host: Set host_rx_fifo_size to 528 for rk3066
4. usb: dwc2: host: Set host_perio_tx_fifo_size to 304 for rk3066
Seems like a good idea and small impact, but if someone hates it or it breaks on some Rockchip SoC, just drop it. I've only tested on rk3288 so it would be nice if someone with access to more Rockchip SoCs can give a tested by.
5. usb: dwc2: host: Avoid use of chan->qh after qh freed
Simple bugfix. Unrelated to the series but thrown in here.
6. usb: dwc2: host: Always add to the tail of queues
Big functionality improvement. Small patch. Suggest applying ASAP.
7. usb: dwc2: hcd: fix split transfer schedule sequence
Unless I'm misunderstanding, this should be a no-brainer to fix. Could be some bikeshedding on how to fix this. Let me know if/how you want me to spin. Otherwise I'd say land it and it will fix a bunch of stuff.
8. usb: dwc2: host: Add scheduler tracing
Shouldn't hurt anything. If you have bikesheds, let me know.
9. usb: dwc2: host: Add a delay before releasing periodic bandwidth
10. usb: dwc2: host: Giveback URB in tasklet context
I think we should take these. They improve things a bunch and I have found no regressions due to them. Additional testing appreciated, of course.
11. usb: dwc2: host: Use periodic interrupt even with DMA
Just came up with this one recently so it's had slightly less testing. ...but it certainly fixed a bunch of stuff. Could probably be moved around in the series to be pretty much anywhere. I don't think this has a huge impact until we fix the scheduler (below) but at the same time I'm pretty sure it's something that's been wrong for a long time.
12. usb: dwc2: host: Rename some fields in struct dwc2_qh
13. usb: dwc2: host: Reorder things in hcd_queue.c
14. usb: dwc2: host: Split code out to make dwc2_do_reserve()
Cleanups to make future patches easier to understand. Bikeshed away. All no-op changes.
15. usb: dwc2: host: Add scheduler logging for missed SOFs
I found this to be quite helpful. If you hate it, drop it from the series.
16. usb: dwc2: host: Manage frame nums better in scheduler
Doesn't totally make sense on its own, but a good halfway point to the microframe scheduler. ...and shouldn't regress anything. Allows us to do the "Properly set even/odd frame" patch below which definitely improves things.
17. usb: dwc2: host: Schedule periodic right away if it's time
Yet another small change to make scheduling tighter.
18. usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call
Prep for ("usb: dwc2: host: Properly set even/odd frame")
19. usb: dwc2: host: Properly set even/odd frame
Helps quite a bit. Helps even more after the redone microframe scheduler. Feel free to tidy up if you see easy ways to do this. Maybe someone has a better way to estimate time on the wire?
20. usb: dwc2: host: Totally redo the microframe scheduler
Eyeballs please! I think I've stared at this too much and now my eyes are glazing over. This definitely helps but also probably needs a few more spins? Of course, if nobody wants to review it, IMHO checking it in as-is is WAAAAY better than what we had before.
21. usb: dwc2: host: If using uframe scheduler, end splits better
Low confidence in this one. Worry that it will end something too soon, but haven't seen it yet.
===
Below is discussion of some of the speedup stuff (mostly relevant to the first few patches).
===
The dwc2 interrupt handler is quite slow. On rk3288 with a few things plugged into the ports and with cpufreq locked at 696MHz (to simulate real world idle system), I can easily observe dwc2_handle_hcd_intr() taking > 120 us, sometimes > 150 us. Note that SOF interrupts come every 125 us with high speed USB, so taking > 120 us in the interrupt handler is a big deal.
The patches here will speed up the interrupt controller significantly. After this series, I have a hard time seeing the interrupt controller taking > 20 us and I don't ever see it taking > 30 us ever in my tests unless I bring the cpufreq back down. With the cpufreq at 126 MHz I can still see the interrupt handler take > 50 us, so I'm sure we could improve this further. ...but hey, it's a start.
This series also shows big speed improvements when testing with a USB Gigabit Ethernet adapter. Previously the tested adapter would top out at about 15MB/s. After these changes it gets about 23MB/s.
In addition to the speedup, this series also has the advantage of simplifying dwc2 and making it more like everyone else (introducing the possibility of future simplifications). Picking this series up will help your diffstat and likely win you friends. ;)
===
Steps for gathering data with ftrace (for some reason I have to run twice):
cd /sys/devices/system/cpu/cpu0/cpufreq/
echo userspace > scaling_governor
echo 696000 > scaling_setspeed
cd /sys/kernel/debug/tracing
echo 0 > tracing_on
echo "" > trace
echo nop > current_tracer
echo function_graph > current_tracer
echo dwc2_handle_hcd_intr > set_graph_function echo dwc2_handle_common_intr >> set_graph_function echo dwc2_handle_hcd_intr > set_ftrace_filter echo dwc2_handle_common_intr >> set_ftrace_filter echo funcgraph-abstime > trace_options echo 70 > tracing_thresh
echo 1 > /sys/kernel/debug/tracing/tracing_on
sleep 2
cat trace
Changes in v4:
- Add John's Acks from <https://patchwork.kernel.org/patch/7631551>
- Set host_rx_fifo_size to 528 for rk3066 new for v4.
- Set host_perio_tx_fifo_size to 304 for rk3066 new for v4.
- Avoid use of chan->qh after qh freed new for v4.
- Always add to the tail of queues new for v4.
- fix split transfer schedule sequence new for v4.
- Retooled scheduler tracing a bit, so left off John's Ack from v3.
- Moved periodic bandwidth release delay patch earlier again.
- A bit earlier in the list of patches than in v3.
- Use periodic interrupt even with DMA new for v4.
- Rename some fields in struct dwc2_qh new for v4.
- Reorder things in hcd_queue.c new for v4.
- Split code out to make dwc2_do_reserve() new for v4.
- Add scheduler logging for missed SOFs new for v4.
- Manage frame nums better in scheduler new for v4.
- Schedule periodic right away if it's time new for v4.
- Add dwc2_hcd_get_future_frame_number() call new for v4.
- Properly set even/odd frame new for v4.
- Figured out what the microframe scheduler was supposed to do.
- Microframe rewrite is totally different from v3, hopefully more right.
- Microframe rewrite is later in the series now.
- If using uframe scheduler, end splits better new for v4.
Changes in v3:
- Moved periodic bandwidth release delay patch later in the series.
- The uframe scheduler patch is folded into optimization series.
- Optimize uframe scheduler "single uframe" case a little.
- uframe scheduler now atop logging patches.
- uframe scheduler now before delayed bandwidth release patches.
- Add defines like EARLY_FRAME_USEC
- Reorder dwc2_deschedule_periodic() in prep for future patches.
- uframe scheduler now shows real usefulness w/ future patches!
- Assuming single_tt is new for v3; not terribly well tested (yet).
- Keep track and use our uframe new for v3.
Changes in v2:
- Add a warn if setup_dma is not aligned (Julius Werner).
- Periodic bandwidth release delay new for V2
- Commit message now says that URB giveback change needs delay change.
- Totally rewrote uframe scheduler again after writing test code.
- uframe scheduler atop delayed bandwidth release patches.
Douglas Anderson (21):
usb: dwc2: rockchip: Make the max_transfer_size automatic
usb: dwc2: host: Get aligned DMA in a more supported way
usb: dwc2: host: Set host_rx_fifo_size to 528 for rk3066
usb: dwc2: host: Set host_perio_tx_fifo_size to 304 for rk3066
usb: dwc2: host: Avoid use of chan->qh after qh freed
usb: dwc2: host: Always add to the tail of queues
usb: dwc2: hcd: fix split transfer schedule sequence
usb: dwc2: host: Add scheduler tracing
usb: dwc2: host: Add a delay before releasing periodic bandwidth
usb: dwc2: host: Giveback URB in tasklet context
usb: dwc2: host: Use periodic interrupt even with DMA
usb: dwc2: host: Rename some fields in struct dwc2_qh
usb: dwc2: host: Reorder things in hcd_queue.c
usb: dwc2: host: Split code out to make dwc2_do_reserve()
usb: dwc2: host: Add scheduler logging for missed SOFs
usb: dwc2: host: Manage frame nums better in scheduler
usb: dwc2: host: Schedule periodic right away if it's time
usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call
usb: dwc2: host: Properly set even/odd frame
usb: dwc2: host: Totally redo the microframe scheduler
usb: dwc2: host: If using uframe scheduler, end splits better
drivers/usb/dwc2/core.c | 119 ++- drivers/usb/dwc2/core.h | 115 ++- drivers/usb/dwc2/hcd.c | 385 +++++--- drivers/usb/dwc2/hcd.h | 126 ++- drivers/usb/dwc2/hcd_ddma.c | 41 +- drivers/usb/dwc2/hcd_intr.c | 164 ++-- drivers/usb/dwc2/hcd_queue.c | 1995 ++++++++++++++++++++++++++++++++++-------- drivers/usb/dwc2/platform.c | 6 +- 8 files changed, 2279 insertions(+), 672 deletions(-)
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 1/21 usb: dwc2: rockchip: Make the max_transfer_size automatic
Previously we needed to set the max_transfer_size to explicitly be 65535 because the old driver would detect that our hardware could support much bigger transfers and then would try to do them. This wouldn't work since the DMA alignment code couldn't support it.
Later in commit e8f8c14d9da7 ("usb: dwc2: clip max_transfer_size to 65535") upstream added support for clipping this automatically. Since that commit it has been OK to just use "-1" (default), but nobody bothered to change it.
Let's change it to default now for two reasons:
- It's nice to use autodetected params.
- If we can remove the 65535 limit, we can transfer more!
---
Changes in v4:
- Add John's Acks from <https://patchwork.kernel.org/patch/7631551>
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/platform.c +1 -1
@@ -129,7 +129,7 @@ static const struct dwc2_core_params params_rk3066 = { .host_rx_fifo_size = 520, /* 520 DWORDs */ .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ - .max_transfer_size = 65535, + .max_transfer_size = -1, .max_packet_count = -1, .host_channels = -1, .phy_type = -1,
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 2/21 usb: dwc2: host: Get aligned DMA in a more supported way
In reply to Douglas AndersonAll other host controllers who want aligned buffers for DMA do it a certain way. Let's do that too instead of working behind the USB core's back. This makes our interrupt handler not take forever and also rips out a lot of code, simplifying things a bunch.
This also has the side effect of removing the 65535 max transfer size limit.
NOTE: The actual code to allocate the aligned buffers is ripped almost completely from the tegra EHCI driver. At some point in the future we may want to add this functionality to the USB core to share more code everywhere.
---
Changes in v4:
- Add John's Acks from <https://patchwork.kernel.org/patch/7631551>
Changes in v3: None
Changes in v2:
- Add a warn if setup_dma is not aligned (Julius Werner).
drivers/usb/dwc2/core.c | 21 +----- drivers/usb/dwc2/hcd.c | 170 +++++++++++++++++++++---------------------- drivers/usb/dwc2/hcd.h | 10 --- drivers/usb/dwc2/hcd_intr.c | 65 ----------------- drivers/usb/dwc2/hcd_queue.c | 7 +- 5 files changed, 87 insertions(+), 186 deletions(-)
drivers/usb/dwc2/core.c +3 -18
@@ -1958,19 +1958,11 @@ void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, }if (hsotg->core_params->dma_enable >0 ) { -dma_addr_t dma_addr; - -if (chan->align_buf) { -if (dbg_hc (chan)) -dev_vdbg (hsotg->dev,"align_buf\n" ); - dma_addr = chan->align_buf; - }else { - dma_addr = chan->xfer_dma; - } -dwc2_writel ((u32 )dma_addr, hsotg->regs +HCDMA (chan->hc_num)); +dwc2_writel ((u32 )chan->xfer_dma, + hsotg->regs +HCDMA (chan->hc_num));if (dbg_hc (chan))dev_vdbg (hsotg->dev,"Wrote %08lx to HCDMA(%d)\n" , - (unsigned long )dma_addr, chan->hc_num); + (unsigned long )chan->xfer_dma, chan->hc_num); }/* Start the split */
@@ -3363,13 +3355,6 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg) width = (hwcfg3 &GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK ) >>GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT ; hw->max_transfer_size = (1 << (width +11 )) -1 ; -/* -* Clip max_transfer_size to 65535. dwc2_hc_setup_align_buf() allocates -* coherent buffers with this size, and if it's too large we can -* exhaust the coherent DMA pool. -*/ -if (hw->max_transfer_size >65535 ) - hw->max_transfer_size =65535 ; width = (hwcfg3 &GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK ) >>GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT ; hw->max_packet_count = (1 << (width +4 )) -1 ;
drivers/usb/dwc2/hcd.c +83 -87
239 lines not on this page · raw message
drivers/usb/dwc2/hcd.h +0 -10
@@ -75,8 +75,6 @@ struct dwc2_qh;* (micro)frame * @xfer_buf: Pointer to current transfer buffer position * @xfer_dma: DMA address of xfer_buf -* @align_buf: In Buffer DMA mode this will be used if xfer_buf is not -* DWORD aligned * @xfer_len: Total number of bytes to transfer * @xfer_count: Number of bytes transferred so far * @start_pkt_count: Packet count at start of transfer
@@ -133,7 +131,6 @@ struct dwc2_host_chan {u8 *xfer_buf;dma_addr_t xfer_dma; -dma_addr_t align_buf;u32 xfer_len;u32 xfer_count;u16 start_pkt_count;
@@ -243,10 +240,6 @@ enum dwc2_transaction_type {* @frame_usecs: Internal variable used by the microframe scheduler * @start_split_frame: (Micro)frame at which last start split was initialized * @ntd: Actual number of transfer descriptors in a list -* @dw_align_buf: Used instead of original buffer if its physical address -* is not dword-aligned -* @dw_align_buf_size: Size of dw_align_buf -* @dw_align_buf_dma: DMA address for dw_align_buf * @qtd_list: List of QTDs for this QH * @channel: Host channel currently processing transfers for this QH * @qh_list_entry: Entry for QH in either the periodic or non-periodic
@@ -279,9 +272,6 @@ struct dwc2_qh {u16 frame_usecs[8 ];u16 start_split_frame;u16 ntd; -u8 *dw_align_buf; -int dw_align_buf_size; -dma_addr_t dw_align_buf_dma;struct list_head qtd_list;struct dwc2_host_chan *channel;struct list_head qh_list_entry;
drivers/usb/dwc2/hcd_intr.c +0 -65
101 lines not on this page · raw message
drivers/usb/dwc2/hcd_queue.c +1 -6
@@ -232,13 +232,8 @@ struct dwc2_qh *dwc2_hcd_qh_create(struct dwc2_hsotg *hsotg,*/ void dwc2_hcd_qh_free (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) { -if (qh->desc_list) { +if (qh->desc_list)dwc2_hcd_qh_free_ddma (hsotg, qh); - }else { -/* kfree(NULL) is safe */ -kfree (qh->dw_align_buf); - qh->dw_align_buf_dma = (dma_addr_t )0 ; - }kfree (qh); }
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 3/21 usb: dwc2: host: Set host_rx_fifo_size to 528 for rk3066
In reply to Douglas AndersonAs documented in dwc2_calculate_dynamic_fifo(), host_rx_fifo_size should really be:
2 * ((Largest Packet size / 4) + 1 + 1) + n
with n = number of host channel.
We have 9 host channels, so
2 * ((1024/4) + 2) + 9 = 516 + 9 = 525
We've got 960 / 972 total_fifo_size on rk3288 (and presumably on rk3066) and 525 + 128 + 256 = 909 so we're still under on both ports even when we increment by 5.
Since we have space, Kever Yang suggests bumping by 8. He says this will meet INCR16 access and next fifo type can start with a aligned address.
...so let's bump up by 8. In the future, it would be nice if dwc2_calculate_dynamic_fifo() could handle the "too small" FIFO case and come up with something more dynamically. When we do that we can figure out how to allocate the extra 48 / 60 bytes of FIFO that we're currently wasting.
NOTE: no known bugs are fixed by this patch, but it seems like a simple fix and ought to fix someone.
---
Changes in v4:
- Set host_rx_fifo_size to 528 for rk3066 new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/platform.c +1 -1
@@ -126,7 +126,7 @@ static const struct dwc2_core_params params_rk3066 = { .speed = -1, .enable_dynamic_fifo = 1, .en_multiple_tx_fifo = -1, - .host_rx_fifo_size = 520, /* 520 DWORDs */ + .host_rx_fifo_size = 528, /* 528 DWORDs */ .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ .max_transfer_size = -1,
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 4/21 usb: dwc2: host: Set host_perio_tx_fifo_size to 304 for rk3066
In reply to Douglas AndersonLooking at rk3288, there are two dwc2 ports. One has 960 total_fifo_size and the other 972.
We're currently assigning 528 + 128 + 256 = 912. That means we're wasting 48 words on one port and 60 words on the other. Since we have one settings block for both ports, let's just eat the 48 words that we know we have and assign them to what's probably the most latency-senstive part of the system: periodic transfers.
Presumably other rk3288 parts using the rk3066 settings also have these extra 48 words as well.
Note: ideally we'd adjust dwc2_calculate_dynamic_fifo() to handle this more dynamically, but until that's done hardcoding things here seems OK.
NOTE: no known use cases are improved by this patch, but in my stressful USB tests I certainly see my periodic FIFO filling up both before and after this change. Presumably there are some USB configurations where the periodic FIFO would have been filled before where it no longer is.
---
Changes in v4:
- Set host_perio_tx_fifo_size to 304 for rk3066 new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/dwc2/platform.c +1 -1
@@ -128,7 +128,7 @@ static const struct dwc2_core_params params_rk3066 = { .en_multiple_tx_fifo = -1, .host_rx_fifo_size = 528, /* 528 DWORDs */ .host_nperio_tx_fifo_size = 128, /* 128 DWORDs */ - .host_perio_tx_fifo_size = 256, /* 256 DWORDs */ + .host_perio_tx_fifo_size = 304, /* 304 DWORDs */ .max_transfer_size = -1, .max_packet_count = -1, .host_channels = -1,
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 5/21 usb: dwc2: host: Avoid use of chan->qh after qh freed
In reply to Douglas AndersonWhen poking around with USB devices with slub_debug enabled, I found another obvious use after free. Turns out that in dwc2_hc_n_intr() I was in a state when the contents of chan->qh was filled with 0x6b, indicating that chan->qh was freed but chan still had a reference to it.
Let's make sure that whenever we free qh we also make sure we remove a reference from its channel.
The bug fixed here doesn't appear to be new--I believe I just got lucky and happened to see it while stress testing.
---
Changes in v4:
- Avoid use of chan->qh after qh freed new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd.c | 8 ++++++++ drivers/usb/dwc2/hcd_intr.c | 10 ++++++++++ 2 files changed, 18 insertions(+)
drivers/usb/dwc2/hcd.c +8 -0
@@ -164,6 +164,9 @@ static void dwc2_qh_list_free(struct dwc2_hsotg *hsotg, qtd_list_entry)dwc2_hcd_qtd_unlink_and_free (hsotg ,qtd ,qh ); +if (qh->channel && qh->channel->qh == qh) + qh->channel->qh =NULL ; +spin_unlock_irqrestore (&hsotg->lock, flags);dwc2_hcd_qh_free (hsotg, qh);spin_lock_irqsave (&hsotg->lock, flags);
@@ -554,7 +557,12 @@ static int dwc2_hcd_endpoint_disable(struct dwc2_hsotg *hsotg,dwc2_hcd_qtd_unlink_and_free (hsotg, qtd, qh); ep->hcpriv =NULL ; + +if (qh->channel && qh->channel->qh == qh) + qh->channel->qh =NULL ; +spin_unlock_irqrestore (&hsotg->lock, flags); +dwc2_hcd_qh_free (hsotg, qh);return 0 ;
drivers/usb/dwc2/hcd_intr.c +10 -0
@@ -1935,6 +1935,16 @@ static void dwc2_hc_n_intr(struct dwc2_hsotg *hsotg, int chnum) }dwc2_writel (hcint, hsotg->regs +HCINT (chnum)); + +/* +* If we got an interrupt after someone called +* dwc2_hcd_endpoint_disable() we don't want to crash below +*/ +if (!chan->qh) { +dev_warn (hsotg->dev,"Interrupt on disabled channel\n" ); +return ; + } + chan->hcint = hcint; hcint &= hcintmsk;
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 6/21 usb: dwc2: host: Always add to the tail of queues
In reply to Douglas AndersonThe queues the the dwc2 host controller used are truly queues. That means FIFO or first in first out.
Unfortunately though the code was iterating through these queues starting from the head, some places in the code was adding things to the queue by adding at the head instead of the tail. That means last in first out. Doh.
Go through and just always add to the tail.
Doing this makes things much happier when I've got:
* 7-port USB 2.0 Single-TT hub
* - Microsoft 2.4 GHz Transceiver v7.0 dongle
* - Jabra speakerphone playing music
---
Changes in v4:
- Always add to the tail of queues new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd.c | 11 ++++++----- drivers/usb/dwc2/hcd_ddma.c | 4 ++-- drivers/usb/dwc2/hcd_intr.c | 4 ++-- drivers/usb/dwc2/hcd_queue.c | 6 ++++-- 4 files changed, 14 insertions(+), 11 deletions(-)
drivers/usb/dwc2/hcd.c +6 -5
@@ -969,7 +969,8 @@ enum dwc2_transaction_type dwc2_hcd_select_transactions(* periodic assigned schedule */ qh_ptr = qh_ptr->next; -list_move (&qh->qh_list_entry, &hsotg->periodic_sched_assigned); +list_move_tail (&qh->qh_list_entry, + &hsotg->periodic_sched_assigned); ret_val =DWC2_TRANSACTION_PERIODIC ; }
@@ -1002,8 +1003,8 @@ enum dwc2_transaction_type dwc2_hcd_select_transactions(* non-periodic active schedule */ qh_ptr = qh_ptr->next; -list_move (&qh->qh_list_entry, - &hsotg->non_periodic_sched_active); +list_move_tail (&qh->qh_list_entry, + &hsotg->non_periodic_sched_active);if (ret_val ==DWC2_TRANSACTION_NONE ) ret_val =DWC2_TRANSACTION_NON_PERIODIC ;
@@ -1176,8 +1177,8 @@ static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg)* Move the QH from the periodic assigned schedule to * the periodic queued schedule */ -list_move (&qh->qh_list_entry, - &hsotg->periodic_sched_queued); +list_move_tail (&qh->qh_list_entry, + &hsotg->periodic_sched_queued);/* done queuing high bandwidth */ hsotg->queuing_high_bandwidth =0 ;
drivers/usb/dwc2/hcd_ddma.c +2 -2
@@ -1327,8 +1327,8 @@ void dwc2_hcd_complete_xfer_ddma(struct dwc2_hsotg *hsotg,dwc2_hcd_qh_unlink (hsotg, qh); }else {/* Keep in assigned schedule to continue transfer */ -list_move (&qh->qh_list_entry, - &hsotg->periodic_sched_assigned); +list_move_tail (&qh->qh_list_entry, + &hsotg->periodic_sched_assigned);/* * If channel has been halted during giveback of urb * then prevent any new scheduling.
drivers/usb/dwc2/hcd_intr.c +2 -2
@@ -143,7 +143,7 @@ static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)* Move QH to the ready list to be executed next * (micro)frame */ -list_move (&qh->qh_list_entry, +list_move_tail (&qh->qh_list_entry, &hsotg->periodic_sched_ready); } tr_type =dwc2_hcd_select_transactions (hsotg);
@@ -794,7 +794,7 @@ static void dwc2_halt_channel(struct dwc2_hsotg *hsotg,* halt to be queued when the periodic schedule is * processed. */ -list_move (&chan->qh->qh_list_entry, +list_move_tail (&chan->qh->qh_list_entry, &hsotg->periodic_sched_assigned);/*
drivers/usb/dwc2/hcd_queue.c +4 -2
@@ -732,9 +732,11 @@ void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, dwc2_frame_num_le(qh->sched_frame, frame_number)) || (hsotg->core_params->uframe_sched <= 0 && qh->sched_frame == frame_number)) -list_move (&qh->qh_list_entry, &hsotg->periodic_sched_ready); +list_move_tail (&qh->qh_list_entry, + &hsotg->periodic_sched_ready); else - list_move(&qh->qh_list_entry, &hsotg->periodic_sched_inactive); + list_move_tail(&qh->qh_list_entry, + &hsotg->periodic_sched_inactive); }/**
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 7/21 usb: dwc2: hcd: fix split transfer schedule sequence
In reply to Douglas AndersonWe're supposed to keep outstanding splits in order. Keep track of a list of the order of splits and process channel interrupts in that order.
Without this change and the following setup:
* Rockchip rk3288 Chromebook, using port ff540000
-> Pluggable 7-port Hub with Charging (powered)
-> Microsoft Wireless Keyboard 2000 in port 1.
-> Das Keyboard in port 2....I find that I get dropped keys on the Microsoft keyboard (I'm sure there are other combinations that fail, but this documents my test). Specifically I've been typing "hahahahahahaha" on the keyboard and often see keys dropped or repeated.
After this change the above setup works properly. This patch is based on a previous patch proposed by Yunzhi Li ("usb: dwc2: hcd: fix periodic transfer schedule sequence")
---
Changes in v4:
- fix split transfer schedule sequence new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/core.c | 6 ++++++ drivers/usb/dwc2/core.h | 2 ++ drivers/usb/dwc2/hcd.c | 3 +++ drivers/usb/dwc2/hcd.h | 2 ++ drivers/usb/dwc2/hcd_intr.c | 17 +++++++++++++++++ 5 files changed, 30 insertions(+)
drivers/usb/dwc2/core.c +6 -0
@@ -1676,6 +1676,8 @@ void dwc2_hc_cleanup(struct dwc2_hsotg *hsotg, struct dwc2_host_chan *chan) chan->xfer_started =0 ; +list_del_init (&chan->split_order_list_entry); +/* * Clear channel interrupt enables and any unhandled channel interrupt * conditions
@@ -1868,6 +1870,10 @@ void dwc2_hc_start_transfer(struct dwc2_hsotg *hsotg, ec_mc =3 ; else ec_mc =1 ; + +/* Put ourselves on the list to keep order straight */ +list_move_tail (&chan->split_order_list_entry, + &hsotg->split_order); }else {if (dbg_hc (chan))dev_vdbg (hsotg->dev,"no split\n" );
drivers/usb/dwc2/core.h +2 -0
@@ -657,6 +657,7 @@ struct dwc2_hregs_backup {* periodic_sched_ready because it must be rescheduled for * the next frame. Otherwise, the item moves to * periodic_sched_inactive. +* @split_order: List keeping track of channels doing splits, in order. * @periodic_usecs: Total bandwidth claimed so far for periodic transfers. * This value is in microseconds per (micro)frame. The * assumption is that all periodic transfers may occur in
@@ -780,6 +781,7 @@ struct dwc2_hsotg {struct list_head periodic_sched_ready;struct list_head periodic_sched_assigned;struct list_head periodic_sched_queued; +struct list_head split_order;u16 periodic_usecs;u16 frame_usecs[8 ];u16 frame_number;
drivers/usb/dwc2/hcd.c +3 -0
@@ -3151,6 +3151,8 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)INIT_LIST_HEAD (&hsotg->periodic_sched_assigned);INIT_LIST_HEAD (&hsotg->periodic_sched_queued); +INIT_LIST_HEAD (&hsotg->split_order); +/* * Create a host channel descriptor for each host channel implemented * in the controller. Initialize the channel descriptor array.
@@ -3164,6 +3166,7 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)if (channel ==NULL ) goto error3; channel->hc_num = i; +INIT_LIST_HEAD (&channel->split_order_list_entry); hsotg->hc_ptr_array[i] = channel; }
drivers/usb/dwc2/hcd.h +2 -0
@@ -106,6 +106,7 @@ struct dwc2_qh;* @hc_list_entry: For linking to list of host channels * @desc_list_addr: Current QH's descriptor list DMA address * @desc_list_sz: Current QH's descriptor list size +* @split_order_list_entry: List entry for keeping track of the order of splits * * This structure represents the state of a single host channel when acting in * host mode. It contains the data items needed to transfer packets to an
@@ -158,6 +159,7 @@ struct dwc2_host_chan {struct list_head hc_list_entry;dma_addr_t desc_list_addr;u32 desc_list_sz; +struct list_head split_order_list_entry; };struct dwc2_hcd_pipe_info {
drivers/usb/dwc2/hcd_intr.c +17 -0
@@ -2067,6 +2067,7 @@ static void dwc2_hc_intr(struct dwc2_hsotg *hsotg) {u32 haint;int i; +struct dwc2_host_chan *chan, *chan_tmp; haint =dwc2_readl (hsotg->regs +HAINT );if (dbg_perio ()) {
@@ -2075,6 +2076,22 @@ static void dwc2_hc_intr(struct dwc2_hsotg *hsotg)dev_vdbg (hsotg->dev,"HAINT=%08x\n" , haint); } +/* +* According to USB 2.0 spec section 11.18.8, a host must +* issue complete-split transactions in a microframe for a +* set of full-/low-speed endpoints in the same relative +* order as the start-splits were issued in a microframe for. +*/ +list_for_each_entry_safe (chan, chan_tmp, &hsotg->split_order, + split_order_list_entry) { +int hc_num = chan->hc_num; + +if (haint & (1 << hc_num)) { +dwc2_hc_n_intr (hsotg, hc_num); + haint &= ~(1 << hc_num); + } + } +for (i =0 ; i < hsotg->core_params->host_channels; i++) {if (haint & (1 << i))dwc2_hc_n_intr (hsotg, i);
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 8/21 usb: dwc2: host: Add scheduler tracing
In reply to Douglas AndersonIn preparation for future changes to the scheduler let's add some tracing that makes it easy for us to see what's happening. By default this tracing will be off.
By changing "core.h" you can easily trace to ftrace, the console, or nowhere.
---
Changes in v4:
- Retooled scheduler tracing a bit, so left off John's Ack from v3.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/core.h | 20 ++++++++++++++++++++ drivers/usb/dwc2/hcd.h | 5 +++++ drivers/usb/dwc2/hcd_intr.c | 6 +++++- drivers/usb/dwc2/hcd_queue.c | 24 +++++++++++++++++++++++- 4 files changed, 53 insertions(+), 2 deletions(-)
drivers/usb/dwc2/core.h +20 -0
@@ -44,6 +44,26 @@#include <linux/usb/phy.h> #include "hw.h" +/* +* Suggested defines for tracers: +* - no_printk: Disable tracing +* - pr_info: Print this info to the console +* - trace_printk: Print this info to trace buffer (good for verbose logging) +*/ + +#define DWC2_TRACE_SCHEDULER no_printk +#define DWC2_TRACE_SCHEDULER_VB no_printk + +/* Detailed scheduler tracing, but won't overwhelm console */ +#define dwc2_sch_dbg (hsotg, fmt, ...) \ + DWC2_TRACE_SCHEDULER(pr_fmt("%s: SCH: " fmt), \ + dev_name(hsotg->dev), ##__VA_ARGS__) + +/* Verbose scheduler tracing */ +#define dwc2_sch_vdbg (hsotg, fmt, ...) \ + DWC2_TRACE_SCHEDULER_VB(pr_fmt("%s: SCH: " fmt), \ + dev_name(hsotg->dev), ##__VA_ARGS__) +static inline u32 dwc2_readl (const void __iomem *addr) {u32 value =__raw_readl (addr);
drivers/usb/dwc2/hcd.h +5 -0
@@ -563,6 +563,11 @@ static inline u16 dwc2_frame_num_inc(u16 frame, u16 inc)return (frame + inc) &HFNUM_MAX_FRNUM ; } +static inline u16 dwc2_frame_num_dec (u16 frame,u16 dec) +{ +return (frame +HFNUM_MAX_FRNUM +1 - dec) &HFNUM_MAX_FRNUM ; +} +static inline u16 dwc2_full_frame_num (u16 frame) {return (frame &HFNUM_MAX_FRNUM ) >>3 ;
drivers/usb/dwc2/hcd_intr.c +5 -1
@@ -138,13 +138,17 @@ static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)while (qh_entry != &hsotg->periodic_sched_inactive) { qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry); qh_entry = qh_entry->next; -if (dwc2_frame_num_le (qh->sched_frame, hsotg->frame_number)) +if (dwc2_frame_num_le (qh->sched_frame, hsotg->frame_number)) { +dwc2_sch_vdbg (hsotg,"QH=%p ready fn=%04x, sch=%04x\n" , + qh, hsotg->frame_number, qh->sched_frame); +/* * Move QH to the ready list to be executed next * (micro)frame */ list_move_tail (&qh->qh_list_entry, &hsotg->periodic_sched_ready); + } } tr_type =dwc2_hcd_select_transactions (hsotg);if (tr_type !=DWC2_TRANSACTION_NONE )
drivers/usb/dwc2/hcd_queue.c +23 -1
@@ -113,6 +113,9 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, qh->sched_frame =dwc2_frame_num_inc (hsotg->frame_number,SCHEDULE_SLOP ); qh->interval = urb->interval; +dwc2_sch_dbg (hsotg,"QH=%p init sch=%04x, fn=%04x, int=%#x\n" , + qh, qh->sched_frame, hsotg->frame_number, + qh->interval);#if 0 /* Increase interrupt polling rate for debugging */ if (qh->ep_type ==USB_ENDPOINT_XFER_INT )
@@ -126,6 +129,11 @@ static void dwc2_qh_init(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, qh->interval *=8 ; qh->sched_frame |=0x7 ; qh->start_split_frame = qh->sched_frame; +dwc2_sch_dbg (hsotg, +"QH=%p init*8 sch=%04x, fn=%04x, int=%#x\n" , + qh, qh->sched_frame, hsotg->frame_number, + qh->interval); + }dev_dbg (hsotg->dev,"interval=%d\n" , qh->interval); }
@@ -482,6 +490,8 @@ static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)if (frame >=0 ) { qh->sched_frame &= ~0x7 ; qh->sched_frame |= (frame &7 ); +dwc2_sch_dbg (hsotg,"QH=%p sched_p sch=%04x, uf=%d\n" , + qh, qh->sched_frame, frame); }if (status >0 )
@@ -583,10 +593,16 @@ int dwc2_hcd_qh_add(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)if (!dwc2_frame_num_le (qh->sched_frame, hsotg->frame_number) && !hsotg->frame_number) { +u16 new_frame; +dev_dbg (hsotg->dev,"reset frame number counter\n" ); - qh->sched_frame =dwc2_frame_num_inc (hsotg->frame_number, + new_frame =dwc2_frame_num_inc (hsotg->frame_number,SCHEDULE_SLOP ); + +dwc2_sch_vdbg (hsotg,"QH=%p reset sch=%04x=>%04x\n" , + qh, qh->sched_frame, new_frame); + qh->sched_frame = new_frame; }/* Add the new QH to the appropriate schedule */
@@ -652,6 +668,7 @@ static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg, int sched_next_periodic_split) {u16 incr; +u16 old_frame = qh->sched_frame;if (sched_next_periodic_split) { qh->sched_frame = frame_number;
@@ -677,6 +694,11 @@ static void dwc2_sched_periodic_split(struct dwc2_hsotg *hsotg, qh->sched_frame |=0x7 ; qh->start_split_frame = qh->sched_frame; } + +dwc2_sch_vdbg (hsotg,"QH=%p next(%d) fn=%04x, sch=%04x=>%04x (%+d)\n" , + qh, sched_next_periodic_split, frame_number, old_frame, + qh->sched_frame, +dwc2_frame_num_dec (qh->sched_frame, old_frame)); }/*
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 9/21 usb: dwc2: host: Add a delay before releasing periodic bandwidth
In reply to Douglas AndersonWe'd like to be able to use HCD_BH in order to speed up the dwc2 host interrupt handler quite a bit. However, according to the kernel doc for usb_submit_urb() (specifically the part about "Reserved Bandwidth Transfers"), we need to keep a reservation active as long as a device driver keeps submitting. That was easy to do when we gave back the URB in the interrupt context: we just looked at when our queue was empty and released the reserved bandwidth then. ...but now we need a little more complexity.
We'll follow EHCI's lead in commit 9118f9eb4f1e ("USB: EHCI: improve interrupt qh unlink") and add a 5ms delay. Since we don't have a whole timer infrastructure in dwc2, we'll just add a timer per QH. The overhead for this is very small.
Note that the dwc2 scheduler is pretty broken (see future patches to fix it). This patch attempts to replicate all old behavior and just add the proper delay.
---
Changes in v4:
- Moved periodic bandwidth release delay patch earlier again.
Changes in v3:
- Moved periodic bandwidth release delay patch later in the series.
Changes in v2:
- Periodic bandwidth release delay new for V2
drivers/usb/dwc2/hcd.h | 6 ++ drivers/usb/dwc2/hcd_queue.c | 237 +++++++++++++++++++++++++++++++++---------- 2 files changed, 187 insertions(+), 56 deletions(-)
drivers/usb/dwc2/hcd.h +6 -0
@@ -215,6 +215,7 @@ enum dwc2_transaction_type {/** * struct dwc2_qh - Software queue head structure * +* @hsotg: The HCD state structure for the DWC OTG controller * @ep_type: Endpoint type. One of the following values: * - USB_ENDPOINT_XFER_CONTROL * - USB_ENDPOINT_XFER_BULK
@@ -252,13 +253,16 @@ enum dwc2_transaction_type {* @n_bytes: Xfer Bytes array. Each element corresponds to a transfer * descriptor and indicates original XferSize value for the * descriptor +* @unreserve_timer: Timer for releasing periodic reservation. * @tt_buffer_dirty True if clear_tt_buffer_complete is pending +* @unreserve_pending: True if we planned to unreserve but haven't yet. * * A Queue Head (QH) holds the static characteristics of an endpoint and * maintains a list of transfers (QTDs) for that endpoint. A QH structure may * be entered in either the non-periodic or periodic schedule. */ struct dwc2_qh { +struct dwc2_hsotg *hsotg;u8 ep_type;u8 ep_is_in;u16 maxp;
@@ -281,7 +285,9 @@ struct dwc2_qh {dma_addr_t desc_list_dma;u32 desc_list_sz;u32 *n_bytes; +struct timer_list unreserve_timer; unsigned tt_buffer_dirty:1; + unsigned unreserve_pending:1; };/**
drivers/usb/dwc2/hcd_queue.c +181 -56
285 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 10/21 usb: dwc2: host: Giveback URB in tasklet context
In reply to Douglas AndersonIn commit 94dfd7edfd5c ("USB: HCD: support giveback of URB in tasklet context") support was added to give back the URB in tasklet context. Let's take advantage of this in dwc2.
This speeds up the dwc2 interrupt handler considerably.
Note that this requires the change ("usb: dwc2: host: Add a delay before releasing periodic bandwidth") to come first.
Note that, as per Alan Stern in
<https://patchwork.kernel.org/patch/7555771/>, we also need to make sure that the extra delay before the device drivers submit more data doesn't break the scheduler. At the moment the scheduler is pretty broken (see future patches) so it's hard to be 100% certain, but I have yet to see any new breakage introduced by this delay. ...and speeding up interrupt processing for dwc2 is a huge deal because it means we've got a better chance of not missing SOF interrupts. That means we've got an overall win here.
Note that when playing USB audio and using a USB webcam and having several USB keyboards plugged in, the crackling on the USB audio device is noticably reduced with this patch.
---
Changes in v4:
- A bit earlier in the list of patches than in v3.
Changes in v3: None
Changes in v2:
- Commit message now says that URB giveback change needs delay change.
drivers/usb/dwc2/hcd.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/dwc2/hcd.c +1 -3
@@ -2336,9 +2336,7 @@ void dwc2_host_complete(struct dwc2_hsotg *hsotg, struct dwc2_qtd *qtd,kfree (qtd->urb); qtd->urb =NULL ; -spin_unlock (&hsotg->lock);usb_hcd_giveback_urb (dwc2_hsotg_to_hcd (hsotg), urb, status); -spin_lock (&hsotg->lock); }/*
@@ -2957,7 +2955,7 @@ static struct hc_driver dwc2_hc_driver = { .hcd_priv_size = sizeof(struct wrapper_priv_data), .irq = _dwc2_hcd_irq, - .flags = HCD_MEMORY | HCD_USB2, + .flags = HCD_MEMORY | HCD_USB2 | HCD_BH, .start = _dwc2_hcd_start, .stop = _dwc2_hcd_stop,
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 11/21 usb: dwc2: host: Use periodic interrupt even with DMA
In reply to Douglas AndersonThe old code in dwc2_process_periodic_channels() would only enable the "periodic empty" interrupt if we weren't using DMA. That wasn't right since we can still get into cases where we have small FIFOs even on systems that have DMA (the rk3288 is a prime example).
Let's always enable/disable the "periodic empty" when appropriate. As part of this:
* Always call dwc2_process_periodic_channels() even if there's nothing in periodic_sched_assigned (we move the queue empty check so we still avoid the extra work). That will make extra certain that we will properly disable the "periodic empty" interrupt even if there's nothing queued up.
* Move the enable of "periodic empty" due to non-empty periodic_sched_assigned to be for slave mode (non-DMA mode) only. Presumably this was the original intention of the check for DMA since it seems to match the comments above where in slave mode we leave things on the assigned queue.
Note that even before this change slave mode didn't work for me, so I can't say for sure that my understanding of slave mode is correct. However, this shouldn't change anything for slave mode so if slave mode worked for someone in the past it ought to still work.
With this change, I no longer get constant misses reported by my other debugging code (and with future patches) when I've got:
* Rockchip rk3288 Chromebook, using port ff540000
-> Pluggable 7-port Hub with Charging (powered)
-> Microsoft Wireless Keyboard 2000 in port 1.
-> Das Keyboard in port 2.
-> Jabra Speaker in port 3
-> Logitech, Inc. Webcam C600 in port 4
-> Microsoft Sidewinder X6 Keyboard in port 5...and I'm playing music on the USB speaker and capturing video from the webcam.
---
Changes in v4:
- Use periodic interrupt even with DMA new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd.c | 71 +++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 39 deletions(-)
drivers/usb/dwc2/hcd.c +32 -39
@@ -1104,10 +1104,14 @@ static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg)u32 fspcavail;u32 gintmsk;int status; -int no_queue_space =0 ; -int no_fifo_space =0 ; +bool no_queue_space = false; +bool no_fifo_space = false;u32 qspcavail; +/* If empty list then just adjust interrupt enables */ +if (list_empty (&hsotg->periodic_sched_assigned)) + goto exit; +if (dbg_perio ())dev_vdbg (hsotg->dev,"Queue periodic transactions\n" );
@@ -1185,42 +1189,32 @@ static void dwc2_process_periodic_channels(struct dwc2_hsotg *hsotg) } } -if (hsotg->core_params->dma_enable <=0 ) { - tx_status =dwc2_readl (hsotg->regs +HPTXSTS ); - qspcavail = (tx_status &TXSTS_QSPCAVAIL_MASK ) >> -TXSTS_QSPCAVAIL_SHIFT ; - fspcavail = (tx_status &TXSTS_FSPCAVAIL_MASK ) >> -TXSTS_FSPCAVAIL_SHIFT ; -if (dbg_perio ()) { -dev_vdbg (hsotg->dev, -" P Tx Req Queue Space Avail (after queue): %d\n" , - qspcavail); -dev_vdbg (hsotg->dev, -" P Tx FIFO Space Avail (after queue): %d\n" , - fspcavail); - } - -if (!list_empty (&hsotg->periodic_sched_assigned) || - no_queue_space || no_fifo_space) { -/* -* May need to queue more transactions as the request -* queue or Tx FIFO empties. Enable the periodic Tx -* FIFO empty interrupt. (Always use the half-empty -* level to ensure that new requests are loaded as -* soon as possible.) -*/ - gintmsk =dwc2_readl (hsotg->regs +GINTMSK ); +exit: +if (no_queue_space || no_fifo_space || + (hsotg->core_params->dma_enable <=0 && + !list_empty (&hsotg->periodic_sched_assigned))) { +/* +* May need to queue more transactions as the request +* queue or Tx FIFO empties. Enable the periodic Tx +* FIFO empty interrupt. (Always use the half-empty +* level to ensure that new requests are loaded as +* soon as possible.) +*/ + gintmsk =dwc2_readl (hsotg->regs +GINTMSK ); +if (!(gintmsk &GINTSTS_PTXFEMP )) { gintmsk |=GINTSTS_PTXFEMP ;dwc2_writel (gintmsk, hsotg->regs +GINTMSK ); - }else { -/* -* Disable the Tx FIFO empty interrupt since there are -* no more transactions that need to be queued right -* now. This function is called from interrupt -* handlers to queue more transactions as transfer -* states change. -*/ - gintmsk =dwc2_readl (hsotg->regs +GINTMSK ); + } + }else { +/* +* Disable the Tx FIFO empty interrupt since there are +* no more transactions that need to be queued right +* now. This function is called from interrupt +* handlers to queue more transactions as transfer +* states change. +*/ + gintmsk =dwc2_readl (hsotg->regs +GINTMSK ); +if (gintmsk &GINTSTS_PTXFEMP ) { gintmsk &= ~GINTSTS_PTXFEMP ;dwc2_writel (gintmsk, hsotg->regs +GINTMSK ); }
@@ -1367,9 +1361,8 @@ void dwc2_hcd_queue_transactions(struct dwc2_hsotg *hsotg,dev_vdbg (hsotg->dev,"Queue Transactions\n" );#endif /* Process host channels associated with periodic transfers */ -if ((tr_type ==DWC2_TRANSACTION_PERIODIC || - tr_type ==DWC2_TRANSACTION_ALL ) && - !list_empty (&hsotg->periodic_sched_assigned)) +if (tr_type ==DWC2_TRANSACTION_PERIODIC || + tr_type ==DWC2_TRANSACTION_ALL )dwc2_process_periodic_channels (hsotg);/* Process host channels associated with non-periodic transfers */
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 12/21 usb: dwc2: host: Rename some fields in struct dwc2_qh
In reply to Douglas AndersonThis no-op change just does some renames to simplify a future patch.
1. The "interval" field is renamed to "host_interval" to make it more obvious that this interval may be 8 times the interval that the device sees (if we're doing split transactions). A future patch will also add the "device_interval" field.
2. The "usecs" field is renamed to "host_us" again to make it more obvious that this is the time for the transaction as seen by the host. For split transactions the device may see a much longer transaction time. A future patch will also add "device_us".
3. The "sched_frame" field is renamed to "next_active_frame". The name "sched_frame" kept confusing me because it felt like something more permament (the QH's reservation or something). The name "next_active_frame" makes it more obvious that this field is constantly changing.
---
Changes in v4:
- Rename some fields in struct dwc2_qh new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd.h | 20 ++++---- drivers/usb/dwc2/hcd_ddma.c | 37 ++++++++------- drivers/usb/dwc2/hcd_intr.c | 10 ++-- drivers/usb/dwc2/hcd_queue.c | 107 ++++++++++++++++++++++--------------------- 4 files changed, 92 insertions(+), 82 deletions(-)
drivers/usb/dwc2/hcd.h +12 -8
@@ -236,10 +236,14 @@ enum dwc2_transaction_type {* @do_split: Full/low speed endpoint on high-speed hub requires split * @td_first: Index of first activated isochronous transfer descriptor * @td_last: Index of last activated isochronous transfer descriptor -* @usecs: Bandwidth in microseconds per (micro)frame -* @interval: Interval between transfers in (micro)frames -* @sched_frame: (Micro)frame to initialize a periodic transfer. -* The transfer executes in the following (micro)frame. +* @host_us: Bandwidth in microseconds per transfer as seen by host +* @host_interval: Interval between transfers as seen by the host. If +* the host is high speed and the device is low speed this +* will be 8 times device interval. +* @next_active_frame: (Micro)frame before we next need to put something on +* the bus. We'll move the qh to active here. If the +* host is in high speed mode this will be a uframe. If +* the host is in low speed mode this will be a full frame. * @frame_usecs: Internal variable used by the microframe scheduler * @start_split_frame: (Micro)frame at which last start split was initialized * @ntd: Actual number of transfer descriptors in a list
@@ -272,9 +276,9 @@ struct dwc2_qh {u8 do_split;u8 td_first;u8 td_last; -u16 usecs; -u16 interval; -u16 sched_frame; +u16 host_us; +u16 host_interval; +u16 next_active_frame;u16 frame_usecs[8 ];u16 start_split_frame;u16 ntd;
@@ -651,7 +655,7 @@ static inline u16 dwc2_hcd_get_ep_bandwidth(struct dwc2_hsotg *hsotg,return 0 ; } -return qh->usecs; +return qh->host_us; } extern void dwc2_hcd_save_data_toggle(struct dwc2_hsotg *hsotg,
drivers/usb/dwc2/hcd_ddma.c +20 -17
@@ -81,7 +81,7 @@ static u16 dwc2_max_desc_num(struct dwc2_qh *qh)static u16 dwc2_frame_incr_val (struct dwc2_qh *qh) {return qh->dev_speed ==USB_SPEED_HIGH ? - (qh->interval +8 -1 ) /8 : qh->interval; + (qh->host_interval +8 -1 ) /8 : qh->host_interval; } static int dwc2_desc_list_alloc(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,
@@ -252,7 +252,7 @@ static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh, chan = qh->channel; inc =dwc2_frame_incr_val (qh);if (qh->ep_type ==USB_ENDPOINT_XFER_ISOC ) - i =dwc2_frame_list_idx (qh->sched_frame); + i =dwc2_frame_list_idx (qh->next_active_frame);else i =0 ;
@@ -278,13 +278,13 @@ static void dwc2_update_frame_list(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,return ; chan->schinfo =0 ; -if (chan->speed ==USB_SPEED_HIGH && qh->interval) { +if (chan->speed ==USB_SPEED_HIGH && qh->host_interval) { j =1 ;/* TODO - check this */ - inc = (8 + qh->interval -1 ) / qh->interval; + inc = (8 + qh->host_interval -1 ) / qh->host_interval;for (i =0 ; i < inc; i++) { chan->schinfo |= j; - j = j << qh->interval; + j = j << qh->host_interval; } }else { chan->schinfo =0xff ;
@@ -431,7 +431,10 @@ static u16 dwc2_calc_starting_frame(struct dwc2_hsotg *hsotg, hsotg->frame_number =dwc2_hcd_get_frame_number (hsotg); -/* sched_frame is always frame number (not uFrame) both in FS and HS! */ +/* +* next_active_frame is always frame number (not uFrame) both in FS +* and HS! +*/ /* * skip_frames is used to limit activated descriptors number
@@ -514,13 +517,13 @@ static u16 dwc2_recalc_initial_desc_idx(struct dwc2_hsotg *hsotg,*/ fr_idx_tmp =dwc2_frame_list_idx (frame); fr_idx = (FRLISTEN_64_SIZE + -dwc2_frame_list_idx (qh->sched_frame) - fr_idx_tmp) - %dwc2_frame_incr_val (qh); +dwc2_frame_list_idx (qh->next_active_frame) - + fr_idx_tmp) %dwc2_frame_incr_val (qh); fr_idx = (fr_idx + fr_idx_tmp) %FRLISTEN_64_SIZE ; }else { - qh->sched_frame =dwc2_calc_starting_frame (hsotg, qh, + qh->next_active_frame =dwc2_calc_starting_frame (hsotg, qh, &skip_frames); - fr_idx =dwc2_frame_list_idx (qh->sched_frame); + fr_idx =dwc2_frame_list_idx (qh->next_active_frame); } qh->td_first = qh->td_last =dwc2_frame_to_desc_idx (qh, fr_idx);
@@ -583,7 +586,7 @@ static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg,u16 next_idx; idx = qh->td_last; - inc = qh->interval; + inc = qh->host_interval; hsotg->frame_number =dwc2_hcd_get_frame_number (hsotg); cur_idx =dwc2_frame_list_idx (hsotg->frame_number); next_idx =dwc2_desclist_idx_inc (qh->td_last, inc, qh->dev_speed);
@@ -605,11 +608,11 @@ static void dwc2_init_isoc_dma_desc(struct dwc2_hsotg *hsotg, } } -if (qh->interval) { - ntd_max = (dwc2_max_desc_num (qh) + qh->interval -1 ) / - qh->interval; +if (qh->host_interval) { + ntd_max = (dwc2_max_desc_num (qh) + qh->host_interval -1 ) / + qh->host_interval;if (skip_frames && !qh->channel) - ntd_max -= skip_frames / qh->interval; + ntd_max -= skip_frames / qh->host_interval; } max_xfer_size = qh->dev_speed == USB_SPEED_HIGH ?
@@ -1029,7 +1032,7 @@ static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg, idx);if (rc <0 )return ; - idx =dwc2_desclist_idx_inc (idx, qh->interval, + idx =dwc2_desclist_idx_inc (idx, qh->host_interval, chan->speed);if (!rc)continue ;
@@ -1039,7 +1042,7 @@ static void dwc2_complete_isoc_xfer_ddma(struct dwc2_hsotg *hsotg,/* rc == DWC2_CMPL_STOP */ -if (qh->interval >=32 ) +if (qh->host_interval >=32 ) goto stop_scan; qh->td_first = idx;
drivers/usb/dwc2/hcd_intr.c +6 -4
@@ -138,9 +138,11 @@ static void dwc2_sof_intr(struct dwc2_hsotg *hsotg)while (qh_entry != &hsotg->periodic_sched_inactive) { qh = list_entry(qh_entry, struct dwc2_qh, qh_list_entry); qh_entry = qh_entry->next; -if (dwc2_frame_num_le (qh->sched_frame, hsotg->frame_number)) { -dwc2_sch_vdbg (hsotg,"QH=%p ready fn=%04x, sch=%04x\n" , - qh, hsotg->frame_number, qh->sched_frame); +if (dwc2_frame_num_le (qh->next_active_frame, + hsotg->frame_number)) { +dwc2_sch_vdbg (hsotg,"QH=%p ready fn=%04x, nxt=%04x\n" , + qh, hsotg->frame_number, + qh->next_active_frame);/* * Move QH to the ready list to be executed next
@@ -1350,7 +1352,7 @@ static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,int frnum =dwc2_hcd_get_frame_number (hsotg);if (dwc2_full_frame_num (frnum) != -dwc2_full_frame_num (chan->qh->sched_frame)) { +dwc2_full_frame_num (chan->qh->next_active_frame)) {/* * No longer in the same full speed frame. * Treat this as a transaction error.
drivers/usb/dwc2/hcd_queue.c +54 -53
229 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 13/21 usb: dwc2: host: Reorder things in hcd_queue.c
In reply to Douglas AndersonThis no-op change just reorders a few functions in hcd_queue.c in order to prepare for future changes. Motivations here:
The functions dwc2_hcd_qh_free() and dwc2_hcd_qh_create() are exported functions. They are not called within the file. That means that they should be near the bottom so that they can easily call static helpers.
The function dwc2_qh_init() is only called by dwc2_hcd_qh_create() and should move near the bottom with it.
The only reason that the dwc2_unreserve_timer_fn() timer function (and its subroutine dwc2_do_unreserve()) were so high in the file was that they needed to be above dwc2_qh_init(). Now that dwc2_qh_init() has been moved down it can be moved down a bit. A later patch will split the reserve code out of dwc2_schedule_periodic() and the reserve function should be near the unreserve function. The reserve function needs to be below dwc2_find_uframe() since it calls that.
---
Changes in v4:
- Reorder things in hcd_queue.c new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd_queue.c | 600 +++++++++++++++++++++---------------------- 1 file changed, 300 insertions(+), 300 deletions(-)
drivers/usb/dwc2/hcd_queue.c +300 -300
@@ -57,295 +57,6 @@#define DWC2_UNRESERVE_DELAY (msecs_to_jiffies(5))/** -* dwc2_do_unreserve() - Actually release the periodic reservation -* -* This function actually releases the periodic bandwidth that was reserved -* by the given qh. -* -* @hsotg: The HCD state structure for the DWC OTG controller -* @qh: QH for the periodic transfer. -*/ -static void dwc2_do_unreserve (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) -{ -assert_spin_locked (&hsotg->lock); - -WARN_ON (!qh->unreserve_pending); - -/* No more unreserve pending--we're doing it */ - qh->unreserve_pending = false; - -if (WARN_ON (!list_empty (&qh->qh_list_entry))) -list_del_init (&qh->qh_list_entry); - -/* Update claimed usecs per (micro)frame */ - hsotg->periodic_usecs -= qh->host_us; - -if (hsotg->core_params->uframe_sched >0 ) { -int i; - -for (i =0 ; i <8 ; i++) { - hsotg->frame_usecs[i] += qh->frame_usecs[i]; - qh->frame_usecs[i] =0 ; - } - }else { -/* Release periodic channel reservation */ - hsotg->periodic_channels--; - } -} - -/** -* dwc2_unreserve_timer_fn() - Timer function to release periodic reservation -* -* According to the kernel doc for usb_submit_urb() (specifically the part about -* "Reserved Bandwidth Transfers"), we need to keep a reservation active as -* long as a device driver keeps submitting. Since we're using HCD_BH to give -* back the URB we need to give the driver a little bit of time before we -* release the reservation. This worker is called after the appropriate -* delay. -* -* @work: Pointer to a qh unreserve_work. -*/ -static void dwc2_unreserve_timer_fn (unsigned long data) -{ -struct dwc2_qh *qh = (struct dwc2_qh *)data; -struct dwc2_hsotg *hsotg = qh->hsotg; -unsigned long flags; - -/* -* Wait for the lock, or for us to be scheduled again. We -* could be scheduled again if: -* - We started executing but didn't get the lock yet. -* - A new reservation came in, but cancel didn't take effect -* because we already started executing. -* - The timer has been kicked again. -* In that case cancel and wait for the next call. -*/ -while (!spin_trylock_irqsave (&hsotg->lock, flags)) { -if (timer_pending (&qh->unreserve_timer)) -return ; - } - -/* -* Might be no more unreserve pending if: -* - We started executing but didn't get the lock yet. -* - A new reservation came in, but cancel didn't take effect -* because we already started executing. -* -* We can't put this in the loop above because unreserve_pending needs -* to be accessed under lock, so we can only check it once we got the -* lock. -*/ -if (qh->unreserve_pending) -dwc2_do_unreserve (hsotg, qh); - -spin_unlock_irqrestore (&hsotg->lock, flags); -} - -/** -* dwc2_qh_init() - Initializes a QH structure -* -* @hsotg: The HCD state structure for the DWC OTG controller -* @qh: The QH to init -* @urb: Holds the information about the device/endpoint needed to initialize -* the QH -*/ -#define SCHEDULE_SLOP 10 -static void dwc2_qh_init (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh, -struct dwc2_hcd_urb *urb) -{ -int dev_speed, hub_addr, hub_port; -char *speed, *type; - -dev_vdbg (hsotg->dev,"%s()\n" , __func__); - -/* Initialize QH */ - qh->hsotg = hsotg; -setup_timer (&qh->unreserve_timer, dwc2_unreserve_timer_fn, - (unsigned long )qh); - qh->ep_type =dwc2_hcd_get_pipe_type (&urb->pipe_info); - qh->ep_is_in =dwc2_hcd_is_pipe_in (&urb->pipe_info) ?1 :0 ; - - qh->data_toggle =DWC2_HC_PID_DATA0 ; - qh->maxp =dwc2_hcd_get_mps (&urb->pipe_info); -INIT_LIST_HEAD (&qh->qtd_list); -INIT_LIST_HEAD (&qh->qh_list_entry); - -/* FS/LS Endpoint on HS Hub, NOT virtual root hub */ - dev_speed =dwc2_host_get_speed (hsotg, urb->priv); - -dwc2_host_hub_info (hsotg, urb->priv, &hub_addr, &hub_port); - -if ((dev_speed ==USB_SPEED_LOW || dev_speed ==USB_SPEED_FULL ) && - hub_addr !=0 && hub_addr !=1 ) { -dev_vdbg (hsotg->dev, -"QH init: EP %d: TT found at hub addr %d, for port %d\n" , -dwc2_hcd_get_ep_num (&urb->pipe_info), hub_addr, - hub_port); - qh->do_split =1 ; - } - -if (qh->ep_type ==USB_ENDPOINT_XFER_INT || - qh->ep_type ==USB_ENDPOINT_XFER_ISOC ) { -/* Compute scheduling parameters once and save them */ -u32 hprt, prtspd; - -/* Todo: Account for split transfers in the bus time */ -int bytecount = -dwc2_hb_mult (qh->maxp) *dwc2_max_packet (qh->maxp); - - qh->host_us =NS_TO_US (usb_calc_bus_time (qh->do_split ? -USB_SPEED_HIGH : dev_speed, qh->ep_is_in, - qh->ep_type ==USB_ENDPOINT_XFER_ISOC , - bytecount)); - -/* Ensure frame_number corresponds to the reality */ - hsotg->frame_number =dwc2_hcd_get_frame_number (hsotg); -/* Start in a slightly future (micro)frame */ - qh->next_active_frame =dwc2_frame_num_inc (hsotg->frame_number, -SCHEDULE_SLOP ); - qh->host_interval = urb->interval; -dwc2_sch_dbg (hsotg,"QH=%p init nxt=%04x, fn=%04x, int=%#x\n" , - qh, qh->next_active_frame, hsotg->frame_number, - qh->host_interval); -#if 0 -/* Increase interrupt polling rate for debugging */ -if (qh->ep_type ==USB_ENDPOINT_XFER_INT ) - qh->host_interval =8 ; -#endif - hprt =dwc2_readl (hsotg->regs +HPRT0 ); - prtspd = (hprt &HPRT0_SPD_MASK ) >>HPRT0_SPD_SHIFT ; -if (prtspd ==HPRT0_SPD_HIGH_SPEED && - (dev_speed ==USB_SPEED_LOW || - dev_speed ==USB_SPEED_FULL )) { - qh->host_interval *=8 ; - qh->next_active_frame |=0x7 ; - qh->start_split_frame = qh->next_active_frame; -dwc2_sch_dbg (hsotg, -"QH=%p init*8 nxt=%04x, fn=%04x, int=%#x\n" , - qh, qh->next_active_frame, - hsotg->frame_number, qh->host_interval); - - } -dev_dbg (hsotg->dev,"interval=%d\n" , qh->host_interval); - } - -dev_vdbg (hsotg->dev,"DWC OTG HCD QH Initialized\n" ); -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - qh = %p\n" , qh); -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Device Address = %d\n" , -dwc2_hcd_get_dev_addr (&urb->pipe_info)); -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Endpoint %d, %s\n" , -dwc2_hcd_get_ep_num (&urb->pipe_info), -dwc2_hcd_is_pipe_in (&urb->pipe_info) ?"IN" :"OUT" ); - - qh->dev_speed = dev_speed; - -switch (dev_speed) { -case USB_SPEED_LOW : - speed ="low" ; -break ; -case USB_SPEED_FULL : - speed ="full" ; -break ; -case USB_SPEED_HIGH : - speed ="high" ; -break ; -default : - speed ="?" ; -break ; - } -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Speed = %s\n" , speed); - -switch (qh->ep_type) { -case USB_ENDPOINT_XFER_ISOC : - type ="isochronous" ; -break ; -case USB_ENDPOINT_XFER_INT : - type ="interrupt" ; -break ; -case USB_ENDPOINT_XFER_CONTROL : - type ="control" ; -break ; -case USB_ENDPOINT_XFER_BULK : - type ="bulk" ; -break ; -default : - type ="?" ; -break ; - } - -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Type = %s\n" , type); - -if (qh->ep_type ==USB_ENDPOINT_XFER_INT ) { -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - usecs = %d\n" , - qh->host_us); -dev_vdbg (hsotg->dev,"DWC OTG HCD QH - interval = %d\n" , - qh->host_interval); - } -} - -/** -* dwc2_hcd_qh_create() - Allocates and initializes a QH -* -* @hsotg: The HCD state structure for the DWC OTG controller -* @urb: Holds the information about the device/endpoint needed -* to initialize the QH -* @atomic_alloc: Flag to do atomic allocation if needed -* -* Return: Pointer to the newly allocated QH, or NULL on error -*/ -struct dwc2_qh *dwc2_hcd_qh_create (struct dwc2_hsotg *hsotg, -struct dwc2_hcd_urb *urb, -gfp_t mem_flags) -{ -struct dwc2_qh *qh; - -if (!urb->priv) -return NULL ; - -/* Allocate memory */ - qh =kzalloc (sizeof (*qh), mem_flags); -if (!qh) -return NULL ; - -dwc2_qh_init (hsotg, qh, urb); - -if (hsotg->core_params->dma_desc_enable >0 && -dwc2_hcd_qh_init_ddma (hsotg, qh, mem_flags) <0 ) { -dwc2_hcd_qh_free (hsotg, qh); -return NULL ; - } - -return qh; -} - -/** -* dwc2_hcd_qh_free() - Frees the QH -* -* @hsotg: HCD instance -* @qh: The QH to free -* -* QH should already be removed from the list. QTD list should already be empty -* if called from URB Dequeue. -* -* Must NOT be called with interrupt disabled or spinlock held -*/ -void dwc2_hcd_qh_free (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) -{ -/* Make sure any unreserve work is finished. */ -if (del_timer_sync (&qh->unreserve_timer)) { -unsigned long flags; - -spin_lock_irqsave (&hsotg->lock, flags); -dwc2_do_unreserve (hsotg, qh); -spin_unlock_irqrestore (&hsotg->lock, flags); - } - -if (qh->desc_list) -dwc2_hcd_qh_free_ddma (hsotg, qh); -kfree (qh); -} - -/** * dwc2_periodic_channel_available() - Checks that a channel is available for a * periodic transfer *
@@ -518,19 +229,104 @@ static int dwc2_find_multi_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)static int dwc2_find_uframe (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) { -int ret; +int ret; + +if (qh->dev_speed ==USB_SPEED_HIGH ) { +/* if this is a hs transaction we need a full frame */ + ret =dwc2_find_single_uframe (hsotg, qh); + }else { +/* +* if this is a fs transaction we may need a sequence +* of frames +*/ + ret =dwc2_find_multi_uframe (hsotg, qh); + } +return ret; +} + +/** +* dwc2_do_unreserve() - Actually release the periodic reservation +* +* This function actually releases the periodic bandwidth that was reserved +* by the given qh. +* +* @hsotg: The HCD state structure for the DWC OTG controller +* @qh: QH for the periodic transfer. +*/ +static void dwc2_do_unreserve (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) +{ +assert_spin_locked (&hsotg->lock); + +WARN_ON (!qh->unreserve_pending); + +/* No more unreserve pending--we're doing it */ + qh->unreserve_pending = false; + +if (WARN_ON (!list_empty (&qh->qh_list_entry))) +list_del_init (&qh->qh_list_entry); + +/* Update claimed usecs per (micro)frame */ + hsotg->periodic_usecs -= qh->host_us; + +if (hsotg->core_params->uframe_sched >0 ) { +int i; + +for (i =0 ; i <8 ; i++) { + hsotg->frame_usecs[i] += qh->frame_usecs[i]; + qh->frame_usecs[i] =0 ; + } + }else { +/* Release periodic channel reservation */ + hsotg->periodic_channels--; + } +} + +/** +* dwc2_unreserve_timer_fn() - Timer function to release periodic reservation +* +* According to the kernel doc for usb_submit_urb() (specifically the part about +* "Reserved Bandwidth Transfers"), we need to keep a reservation active as +* long as a device driver keeps submitting. Since we're using HCD_BH to give +* back the URB we need to give the driver a little bit of time before we +* release the reservation. This worker is called after the appropriate +* delay. +* +* @work: Pointer to a qh unreserve_work. +*/ +static void dwc2_unreserve_timer_fn (unsigned long data) +{ +struct dwc2_qh *qh = (struct dwc2_qh *)data; +struct dwc2_hsotg *hsotg = qh->hsotg; +unsigned long flags; -if (qh->dev_speed ==USB_SPEED_HIGH ) { -/* if this is a hs transaction we need a full frame */ - ret =dwc2_find_single_uframe (hsotg, qh); - }else { -/* -* if this is a fs transaction we may need a sequence -* of frames -*/ - ret =dwc2_find_multi_uframe (hsotg, qh); +/* +* Wait for the lock, or for us to be scheduled again. We +* could be scheduled again if: +* - We started executing but didn't get the lock yet. +* - A new reservation came in, but cancel didn't take effect +* because we already started executing. +* - The timer has been kicked again. +* In that case cancel and wait for the next call. +*/ +while (!spin_trylock_irqsave (&hsotg->lock, flags)) { +if (timer_pending (&qh->unreserve_timer)) +return ; } -return ret; + +/* +* Might be no more unreserve pending if: +* - We started executing but didn't get the lock yet. +* - A new reservation came in, but cancel didn't take effect +* because we already started executing. +* +* We can't put this in the loop above because unreserve_pending needs +* to be accessed under lock, so we can only check it once we got the +* lock. +*/ +if (qh->unreserve_pending) +dwc2_do_unreserve (hsotg, qh); + +spin_unlock_irqrestore (&hsotg->lock, flags); }/**
@@ -695,6 +491,210 @@ static void dwc2_deschedule_periodic(struct dwc2_hsotg *hsotg, }/** +* dwc2_qh_init() - Initializes a QH structure +* +* @hsotg: The HCD state structure for the DWC OTG controller +* @qh: The QH to init +* @urb: Holds the information about the device/endpoint needed to initialize +* the QH +*/ +#define SCHEDULE_SLOP 10 +static void dwc2_qh_init (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh, +struct dwc2_hcd_urb *urb) +{ +int dev_speed, hub_addr, hub_port; +char *speed, *type; + +dev_vdbg (hsotg->dev,"%s()\n" , __func__); + +/* Initialize QH */ + qh->hsotg = hsotg; +setup_timer (&qh->unreserve_timer, dwc2_unreserve_timer_fn, + (unsigned long )qh); + qh->ep_type =dwc2_hcd_get_pipe_type (&urb->pipe_info); + qh->ep_is_in =dwc2_hcd_is_pipe_in (&urb->pipe_info) ?1 :0 ; + + qh->data_toggle =DWC2_HC_PID_DATA0 ; + qh->maxp =dwc2_hcd_get_mps (&urb->pipe_info); +INIT_LIST_HEAD (&qh->qtd_list); +INIT_LIST_HEAD (&qh->qh_list_entry); + +/* FS/LS Endpoint on HS Hub, NOT virtual root hub */ + dev_speed =dwc2_host_get_speed (hsotg, urb->priv); + +dwc2_host_hub_info (hsotg, urb->priv, &hub_addr, &hub_port); + +if ((dev_speed ==USB_SPEED_LOW || dev_speed ==USB_SPEED_FULL ) && + hub_addr !=0 && hub_addr !=1 ) { +dev_vdbg (hsotg->dev, +"QH init: EP %d: TT found at hub addr %d, for port %d\n" , +dwc2_hcd_get_ep_num (&urb->pipe_info), hub_addr, + hub_port); + qh->do_split =1 ; + } + +if (qh->ep_type ==USB_ENDPOINT_XFER_INT || + qh->ep_type ==USB_ENDPOINT_XFER_ISOC ) { +/* Compute scheduling parameters once and save them */ +u32 hprt, prtspd; + +/* Todo: Account for split transfers in the bus time */ +int bytecount = +dwc2_hb_mult (qh->maxp) *dwc2_max_packet (qh->maxp); + + qh->host_us =NS_TO_US (usb_calc_bus_time (qh->do_split ? +USB_SPEED_HIGH : dev_speed, qh->ep_is_in, + qh->ep_type ==USB_ENDPOINT_XFER_ISOC , + bytecount)); + +/* Ensure frame_number corresponds to the reality */ + hsotg->frame_number =dwc2_hcd_get_frame_number (hsotg); +/* Start in a slightly future (micro)frame */ + qh->next_active_frame =dwc2_frame_num_inc (hsotg->frame_number, +SCHEDULE_SLOP ); + qh->host_interval = urb->interval; +dwc2_sch_dbg (hsotg,"QH=%p init nxt=%04x, fn=%04x, int=%#x\n" , + qh, qh->next_active_frame, hsotg->frame_number, + qh->host_interval); +#if 0 +/* Increase interrupt polling rate for debugging */ +if (qh->ep_type ==USB_ENDPOINT_XFER_INT ) + qh->host_interval =8 ; +#endif + hprt =dwc2_readl (hsotg->regs +HPRT0 ); + prtspd = (hprt &HPRT0_SPD_MASK ) >>HPRT0_SPD_SHIFT ; +if (prtspd ==HPRT0_SPD_HIGH_SPEED && + (dev_speed ==USB_SPEED_LOW || + dev_speed ==USB_SPEED_FULL )) { + qh->host_interval *=8 ; + qh->next_active_frame |=0x7 ; + qh->start_split_frame = qh->next_active_frame; +dwc2_sch_dbg (hsotg, +"QH=%p init*8 nxt=%04x, fn=%04x, int=%#x\n" , + qh, qh->next_active_frame, + hsotg->frame_number, qh->host_interval); + + } +dev_dbg (hsotg->dev,"interval=%d\n" , qh->host_interval); + } + +dev_vdbg (hsotg->dev,"DWC OTG HCD QH Initialized\n" ); +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - qh = %p\n" , qh); +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Device Address = %d\n" , +dwc2_hcd_get_dev_addr (&urb->pipe_info)); +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Endpoint %d, %s\n" , +dwc2_hcd_get_ep_num (&urb->pipe_info), +dwc2_hcd_is_pipe_in (&urb->pipe_info) ?"IN" :"OUT" ); + + qh->dev_speed = dev_speed; + +switch (dev_speed) { +case USB_SPEED_LOW : + speed ="low" ; +break ; +case USB_SPEED_FULL : + speed ="full" ; +break ; +case USB_SPEED_HIGH : + speed ="high" ; +break ; +default : + speed ="?" ; +break ; + } +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Speed = %s\n" , speed); + +switch (qh->ep_type) { +case USB_ENDPOINT_XFER_ISOC : + type ="isochronous" ; +break ; +case USB_ENDPOINT_XFER_INT : + type ="interrupt" ; +break ; +case USB_ENDPOINT_XFER_CONTROL : + type ="control" ; +break ; +case USB_ENDPOINT_XFER_BULK : + type ="bulk" ; +break ; +default : + type ="?" ; +break ; + } + +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - Type = %s\n" , type); + +if (qh->ep_type ==USB_ENDPOINT_XFER_INT ) { +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - usecs = %d\n" , + qh->host_us); +dev_vdbg (hsotg->dev,"DWC OTG HCD QH - interval = %d\n" , + qh->host_interval); + } +} + +/** +* dwc2_hcd_qh_create() - Allocates and initializes a QH +* +* @hsotg: The HCD state structure for the DWC OTG controller +* @urb: Holds the information about the device/endpoint needed +* to initialize the QH +* @atomic_alloc: Flag to do atomic allocation if needed +* +* Return: Pointer to the newly allocated QH, or NULL on error +*/ +struct dwc2_qh *dwc2_hcd_qh_create (struct dwc2_hsotg *hsotg, +struct dwc2_hcd_urb *urb, +gfp_t mem_flags) +{ +struct dwc2_qh *qh; + +if (!urb->priv) +return NULL ; + +/* Allocate memory */ + qh =kzalloc (sizeof (*qh), mem_flags); +if (!qh) +return NULL ; + +dwc2_qh_init (hsotg, qh, urb); + +if (hsotg->core_params->dma_desc_enable >0 && +dwc2_hcd_qh_init_ddma (hsotg, qh, mem_flags) <0 ) { +dwc2_hcd_qh_free (hsotg, qh); +return NULL ; + } + +return qh; +} + +/** +* dwc2_hcd_qh_free() - Frees the QH +* +* @hsotg: HCD instance +* @qh: The QH to free +* +* QH should already be removed from the list. QTD list should already be empty +* if called from URB Dequeue. +* +* Must NOT be called with interrupt disabled or spinlock held +*/ +void dwc2_hcd_qh_free (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) +{ +/* Make sure any unreserve work is finished. */ +if (del_timer_sync (&qh->unreserve_timer)) { +unsigned long flags; + +spin_lock_irqsave (&hsotg->lock, flags); +dwc2_do_unreserve (hsotg, qh); +spin_unlock_irqrestore (&hsotg->lock, flags); + } + +if (qh->desc_list) +dwc2_hcd_qh_free_ddma (hsotg, qh); +kfree (qh); +} + +/** * dwc2_hcd_qh_add() - Adds a QH to either the non periodic or periodic * schedule if it is not already in the schedule. If the QH is already in * the schedule, no action is taken.
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 14/21 usb: dwc2: host: Split code out to make dwc2_do_reserve()
In reply to Douglas AndersonThis no-op change splits code out of dwc2_schedule_periodic() into a dwc2_do_reserve() function. This makes it a little easier to follow the logic.
---
Changes in v4:
- Split code out to make dwc2_do_reserve() new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd_queue.c | 112 ++++++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 45 deletions(-)
drivers/usb/dwc2/hcd_queue.c +67 -45
@@ -245,6 +245,70 @@ static int dwc2_find_uframe(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh) }/** +* dwc2_do_reserve() - Make a periodic reservation +* +* Try to allocate space in the periodic schedule. Depending on parameters +* this might use the microframe scheduler or the dumb scheduler. +* +* @hsotg: The HCD state structure for the DWC OTG controller +* @qh: QH for the periodic transfer. +* +* Returns: 0 upon success; error upon failure. +*/ +static int dwc2_do_reserve (struct dwc2_hsotg *hsotg,struct dwc2_qh *qh) +{ +int status; + +if (hsotg->core_params->uframe_sched >0 ) { +int frame =-1 ; + + status =dwc2_find_uframe (hsotg, qh); +if (status ==0 ) + frame =7 ; +else if (status >0 ) + frame = status -1 ; + +/* Set the new frame up */ +if (frame >=0 ) { + qh->next_active_frame &= ~0x7 ; + qh->next_active_frame |= (frame &7 ); +dwc2_sch_dbg (hsotg, +"QH=%p sched_p nxt=%04x, uf=%d\n" , + qh, qh->next_active_frame, frame); + } + +if (status >0 ) + status =0 ; + }else { + status =dwc2_periodic_channel_available (hsotg); +if (status) { +dev_info (hsotg->dev, +"%s: No host channel available for periodic transfer\n" , + __func__); +return status; + } + + status =dwc2_check_periodic_bandwidth (hsotg, qh); + } + +if (status) { +dev_dbg (hsotg->dev, +"%s: Insufficient periodic bandwidth for periodic transfer\n" , + __func__); +return status; + } + +if (hsotg->core_params->uframe_sched <=0 ) +/* Reserve periodic channel */ + hsotg->periodic_channels++; + +/* Update claimed usecs per (micro)frame */ + hsotg->periodic_usecs += qh->host_us; + +return 0 ; +} + +/** * dwc2_do_unreserve() - Actually release the periodic reservation * * This function actually releases the periodic bandwidth that was reserved
@@ -393,51 +457,9 @@ static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)* that case. */ if (!qh->unreserve_pending) { -if (hsotg->core_params->uframe_sched >0 ) { -int frame =-1 ; - - status =dwc2_find_uframe (hsotg, qh); -if (status ==0 ) - frame =7 ; -else if (status >0 ) - frame = status -1 ; - -/* Set the new frame up */ -if (frame >=0 ) { - qh->next_active_frame &= ~0x7 ; - qh->next_active_frame |= (frame &7 ); -dwc2_sch_dbg (hsotg, -"QH=%p sched_p nxt=%04x, uf=%d\n" , - qh, qh->next_active_frame, frame); - } - -if (status >0 ) - status =0 ; - }else { - status =dwc2_periodic_channel_available (hsotg); -if (status) { -dev_info (hsotg->dev, -"%s: No host channel available for periodic transfer\n" , - __func__); -return status; - } - - status =dwc2_check_periodic_bandwidth (hsotg, qh); - } - -if (status) { -dev_dbg (hsotg->dev, -"%s: Insufficient periodic bandwidth for periodic transfer\n" , - __func__); + status =dwc2_do_reserve (hsotg, qh); +if (status)return status; - } - -if (hsotg->core_params->uframe_sched <=0 ) -/* Reserve periodic channel */ - hsotg->periodic_channels++; - -/* Update claimed usecs per (micro)frame */ - hsotg->periodic_usecs += qh->host_us; } qh->unreserve_pending =0 ;
@@ -450,7 +472,7 @@ static int dwc2_schedule_periodic(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh)list_add_tail (&qh->qh_list_entry, &hsotg->periodic_sched_inactive); -return status; +return 0 ; }/**
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 15/21 usb: dwc2: host: Add scheduler logging for missed SOFs
In reply to Douglas AndersonWe'll use the new "scheduler verbose debugging" macro to log missed SOFs. This is fast enough (assuming you configure it to use the ftrace buffer) that we can do it without worrying about the speed hit. The overhead hit if the scheduler tracing is set to "no_printk" should be near zero.
---
Changes in v4:
- Add scheduler logging for missed SOFs new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/core.h | 3 ++- drivers/usb/dwc2/hcd.c | 2 +- drivers/usb/dwc2/hcd_intr.c | 12 ++++++++---- 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/usb/dwc2/core.h +2 -1
@@ -809,9 +809,10 @@ struct dwc2_hsotg {bool bus_suspended;bool new_connection; +u16 last_frame_num; +#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS #define FRAME_NUM_ARRAY_SIZE 1000 -u16 last_frame_num;u16 *frame_num_array;u16 *last_frame_num_array;int frame_num_idx;
drivers/usb/dwc2/hcd.c +1 -1
@@ -3077,8 +3077,8 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq) FRAME_NUM_ARRAY_SIZE, GFP_KERNEL);if (!hsotg->last_frame_num_array) goto error1; - hsotg->last_frame_num =HFNUM_MAX_FRNUM ;#endif + hsotg->last_frame_num =HFNUM_MAX_FRNUM ;/* Check if the bus driver or platform code has setup a dma_mask */ if (hsotg->core_params->dma_enable > 0 &&
drivers/usb/dwc2/hcd_intr.c +8 -4
@@ -55,12 +55,16 @@/* This function is for debug only */ static void dwc2_track_missed_sofs (struct dwc2_hsotg *hsotg) { -#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS u16 curr_frame_number = hsotg->frame_number; +u16 expected =dwc2_frame_num_inc (hsotg->last_frame_num,1 ); + +if (expected != curr_frame_number) +dwc2_sch_vdbg (hsotg,"MISSED SOF %04x != %04x\n" , + expected, curr_frame_number); +#ifdef CONFIG_USB_DWC2_TRACK_MISSED_SOFS if (hsotg->frame_num_idx <FRAME_NUM_ARRAY_SIZE ) { -if (((hsotg->last_frame_num +1 ) &HFNUM_MAX_FRNUM ) != - curr_frame_number) { +if (expected != curr_frame_number) { hsotg->frame_num_array[hsotg->frame_num_idx] = curr_frame_number; hsotg->last_frame_num_array[hsotg->frame_num_idx] =
@@ -79,8 +83,8 @@ static void dwc2_track_missed_sofs(struct dwc2_hsotg *hsotg) } hsotg->dumped_frame_num_array =1 ; } - hsotg->last_frame_num = curr_frame_number;#endif + hsotg->last_frame_num = curr_frame_number; } static void dwc2_hc_handle_tt_clear(struct dwc2_hsotg *hsotg,
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 16/21 usb: dwc2: host: Manage frame nums better in scheduler
In reply to Douglas AndersonThe dwc2 scheduler (contained in hcd_queue.c) was a bit confusing in the way it initted / kept track of which frames a QH was going to be active in. Let's clean things up a little bit in preparation for a rewrite of the microframe scheduler.
Specifically:
* Old code would pick a frame number in dwc2_qh_init() and would try to pick it "in a slightly future (micro)frame". As far as I can tell the reason for this was that there was a delay between dwc2_qh_init() and when we actually wanted to dwc2_hcd_qh_add(). ...but apparently this attempt to be slightly in the future wasn't enough because dwc2_hcd_qh_add() then had code to reset things if the frame _wasn't_ in the future. There's no reason not to just pick the frame later. For non-periodic QH we now pick the frame in dwc2_hcd_qh_add(). For periodic QH we pick the frame at dwc2_schedule_periodic() time.
* The old "dwc2_qh_init() actually assigned to "hsotg->frame_number". This doesn't seem like a great idea since that variable is supposed to be used to keep track of which SOF the interrupt handler has seen. Let's be clean: anyone who wants the current frame number (instead of the one as of the last interrupt) should ask for it.
* The old code wasn't terribly consistent about trying to use the frame that the microframe scheduler assigned to it. In dwc2_sched_periodic_split() when it was scheduling the first frame it always "ORed" in 0x7 (!). Since the frame goes on the wire 1 uFrame after next_active_frame it meant that the SSPLIT would always try for uFrame 0 and the transaction would happen on the low speed bus during uFrame 1. This is irregardless of what the microframe scheduler said.
* The old code assumed it would get called to schedule the next in a periodic split very quickly. That is if next_active_frame was 0 (transfer on wire in uFrame 1) it assumed it was getting called to schedule the next uFrame during uFrame 1 too (so it could queue something up for uFrame 2). It should be possible to actually queue something up for uFrame 2 while in uFrame 2 (AKA queue up ASAP). To do this, code needs to look at the previously scheduled frame when deciding when to next be active, not look at the current frame number.
* If there was no microframe scheduler, the old code would check for whether we should be active using "qh->next_active_frame == frame_number". This seemed like a race waiting to happen. ...plus there's no way that you wouldn't want to schedule if next_active_frame was actually less than frame number.
Note that this change doesn't make 100% sense on its own since it's expecting some sanity in the frame numbers assigned by the microframe scheduler and (as per the future patch which rewries it) I think that the current microframe scheduler is quite insane. However, it seems like splitting this up from the microframe scheduler patch makes things into smaller chunks and hopefully adds to clarity rather than reduces it. The two patches could certainly be squashed. Not that in the very least, I don't see any obvious bad behavior introduced with just this patch.
I've attempted to keep the config parameter to disable the microframe scheduler in tact in this change, though I'm not sure it's worth it. Obviously the code is touched a lot so it's possible I regressed something when the microframe scheduler is disabled, though I did some basic testing and it seemed to work OK. I'm still not 100% sure why you wouldn't want the microframe scheduler (presuming it works), so maybe a future patch (or a future version of this patch?) could remove that parameter.
---
Changes in v4:
- Manage frame nums better in scheduler new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd.h | 10 +- drivers/usb/dwc2/hcd_queue.c | 355 ++++++++++++++++++++++++++++++++----------- 2 files changed, 273 insertions(+), 92 deletions(-)
drivers/usb/dwc2/hcd.h +7 -3
@@ -244,8 +244,11 @@ enum dwc2_transaction_type {* the bus. We'll move the qh to active here. If the * host is in high speed mode this will be a uframe. If * the host is in low speed mode this will be a full frame. +* @start_active_frame: If we are partway through a split transfer, this will be +* what next_active_frame was when we started. Otherwise +* it should always be the same as next_active_frame. +* @assigned_uframe: The uframe (0 -7) assigned by dwc2_find_uframe(). * @frame_usecs: Internal variable used by the microframe scheduler -* @start_split_frame: (Micro)frame at which last start split was initialized * @ntd: Actual number of transfer descriptors in a list * @qtd_list: List of QTDs for this QH * @channel: Host channel currently processing transfers for this QH
@@ -279,8 +282,9 @@ struct dwc2_qh {u16 host_us;u16 host_interval;u16 next_active_frame; +u16 start_active_frame; +u16 assigned_uframe;u16 frame_usecs[8 ]; -u16 start_split_frame;u16 ntd;struct list_head qtd_list;struct dwc2_host_chan *channel;
@@ -746,7 +750,7 @@ do { \ _qtd_ = list_entry((_qh_)->qtd_list.next, struct dwc2_qtd, \ qtd_list_entry); \if (usb_pipeint (_qtd_->urb->pipe) && \ - (_qh_)->start_split_frame !=0 && !_qtd_->complete_split) { \ + (_qh_)->start_active_frame !=0 && !_qtd_->complete_split) { \ _hfnum_.d32 =dwc2_readl ((_hcd_)->regs +HFNUM ); \switch (_hfnum_.b.frnum &0x7 ) { \case 7 : \
drivers/usb/dwc2/hcd_queue.c +266 -89
446 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 17/21 usb: dwc2: host: Schedule periodic right away if it's time
In reply to Douglas AndersonIn dwc2_hcd_qh_deactivate() we will put some things on the periodic_sched_ready list. These things won't be taken off the ready list until the next SOF, which might be a little late. Let's put them on right away.
---
Changes in v4:
- Schedule periodic right away if it's time new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd_queue.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/usb/dwc2/hcd_queue.c +16 -2
@@ -1078,12 +1078,26 @@ void dwc2_hcd_qh_deactivate(struct dwc2_hsotg *hsotg, struct dwc2_qh *qh,* Note: we purposely use the frame_number from the "hsotg" structure * since we know SOF interrupt will handle future frames. */ -if (dwc2_frame_num_le (qh->next_active_frame, hsotg->frame_number)) +if (dwc2_frame_num_le (qh->next_active_frame, hsotg->frame_number)) { +enum dwc2_transaction_type tr_type; + +/* +* We're bypassing the SOF handler which is normally what puts +* us on the ready list because we're in a hurry and need to +* try to catch up. +*/ +dwc2_sch_vdbg (hsotg,"QH=%p IMM ready fn=%04x, nxt=%04x\n" , + qh, frame_number, qh->next_active_frame);list_move_tail (&qh->qh_list_entry, &hsotg->periodic_sched_ready); -else + + tr_type =dwc2_hcd_select_transactions (hsotg); +if (tr_type !=DWC2_TRANSACTION_NONE ) +dwc2_hcd_queue_transactions (hsotg, tr_type); + }else {list_move_tail (&qh->qh_list_entry, &hsotg->periodic_sched_inactive); + } }/**
Signature · 6 lines
2.7.0.rc3.207.g0ac5344 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v4 18/21 usb: dwc2: host: Add dwc2_hcd_get_future_frame_number() call
In reply to Douglas AndersonAs we start getting more exact about our scheduling it's becoming more and more important to know exactly how far through the current frame we are. This lets us make decisions about whether there's still time left to start a new transaction in the current frame.
We'll add dwc2_hcd_get_future_frame_number() which will tell you what the frame number will be a certain number of microseconds (us) from now. We can use this information to help decide if there's enough time left in the frame for a transaction that will take a certain duration.
This is expected to be used by a future change ("usb: dwc2: host:
Properly set even/odd frame").
---
Changes in v4:
- Add dwc2_hcd_get_future_frame_number() call new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/core.h | 4 ++++ drivers/usb/dwc2/hcd.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
drivers/usb/dwc2/core.h +4 -0
@@ -1235,12 +1235,16 @@ static inline int dwc2_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,#if IS_ENABLED (CONFIG_USB_DWC2_HOST ) ||IS_ENABLED (CONFIG_USB_DWC2_DUAL_ROLE )extern int dwc2_hcd_get_frame_number (struct dwc2_hsotg *hsotg); +extern int dwc2_hcd_get_future_frame_number (struct dwc2_hsotg *hsotg,int us);extern void dwc2_hcd_connect (struct dwc2_hsotg *hsotg);extern void dwc2_hcd_disconnect (struct dwc2_hsotg *hsotg,bool force);extern void dwc2_hcd_start (struct dwc2_hsotg *hsotg);#else static inline int dwc2_hcd_get_frame_number (struct dwc2_hsotg *hsotg) {return 0 ; } +static inline int dwc2_hcd_get_future_frame_number (struct dwc2_hsotg *hsotg, +int us) +{return 0 ; }static inline void dwc2_hcd_connect (struct dwc2_hsotg *hsotg) {}static inline void dwc2_hcd_disconnect (struct dwc2_hsotg *hsotg,bool force) {}static inline void dwc2_hcd_start (struct dwc2_hsotg *hsotg) {}
drivers/usb/dwc2/hcd.c +29 -0
@@ -1942,6 +1942,35 @@ int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)return (hfnum &HFNUM_FRNUM_MASK ) >>HFNUM_FRNUM_SHIFT ; } +int dwc2_hcd_get_future_frame_number (struct dwc2_hsotg *hsotg,int us) +{ +u32 hprt =dwc2_readl (hsotg->regs +HPRT0 ); +u32 hfir =dwc2_readl (hsotg->regs +HFIR ); +u32 hfnum =dwc2_readl (hsotg->regs +HFNUM ); +unsigned int us_per_frame; +unsigned int frame_number; +unsigned int remaining; +unsigned int interval; +unsigned int phy_clks; + +/* High speed has 125 us per (micro) frame; others are 1 ms per */ + us_per_frame = (hprt &HPRT0_SPD_MASK ) ?1000 :125 ; + +/* Extract fields */ + frame_number = (hfnum &HFNUM_FRNUM_MASK ) >>HFNUM_FRNUM_SHIFT ; + remaining = (hfnum &HFNUM_FRREM_MASK ) >>HFNUM_FRREM_SHIFT ; + interval = (hfir &HFIR_FRINT_MASK ) >>HFIR_FRINT_SHIFT ; + +/* +* Number of phy clocks since the last tick of the frame number after +* "us" has passed. +*/ + phy_clks = (interval - remaining) + +DIV_ROUND_UP (interval * us, us_per_frame); + +return dwc2_frame_num_inc (frame_number, phy_clks / interval); +} +int dwc2_hcd_is_b_host (struct dwc2_hsotg *hsotg) {return hsotg->op_state ==OTG_STATE_B_HOST ;
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 19/21 usb: dwc2: host: Properly set even/odd frame
In reply to Douglas AndersonWhen setting up ISO and INT transfers dwc2 needs to specify whether the transfer is for an even or an odd frame (or microframe if the controller is running in high speed mode).
The controller appears to use this as a simple way to figure out if a transfer should happen right away (in the current microframe) or should happen at the start of the next microframe. Said another way:
- If you set "odd" and the current frame number is odd it appears that the controller will try to transfer right away. Same thing if you set "even" and the current frame number is even.
- If the oddness you set and the oddness of the frame number are _different_, the transfer will be delayed until the frame number changes.
As I understand it, the above technique allows you to plan ahead of time where possible by always working on the next frame. ...but it still allows you to properly respond immediately to things that happened in the previous frame.
The old dwc2_hc_set_even_odd_frame() didn't really handle this concept. It always looked at the frame number and setup the transfer to happen in the next frame. In some cases that meant that certain transactions would be transferred in the wrong frame.
We'll try our best to set the even / odd to do the transfer in the scheduled frame. If that fails then we'll do an ugly "schedule ASAP". We'll also modify the scheduler code to handle this and not try to schedule a second transfer for the same frame.
Note that this change relies on the work to redo the microframe scheduler. It can work atop ("usb: dwc2: host: Manage frame nums better in scheduler") but it works even better after ("usb: dwc2: host: Totally redo the microframe scheduler").
With this change my stressful USB test (USB webcam + USB audio + keyboards) has less audio crackling than before.
---
Changes in v4:
- Properly set even/odd frame new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/core.c | 92 +++++++++++++++++++++++++++++++++++++++++++- drivers/usb/dwc2/hcd_queue.c | 11 +++++- 2 files changed, 100 insertions(+), 3 deletions(-)
drivers/usb/dwc2/core.c +90 -2
@@ -1703,9 +1703,97 @@ static void dwc2_hc_set_even_odd_frame(struct dwc2_hsotg *hsotg, {if (chan->ep_type ==USB_ENDPOINT_XFER_INT || chan->ep_type ==USB_ENDPOINT_XFER_ISOC ) { -/* 1 if _next_ frame is odd, 0 if it's even */ -if (!(dwc2_hcd_get_frame_number (hsotg) &0x1 )) +int host_speed; +int xfer_ns; +int xfer_us; +int bytes_in_fifo; +u16 fifo_space; +u16 frame_number; +u16 wire_frame; + +/* +* Try to figure out if we're an even or odd frame. If we set +* even and the current frame number is even the the transfer +* will happen immediately. Similar if both are odd. If one is +* even and the other is odd then the transfer will happen when +* the frame number ticks. +* +* There's a bit of a balancing act to get this right. +* Sometimes we may want to send data in the current frame (AK +* right away). We might want to do this if the frame number +* _just_ ticked, but we might also want to do this in order +* to continue a split transaction that happened late in a +* microframe (so we didn't know to queue the next transfer +* until the frame number had ticked). The problem is that we +* need a lot of knowledge to know if there's actually still +* time to send things or if it would be better to wait until +* the next frame. +* +* We can look at how much time is left in the current frame +* and make a guess about whether we'll have time to transfer. +* We'll do that. +*/ + +/* Get speed host is running at */ + host_speed = (chan->speed !=USB_SPEED_HIGH && + !chan->do_split) ? chan->speed :USB_SPEED_HIGH ; + +/* See how many bytes are in the periodic FIFO right now */ + fifo_space = (dwc2_readl (hsotg->regs +HPTXSTS ) & +TXSTS_FSPCAVAIL_MASK ) >>TXSTS_FSPCAVAIL_SHIFT ; + bytes_in_fifo =sizeof (u32) * + (hsotg->core_params->host_perio_tx_fifo_size - + fifo_space); + +/* +* Roughly estimate bus time for everything in the periodic +* queue + our new transfer. This is "rough" because we're +* using a function that makes takes into account IN/OUT +* and INT/ISO and we're just slamming in one value for all +* transfers. This should be an over-estimate and that should +* be OK, but we can probably tighten it. +*/ + xfer_ns =usb_calc_bus_time (host_speed, false, false, + chan->xfer_len + bytes_in_fifo); + xfer_us =NS_TO_US (xfer_ns); + +/* See what frame number we'll be at by the time we finish */ + frame_number =dwc2_hcd_get_future_frame_number (hsotg, xfer_us); + +/* This is when we were scheduled to be on the wire */ + wire_frame =dwc2_frame_num_inc (chan->qh->next_active_frame,1 ); + +/* +* If we'd finish _after_ the frame we're scheduled in then +* it's hopeless. Just schedule right away and hope for the +* best. Note that it _might_ be wise to call back into the +* scheduler to pick a better frame, but this is better than +* nothing. +*/ +if (dwc2_frame_num_gt (frame_number, wire_frame)) { +dwc2_sch_vdbg (hsotg, +"QH=%p EO MISS fr=%04x=>%04x (%+d)\n" , + chan->qh, wire_frame, frame_number, +dwc2_frame_num_dec (frame_number, + wire_frame)); + wire_frame = frame_number; + +/* +* We picked a different frame number; communicate this +* back to the scheduler so it doesn't try to schedule +* another in the same frame. +* +* Remember that next_active_frame is 1 before the wire +* frame. +*/ + chan->qh->next_active_frame = +dwc2_frame_num_dec (frame_number,1 ); + } + +if (wire_frame &1 ) *hcchar |=HCCHAR_ODDFRM ; +else + *hcchar &= ~HCCHAR_ODDFRM ; } }
drivers/usb/dwc2/hcd_queue.c +10 -1
@@ -983,6 +983,14 @@ static int dwc2_next_periodic_start(struct dwc2_hsotg *hsotg,* and next_active_frame are always 1 frame before we want things * to be active and we assume we can still get scheduled in the * current frame number. +* - It's possible for start_active_frame (now incremented) to be +* next_active_frame if we got an EO MISS (even_odd miss) which +* basically means that we detected there wasn't enough time for +* the last packet and dwc2_hc_set_even_odd_frame() rescheduled us +* at the last second. We want to make sure we don't schedule +* another transfer for the same frame. My test webcam doesn't seem +* terribly upset by missing a transfer but really doesn't like when +* we do two transfers in the same frame. * - Some misses are expected. Specifically, in order to work * perfectly dwc2 really needs quite spectacular interrupt latency * requirements. It needs to be able to handle its interrupts
@@ -993,7 +1001,8 @@ static int dwc2_next_periodic_start(struct dwc2_hsotg *hsotg,* guarantee that a system will have interrupt latency < 125 us, so * we have to be robust to some misses. */ -if (dwc2_frame_num_gt (prev_frame_number, qh->start_active_frame)) { +if (qh->start_active_frame == qh->next_active_frame || +dwc2_frame_num_gt (prev_frame_number, qh->start_active_frame)) {u16 ideal_start = qh->start_active_frame;/* Adjust interval as per gcd with plan length. */
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 20/21 usb: dwc2: host: Totally redo the microframe scheduler
In reply to Douglas AndersonThis totally reimplements the microframe scheduler in dwc2 to attempt to handle periodic splits properly. The old code didn't even try, so this was a significant effort since periodic splits are one of the most complicated things in USB.
I've attempted to keep the old "don't use the microframe" schduler around for now, but not sure it's needed. It has also only been lightly tested.
I think it's pretty certain that this scheduler isn't perfect and might have some bugs, but it seems much better than what was there before. With this change my stressful USB test (USB webcam + USB audio + some keyboards) crackles less.
---
Changes in v4:
- Figured out what the microframe scheduler was supposed to do.
- Microframe rewrite is totally different from v3, hopefully more right.
- Microframe rewrite is later in the series now.
Changes in v3:
- The uframe scheduler patch is folded into optimization series.
- Optimize uframe scheduler "single uframe" case a little.
- uframe scheduler now atop logging patches.
- uframe scheduler now before delayed bandwidth release patches.
- Add defines like EARLY_FRAME_USEC
- Reorder dwc2_deschedule_periodic() in prep for future patches.
- uframe scheduler now shows real usefulness w/ future patches!
- Assuming single_tt is new for v3; not terribly well tested (yet).
- Keep track and use our uframe new for v3.
Changes in v2:
- Totally rewrote uframe scheduler again after writing test code.
- uframe scheduler atop delayed bandwidth release patches.
drivers/usb/dwc2/core.h | 86 ++- drivers/usb/dwc2/hcd.c | 87 ++- drivers/usb/dwc2/hcd.h | 79 ++- drivers/usb/dwc2/hcd_queue.c | 1208 +++++++++++++++++++++++++++++++++++------- 4 files changed, 1272 insertions(+), 188 deletions(-)
drivers/usb/dwc2/core.h +84 -2
@@ -682,7 +682,9 @@ struct dwc2_hregs_backup {* This value is in microseconds per (micro)frame. The * assumption is that all periodic transfers may occur in * the same (micro)frame. -* @frame_usecs: Internal variable used by the microframe scheduler +* @hs_periodic_bitmap: Bitmap used by the microframe scheduler any time the +* host is in high speed mode; low speed schedules are +* stored elsewhere since we need one per TT. * @frame_number: Frame number read from the core at SOF. The value ranges * from 0 to HFNUM_MAX_FRNUM. * @periodic_qh_count: Count of periodic QHs, if using several eps. Used for
@@ -780,6 +782,85 @@ struct dwc2_hsotg {#define DWC2_CORE_REV_3_00a 0x4f54300a #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE) + +/* + * Constants related to high speed periodic scheduling + * + * We have a periodic schedule that is DWC2_HS_SCHEDULE_UFRAMES long. From a + * reservation point of view it's assumed that the schedule goes right back to + * the beginning after the end of the schedule. + * + * What does that mean for scheduling things with a long interval? It means + * we'll reserve time for them in every possible microframe that they could + * ever be scheduled in. ...but we'll still only actually schedule them as + * often as they were requested. + * + * We keep our schedule in a "bitmap" structure. This simplifies having + * to keep track of and merge intervals: we just let the bitmap code do most + * of the heavy lifting. In a way scheduling is much like memory allocation. + * + * We schedule 100us per uframe or 80% of 125us (the maximum amount you're + * supposed to schedule for periodic transfers). That's according to spec. + * + * Note that though we only schedule 80% of each microframe, the bitmap that we + * keep the schedule in is tightly packed (AKA it doesn't have 100us worth of + * space for each uFrame). + * + * Requirements: + * - DWC2_HS_SCHEDULE_UFRAMES must even divide 0x4000 (HFNUM_MAX_FRNUM + 1) + * - DWC2_HS_SCHEDULE_UFRAMES must be 8 times DWC2_LS_SCHEDULE_FRAMES (probably + * could be any multiple of 8 times DWC2_LS_SCHEDULE_FRAMES, but there might + * be bugs). The 8 comes from the USB spec: number of microframes per frame. + */ +#define DWC2_US_PER_UFRAME 125 +#define DWC2_HS_PERIODIC_US_PER_UFRAME 100 + +#define DWC2_HS_SCHEDULE_UFRAMES 8 +#define DWC2_HS_SCHEDULE_US (DWC2_HS_SCHEDULE_UFRAMES * \ + DWC2_HS_PERIODIC_US_PER_UFRAME) + +/* + * Constants related to low speed scheduling + * + * For high speed we schedule every 1us. For low speed that's a bit overkill, + * so we make up a unit called a "slice" that's worth 25us. There are 40 + * slices in a full frame and we can schedule 36 of those (90%) for periodic + * transfers. + * + * Our low speed schedule can be as short as 1 frame or could be longer. When + * we only schedule 1 frame it means that we'll need to reserve a time every + * frame even for things that only transfer very rarely, so something that runs + * every 2048 frames will get time reserved in every frame. Our low speed + * schedule can be longer and we'll be able to handle more overlap, but that + * will come at increased memory cost and increased time to schedule. + * + * Note: one other advantage of a short low speed schedule is that if we mess + * up and miss scheduling we can jump in and use any of the slots that we + * happened to reserve. + * + * With 25 us per slice and 1 frame in the schedule, we only need 4 bytes for + * the schedule. There will be one schedule per TT. + * + * Requirements: + * - DWC2_US_PER_SLICE must evenly divide DWC2_LS_PERIODIC_US_PER_FRAME. + */ +#define DWC2_US_PER_SLICE 25 +#define DWC2_SLICES_PER_UFRAME (DWC2_US_PER_UFRAME / DWC2_US_PER_SLICE) + +#define DWC2_ROUND_US_TO_SLICE(us) \ + (DIV_ROUND_UP((us), DWC2_US_PER_SLICE) * \ + DWC2_US_PER_SLICE) + +#define DWC2_LS_PERIODIC_US_PER_FRAME \ + 900 +#define DWC2_LS_PERIODIC_SLICES_PER_FRAME \ + (DWC2_LS_PERIODIC_US_PER_FRAME / \ + DWC2_US_PER_SLICE) + +#define DWC2_LS_SCHEDULE_FRAMES 1 +#define DWC2_LS_SCHEDULE_SLICES (DWC2_LS_SCHEDULE_FRAMES * \ + DWC2_LS_PERIODIC_SLICES_PER_FRAME) + union dwc2_hcd_internal_flags { u32 d32; struct {
@@ -803,7 +884,8 @@ struct dwc2_hsotg {struct list_head periodic_sched_queued;struct list_head split_order;u16 periodic_usecs; -u16 frame_usecs[8 ]; +unsigned long hs_periodic_bitmap[ +DIV_ROUND_UP (DWC2_HS_SCHEDULE_US ,BITS_PER_LONG )];u16 frame_number;u16 periodic_qh_count;bool bus_suspended;
drivers/usb/dwc2/hcd.c +84 -3
99 lines not on this page · raw message
drivers/usb/dwc2/hcd.h +73 -6
137 lines not on this page · raw message
drivers/usb/dwc2/hcd_queue.c +1031 -177
1,351 lines not on this page · raw message
Signature · 1 line
2.7.0.rc3.207.g0ac5344
PATCH v4 21/21 usb: dwc2: host: If using uframe scheduler, end splits better
In reply to Douglas AndersonThe microframe scheduler figured out exactly how many transfers we need for a split transaction. Let's use this knowledge to know when to end things.
Without this I found that certain devices would just keep responding with tons of NYET resonses on their INT_IN endpoint. These would just keep going and going and eventually we'd decide to terminate the transfer (because the whole frame changed), but by that time the scheduler would decide that we "missed" the start of the next transfer. I can also imagine that if we blow past the end of our scheduled time we may mess up other things that were scheduled to happen.
No known test cases are improved by this patch except that the scheduler code doesn't yell about MISSES constantly anymore.
---
Changes in v4:
- If using uframe scheduler, end splits better new for v4.
Changes in v3: None
Changes in v2: None
drivers/usb/dwc2/hcd_intr.c | 48 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 6 deletions(-)
drivers/usb/dwc2/hcd_intr.c +42 -6
@@ -1353,14 +1353,50 @@ static void dwc2_hc_nyet_intr(struct dwc2_hsotg *hsotg,if (chan->ep_type ==USB_ENDPOINT_XFER_INT || chan->ep_type ==USB_ENDPOINT_XFER_ISOC ) { -int frnum =dwc2_hcd_get_frame_number (hsotg); +struct dwc2_qh *qh = chan->qh; +bool past_end; + +if (hsotg->core_params->uframe_sched <=0 ) { +int frnum =dwc2_hcd_get_frame_number (hsotg); + +/* Don't have num_hs_transfers; simple logic */ + past_end =dwc2_full_frame_num (frnum) != +dwc2_full_frame_num (qh->next_active_frame); + }else { +int end_frnum; -if (dwc2_full_frame_num (frnum) != -dwc2_full_frame_num (chan->qh->next_active_frame)) {/* -* No longer in the same full speed frame. -* Treat this as a transaction error. -*/ +* Figure out the end frame based on schedule. +* +* We don't want to go on trying again and again +* forever. Let's stop when we've done all the +* transfers that were scheduled. +* +* We're going to be comparing start_active_frame +* and next_active_frame, both of which are 1 +* before the time the packet goes on the wire, +* so that cancels out. Basically if had 1 +* transfer and we saw 1 NYET then we're done. +* We're getting a NYET here so if next >= +* (start + num_transfers) we're done. The +* complexity is that for all but ISOC_OUT we +* skip one slot. +*/ + end_frnum =dwc2_frame_num_inc ( + qh->start_active_frame, + qh->num_hs_transfers); + +if (qh->ep_type !=USB_ENDPOINT_XFER_ISOC || + qh->ep_is_in) + end_frnum = +dwc2_frame_num_inc (end_frnum,1 ); + + past_end =dwc2_frame_num_le ( + end_frnum, qh->next_active_frame); + } + +if (past_end) { +/* Treat this as a transaction error. */ #if 0 /* * Todo: Fix system performance so this can
Signature · 1 line
2.7.0.rc3.207.g0ac5344
kbuild test robot
build botRe: [PATCH v4 07/21] usb: dwc2: hcd: fix split transfer schedule sequence
In reply to Douglas Andersonreproduce:
Hi Douglas,
[auto build test ERROR on next-20160120]
[cannot apply to v4.4-rc8 v4.4-rc7 v4.4-rc6 v4.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Douglas-Anderson/usb-dwc2-host-Fix-and-speed-up-all-the-stuff-especially-with-splits/20160121-131414 config: x86_64-randconfig-x019-01201142 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
drivers/usb/dwc2/core.c: In function 'dwc2_hc_start_transfer':
>> drivers/usb/dwc2/core.c:1876:17: error: 'struct dwc2_hsotg' has no member named 'split_order'
&hsotg->split_order);
^
--
>> /bin/bash: line 0: [: -ge: unary operator expectedvim +1876 drivers/usb/dwc2/core.c
1870 ec_mc = 3;
1871 else
1872 ec_mc = 1;
1873
1874 /* Put ourselves on the list to keep order straight */
1875 list_move_tail(&chan->split_order_list_entry,
> 1876 &hsotg->split_order);
1877 } else {
1878 if (dbg_hc(chan))
1879 dev_vdbg(hsotg->dev, "no split\n");
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
kbuild test robot
build botRe: [PATCH v4 20/21] usb: dwc2: host: Totally redo the microframe scheduler
In reply to Douglas Andersonreproduce:
Hi Douglas,
[auto build test ERROR on next-20160120]
[cannot apply to v4.4-rc8 v4.4-rc7 v4.4-rc6 v4.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Douglas-Anderson/usb-dwc2-host-Fix-and-speed-up-all-the-stuff-especially-with-splits/20160121-131414 config: x86_64-randconfig-x019-01201142 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64
All errors (new ones prefixed by >>):
In file included from drivers/usb/dwc2/core.c:57:0:
>> drivers/usb/dwc2/hcd.h:345:44: error: 'DWC2_HS_SCHEDULE_UFRAMES' undeclared here (not in a function)
struct dwc2_hs_transfer_time hs_transfers[DWC2_HS_SCHEDULE_UFRAMES];
^
drivers/usb/dwc2/core.c: In function 'dwc2_hc_start_transfer':
drivers/usb/dwc2/core.c:1964:17: error: 'struct dwc2_hsotg' has no member named 'split_order'
&hsotg->split_order);
^
--
In file included from drivers/usb/dwc2/core_intr.c:54:0:
>> drivers/usb/dwc2/hcd.h:345:44: error: 'DWC2_HS_SCHEDULE_UFRAMES' undeclared here (not in a function)
struct dwc2_hs_transfer_time hs_transfers[DWC2_HS_SCHEDULE_UFRAMES];
^vim +/DWC2_HS_SCHEDULE_UFRAMES +345 drivers/usb/dwc2/hcd.h
339 u16 device_us;
340 u16 host_interval;
341 u16 device_interval;
342 u16 next_active_frame;
343 u16 start_active_frame;
344 s16 num_hs_transfers;
> 345 struct dwc2_hs_transfer_time hs_transfers[DWC2_HS_SCHEDULE_UFRAMES];
346 u32 ls_start_schedule_slice;
347 u16 ntd;
348 struct list_head qtd_list;
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v4 07/21] usb: dwc2: hcd: fix split transfer schedule sequence
In reply to kbuild test robotHi,
Quoted 29 lines · kbuild test robot
Hi Douglas,
[auto build test ERROR on next-20160120]
[cannot apply to v4.4-rc8 v4.4-rc7 v4.4-rc6 v4.4]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]url: https://github.com/0day-ci/linux/commits/Douglas-Anderson/usb-dwc2-host-Fix-and-speed-up-all-the-stuff-especially-with-splits/20160121-131414 config: x86_64-randconfig-x019-01201142 (attached as .config) reproduce: # save the attached .config to linux build tree make ARCH=x86_64All errors (new ones prefixed by >>):
drivers/usb/dwc2/core.c: In function 'dwc2_hc_start_transfer':Quoted 1 line
Quoted 1 line
drivers/usb/dwc2/core.c:1876:17: error: 'structdwc2_hsotg' has no member named 'split_order'&hsotg->split_order); ^--
Quoted 1 line
Quoted 1 line
/bin/bash: line 0: [: -ge: unary operator expectedvim +1876
drivers/usb/dwc2/core.c1870
ec_mc= 3;
1871 else
1872ec_mc= 1;
1873
1874 /* Put ourselves on the list to keep order straight */
1875 list_move_tail(&chan->split_order_list_entry,
Quoted 8 lines
Quoted 1 line
1876
&hsotg->split_order);1877 } else {
1878 if (dbg_hc(chan))
1879dev_vdbg(hsotg->dev, "no split\n");---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
I've got a fix this and the other error reported by the bot. I'll plan to fix both tomorrow and send up a v5 unless someone gives me some other feedback on the series that takes me longer than a day to deal with.
-Doug