u-boot/drivers/usb/dwc3
Philipp Tomsich 889239d6b5 usb: dwc3: gadget: make cache-maintenance on event buffers more robust
Merely using dma_alloc_coherent does not ensure that there is no stale
data left in the caches for the allocated DMA buffer (i.e. that the
affected cacheline may still be dirty).

The original code was doing the following (on AArch64, which
translates a 'flush' into a 'clean + invalidate'):
  # during initialisation:
      1. allocate buffers via memalign
      	 => buffers may still be modified (cached, dirty)
  # during interrupt processing
      2. clean + invalidate buffers
      	 => may commit stale data from a modified cacheline
      3. read from buffers

This could lead to garbage info being written to buffers before
reading them during even-processing.

To make the event processing more robust, we use the following sequence
for the cache-maintenance:
  # during initialisation:
      1. allocate buffers via memalign
      2. clean + invalidate buffers
      	 (we only need the 'invalidate' part, but dwc3_flush_cache()
	  always performs a 'clean + invalidate')
  # during interrupt processing
      3. read the buffers
      	 (we know these lines are not cached, due to the previous
	  invalidation and no other code touching them in-between)
      4. clean + invalidate buffers
      	 => writes back any modification we may have made during event
	    processing and ensures that the lines are not in the cache
	    the next time we enter interrupt processing

Note that with the original sequence, we observe reproducible
(depending on the cache state: i.e. running dhcp/usb start before will
upset caches to get us around this) issues in the event processing (a
fatal synchronous abort in dwc3_gadget_uboot_handle_interrupt on the
first time interrupt handling is invoked) when running USB mass
storage emulation on our RK3399-Q7 with data-caches on.

Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
2017-04-14 16:44:16 +02:00
..
core.c usb: dwc3: gadget: make cache-maintenance on event buffers more robust 2017-04-14 16:44:16 +02:00
core.h usb: dwc3: make dwc3_set_mode to static 2015-04-14 05:48:12 +02:00
dwc3-omap.c usb: dwc3: fix build warnings 2015-12-07 00:14:59 +01:00
ep0.c usb: dwc3: ensure consistent types for dwc3_flush_cache 2017-04-14 16:44:16 +02:00
gadget.c usb: dwc3: gadget: make cache-maintenance on event buffers more robust 2017-04-14 16:44:16 +02:00
gadget.h usb: dwc3: gadget: make dwc3 gadget build in uboot 2015-04-14 05:48:09 +02:00
io.h usb: dwc3: ensure consistent types for dwc3_flush_cache 2017-04-14 16:44:16 +02:00
Kconfig usb: dwc3: Move CONFIG_USB_DWC3_PHY_* to Kconfig 2016-04-20 11:43:28 +02:00
linux-compat.h bug.h: move BUILD_BUG_* defines to include/linux/bug.h 2016-01-25 10:39:59 -05:00
Makefile usb: dwc3: Makefile: Don't build gadget code if USB_GADGET is disabled 2016-05-27 15:39:49 -04:00
samsung_usb_phy.c samsung: usb: phy: Support for DWC3 PHY 2015-06-08 15:25:44 +02:00
ti_usb_phy.c ARM: DRA7x/AM57xx: Get rid of CONFIG_AM57XX 2016-12-03 13:21:11 -05:00