Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: dwc3: core: leave default DMA if the controller does not support 64-bit DMA

On some DWC3 controllers (e.g. Rockchip SoCs), the DWC3 core
doesn't support 64-bit DMA address width. In this case, this
driver should use the default 32-bit mask. Otherwise, the DWC3
controller will break if it runs on above 4GB physical memory
environment.

This patch reads the DWC_USB3_AWIDTH bits of GHWPARAMS0 which
used for the DMA address width, and only configure 64-bit DMA
mask if the DWC_USB3_AWIDTH is 64.

Fixes: 45d39448b4d0 ("usb: dwc3: support 64 bit DMA in platform driver")
Cc: stable <stable@kernel.org>
Reviewed-by: Sven Peter <sven@svenpeter.dev>
Signed-off-by: William Wu <william.wu@rock-chips.com>
Link: https://lore.kernel.org/r/20220901083446.3799754-1-william.wu@rock-chips.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

William Wu and committed by
Greg Kroah-Hartman
91062e66 766a96dc

+7 -6
+7 -6
drivers/usb/dwc3/core.c
··· 1752 1752 1753 1753 dwc3_get_properties(dwc); 1754 1754 1755 - if (!dwc->sysdev_is_parent) { 1756 - ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); 1757 - if (ret) 1758 - return ret; 1759 - } 1760 - 1761 1755 dwc->reset = devm_reset_control_array_get_optional_shared(dev); 1762 1756 if (IS_ERR(dwc->reset)) 1763 1757 return PTR_ERR(dwc->reset); ··· 1816 1822 1817 1823 platform_set_drvdata(pdev, dwc); 1818 1824 dwc3_cache_hwparams(dwc); 1825 + 1826 + if (!dwc->sysdev_is_parent && 1827 + DWC3_GHWPARAMS0_AWIDTH(dwc->hwparams.hwparams0) == 64) { 1828 + ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64)); 1829 + if (ret) 1830 + goto disable_clks; 1831 + } 1819 1832 1820 1833 spin_lock_init(&dwc->lock); 1821 1834 mutex_init(&dwc->mutex);