[PATCH v5 1/2] usb: make xhci platform driver use 64 bit or 32 bit DMA
From: Duc Dang <hidden>
Date: 2015-08-08 20:31:34
Also in:
lkml
On Sat, Aug 8, 2015 at 2:22 AM, Russell King - ARM Linux [off-list ref] wrote:
On Fri, Aug 07, 2015 at 08:18:48PM -0700, Duc Dang wrote:quoted
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 890ad9d..5d03f8b 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c@@ -93,14 +93,14 @@ static int xhci_plat_probe(struct platform_device *pdev) if (irq < 0) return -ENODEV; - /* Initialize dma_mask and coherent_dma_mask to 32-bits */ - ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32)); - if (ret) - return ret; - if (!pdev->dev.dma_mask) - pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; - else - dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); + /* Try setting the coherent_dma_mask to 64 bits, then try 32 bits */ + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); + if (ret) { + ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); + if (ret) + return ret; + }Note that dma_set_mask_and_coherent() and the original code are not equivalent because of this: if (!pdev->dev.dma_mask) pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask; If we know that pdev->dev.dma_mask will always be initialised at this point, then the above change is fine. If not, it's introducing a regression - dma_set_mask_and_coherent() will fail if pdev->dev.dma_mask is NULL (depending on the architectures implementation of dma_set_mask()). Prefixing the above change with the two lines I mention above would ensure equivalent behaviour. Even if we do want to get rid of this, I'd advise to do it as a separate patch after this change, which can be independently reverted if there's problems with its removal.
Hi Russell, I will add the 2 lines you mentioned back to next version of the patch. It is safer to do it that way as I do not see pdev->dev.dma_mask gets initialized before the call dma_set_mask_and_coherent inside this xhci_plat.c file.
-- FTTC broadband for 0.8mile line: currently at 10.5Mbps down 400kbps up according to speedtest.net.
-- Regards, Duc Dang.