Re: [PATCH v3] usb: dwc3: support 64 bit DMA in platform driver
From: Arnd Bergmann
Date: Mon Jun 07 2021 - 03:27:35 EST
On Mon, Jun 7, 2021 at 8:18 AM Sven Peter <sven@xxxxxxxxxxxxx> wrote:
>
> Currently, the dwc3 platform driver does not explicitly ask for
> a DMA mask. This makes it fall back to the default 32-bit mask which
> breaks the driver on systems that only have RAM starting above the
> first 4G like the Apple M1 SoC.
>
> Fix this by calling dma_set_mask_and_coherent with a 64bit mask.
>
> Signed-off-by: Sven Peter <sven@xxxxxxxxxxxxx>
> ---
>
> Third time's a charm I hope - this time much simpler :)
I think this is almost good, but there is still one small issue:
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index b6e53d8212cd..ba4792b6a98f 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -1545,6 +1545,10 @@ static int dwc3_probe(struct platform_device *pdev)
>
> dwc3_get_properties(dwc);
>
> + ret = dma_set_mask_and_coherent(dwc->sysdev, DMA_BIT_MASK(64));
> + if (ret)
> + return ret;
This will now fail on machines with dwc3 connected to a 32-bit bus (or a
bus that is accidentally not annotated as supporting 64-bit) when there is
some memory that is not addressable through that bus.
If dma_set_mask_and_coherent() fails, the platform should just fall back to
32-bit addressing as it did before your change. dma_alloc_*() will do that
implicitly by allocating from ZONE_DMA32, while dma_map_*() fails
on any non-addressable memory, or falls back to swiotlb if that is available.
Arnd