84fcbafb5b9cd03f634377120a87a8224d766686
[openwrt.git] / target / linux / mvebu / patches-3.10 / 0197-xhci-fix-dma-mask-setup-in-xhci.c.patch
1 From 5cb802766e9cdc9a56e8ce8e4686692ebbcfb5cc Mon Sep 17 00:00:00 2001
2 From: Xenia Ragiadakou <burzalodowa@gmail.com>
3 Date: Mon, 23 Dec 2013 16:59:02 +0100
4 Subject: [PATCH 197/203] xhci: fix dma mask setup in xhci.c
5
6 The function dma_set_mask() tests internally whether the dma_mask pointer
7 for the device is initialized and fails if the dma_mask pointer is NULL.
8 On pci platforms, the device dma_mask pointer is initialized, when pci
9 devices are enumerated, to point to the pci_dev->dma_mask which is 0xffffffff.
10 However, for non-pci platforms, the dma_mask pointer may not be initialized
11 and in that case dma_set_mask() will fail.
12
13 This patch initializes the dma_mask and the coherent_dma_mask to 32bits
14 in xhci_plat_probe(), before the call to usb_create_hcd() that sets the
15 "uses_dma" flag for the usb bus and the call to usb_add_hcd() that creates
16 coherent dma pools for the usb hcd.
17
18 Moreover, a call to dma_set_mask() does not set the device coherent_dma_mask.
19 Since the xhci-hcd driver calls dma_alloc_coherent() and dma_pool_alloc()
20 to allocate consistent DMA memory blocks, the coherent DMA address mask
21 has to be set explicitly.
22
23 This patch sets the coherent_dma_mask to 64bits in xhci_gen_setup() when
24 the xHC is capable for 64-bit DMA addressing.
25
26 If dma_set_mask() succeeds, for a given bitmask, it is guaranteed that
27 the given bitmask is also supported for consistent DMA mappings.
28
29 Other changes introduced in this patch are:
30
31 - The return value of dma_set_mask() is checked to ensure that the required
32   dma bitmask conforms with the host system's addressing capabilities.
33
34 - The dma_mask setup code for the non-primary hcd was removed since both
35   primary and non-primary hcd refer to the same generic device whose
36   dma_mask and coherent_dma_mask are already set during the setup of
37   the primary hcd.
38
39 - The code for reading the HCCPARAMS register to find out the addressing
40   capabilities of xHC was removed since its value is already cached in
41   xhci->hccparams.
42
43 - hcd->self.controller was replaced with the dev variable since it is
44   already available.
45
46 Signed-off-by: Xenia Ragiadakou <burzalodowa@gmail.com>
47 Signed-off-by: Sarah Sharp <sarah.a.sharp@linux.intel.com>
48
49 Conflicts:
50         drivers/usb/host/xhci-plat.c
51 ---
52  drivers/usb/host/xhci-plat.c | 10 ++++++++++
53  drivers/usb/host/xhci.c      | 19 +++++--------------
54  2 files changed, 15 insertions(+), 14 deletions(-)
55
56 --- a/drivers/usb/host/xhci-plat.c
57 +++ b/drivers/usb/host/xhci-plat.c
58 @@ -15,6 +15,7 @@
59  #include <linux/module.h>
60  #include <linux/slab.h>
61  #include <linux/of.h>
62 +#include <linux/dma-mapping.h>
63  
64  #include "xhci.h"
65  
66 @@ -105,6 +106,15 @@ static int xhci_plat_probe(struct platfo
67         if (!res)
68                 return -ENODEV;
69  
70 +       /* Initialize dma_mask and coherent_dma_mask to 32-bits */
71 +       ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
72 +       if (ret)
73 +               return ret;
74 +       if (!pdev->dev.dma_mask)
75 +               pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
76 +       else
77 +               dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
78 +
79         hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
80         if (!hcd)
81                 return -ENOMEM;
82 --- a/drivers/usb/host/xhci.c
83 +++ b/drivers/usb/host/xhci.c
84 @@ -4654,7 +4654,6 @@ int xhci_gen_setup(struct usb_hcd *hcd,
85         struct xhci_hcd         *xhci;
86         struct device           *dev = hcd->self.controller;
87         int                     retval;
88 -       u32                     temp;
89  
90         /* Accept arbitrarily long scatter-gather lists */
91         hcd->self.sg_tablesize = ~0;
92 @@ -4682,14 +4681,6 @@ int xhci_gen_setup(struct usb_hcd *hcd,
93                 /* xHCI private pointer was set in xhci_pci_probe for the second
94                  * registered roothub.
95                  */
96 -               xhci = hcd_to_xhci(hcd);
97 -               temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
98 -               if (HCC_64BIT_ADDR(temp)) {
99 -                       xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
100 -                       dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
101 -               } else {
102 -                       dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
103 -               }
104                 return 0;
105         }
106  
107 @@ -4728,12 +4719,12 @@ int xhci_gen_setup(struct usb_hcd *hcd,
108                 goto error;
109         xhci_dbg(xhci, "Reset complete\n");
110  
111 -       temp = xhci_readl(xhci, &xhci->cap_regs->hcc_params);
112 -       if (HCC_64BIT_ADDR(temp)) {
113 +       /* Set dma_mask and coherent_dma_mask to 64-bits,
114 +        * if xHC supports 64-bit addressing */
115 +       if (HCC_64BIT_ADDR(xhci->hcc_params) &&
116 +                       !dma_set_mask(dev, DMA_BIT_MASK(64))) {
117                 xhci_dbg(xhci, "Enabling 64-bit DMA addresses.\n");
118 -               dma_set_mask(hcd->self.controller, DMA_BIT_MASK(64));
119 -       } else {
120 -               dma_set_mask(hcd->self.controller, DMA_BIT_MASK(32));
121 +               dma_set_coherent_mask(dev, DMA_BIT_MASK(64));
122         }
123  
124         xhci_dbg(xhci, "Calling HCD init\n");