Re: [v5,5/6] usb: dwc3: use bus->sysdev for DMA configuration
Hi! On 17/11/16 12:43, Sriram Dash wrote: > From: Arnd Bergmann> > The dma ops for dwc3 devices are not set properly. So, use a > physical device sysdev, which will be inherited from parent, > to set the hardware / firmware parameters like dma. > > Signed-off-by: Arnd Bergmann > Signed-off-by: Sriram Dash > Tested-by: Baolin Wang Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore: Tested-by: Alexander Sverdlin > --- > Changes in v5: > - rebase to usb testing/next > > Changes in v4: > - removed the ifdefs for pci > - made the sysdev as a device property > - phy create lookup take up the correct device. > > Changes in v3: > - No update > > Changes in v2: > - integrate dwc3 driver changes together > > drivers/usb/dwc3/core.c | 27 ++- > drivers/usb/dwc3/core.h | 3 +++ > drivers/usb/dwc3/dwc3-pci.c | 10 ++ > drivers/usb/dwc3/ep0.c | 8 > drivers/usb/dwc3/gadget.c | 33 + > drivers/usb/dwc3/host.c | 16 ++-- > 6 files changed, 54 insertions(+), 43 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index e951448..e5fbab2 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -202,7 +202,7 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc) > static void dwc3_free_one_event_buffer(struct dwc3 *dwc, > struct dwc3_event_buffer *evt) > { > - dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); > + dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); > } > > /** > @@ -228,7 +228,7 @@ static struct dwc3_event_buffer > *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, > if (!evt->cache) > return ERR_PTR(-ENOMEM); > > - evt->buf= dma_alloc_coherent(dwc->dev, length, > + evt->buf= dma_alloc_coherent(dwc->sysdev, length, > >dma, GFP_KERNEL); > if (!evt->buf) > return ERR_PTR(-ENOMEM); > @@ -341,11 +341,11 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) > if (!WARN_ON(dwc->scratchbuf)) > return 0; > > - scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf, > + scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, > dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, > DMA_BIDIRECTIONAL); > - if (dma_mapping_error(dwc->dev, scratch_addr)) { > - dev_err(dwc->dev, "failed to map scratch buffer\n"); > + if (dma_mapping_error(dwc->sysdev, scratch_addr)) { > + dev_err(dwc->sysdev, "failed to map scratch buffer\n"); > ret = -EFAULT; > goto err0; > } > @@ -369,7 +369,7 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) > return 0; > > err1: > - dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * > + dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * > DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); > > err0: > @@ -388,7 +388,7 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc) > if (!WARN_ON(dwc->scratchbuf)) > return; > > - dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * > + dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * > DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); > kfree(dwc->scratchbuf); > } > @@ -927,6 +927,13 @@ static void dwc3_get_properties(struct dwc3 *dwc) > dwc->dr_mode = usb_get_dr_mode(dev); > dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); > > + dwc->sysdev_is_parent = device_property_read_bool(dev, > + "linux,sysdev_is_parent"); > + if (dwc->sysdev_is_parent) > + dwc->sysdev = dwc->dev->parent; > + else > + dwc->sysdev = dwc->dev; > + > dwc->has_lpm_erratum = device_property_read_bool(dev, > "snps,has-lpm-erratum"); > device_property_read_u8(dev, "snps,lpm-nyet-threshold", > @@ -1097,12 +1104,6 @@ static int dwc3_probe(struct platform_device *pdev) > > spin_lock_init(>lock); > > - if (!dev->dma_mask) { > - dev->dma_mask = dev->parent->dma_mask; > - dev->dma_parms = dev->parent->dma_parms; > - dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); > - } > - > pm_runtime_set_active(dev); > pm_runtime_use_autosuspend(dev); > pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY); > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index ef81fa5..de5a857 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -819,6 +819,7 @@ struct dwc3_scratchpad_array { > *
Re: [v5,5/6] usb: dwc3: use bus->sysdev for DMA configuration
Hi! On 17/11/16 12:43, Sriram Dash wrote: > From: Arnd Bergmann > > The dma ops for dwc3 devices are not set properly. So, use a > physical device sysdev, which will be inherited from parent, > to set the hardware / firmware parameters like dma. > > Signed-off-by: Arnd Bergmann > Signed-off-by: Sriram Dash > Tested-by: Baolin Wang Successfully tested on arm64/axxia with DWC3 USB host, XHCIs properly inherit DMA configuration. Therefore: Tested-by: Alexander Sverdlin > --- > Changes in v5: > - rebase to usb testing/next > > Changes in v4: > - removed the ifdefs for pci > - made the sysdev as a device property > - phy create lookup take up the correct device. > > Changes in v3: > - No update > > Changes in v2: > - integrate dwc3 driver changes together > > drivers/usb/dwc3/core.c | 27 ++- > drivers/usb/dwc3/core.h | 3 +++ > drivers/usb/dwc3/dwc3-pci.c | 10 ++ > drivers/usb/dwc3/ep0.c | 8 > drivers/usb/dwc3/gadget.c | 33 + > drivers/usb/dwc3/host.c | 16 ++-- > 6 files changed, 54 insertions(+), 43 deletions(-) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index e951448..e5fbab2 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -202,7 +202,7 @@ static void dwc3_frame_length_adjustment(struct dwc3 *dwc) > static void dwc3_free_one_event_buffer(struct dwc3 *dwc, > struct dwc3_event_buffer *evt) > { > - dma_free_coherent(dwc->dev, evt->length, evt->buf, evt->dma); > + dma_free_coherent(dwc->sysdev, evt->length, evt->buf, evt->dma); > } > > /** > @@ -228,7 +228,7 @@ static struct dwc3_event_buffer > *dwc3_alloc_one_event_buffer(struct dwc3 *dwc, > if (!evt->cache) > return ERR_PTR(-ENOMEM); > > - evt->buf= dma_alloc_coherent(dwc->dev, length, > + evt->buf= dma_alloc_coherent(dwc->sysdev, length, > >dma, GFP_KERNEL); > if (!evt->buf) > return ERR_PTR(-ENOMEM); > @@ -341,11 +341,11 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) > if (!WARN_ON(dwc->scratchbuf)) > return 0; > > - scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf, > + scratch_addr = dma_map_single(dwc->sysdev, dwc->scratchbuf, > dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE, > DMA_BIDIRECTIONAL); > - if (dma_mapping_error(dwc->dev, scratch_addr)) { > - dev_err(dwc->dev, "failed to map scratch buffer\n"); > + if (dma_mapping_error(dwc->sysdev, scratch_addr)) { > + dev_err(dwc->sysdev, "failed to map scratch buffer\n"); > ret = -EFAULT; > goto err0; > } > @@ -369,7 +369,7 @@ static int dwc3_setup_scratch_buffers(struct dwc3 *dwc) > return 0; > > err1: > - dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * > + dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * > DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); > > err0: > @@ -388,7 +388,7 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc) > if (!WARN_ON(dwc->scratchbuf)) > return; > > - dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch * > + dma_unmap_single(dwc->sysdev, dwc->scratch_addr, dwc->nr_scratch * > DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL); > kfree(dwc->scratchbuf); > } > @@ -927,6 +927,13 @@ static void dwc3_get_properties(struct dwc3 *dwc) > dwc->dr_mode = usb_get_dr_mode(dev); > dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node); > > + dwc->sysdev_is_parent = device_property_read_bool(dev, > + "linux,sysdev_is_parent"); > + if (dwc->sysdev_is_parent) > + dwc->sysdev = dwc->dev->parent; > + else > + dwc->sysdev = dwc->dev; > + > dwc->has_lpm_erratum = device_property_read_bool(dev, > "snps,has-lpm-erratum"); > device_property_read_u8(dev, "snps,lpm-nyet-threshold", > @@ -1097,12 +1104,6 @@ static int dwc3_probe(struct platform_device *pdev) > > spin_lock_init(>lock); > > - if (!dev->dma_mask) { > - dev->dma_mask = dev->parent->dma_mask; > - dev->dma_parms = dev->parent->dma_parms; > - dma_set_coherent_mask(dev, dev->parent->coherent_dma_mask); > - } > - > pm_runtime_set_active(dev); > pm_runtime_use_autosuspend(dev); > pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY); > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index ef81fa5..de5a857 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -819,6 +819,7 @@ struct dwc3_scratchpad_array { > * @ep0_bounced: true when we used bounce buffer > * @ep0_expect_in: true when we expect a DATA IN transfer >