[PATCH v2 4/6] usb: xhci: use bus->sysdev for DMA configuration

2016-11-01 Thread Sriram Dash
From: Arnd Bergmann 

For xhci-hcd platform device, all the DMA parameters are not
configured properly, notably dma ops for dwc3 devices. So, set
the dma for xhci from sysdev. sysdev is pointing to device that
is known to the system firmware or hardware.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Sriram Dash 
---
Changes in v2:
  - Separate out xhci driver changes apart


 drivers/usb/host/xhci-mem.c  | 12 ++--
 drivers/usb/host/xhci-plat.c | 33 ++---
 drivers/usb/host/xhci.c  | 15 +++
 3 files changed, 43 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6afe323..79608df 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -586,7 +586,7 @@ static void xhci_free_stream_ctx(struct xhci_hcd *xhci,
unsigned int num_stream_ctxs,
struct xhci_stream_ctx *stream_ctx, dma_addr_t dma)
 {
-   struct device *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -614,7 +614,7 @@ static struct xhci_stream_ctx *xhci_alloc_stream_ctx(struct 
xhci_hcd *xhci,
unsigned int num_stream_ctxs, dma_addr_t *dma,
gfp_t mem_flags)
 {
-   struct device *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
size_t size = sizeof(struct xhci_stream_ctx) * num_stream_ctxs;
 
if (size > MEDIUM_STREAM_ARRAY_SIZE)
@@ -1644,7 +1644,7 @@ void xhci_slot_copy(struct xhci_hcd *xhci,
 static int scratchpad_alloc(struct xhci_hcd *xhci, gfp_t flags)
 {
int i;
-   struct device *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
int num_sp = HCS_MAX_SCRATCHPAD(xhci->hcs_params2);
 
xhci_dbg_trace(xhci, trace_xhci_dbg_init,
@@ -1716,7 +1716,7 @@ static void scratchpad_free(struct xhci_hcd *xhci)
 {
int num_sp;
int i;
-   struct device *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device *dev = xhci_to_hcd(xhci)->self.sysdev;
 
if (!xhci->scratchpad)
return;
@@ -1792,7 +1792,7 @@ void xhci_free_command(struct xhci_hcd *xhci,
 
 void xhci_mem_cleanup(struct xhci_hcd *xhci)
 {
-   struct device   *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device   *dev = xhci_to_hcd(xhci)->self.sysdev;
int size;
int i, j, num_ports;
 
@@ -2334,7 +2334,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, 
gfp_t flags)
 int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 {
dma_addr_t  dma;
-   struct device   *dev = xhci_to_hcd(xhci)->self.controller;
+   struct device   *dev = xhci_to_hcd(xhci)->self.sysdev;
unsigned intval, val2;
u64 val_64;
struct xhci_segment *seg;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index ed56bf9..beb95c8 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -139,6 +140,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 {
const struct of_device_id *match;
const struct hc_driver  *driver;
+   struct device   *sysdev;
struct xhci_hcd *xhci;
struct resource *res;
struct usb_hcd  *hcd;
@@ -155,22 +157,39 @@ static int xhci_plat_probe(struct platform_device *pdev)
if (irq < 0)
return -ENODEV;
 
+   /*
+* sysdev must point to a device that is known to the system firmware
+* or PCI hardware. We handle these three cases here:
+* 1. xhci_plat comes from firmware
+* 2. xhci_plat is child of a device from firmware (dwc3-plat)
+* 3. xhci_plat is grandchild of a pci device (dwc3-pci)
+*/
+   sysdev = &pdev->dev;
+   if (sysdev->parent && !sysdev->of_node && sysdev->parent->of_node)
+   sysdev = sysdev->parent;
+#ifdef CONFIG_PCI
+   else if (sysdev->parent && sysdev->parent->parent &&
+sysdev->parent->parent->bus == &pci_bus_type)
+   sysdev = sysdev->parent->parent;
+#endif
+
/* Try to set 64-bit DMA first */
-   if (WARN_ON(!pdev->dev.dma_mask))
+   if (WARN_ON(!sysdev->dma_mask))
/* Platform did not initialize dma_mask */
-   ret = dma_coerce_mask_and_coherent(&pdev->dev,
+   ret = dma_coerce_mask_and_coherent(sysdev,
   DMA_BIT_MASK(64));
else
-   ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
+   ret = dma_set_mask_and_coherent(sysdev, DMA_BIT_MASK(64));
 

Re: [PATCH v2 2/6] usb: chipidea: use bus->sysdev for DMA configuration

2016-11-01 Thread Peter Chen
On Wed, Nov 02, 2016 at 11:08:09AM +0530, Sriram Dash wrote:
> From: Arnd Bergmann 
> 
> Set the dma for chipidea from sysdev. This is inherited from its
> parent node. Also, do not set dma mask for child as it is not required
> now.
> 
> Signed-off-by: Arnd Bergmann 
> Signed-off-by: Sriram Dash 
> ---
> Changes in v2:
>   - integrate chipidea driver changes together.
> 
>  drivers/usb/chipidea/core.c |  3 ---
>  drivers/usb/chipidea/host.c |  3 ++-
>  drivers/usb/chipidea/udc.c  | 10 ++
>  3 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index 69426e6..8917a03 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -833,9 +833,6 @@ struct platform_device *ci_hdrc_add_device(struct device 
> *dev,
>   }
>  
>   pdev->dev.parent = dev;
> - pdev->dev.dma_mask = dev->dma_mask;
> - pdev->dev.dma_parms = dev->dma_parms;
> - dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
>  
>   ret = platform_device_add_resources(pdev, res, nres);
>   if (ret)
> diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
> index 96ae695..ca27893 100644
> --- a/drivers/usb/chipidea/host.c
> +++ b/drivers/usb/chipidea/host.c
> @@ -116,7 +116,8 @@ static int host_start(struct ci_hdrc *ci)
>   if (usb_disabled())
>   return -ENODEV;
>  
> - hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
> + hcd = __usb_create_hcd(&ci_ehci_hc_driver, ci->dev->parent,
> +ci->dev, dev_name(ci->dev), NULL);
>   if (!hcd)
>   return -ENOMEM;
>  
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index 661f43f..bc55922 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -423,7 +423,8 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, 
> struct ci_hw_req *hwreq)
>  
>   hwreq->req.status = -EALREADY;
>  
> - ret = usb_gadget_map_request(&ci->gadget, &hwreq->req, hwep->dir);
> + ret = usb_gadget_map_request_by_dev(ci->dev->parent,
> + &hwreq->req, hwep->dir);
>   if (ret)
>   return ret;
>  
> @@ -603,7 +604,8 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, 
> struct ci_hw_req *hwreq)
>   list_del_init(&node->td);
>   }
>  
> - usb_gadget_unmap_request(&hwep->ci->gadget, &hwreq->req, hwep->dir);
> + usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent,
> + &hwreq->req, hwep->dir);
>  
>   hwreq->req.actual += actual;
>  
> @@ -1904,13 +1906,13 @@ static int udc_start(struct ci_hdrc *ci)
>   INIT_LIST_HEAD(&ci->gadget.ep_list);
>  
>   /* alloc resources */
> - ci->qh_pool = dma_pool_create("ci_hw_qh", dev,
> + ci->qh_pool = dma_pool_create("ci_hw_qh", dev->parent,
>  sizeof(struct ci_hw_qh),
>  64, CI_HDRC_PAGE_SIZE);
>   if (ci->qh_pool == NULL)
>   return -ENOMEM;
>  
> - ci->td_pool = dma_pool_create("ci_hw_td", dev,
> + ci->td_pool = dma_pool_create("ci_hw_td", dev->parent,
>  sizeof(struct ci_hw_td),
>  64, CI_HDRC_PAGE_SIZE);
>   if (ci->td_pool == NULL) {
> -- 

Acked-by: Peter Chen 

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: u_ether: remove interrupt throttling

2016-11-01 Thread Peter Chen
On Tue, Nov 01, 2016 at 01:29:59PM +0200, Felipe Balbi wrote:
> According to Dave Miller "the networking stack has a
> hard requirement that all SKBs which are transmitted
> must have their completion signalled in a fininte
> amount of time. This is because, until the SKB is
> freed by the driver, it holds onto socket,
> netfilter, and other subsystem resources."
> 
> In summary, this means that using TX IRQ throttling
> for the networking gadgets is, at least, complex and
> we should avoid it for the time being.
> 
> Cc: 
> Reported-by: Ville Syrjälä 
> Suggested-by: David Miller 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/gadget/function/u_ether.c | 8 
>  1 file changed, 8 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_ether.c 
> b/drivers/usb/gadget/function/u_ether.c
> index f4a640216913..119a2e5848e8 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -589,14 +589,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
>  
>   req->length = length;
>  
> - /* throttle high/super speed IRQ rate back slightly */
> - if (gadget_is_dualspeed(dev->gadget))
> - req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH ||
> -dev->gadget->speed == USB_SPEED_SUPER)) 
> &&
> - !list_empty(&dev->tx_reqs))
> - ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
> - : 0;
> -
>   retval = usb_ep_queue(in, req, GFP_ATOMIC);
>   switch (retval) {
>   default:
> -- 

Felipe, it may increase cpu utilization since more interrupts will be there,
it may affect the SoC which has lower cpu frequency. This code existed
many years, why this problem has only reported at dwc3 recently?

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 0/6] inherit dma configuration from parent dev

2016-11-01 Thread Sriram Dash
For xhci-hcd platform device, all the DMA parameters are not
configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along
with the child device pointer, so it would behave exactly
like the parent already does. The difference is that it also
handles all the other attributes besides the mask.


Arnd Bergmann (6):
  usb: separate out sysdev pointer from usb_bus
  usb: chipidea: use bus->sysdev for DMA configuration
  usb: ehci: fsl: use bus->sysdev for DMA configuration
  usb: xhci: use bus->sysdev for DMA configuration
  usb: dwc3: use bus->sysdev for DMA configuration
  usb: dwc3: Do not set dma coherent mask

 drivers/usb/chipidea/core.c|  3 ---
 drivers/usb/chipidea/host.c|  3 ++-
 drivers/usb/chipidea/udc.c | 10 +
 drivers/usb/core/buffer.c  | 12 +--
 drivers/usb/core/hcd.c | 48 +-
 drivers/usb/core/usb.c | 18 
 drivers/usb/dwc3/core.c| 28 
 drivers/usb/dwc3/core.h|  1 +
 drivers/usb/dwc3/dwc3-exynos.c | 10 -
 drivers/usb/dwc3/dwc3-st.c |  1 -
 drivers/usb/dwc3/ep0.c |  8 +++
 drivers/usb/dwc3/gadget.c  | 37 
 drivers/usb/dwc3/host.c| 12 ---
 drivers/usb/host/ehci-fsl.c|  4 ++--
 drivers/usb/host/xhci-mem.c| 12 +--
 drivers/usb/host/xhci-plat.c   | 33 +++--
 drivers/usb/host/xhci.c| 15 +
 include/linux/usb.h|  1 +
 include/linux/usb/hcd.h|  3 +++
 19 files changed, 144 insertions(+), 115 deletions(-)

-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 6/6] usb: dwc3: Do not set dma coherent mask

2016-11-01 Thread Sriram Dash
From: Arnd Bergmann 

The dma mask is correctly set up by the DT probe function, no
need to override it any more.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Sriram Dash 
---
Changes in v2:
  - club the cleanup for dma coherent mask for device

 drivers/usb/dwc3/dwc3-exynos.c | 10 --
 drivers/usb/dwc3/dwc3-st.c |  1 -
 2 files changed, 11 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c
index 2f1fb7e..e27899b 100644
--- a/drivers/usb/dwc3/dwc3-exynos.c
+++ b/drivers/usb/dwc3/dwc3-exynos.c
@@ -20,7 +20,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -117,15 +116,6 @@ static int dwc3_exynos_probe(struct platform_device *pdev)
if (!exynos)
return -ENOMEM;
 
-   /*
-* Right now device-tree probed devices don't get dma_mask set.
-* Since shared usb code relies on it, set it here for now.
-* Once we move to full device tree support this will vanish off.
-*/
-   ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
-   if (ret)
-   return ret;
-
platform_set_drvdata(pdev, exynos);
 
exynos->dev = dev;
diff --git a/drivers/usb/dwc3/dwc3-st.c b/drivers/usb/dwc3/dwc3-st.c
index 89a2f71..4d7439c 100644
--- a/drivers/usb/dwc3/dwc3-st.c
+++ b/drivers/usb/dwc3/dwc3-st.c
@@ -218,7 +218,6 @@ static int st_dwc3_probe(struct platform_device *pdev)
if (IS_ERR(regmap))
return PTR_ERR(regmap);
 
-   dma_set_coherent_mask(dev, dev->coherent_dma_mask);
dwc3_data->dev = dev;
dwc3_data->regmap = regmap;
 
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/6] usb: chipidea: use bus->sysdev for DMA configuration

2016-11-01 Thread Sriram Dash
From: Arnd Bergmann 

Set the dma for chipidea from sysdev. This is inherited from its
parent node. Also, do not set dma mask for child as it is not required
now.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Sriram Dash 
---
Changes in v2:
  - integrate chipidea driver changes together.

 drivers/usb/chipidea/core.c |  3 ---
 drivers/usb/chipidea/host.c |  3 ++-
 drivers/usb/chipidea/udc.c  | 10 ++
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 69426e6..8917a03 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -833,9 +833,6 @@ struct platform_device *ci_hdrc_add_device(struct device 
*dev,
}
 
pdev->dev.parent = dev;
-   pdev->dev.dma_mask = dev->dma_mask;
-   pdev->dev.dma_parms = dev->dma_parms;
-   dma_set_coherent_mask(&pdev->dev, dev->coherent_dma_mask);
 
ret = platform_device_add_resources(pdev, res, nres);
if (ret)
diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 96ae695..ca27893 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -116,7 +116,8 @@ static int host_start(struct ci_hdrc *ci)
if (usb_disabled())
return -ENODEV;
 
-   hcd = usb_create_hcd(&ci_ehci_hc_driver, ci->dev, dev_name(ci->dev));
+   hcd = __usb_create_hcd(&ci_ehci_hc_driver, ci->dev->parent,
+  ci->dev, dev_name(ci->dev), NULL);
if (!hcd)
return -ENOMEM;
 
diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 661f43f..bc55922 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -423,7 +423,8 @@ static int _hardware_enqueue(struct ci_hw_ep *hwep, struct 
ci_hw_req *hwreq)
 
hwreq->req.status = -EALREADY;
 
-   ret = usb_gadget_map_request(&ci->gadget, &hwreq->req, hwep->dir);
+   ret = usb_gadget_map_request_by_dev(ci->dev->parent,
+   &hwreq->req, hwep->dir);
if (ret)
return ret;
 
@@ -603,7 +604,8 @@ static int _hardware_dequeue(struct ci_hw_ep *hwep, struct 
ci_hw_req *hwreq)
list_del_init(&node->td);
}
 
-   usb_gadget_unmap_request(&hwep->ci->gadget, &hwreq->req, hwep->dir);
+   usb_gadget_unmap_request_by_dev(hwep->ci->dev->parent,
+   &hwreq->req, hwep->dir);
 
hwreq->req.actual += actual;
 
@@ -1904,13 +1906,13 @@ static int udc_start(struct ci_hdrc *ci)
INIT_LIST_HEAD(&ci->gadget.ep_list);
 
/* alloc resources */
-   ci->qh_pool = dma_pool_create("ci_hw_qh", dev,
+   ci->qh_pool = dma_pool_create("ci_hw_qh", dev->parent,
   sizeof(struct ci_hw_qh),
   64, CI_HDRC_PAGE_SIZE);
if (ci->qh_pool == NULL)
return -ENOMEM;
 
-   ci->td_pool = dma_pool_create("ci_hw_td", dev,
+   ci->td_pool = dma_pool_create("ci_hw_td", dev->parent,
   sizeof(struct ci_hw_td),
   64, CI_HDRC_PAGE_SIZE);
if (ci->td_pool == NULL) {
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 5/6] usb: dwc3: use bus->sysdev for DMA configuration

2016-11-01 Thread Sriram Dash
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 
---
Changes in v2:
  - integrate dwc3 driver changes together

 drivers/usb/dwc3/core.c   | 28 +++-
 drivers/usb/dwc3/core.h   |  1 +
 drivers/usb/dwc3/ep0.c|  8 
 drivers/usb/dwc3/gadget.c | 37 +++--
 drivers/usb/dwc3/host.c   | 12 
 5 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7287a76..0af0dc0 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -229,7 +230,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);
 }
 
 /**
@@ -251,7 +252,7 @@ static struct dwc3_event_buffer 
*dwc3_alloc_one_event_buffer(struct dwc3 *dwc,
 
evt->dwc= dwc;
evt->length = length;
-   evt->buf= dma_alloc_coherent(dwc->dev, length,
+   evt->buf= dma_alloc_coherent(dwc->sysdev, length,
&evt->dma, GFP_KERNEL);
if (!evt->buf)
return ERR_PTR(-ENOMEM);
@@ -370,11 +371,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;
}
@@ -398,7 +399,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:
@@ -417,7 +418,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);
 }
@@ -943,6 +944,13 @@ static int dwc3_probe(struct platform_device *pdev)
dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
dwc->mem = mem;
dwc->dev = dev;
+#ifdef CONFIG_PCI
+   /* TODO: or some other way of detecting this? */
+   if (dwc->dev->parent && dwc->dev->parent->bus == &pci_bus_type)
+   dwc->sysdev = dwc->dev->parent;
+   else
+#endif
+   dwc->sysdev = dwc->dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
@@ -1051,12 +1059,6 @@ static int dwc3_probe(struct platform_device *pdev)
 
spin_lock_init(&dwc->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 6b60e42..b166b0a 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -851,6 +851,7 @@ struct dwc3 {
spinlock_t  lock;
 
struct device   *dev;
+   struct device   *sysdev;
 
struct platform_device  *xhci;
struct resource xhci_resources[DWC3_XHCI_RESOURCES_NUM];
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index fe79d77..4d13723 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -974,8 +974,8 @@ static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
u32 transfer_size = 0;
u32 maxpacket;
 
-   ret = usb_gadget_map_request(&dwc->gadget, &req->request,
-   dep->number);
+   ret = usb_gadget_map_request_by_dev(dwc->sysdev,
+ 

[PATCH v2 1/6] usb: separate out sysdev pointer from usb_bus

2016-11-01 Thread Sriram Dash
From: Arnd Bergmann 

For xhci-hcd platform device, all the DMA parameters are not
configured properly, notably dma ops for dwc3 devices.

The idea here is that you pass in the parent of_node along with
the child device pointer, so it would behave exactly like the
parent already does. The difference is that it also handles all
the other attributes besides the mask.

sysdev will represent the physical device, as seen from firmware
or bus.Splitting the usb_bus->controller field into the
Linux-internal device (used for the sysfs hierarchy, for printks
and for power management) and a new pointer (used for DMA,
DT enumeration and phy lookup) probably covers all that we really
need.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Sriram Dash 
Cc: Felipe Balbi 
Cc: Grygorii Strashko 
Cc: Sinjan Kumar 
Cc: David Fisher 
Cc: Catalin Marinas 
Cc: "Thang Q. Nguyen" 
Cc: Yoshihiro Shimoda 
Cc: Stephen Boyd 
Cc: Bjorn Andersson 
Cc: Ming Lei 
Cc: Jon Masters 
Cc: Dann Frazier 
Cc: Peter Chen 
Cc: Leo Li 
---
Changes in v2:
  - Split the patch wrt driver

 drivers/usb/core/buffer.c | 12 ++--
 drivers/usb/core/hcd.c| 48 ---
 drivers/usb/core/usb.c| 18 +-
 include/linux/usb.h   |  1 +
 include/linux/usb/hcd.h   |  3 +++
 5 files changed, 48 insertions(+), 34 deletions(-)

diff --git a/drivers/usb/core/buffer.c b/drivers/usb/core/buffer.c
index 98e39f9..1e41ef7 100644
--- a/drivers/usb/core/buffer.c
+++ b/drivers/usb/core/buffer.c
@@ -63,7 +63,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
int i, size;
 
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-   (!hcd->self.controller->dma_mask &&
+   (!hcd->self.sysdev->dma_mask &&
 !(hcd->driver->flags & HCD_LOCAL_MEM)))
return 0;
 
@@ -72,7 +72,7 @@ int hcd_buffer_create(struct usb_hcd *hcd)
if (!size)
continue;
snprintf(name, sizeof(name), "buffer-%d", size);
-   hcd->pool[i] = dma_pool_create(name, hcd->self.controller,
+   hcd->pool[i] = dma_pool_create(name, hcd->self.sysdev,
size, size, 0);
if (!hcd->pool[i]) {
hcd_buffer_destroy(hcd);
@@ -127,7 +127,7 @@ void *hcd_buffer_alloc(
 
/* some USB hosts just use PIO */
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-   (!bus->controller->dma_mask &&
+   (!bus->sysdev->dma_mask &&
 !(hcd->driver->flags & HCD_LOCAL_MEM))) {
*dma = ~(dma_addr_t) 0;
return kmalloc(size, mem_flags);
@@ -137,7 +137,7 @@ void *hcd_buffer_alloc(
if (size <= pool_max[i])
return dma_pool_alloc(hcd->pool[i], mem_flags, dma);
}
-   return dma_alloc_coherent(hcd->self.controller, size, dma, mem_flags);
+   return dma_alloc_coherent(hcd->self.sysdev, size, dma, mem_flags);
 }
 
 void hcd_buffer_free(
@@ -154,7 +154,7 @@ void hcd_buffer_free(
return;
 
if (!IS_ENABLED(CONFIG_HAS_DMA) ||
-   (!bus->controller->dma_mask &&
+   (!bus->sysdev->dma_mask &&
 !(hcd->driver->flags & HCD_LOCAL_MEM))) {
kfree(addr);
return;
@@ -166,5 +166,5 @@ void hcd_buffer_free(
return;
}
}
-   dma_free_coherent(hcd->self.controller, size, addr, dma);
+   dma_free_coherent(hcd->self.sysdev, size, addr, dma);
 }
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 479e223..f8feb08 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -1073,6 +1073,7 @@ static void usb_deregister_bus (struct usb_bus *bus)
 static int register_root_hub(struct usb_hcd *hcd)
 {
struct device *parent_dev = hcd->self.controller;
+   struct device *sysdev = hcd->self.sysdev;
struct usb_device *usb_dev = hcd->self.root_hub;
const int devnum = 1;
int retval;
@@ -1119,7 +1120,7 @@ static int register_root_hub(struct usb_hcd *hcd)
/* Did the HC die before the root hub was registered? */
if (HCD_DEAD(hcd))
usb_hc_died (hcd);  /* This time clean up */
-   usb_dev->dev.of_node = parent_dev->of_node;
+   usb_dev->dev.of_node = sysdev->of_node;
}
mutex_unlock(&usb_bus_idr_lock);
 
@@ -1465,19 +1466,19 @@ void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, 
struct urb *urb)
dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
if (IS_ENABLED(CONFIG_HAS_DMA) &&
(urb->transfer_flags & URB_DMA_MAP_SG))
-   dma_unmap_sg(hcd->self.controller,
+   dma_unmap_sg(hcd->self.sysdev,
urb->sg,
urb->num_sgs,
dir);
else if (IS_ENABLED(CONFIG_HAS_DMA) &&
 

[PATCH v2 3/6] usb: ehci: fsl: use bus->sysdev for DMA configuration

2016-11-01 Thread Sriram Dash
From: Arnd Bergmann 

For the dual role ehci fsl driver, sysdev will handle the dma
config.

Signed-off-by: Arnd Bergmann 
Signed-off-by: Sriram Dash 
---
Changes in v2:
  - fix compile warnings


 drivers/usb/host/ehci-fsl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/ehci-fsl.c b/drivers/usb/host/ehci-fsl.c
index 9f5ffb6..4dde500 100644
--- a/drivers/usb/host/ehci-fsl.c
+++ b/drivers/usb/host/ehci-fsl.c
@@ -96,8 +96,8 @@ static int fsl_ehci_drv_probe(struct platform_device *pdev)
}
irq = res->start;
 
-   hcd = usb_create_hcd(&fsl_ehci_hc_driver, &pdev->dev,
-   dev_name(&pdev->dev));
+   hcd = __usb_create_hcd(&fsl_ehci_hc_driver, &pdev->dev->parent,
+  &pdev->dev, dev_name(&pdev->dev), NULL);
if (!hcd) {
retval = -ENOMEM;
goto err1;
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/1] usb: xhci: remove the use of xhci->addr_dev

2016-11-01 Thread Lu Baolu
xhci->addr_dev is used for the completion of both address device
and enable slot commands. It's shared by enumerations of all USB
devices connected to an xhci host. Hence, it's just a source for
possible races. Since we've introduced command structure and the
command queue to xhci driver.  It is time to get rid of addr_dev
and use the completion in the command structure instead.

Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci-mem.c |  1 -
 drivers/usb/host/xhci.c | 18 ++
 drivers/usb/host/xhci.h |  1 -
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6afe323..4c27828 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2536,7 +2536,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
 * something other than the default (~1ms minimum between interrupts).
 * See section 5.5.1.2.
 */
-   init_completion(&xhci->addr_dev);
for (i = 0; i < MAX_HC_SLOTS; ++i)
xhci->devs[i] = NULL;
for (i = 0; i < USB_MAXCHILDREN; ++i) {
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ad06243..e254af7 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3683,20 +3683,19 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
int ret, slot_id;
struct xhci_command *command;
 
-   command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
+   command = xhci_alloc_command(xhci, false, true, GFP_KERNEL);
if (!command)
return 0;
 
/* xhci->slot_id and xhci->addr_dev are not thread-safe */
mutex_lock(&xhci->mutex);
spin_lock_irqsave(&xhci->lock, flags);
-   command->completion = &xhci->addr_dev;
ret = xhci_queue_slot_control(xhci, command, TRB_ENABLE_SLOT, 0);
if (ret) {
spin_unlock_irqrestore(&xhci->lock, flags);
mutex_unlock(&xhci->mutex);
xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
-   kfree(command);
+   xhci_free_command(xhci, command);
return 0;
}
xhci_ring_cmd_db(xhci);
@@ -3711,7 +3710,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device 
*udev)
xhci_err(xhci, "Max number of devices this xHCI host supports 
is %u.\n",
HCS_MAX_SLOTS(
readl(&xhci->cap_regs->hcs_params1)));
-   kfree(command);
+   xhci_free_command(xhci, command);
return 0;
}
 
@@ -3747,7 +3746,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device 
*udev)
 #endif
 
 
-   kfree(command);
+   xhci_free_command(xhci, command);
/* Is this a LS or FS device under a HS hub? */
/* Hub or peripherial? */
return 1;
@@ -3755,6 +3754,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device 
*udev)
 disable_slot:
/* Disable slot, if we can do it without mem alloc */
spin_lock_irqsave(&xhci->lock, flags);
+   kfree(command->completion);
command->completion = NULL;
command->status = 0;
if (!xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
@@ -3818,14 +3818,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, 
struct usb_device *udev,
}
}
 
-   command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
+   command = xhci_alloc_command(xhci, false, true, GFP_KERNEL);
if (!command) {
ret = -ENOMEM;
goto out;
}
 
command->in_ctx = virt_dev->in_ctx;
-   command->completion = &xhci->addr_dev;
 
slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx);
ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx);
@@ -3943,7 +3942,10 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct 
usb_device *udev,
   le32_to_cpu(slot_ctx->dev_state) & DEV_ADDR_MASK);
 out:
mutex_unlock(&xhci->mutex);
-   kfree(command);
+   if (command) {
+   kfree(command->completion);
+   kfree(command);
+   }
return ret;
 }
 
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f945380..60f254a 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1583,7 +1583,6 @@ struct xhci_hcd {
/* slot enabling and address device helpers */
/* these are not thread safe so use mutex */
struct mutex mutex;
-   struct completion   addr_dev;
int slot_id;
/* For USB 3.0 LPM enable/disable. */
struct xhci_command *lpm_command;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v2] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-01 Thread Yoshihiro Shimoda
Hi Peter,

> From: Peter Chen [mailto:hzpeterc...@gmail.com]
> Sent: Tuesday, November 01, 2016 8:38 PM
> 
> On Tue, Nov 01, 2016 at 04:01:58PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds sysfs "otg_inputs" for usb role swap. This parameter
> > is write-only and if you use them as the following, you can swap
> > the usb role.
> >
> > For example:
> >  1) connect a usb cable using 2 salvator-x boards
> >  2) On A-device (as host), you input the following command:
> ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >  3) On B-device (as peripheral), you input the following command:
> ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Then, the A-device acts as a peripheral (A-peripheral) and the B-device
> > acts as a host (B-host).
> > Please note that A-device must input the following command if you
> > want the board to act as a host again. (even if you disconnect the usb
> > cable, since id state may be the same, the condition keeps "A-peripheral".)
> >  # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Also you can use the following command if you want the B-device board to
> > act as a peripheral again.
> >  # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > ---
> >  This patch is based on the latest linux-phy.git / next branch.
> >  (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)
> >
> >  Since this patch is related to usb, I added email addresses of Greg, 
> > Felipe,
> >  Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)
> >
> >  Changed from v1:
> >   - rebase the latest next branch.
> >
> >  .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 124 
> > -
> >  2 files changed, 134 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> >
> > diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > new file mode 100644
> > index 000..c7e715af
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > @@ -0,0 +1,11 @@
> > +What:  /sys/devices/platform//otg-inputs
> > +Date:  October 2016
> > +KernelVersion: 4.10
> > +Contact:   Yoshihiro Shimoda 
> > +Description:
> > +   This write-only file changes the phy mode for role swap of usb.
> > +   This file accepts the following strings:
> > +"a_bus_req/" - switching from A-Host to A-Peripheral
> > +"a_bus_drop" - switching from A-Peripheral to A-Host
> > +"b_bus_req"  - switching from B-Peripheral to B-Host
> > +"b_bus_req/" - switching from B-Host to B-Peripheral
> 
> Would you really care OTG FSM state machine? If not, you could just use
> "host" and "peripheral" to stand for current USB role, and implement
> role switch sysfs like: /sys/devices/platform//role.

Thank you for the comment!
Since I would not care OTG FSM state machine for now, I will modify the patch to
use "host" and "peripheral" that you suggested.

Best regards,
Yoshihiro Shimoda

> Peter
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 0/2] musb-fixes for v4.9-rc2

2016-11-01 Thread Ladislav Michl
Hi,

On Mon, Oct 24, 2016 at 11:07:08AM -0700, Tony Lindgren wrote:
> Hi,
> 
> * Tony Lindgren  [161021 00:18]:
> > * Ladislav Michl  [161020 12:37]:
> > > [  186.457519] musb-hdrc musb-hdrc.0.auto: VBUS_ERROR in a_wait_bcon (90, 
> > >  > > 
> > > And that's the end, since now it does not react on hub plug/unplug.
> > > 
> > > Also all that VBUS_ERROR conditions are strange as hub is powered 
> > > separately
> > > and power lines from phy are not used.
> > 
> > Hmm yeah. I'd like to be able to reproduce this. Can you email me
> > your .config (again)? You have things in host mode with a powered
> > hub plus few devices with no USB gadgets configured?
> 
> Well I found your earlier .config so presumably that did not change.
> Below patch seems to do the trick for me, but I need to test more.
> 
> Care to test if it helps for you? Please test with v4.9-rc2 and the
> following two fixes heading in Greg's usb-linus branch:
> 
> cacaaf80c3a6 ("usb: musb: Call pm_runtime from musb_gadget_queue")
> d8e5f0eca1e8 ("usb: musb: Fix hardirq-safe hardirq-unsafe lock order error")

tested with v4.9-rc3 which have these included.

> I'll send a proper patch if that works for you.

Unfortunately it's still the same. Direct connection (without hub) remains
untested as there's not enough power to supply display:
usb 2-1: USB disconnect, device number 2
usb 2-1: new high-speed USB device number 3 using musb-hdrc
usb 2-1: New USB device found, idVendor=17e9, idProduct=0335
usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1: Product: MIMO
usb 2-1: Manufacturer: DisplayLink
usb 2-1: SerialNumber: 1071007195
usb 2-1: rejected 1 configuration due to insufficient available bus power
usb 2-1: no configuration chosen from 1 choice

Regards,
ladis

> Regards,
> 
> Tony
> 
> 8< 
> diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
> --- a/drivers/phy/phy-twl4030-usb.c
> +++ b/drivers/phy/phy-twl4030-usb.c
> @@ -459,8 +459,6 @@ static int twl4030_phy_power_off(struct phy *phy)
>   struct twl4030_usb *twl = phy_get_drvdata(phy);
>  
>   dev_dbg(twl->dev, "%s\n", __func__);
> - pm_runtime_mark_last_busy(twl->dev);
> - pm_runtime_put_autosuspend(twl->dev);
>  
>   return 0;
>  }
> @@ -472,6 +470,8 @@ static int twl4030_phy_power_on(struct phy *phy)
>   dev_dbg(twl->dev, "%s\n", __func__);
>   pm_runtime_get_sync(twl->dev);
>   schedule_delayed_work(&twl->id_workaround_work, HZ);
> + pm_runtime_mark_last_busy(twl->dev);
> + pm_runtime_put_autosuspend(twl->dev);
>  
>   return 0;
>  }
> -- 
> 2.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] usb: musb: remove duplicated actions

2016-11-01 Thread Bin Liu
From: Kirill Esipov 

Removing unnecessary duplicated actions that we've got while merging:
Commit 19915e623458 ("Merge 4.1-rc7 into usb-next")

[ b-...@ti.com: added 'Commit' in the commit message ]

Signed-off-by: Kirill Esipov 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 5 -
 1 file changed, 5 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 27dadc0d9114..e01116e4c067 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2114,11 +2114,6 @@ static void musb_deassert_reset(struct work_struct *work)
musb->io.ep_offset = musb_flat_ep_offset;
musb->io.ep_select = musb_flat_ep_select;
}
-   /* And override them with platform specific ops if specified. */
-   if (musb->ops->ep_offset)
-   musb->io.ep_offset = musb->ops->ep_offset;
-   if (musb->ops->ep_select)
-   musb->io.ep_select = musb->ops->ep_select;
 
/* At least tusb6010 has its own offsets */
if (musb->ops->ep_offset)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/2] usb: musb: da8xx: Don't print phy error on -EPROBE_DEFER

2016-11-01 Thread Bin Liu
From: David Lechner 

This suppresses printing the error message "failed to get phy" in the
kernel log when the error is -EPROBE_DEFER. This prevents usless noise
in the kernel log.

Signed-off-by: David Lechner 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/da8xx.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 210b7e43a6fd..2440f88e07a3 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -479,7 +479,8 @@ static int da8xx_probe(struct platform_device *pdev)
 
glue->phy = devm_phy_get(&pdev->dev, "usb-phy");
if (IS_ERR(glue->phy)) {
-   dev_err(&pdev->dev, "failed to get phy\n");
+   if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
+   dev_err(&pdev->dev, "failed to get phy\n");
return PTR_ERR(glue->phy);
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/2] musb-fixes for v4.9-rc4

2016-11-01 Thread Bin Liu
Hi Greg,

Here are musb fixes for v4.9-rc4. They are minor cleanup in musb.
Please let me know if any change is needed.

Thanks,
-Bin.

---
David Lechner (1):
  usb: musb: da8xx: Don't print phy error on -EPROBE_DEFER

Kirill Esipov (1):
  usb: musb: remove duplicated actions

 drivers/usb/musb/da8xx.c | 3 ++-
 drivers/usb/musb/musb_core.c | 5 -
 2 files changed, 2 insertions(+), 6 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: musb: isoc pkt loss with pwc

2016-11-01 Thread Bin Liu
On Sat, Oct 15, 2016 at 10:25:42PM +0300, Matwey V. Kornilov wrote:

[snip]

> >>> > Which means without this commit your camera has been working without
> >>> > issues, and this is a regression with this commit, right?
> >>> >
> >>>
> >>> Right
> >>
> >> Okay, thanks for confirming.
> >>
> >> But we cannot just simply add this flag, as it breaks many other use
> >> cases. I will continue work on this to find a solution which works on
> >> all use cases.
> >>
> >
> > Ok, thank you.
> >
> 
> Excuse me. Any news?

Not solved yet. I used uvc class to exam the issue. uvc_video driver
takes longer time to execute urb complete() on my platform. Using HCD_BH
flag doesn't help, because urb->complete() was running with irq disabled
because of the local_irq. Removing the local_irq as in [1] causes the
system to lockup - uart and network stop responsing, so hard to debug
for now.

Right now, I added a workqueue in musb_host to handle urb->complete()
with local_irq removed. It seems working fine in my test, but it is
still a long way find the proper fix for upstream. I didn't have much
time on this issue.

Once I have a proper solution, I will post it to the mailing list.

[1] http://marc.info/?l=linux-usb&m=147560701431267&w=2

Regards,
-Bin.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: musb: da8xx: Don't print phy error on -EPROBE_DEFER

2016-11-01 Thread Bin Liu
Hi,

On Tue, Oct 25, 2016 at 02:02:50PM -0500, David Lechner wrote:
> This suppresses printing the error message "failed to get phy" in the
> kernel log when the error is -EPROBE_DEFER. This prevents usless noise
> in the kernel log.
> 
> Signed-off-by: David Lechner 

Applied. Thanks.

Regards,
-Bin.

> ---
>  drivers/usb/musb/da8xx.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
> index 481d786..f8a1591 100644
> --- a/drivers/usb/musb/da8xx.c
> +++ b/drivers/usb/musb/da8xx.c
> @@ -516,7 +516,8 @@ static int da8xx_probe(struct platform_device *pdev)
>  
>   glue->phy = devm_phy_get(&pdev->dev, "usb-phy");
>   if (IS_ERR(glue->phy)) {
> - dev_err(&pdev->dev, "failed to get phy\n");
> + if (PTR_ERR(glue->phy) != -EPROBE_DEFER)
> + dev_err(&pdev->dev, "failed to get phy\n");
>   return PTR_ERR(glue->phy);
>   }
>  
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: musb: remove duplicated actions

2016-11-01 Thread Bin Liu
Hi,

On Wed, Oct 26, 2016 at 09:10:07PM +0300, Kirill Esipov wrote:
> Removing unnecessary duplicated actions that we've got while merging:
> 19915e623458 ("Merge 4.1-rc7 into usb-next")
> 
> Signed-off-by: Kirill Esipov 

Applied. Thanks.

Regards,
-Bin.

> ---
>  drivers/usb/musb/musb_core.c | 5 -
>  1 file changed, 5 deletions(-)
> 
> diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
> index 27dadc0..e01116e 100644
> --- a/drivers/usb/musb/musb_core.c
> +++ b/drivers/usb/musb/musb_core.c
> @@ -2114,11 +2114,6 @@ musb_init_controller(struct device *dev, int nIrq, 
> void __iomem *ctrl)
>   musb->io.ep_offset = musb_flat_ep_offset;
>   musb->io.ep_select = musb_flat_ep_select;
>   }
> - /* And override them with platform specific ops if specified. */
> - if (musb->ops->ep_offset)
> - musb->io.ep_offset = musb->ops->ep_offset;
> - if (musb->ops->ep_select)
> - musb->io.ep_select = musb->ops->ep_select;
>  
>   /* At least tusb6010 has its own offsets */
>   if (musb->ops->ep_offset)
> -- 
> 2.7.4
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [dmesg] usb 2-1.5:1.0: rebind failed: -517

2016-11-01 Thread Cristian
Hello,

Run _Always_ start Ubuntu
--
Cristian Aravena Romero




2016-10-30 22:21 GMT-03:00 Peter Chen :
> On Sat, Oct 29, 2016 at 03:53:24PM -0300, Cristian wrote:
>> Hello,
>>
>> Report in https://bugzilla.kernel.org/show_bug.cgi?id=185591
>>
>
> You may provide more information about bug, eg, how to trigger the
> bug, the frequency of the bug?
>
> "-517" is -EPROBE_DEFER, it means some resources for this device
> are not ready.
>
> --
>
> Best Regards,
> Peter Chen



-- 
Cristian
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [dmesg] usb 2-1.5:1.0: rebind failed: -517

2016-11-01 Thread sonofagun



"-517" is -EPROBE_DEFER, it means some resources for this device
are not ready.
Thanks for the info, I fell on it too on a completely different box but 
had no time to find what it is. Now it is clear what is going on.



Here is how the bug reporter fell on it:

dmesg shows that he performed an ACPI S3 transition:
"ACPI: Preparing to enter system sleep state S3"

then he resumed:
"ACPI: Waking up from system sleep state S3"

and the WebCam device failed to resume properly after S3 resume when it 
was reset...


It is specific to the attached device.


Last friday, I had similar findings on my AMD box with an ASMedia XHCI 
controller. The USB device causing it is a combo dongle. It is a dongle 
with a blue LED having an on-board hub chip with two attached devices. A 
USB to IrDA controller and a USB bluetooth controller. I suspect that 
the device fails to resume both devices properly because of async 
suspend-resume. Something similar was observed on libata with combo 
devices such as JMicron controllers.


The suspend issue is not new, I fell on it with Ubuntu 16.04 and when 
resuming from S3:

[ 3183.832344] dpm_run_callback(): usb_dev_resume+0x0/0x20 returns -5
[ 3183.832356] PM: Device 4-2.1 failed to resume async: error -5

After switching to the last Ubuntu the same device did not operate on 
first plug at Ubuntu 16.10 with 4.8.0-26 as I got:

[  353.027824] usb 3-2.2: device descriptor read/64, error -62
and
[  354.783808] usb 3-2.2: device not accepting address 8, error -62
[  354.784433] usb 3-2-port2: unable to enumerate USB device
while the bluetooth LED was off.

Next time I plugged it in, it worked at Ubuntu 16.10 and I performed an 
S3 on purpose. After resume from S3 I got the usual error plus the 517 
error:
[  130.842066] usb 3-2.1: reset full-speed USB device number 4 using 
ohci-pci

[  130.959091] dpm_run_callback(): usb_dev_resume+0x0/0x20 returns -5
[  130.959094] PM: Device 3-2.1 failed to resume async: error -5
[  131.030092] usb 3-2.2: reset full-speed USB device number 5 using 
ohci-pci

[  131.148471] PM: resume of devices complete after 1088.242 msecs
[  131.148538] usb 3-2.2:1.0: rebind failed: -517
[  131.148550] usb 3-2.2:1.1: rebind failed: -517
[  131.148954] PM: Finishing wakeup.

Here is the combo dongle and its devices:
lsusb -t
/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=ohci-pci/4p, 12M
|__ Port 2: Dev 2, If 0, Class=Hub, Driver=hub/2p, 12M
|__ Port 1: Dev 5, If 0, Class=(Defined at Interface level), 
Driver=, 12M

|__ Port 2: Dev 4, If 0, Class=Wireless, Driver=btusb, 12M
|__ Port 2: Dev 4, If 1, Class=Wireless, Driver=btusb, 12M
|__ Port 2: Dev 4, If 2, Class=Application Specific Interface, 
Driver=, 12M


Bus 004 Device 002: ID 0451:2036 Texas Instruments, Inc. TUSB2036 Hub
Bus 004 Device 004: ID 1131:1001 Integrated System Solution Corp. 
KY-BT100 Bluetooth Adapter
Bus 004 Device 005: ID 0e55:110a Speed Dragon Multimedia, Ltd Tanic 
S110-SG1 + ISSC IS1002N [Slow Infra-Red (SIR) & Bluetooth 1.2 (Class 2) 
Adapter]


Tonight I will plug it on the onboard AMD XHCI controller to see if it 
does the same thing.

On the same installation a USB stick has another PM related issue
[2.709375] scsi host4: runtime PM trying to activate child device 
host4 but parent (2-1:1.0) is not active


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [GIT PULL] USB fixes for v4.9-rc4

2016-11-01 Thread Greg Kroah-Hartman
On Tue, Nov 01, 2016 at 04:31:07PM +0200, Felipe Balbi wrote:
> 
> Hi Greg,
> 
> Here's another set of fixes for current -rc cycle. Let me know if you
> want anything to be changed.

Pulled and pushed out, thanks.

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[GIT PULL] USB fixes for v4.9-rc4

2016-11-01 Thread Felipe Balbi

Hi Greg,

Here's another set of fixes for current -rc cycle. Let me know if you
want anything to be changed.

cheers

The following changes since commit a909d3e636995ba7c349e2ca5dbb528154d4ac30:

  Linux 4.9-rc3 (2016-10-29 13:52:02 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
tags/fixes-for-v4.9-rc4

for you to fetch changes up to fd9afd3cbe404998d732be6cc798f749597c5114:

  usb: gadget: u_ether: remove interrupt throttling (2016-11-01 15:48:25 +0200)


usb: fixes for v4.9-rc4

Three more fixes for current -rc cycle. One
randbuild fix on dwc3-st which was lacking
, removal of IRQ
throttling for networking gadgets and a fix for
dwc3's error handling on failed initialization.


Felipe Balbi (2):
  usb: dwc3: st: add missing  include
  usb: gadget: u_ether: remove interrupt throttling

Vivek Gautam (1):
  usb: dwc3: Fix error handling for core init

 drivers/usb/dwc3/core.c   | 5 ++---
 drivers/usb/dwc3/dwc3-st.c| 1 +
 drivers/usb/gadget/function/u_ether.c | 8 
 3 files changed, 3 insertions(+), 11 deletions(-)

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v18 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

2016-11-01 Thread Baolin Wang
Hi,

On 31 October 2016 at 08:00, NeilBrown  wrote:
> On Fri, Oct 28 2016, Baolin Wang wrote:
>
>>>
>>> 3/ usb_charger_notify_state() does nothing if the state doesn't change.
>>>   When the extcon detects an SDP, it will be called to set the state
>>>   to USB_CHARGER_PRESENT.  The value of cur.sdp_max will be whatever
>>>   it happened to be before, which is probably wrong.
>>
>> Sorry, I did not get your points here, could you please explain it 
>> explicitly?
>
> usb_charger_get_current() is used to get the min/max current that is
> supported.
> In the case that an SDP (non-super-speed) has been detected it will
> report the values sdp_min and sdp_max.  Ignoring usb_charger_set_current(),
> sdp_max is set
>  - to DEFAULT_SDP_CUR_MAX (500) at initializaion
>  - to cur_limit when usb_charger_set_cur_limit_by_gadget() is called
>  which happens after USB negotiation, once an allowed vbus_draw is
>  negotiated.
>
> This means that the first time you plug in an SDP cable, the reported
> max will be 500, even though nothing has been negotiated.   The maximum
> before negotiation is much less than that  - I don't remember exactly
> how much.
>
> If negotiation completes, the sdp_max will be set to whatever was
> negotiated.  Maybe 200mA.
> If you unplug, and then plug another SDP cable in, the sdp_max will
> still be 200mA - different from the first time, but still not correct.
> It will remain incorrect until (and unless) USB negotiation completes.

Yes. I need some modification to reset current to default values when
cable unplugged.

>
>>
>>>   When after USB negotiation completes,
>>>   usb_charger_set_cur_limit_by_gadget()
>>>   will call into usb_charger_notify_state() to set USB_CHARGER_PRESENT
>>>   again, but with a new current.  This will be ignored, as the state is
>>>   already USB_CHARGER_PRESENT.
>>
>> No, we will notify the user the current has been changed by one work.
>
> I can see no evidence in the code to justify this assertion, and you
> didn't even try to provide any.

We have one work to notify the user the current has been changed,
please see usb_charger_notify_work().

>
>>
>>>
>>> 4/ I still strongly object to the ->get_charger_type() interface.
>>>  You previously said:
>>>
>>>  No. User can implement the get_charger_type() method to access the
>>>  PMIC registers to get the charger type, which is one very common 
>>> method.
>>>
>>>  I suggest that if the PMIC registers report the charger type, then the
>>>  PMIC driver should register an EXTCON and report the charger type
>>>  through that.  Then the information would be directly available to
>>>  user-space, and the usb-charger framework would have a single uniform
>>>  mechanism for being told the cable type.
>>
>> We just access only one PMIC register to get the charger type, which
>> is no need add one driver for that and there are no any events for
>> extcon. Some sample code in power driver can be like below:
>
> If there are no events, then how do you know when a charger has been
> plugged in?  Do you poll?

We just monitor the plug-in and plug-out events by extcon,  and get
the charger type by accessing PMIC registers when one cable is
plugged.

>
> In any case, one of the major values provided by using an OS like Linux
> is uniform interfaces.  If a device can detect what sort of cable is
> inserted, then that information should be presented as an EXTCON.

Fine. I can remove this callback. We can add it if we need it in future.

>
>>>
>>>  Related:  I don't like charger_type_show().  I don't think
>>>  the usb-charger should export that information to user-space because
>>>  extcon already does that, and duplication is confusing and pointless.
>>
>> I think we should combine all charger related information into one
>> place for user. Moreover if we don't get charger type from extcon, we
>> should also need one place to export the charger type.
>
> Yes and no.
>
> Certainly a uniform consistent interface should be presented.
> "a usb charger" is not the right abstraction.  It is not a thing that
> should have independent existence.  To everybody else in the world, a
> "usb charger" in a box that you plug into the wall, and which has a
> cable to plug into your device.  It is not part of the device itself.
> In general, you cannot point to any component in a device that is the
> "usb charger" so it isn't clear that Linux should even know about a "usb
> charger".

Yes,  we agree that 'usb charger' is not one actual device, and 'usb
charger' is depended on gadget device. Moreover these charger
information is associated with actual gadget device, not virtual usb
charger device.

>
> There is a battery-charger which can take whatever current is available
> and feed it to the battery.  It may well be appropriate for user-space
> to have fine control of the current that this uses quite independently
> of whatever is plugged in (I have a board which can get the current via
> USB or via a more direct connection).
>

Re: xhci_hcd crash on linux 4.7.0

2016-11-01 Thread Alex Damian
Hello,

Coming back to this old thread. I enabled the xhci debug, with little success.

I am running now kernel 4.8.4; there is no dmesg dump anymore, the
system just reboots by itself.
As I am running kernel crash dump, the system loads the kdump kernel,
but doesn't find anything to save.

The interesting bit is that the crashes (and the dmesg errors on
previous kernels) only happen after
the system has been suspended and woken up at least once.

Will continue to update if I get more info - I'm trying to get a
better configuration for kdump, maybe I can learn something from
there.

Cheers,
Alex

>
> Quoting it again here:
>
 Enabling xhci debug could reveal something.
 echo -n 'module xhci_hcd =p' > /sys/kernel/debug/dynamic_debug/control
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: Linux FTDI driver modifications

2016-11-01 Thread Johan Hovold
On Tue, Nov 01, 2016 at 12:33:45PM +0100, Meindert Sprang wrote:
> Hello all,
> 
> I am the developer of the ShipModul (CustomWare) MiniPlex products where 
> we use FTDI chips for USB communications.
> I see that even the latest PID we use (FD4B) is already in the 
> ftdi_sio.c driver and I'm glad to see the Linux community picks this up 
> to fast.
> 
> There is one thing however that I'd like to see added to the driver and 
> that is fixed baud rates for our products. Since PID FD49 (the second 
> PID we assigned) we use fixed baudrates, so the user of our products 
> doesn't have to set the right baud rate in his application.
> 
> When browsing through the source code I found here 
> (http://lxr.free-electrons.com/source/drivers/usb/serial/ftdi_sio.c), I 
> found function
> 
> static __u32 get_ftdi_divisor(struct tty_struct *tty, struct 
> usb_serial_port *port)
> 
> where the devisor for a specific baud rate is set.
> 
> In the case at line 1323, where the FT232BM and similar chips are 
> handled, I see an if statement which obviously checks a few PID's to set 
> a fixed baud rate.

That's not exactly what is being done here; rather a nasty one-off hack
is mapping a specific baudrate to a higher non-standard rate for some
PIDs. There is now a standard way of setting such rates (BOTHER),
which should have been used for this.

> So it appears that it would be fairly easy to add a few other exceptions 
> for our PID's. Am I correct?

I'm afraid this is not something I think we should do. Limiting maximum
baudrate etc based on chip types is one thing, but forcing a fixed rate
based on a particular application a chip is used in is something quite
different (e.g. could change after a firmware update).

Johan
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: u_ether: remove interrupt throttling

2016-11-01 Thread Ville Syrjälä
On Tue, Nov 01, 2016 at 01:29:59PM +0200, Felipe Balbi wrote:
> According to Dave Miller "the networking stack has a
> hard requirement that all SKBs which are transmitted
> must have their completion signalled in a fininte
> amount of time. This is because, until the SKB is
> freed by the driver, it holds onto socket,
> netfilter, and other subsystem resources."
> 
> In summary, this means that using TX IRQ throttling
> for the networking gadgets is, at least, complex and
> we should avoid it for the time being.
> 
> Cc: 
> Reported-by: Ville Syrjälä 
> Suggested-by: David Miller 
> Signed-off-by: Felipe Balbi 

Fixes laggy/hangy g_ether on my BYT FFRD8 tablet, caused by
commit 55a0237f8f47 ("usb: dwc3: gadget: use allocated/queued reqs for LST bit")

Tested-by: Ville Syrjälä 

> ---
>  drivers/usb/gadget/function/u_ether.c | 8 
>  1 file changed, 8 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_ether.c 
> b/drivers/usb/gadget/function/u_ether.c
> index f4a640216913..119a2e5848e8 100644
> --- a/drivers/usb/gadget/function/u_ether.c
> +++ b/drivers/usb/gadget/function/u_ether.c
> @@ -589,14 +589,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
>  
>   req->length = length;
>  
> - /* throttle high/super speed IRQ rate back slightly */
> - if (gadget_is_dualspeed(dev->gadget))
> - req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH ||
> -dev->gadget->speed == USB_SPEED_SUPER)) 
> &&
> - !list_empty(&dev->tx_reqs))
> - ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
> - : 0;
> -
>   retval = usb_ep_queue(in, req, GFP_ATOMIC);
>   switch (retval) {
>   default:
> -- 
> 2.10.1

-- 
Ville Syrjälä
Intel OTC
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] usb: dwc3: gadget: wait for End Transfer to complete

2016-11-01 Thread Baolin Wang
Hi,

On 1 November 2016 at 19:36, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> Hi,
>>
>> On 1 November 2016 at 19:01, Felipe Balbi  wrote:
>>>
>>> Hi,
>>>
>>> Baolin Wang  writes:
 Changes since v1:
  - Move the suspend checking to right place to avoid checking twice.
>>>
>>> there is still one problem
>>>
 @@ -1736,12 +1739,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
  {
   struct dwc3 *dwc = gadget_to_dwc(g);
   unsigned long   flags;
 + int epnum;

   spin_lock_irqsave(&dwc->lock, flags);
   __dwc3_gadget_stop(dwc);
>>>
>>> this tries to access registers. If __dwc3_gadget_stop() runs while
>>> clocks are gated, we will get Data Abort exception.
>>
>> We have suspend checking in __dwc3_gadget_stop(), thus it will not
>> access registers if clocks are disabled.
>>
>>>
>>> How about this version, instead?
>>
>> I think it is OK except we missed set 'dwc->gadget_driver = NULL'.
>
> argh. Man, next time we meet in a conference, I owe you a beer :-)

Okay:) Now it looks good to me. Thanks.

>
> 8<--
> From 06a204f1c2276ca1ffe68d8d59ef2e2ead337bba Mon Sep 17 00:00:00 2001
> From: Baolin Wang 
> Date: Mon, 31 Oct 2016 19:38:36 +0800
> Subject: [PATCH] usb: dwc3: gadget: wait for End Transfer to complete
>
> Instead of just delaying for 100us, we should
> actually wait for End Transfer Command Complete
> interrupt before moving on. Note that this should
> only be done if we're dealing with one of the core
> revisions that actually require the interrupt before
> moving on.
>
> [ felipe.ba...@linux.intel.com: minor improvements ]
>
> Signed-off-by: Baolin Wang 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/dwc3/core.h   |  8 
>  drivers/usb/dwc3/gadget.c | 49 
> +++
>  2 files changed, 49 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 5fc437021ac7..c2b86856e85d 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -26,6 +26,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>  #include 
> @@ -505,6 +506,7 @@ struct dwc3_event_buffer {
>   * @endpoint: usb endpoint
>   * @pending_list: list of pending requests for this endpoint
>   * @started_list: list of started requests on this endpoint
> + * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
>   * @lock: spinlock for endpoint request queue traversal
>   * @regs: pointer to first endpoint register
>   * @trb_pool: array of transaction buffers
> @@ -530,6 +532,8 @@ struct dwc3_ep {
> struct list_headpending_list;
> struct list_headstarted_list;
>
> +   wait_queue_head_t   wait_end_transfer;
> +
> spinlock_t  lock;
> void __iomem*regs;
>
> @@ -546,6 +550,7 @@ struct dwc3_ep {
>  #define DWC3_EP_BUSY   (1 << 4)
>  #define DWC3_EP_PENDING_REQUEST(1 << 5)
>  #define DWC3_EP_MISSED_ISOC(1 << 6)
> +#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
>
> /* This last one is specific to EP0 */
>  #define DWC3_EP0_DIR_IN(1 << 31)
> @@ -1050,6 +1055,9 @@ struct dwc3_event_depevt {
>  #define DEPEVT_TRANSFER_BUS_EXPIRY 2
>
> u32 parameters:16;
> +
> +/* For Command Complete Events */
> +#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
>  } __packed;
>
>  /**
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 4743e53cc295..64d01ff8c119 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -593,11 +593,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
> dep->comp_desc = comp_desc;
> dep->type = usb_endpoint_type(desc);
> dep->flags |= DWC3_EP_ENABLED;
> +   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
>
> reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
> reg |= DWC3_DALEPENA_EP(dep->number);
> dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
>
> +   init_waitqueue_head(&dep->wait_end_transfer);
> +
> if (usb_endpoint_xfer_control(desc))
> return 0;
>
> @@ -699,7 +702,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
> dep->endpoint.desc = NULL;
> dep->comp_desc = NULL;
> dep->type = 0;
> -   dep->flags = 0;
> +   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
>
> return 0;
>  }
> @@ -1783,9 +1786,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
>
>  static void __dwc3_gadget_stop(struct dwc3 *dwc)
>  {
> -   if (pm_runtime_suspended(dwc->dev))
> -   return;
> -
> dwc3_gadget_disable_irq(dwc);
> __dwc3_gadget_ep_disable(dwc->eps[0]);
> __dwc3_gadg

Re: [PATCH 52/82] usb: dwc3: host: extract dwc3_host_get_irq()

2016-11-01 Thread Felipe Balbi
Hi,

Felipe Balbi  writes:
>>>  int dwc3_host_init(struct dwc3 *dwc)
>>>  {
>>> struct property_entry   props[2];
>>> struct platform_device  *xhci;
>>> int ret, irq;
>>> struct resource *res;
>>> -   struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);

forgot to commit the revert of this line, sorry:


8<--
From 3a8a910cbf7f66c63b366e37e9f2513a6455e658 Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Mon, 3 Oct 2016 12:31:48 +0300
Subject: [PATCH] usb: dwc3: host: extract dwc3_host_get_irq()

Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/host.c | 72 -
 1 file changed, 42 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index f6533c68fed1..8c2679e7d4a7 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -19,6 +19,39 @@
 
 #include "core.h"
 
+static int dwc3_host_get_irq(struct dwc3 *dwc)
+{
+   struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
+   int irq;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "host");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq(dwc3_pdev, 0);
+   if (irq > 0)
+   goto out;
+
+   if (irq != -EPROBE_DEFER)
+   dev_err(dwc->dev, "missing host IRQ\n");
+
+   if (!irq)
+   irq = -EINVAL;
+
+out:
+   return irq;
+}
+
 int dwc3_host_init(struct dwc3 *dwc)
 {
struct property_entry   props[2];
@@ -27,39 +60,18 @@ int dwc3_host_init(struct dwc3 *dwc)
struct resource *res;
struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
 
-   irq = platform_get_irq_byname(dwc3_pdev, "host");
-   if (irq == -EPROBE_DEFER)
+   irq = dwc3_host_get_irq(dwc);
+   if (irq < 0)
return irq;
 
-   if (irq <= 0) {
-   irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
-   if (irq == -EPROBE_DEFER)
-   return irq;
-
-   if (irq <= 0) {
-   irq = platform_get_irq(dwc3_pdev, 0);
-   if (irq <= 0) {
-   if (irq != -EPROBE_DEFER) {
-   dev_err(dwc->dev,
-   "missing host IRQ\n");
-   }
-   if (!irq)
-   irq = -EINVAL;
-   return irq;
-   } else {
-   res = platform_get_resource(dwc3_pdev,
-   IORESOURCE_IRQ, 0);
-   }
-   } else {
-   res = platform_get_resource_byname(dwc3_pdev,
-  IORESOURCE_IRQ,
-  "dwc_usb3");
-   }
-
-   } else {
+   res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ, "host");
+   if (!res)
res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ,
-  "host");
-   }
+   "dwc_usb3");
+   if (!res)
+   res = platform_get_resource(dwc3_pdev, IORESOURCE_IRQ, 0);
+   if (!res)
+   return -ENOMEM;
 
dwc->xhci_resources[1].start = irq;
dwc->xhci_resources[1].end = irq;
-- 
2.10.1



-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v2] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-01 Thread Peter Chen
On Tue, Nov 01, 2016 at 04:01:58PM +0900, Yoshihiro Shimoda wrote:
> This patch adds sysfs "otg_inputs" for usb role swap. This parameter
> is write-only and if you use them as the following, you can swap
> the usb role.
> 
> For example:
>  1) connect a usb cable using 2 salvator-x boards
>  2) On A-device (as host), you input the following command:
># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
>  3) On B-device (as peripheral), you input the following command:
># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> 
> Then, the A-device acts as a peripheral (A-peripheral) and the B-device
> acts as a host (B-host).
> Please note that A-device must input the following command if you
> want the board to act as a host again. (even if you disconnect the usb
> cable, since id state may be the same, the condition keeps "A-peripheral".)
>  # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> 
> Also you can use the following command if you want the B-device board to
> act as a peripheral again.
>  # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> 
> Signed-off-by: Yoshihiro Shimoda 
> ---
>  This patch is based on the latest linux-phy.git / next branch.
>  (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)
> 
>  Since this patch is related to usb, I added email addresses of Greg, Felipe,
>  Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)
> 
>  Changed from v1:
>   - rebase the latest next branch.
> 
>  .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
>  drivers/phy/phy-rcar-gen3-usb2.c   | 124 
> -
>  2 files changed, 134 insertions(+), 1 deletion(-)
>  create mode 100644 
> Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> 
> diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
> b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> new file mode 100644
> index 000..c7e715af
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> @@ -0,0 +1,11 @@
> +What:/sys/devices/platform//otg-inputs
> +Date:October 2016
> +KernelVersion:   4.10
> +Contact: Yoshihiro Shimoda 
> +Description:
> + This write-only file changes the phy mode for role swap of usb.
> + This file accepts the following strings:
> +  "a_bus_req/" - switching from A-Host to A-Peripheral
> +  "a_bus_drop" - switching from A-Peripheral to A-Host
> +  "b_bus_req"  - switching from B-Peripheral to B-Host
> +  "b_bus_req/" - switching from B-Host to B-Peripheral

Would you really care OTG FSM state machine? If not, you could just use
"host" and "peripheral" to stand for current USB role, and implement
role switch sysfs like: /sys/devices/platform//role.

Peter

> diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> b/drivers/phy/phy-rcar-gen3-usb2.c
> index 3d97ead..80f5bcc 100644
> --- a/drivers/phy/phy-rcar-gen3-usb2.c
> +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> @@ -70,6 +70,7 @@
>  #define USB2_LINECTRL1_DP_RPDBIT(18)
>  #define USB2_LINECTRL1_DMRPD_EN  BIT(17)
>  #define USB2_LINECTRL1_DM_RPDBIT(16)
> +#define USB2_LINECTRL1_OPMODE_NODRV  BIT(6)
>  
>  /* ADPCTRL */
>  #define USB2_ADPCTRL_OTGSESSVLD  BIT(20)
> @@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct 
> rcar_gen3_chan *ch)
>   schedule_work(&ch->work);
>  }
>  
> +static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
> +{
> + void __iomem *usb2_base = ch->base;
> + u32 val;
> +
> + val = readl(usb2_base + USB2_LINECTRL1);
> + writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
> +
> + rcar_gen3_set_linectrl(ch, 1, 1);
> + rcar_gen3_set_host_mode(ch, 1);
> + rcar_gen3_enable_vbus_ctrl(ch, 0);
> +
> + val = readl(usb2_base + USB2_LINECTRL1);
> + writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
> +}
> +
> +static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
> +{
> + rcar_gen3_set_linectrl(ch, 0, 1);
> + rcar_gen3_set_host_mode(ch, 0);
> + rcar_gen3_enable_vbus_ctrl(ch, 1);
> +}
> +
> +static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
> +{
> + void __iomem *usb2_base = ch->base;
> + u32 val;
> +
> + val = readl(usb2_base + USB2_OBINTEN);
> + writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> +
> + rcar_gen3_enable_vbus_ctrl(ch, 0);
> + rcar_gen3_init_for_host(ch);
> +
> + writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> +}
> +
>  static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
>  {
>   return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
> @@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct 
> rcar_gen3_chan *ch)
>   rcar_gen3_init

Re: [PATCH v2] usb: dwc3: gadget: wait for End Transfer to complete

2016-11-01 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> Hi,
>
> On 1 November 2016 at 19:01, Felipe Balbi  wrote:
>>
>> Hi,
>>
>> Baolin Wang  writes:
>>> Changes since v1:
>>>  - Move the suspend checking to right place to avoid checking twice.
>>
>> there is still one problem
>>
>>> @@ -1736,12 +1739,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>>>  {
>>>   struct dwc3 *dwc = gadget_to_dwc(g);
>>>   unsigned long   flags;
>>> + int epnum;
>>>
>>>   spin_lock_irqsave(&dwc->lock, flags);
>>>   __dwc3_gadget_stop(dwc);
>>
>> this tries to access registers. If __dwc3_gadget_stop() runs while
>> clocks are gated, we will get Data Abort exception.
>
> We have suspend checking in __dwc3_gadget_stop(), thus it will not
> access registers if clocks are disabled.
>
>>
>> How about this version, instead?
>
> I think it is OK except we missed set 'dwc->gadget_driver = NULL'.

argh. Man, next time we meet in a conference, I owe you a beer :-)

8<--
From 06a204f1c2276ca1ffe68d8d59ef2e2ead337bba Mon Sep 17 00:00:00 2001
From: Baolin Wang 
Date: Mon, 31 Oct 2016 19:38:36 +0800
Subject: [PATCH] usb: dwc3: gadget: wait for End Transfer to complete

Instead of just delaying for 100us, we should
actually wait for End Transfer Command Complete
interrupt before moving on. Note that this should
only be done if we're dealing with one of the core
revisions that actually require the interrupt before
moving on.

[ felipe.ba...@linux.intel.com: minor improvements ]

Signed-off-by: Baolin Wang 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h   |  8 
 drivers/usb/dwc3/gadget.c | 49 +++
 2 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 5fc437021ac7..c2b86856e85d 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -505,6 +506,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  * @lock: spinlock for endpoint request queue traversal
  * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
@@ -530,6 +532,8 @@ struct dwc3_ep {
struct list_headpending_list;
struct list_headstarted_list;
 
+   wait_queue_head_t   wait_end_transfer;
+
spinlock_t  lock;
void __iomem*regs;
 
@@ -546,6 +550,7 @@ struct dwc3_ep {
 #define DWC3_EP_BUSY   (1 << 4)
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
+#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
@@ -1050,6 +1055,9 @@ struct dwc3_event_depevt {
 #define DEPEVT_TRANSFER_BUS_EXPIRY 2
 
u32 parameters:16;
+
+/* For Command Complete Events */
+#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
 } __packed;
 
 /**
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4743e53cc295..64d01ff8c119 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -593,11 +593,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
dep->comp_desc = comp_desc;
dep->type = usb_endpoint_type(desc);
dep->flags |= DWC3_EP_ENABLED;
+   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
 
reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
reg |= DWC3_DALEPENA_EP(dep->number);
dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
 
+   init_waitqueue_head(&dep->wait_end_transfer);
+
if (usb_endpoint_xfer_control(desc))
return 0;
 
@@ -699,7 +702,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
dep->endpoint.desc = NULL;
dep->comp_desc = NULL;
dep->type = 0;
-   dep->flags = 0;
+   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
 
return 0;
 }
@@ -1783,9 +1786,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 
 static void __dwc3_gadget_stop(struct dwc3 *dwc)
 {
-   if (pm_runtime_suspended(dwc->dev))
-   return;
-
dwc3_gadget_disable_irq(dwc);
__dwc3_gadget_ep_disable(dwc->eps[0]);
__dwc3_gadget_ep_disable(dwc->eps[1]);
@@ -1795,9 +1795,30 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 {
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long   flags;
+   int epnum;
 
spin_lock_irqsave(&dwc->lock, flags);
+
+   if (pm_runtime_suspended(dwc->de

Linux FTDI driver modifications

2016-11-01 Thread Meindert Sprang

Hello all,

I am the developer of the ShipModul (CustomWare) MiniPlex products where 
we use FTDI chips for USB communications.
I see that even the latest PID we use (FD4B) is already in the 
ftdi_sio.c driver and I'm glad to see the Linux community picks this up 
to fast.


There is one thing however that I'd like to see added to the driver and 
that is fixed baud rates for our products. Since PID FD49 (the second 
PID we assigned) we use fixed baudrates, so the user of our products 
doesn't have to set the right baud rate in his application.


When browsing through the source code I found here 
(http://lxr.free-electrons.com/source/drivers/usb/serial/ftdi_sio.c), I 
found function


static __u32 get_ftdi_divisor(struct tty_struct *tty, struct 
usb_serial_port *port)


where the devisor for a specific baud rate is set.

In the case at line 1323, where the FT232BM and similar chips are 
handled, I see an if statement which obviously checks a few PID's to set 
a fixed baud rate.


So it appears that it would be fairly easy to add a few other exceptions 
for our PID's. Am I correct?


If so, the following code would do the trick for us:

switch (product_id)
{
  case FTDI_CUSTOMWARE_MINIPLEX2_PID: baud = 57600; break;
  case FTDI_CUSTOMWARE_MINIPLEX2WI_PID: baud = 115200; break;
  case FTDI_CUSTOMWARE_MINIPLEX3_PID: baud = 460800; break;
}

Now, I'm not familiar with the process of getting something added to a 
Linux driver so that's why I call for your help. Can you do this for me 
or can you point me into the right direction to get this included?


Best regards,
Meindert
CustomWare/ShipModul

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Revert "usb: dwc3: gadget: use allocated/queued reqs for LST bit"

2016-11-01 Thread Felipe Balbi

Hi,

David Miller  writes:
> From: Ville Syrjälä 
> Date: Fri, 28 Oct 2016 19:33:32 +0300
>
>> On Fri, Oct 28, 2016 at 01:16:13PM +0300, Felipe Balbi wrote:
>>> Yeah, I'm guessing we're gonna need some help from networking folks. The
>>> only thing we did since v4.7 was actually respect req->no_interrupt flag
>>> coming from u_ether itself. No idea why that causes so much trouble for
>>> u_ether.
>>> 
>>> BTW, Instead of reverting so many patches, you can just remove
>>> throttling:
>>> 
>>> diff --git a/drivers/usb/gadget/function/u_ether.c 
>>> b/drivers/usb/gadget/function/u_ether.c
>>> index f4a640216913..119a2e5848e8 100644
>>> --- a/drivers/usb/gadget/function/u_ether.c
>>> +++ b/drivers/usb/gadget/function/u_ether.c
>>> @@ -589,14 +589,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
>>>  
>>> req->length = length;
>>>  
>>> -   /* throttle high/super speed IRQ rate back slightly */
>>> -   if (gadget_is_dualspeed(dev->gadget))
>>> -   req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH 
>>> ||
>>> -  dev->gadget->speed == 
>>> USB_SPEED_SUPER)) &&
>>> -   !list_empty(&dev->tx_reqs))
>>> -   ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
>>> -   : 0;
>>> -
>>> retval = usb_ep_queue(in, req, GFP_ATOMIC);
>>> switch (retval) {
>>> default:
>> 
>> Ah cool. That indeed fixes the problem for me.
>> 
>>> 
>>> I'm adding netdev and couple other folks to the loop.
>>> 
>>> Just to summarize, USB peripheral controller now actually throttles
>>> interrupt when requested to do so and that causes lags for USB
>>> networking gadgets.
>>> 
>>> Without throttle we, potentially, call netif_wake_queue() more
>>> frequently than with throttling. I'm wondering if something changed in
>>> NET layer within the past few years but the USB networking gadgets ended
>>> up being forgotten.
>>> 
>>> Anyway, if anybody has any hints, I'd be glad to hear about them.
>
> This throttling mechanism seems to have the same problem we've seen in
> The past with some ethernet drivers trying to do TX mitigation in
> software.
>
> If I understand correctly, the interrupt bit for TX completions is set
> only periodically.
>
> However, the networking stack has a hard requirement that all SKBs
> which are transmitted must have their completion signalled in a finite
> amount of time.  This is because, until the SKB is freed by the
> driver, it holds onto socket, netfilter, and other subsystem
> resources.
>
> So, for example, if your scheme is that only every 8th TX packet will
> generate an interrupt you run into problems if you suddenly have 7
> pending TX packets and no more traffic is generated for a long time.
>
> Those 7 packets will sit in the TX queue indefinitely, and this is the
> situation which drivers must avoid.
>
> Therefore, for devices with per-TX-queue-entry interrupt bit schemes,
> it's not easy to take advantage of this facility.  The safest thing to
> do is to interrupt for every queue entry.
>
> For the time being, this revert is the way to go and it should be
> submitted formally, with proper commit message and signoffs, via
> whatever tree this gadget driver's changes should be submitted via.
>
> It might be possible to elide TX queue entry interrupts using the
> skb->xmit_more state.  Basically, if the TX queue is not full and
> skb->xmit_more is set, you can skip the interrupt indication bit
> in the descriptor.

thanks for confirming, patch removing throttling sent. You're in Cc.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH] usb: gadget: u_ether: remove interrupt throttling

2016-11-01 Thread Felipe Balbi
According to Dave Miller "the networking stack has a
hard requirement that all SKBs which are transmitted
must have their completion signalled in a fininte
amount of time. This is because, until the SKB is
freed by the driver, it holds onto socket,
netfilter, and other subsystem resources."

In summary, this means that using TX IRQ throttling
for the networking gadgets is, at least, complex and
we should avoid it for the time being.

Cc: 
Reported-by: Ville Syrjälä 
Suggested-by: David Miller 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/u_ether.c | 8 
 1 file changed, 8 deletions(-)

diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index f4a640216913..119a2e5848e8 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -589,14 +589,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
 
req->length = length;
 
-   /* throttle high/super speed IRQ rate back slightly */
-   if (gadget_is_dualspeed(dev->gadget))
-   req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH ||
-  dev->gadget->speed == USB_SPEED_SUPER)) 
&&
-   !list_empty(&dev->tx_reqs))
-   ? ((atomic_read(&dev->tx_qlen) % dev->qmult) != 0)
-   : 0;
-
retval = usb_ep_queue(in, req, GFP_ATOMIC);
switch (retval) {
default:
-- 
2.10.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[balbi-usb:testing/next 52/83] drivers/usb/dwc3/host.c:66:37: error: 'dwc3_pdev' undeclared

2016-11-01 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
testing/next
head:   8e6064194bd2243f182c39708d5225b800ab5549
commit: f57045e5f6876c0460dd80d987f337c1eff5547a [52/83] usb: dwc3: host: 
extract dwc3_host_get_irq()
config: i386-randconfig-x007-201644 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
git checkout f57045e5f6876c0460dd80d987f337c1eff5547a
# save the attached .config to linux build tree
make ARCH=i386 

All errors (new ones prefixed by >>):

   drivers/usb/dwc3/host.c: In function 'dwc3_host_init':
>> drivers/usb/dwc3/host.c:66:37: error: 'dwc3_pdev' undeclared (first use in 
>> this function)
 res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ, "host");
^
   drivers/usb/dwc3/host.c:66:37: note: each undeclared identifier is reported 
only once for each function it appears in

vim +/dwc3_pdev +66 drivers/usb/dwc3/host.c

60  struct resource *res;
61  
62  irq = dwc3_host_get_irq(dwc);
63  if (irq < 0)
64  return irq;
65  
  > 66  res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ, 
"host");
67  if (!res)
68  res = platform_get_resource_byname(dwc3_pdev, 
IORESOURCE_IRQ,
69  "dwc_usb3");

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [RFC/PATCH 15/45] usb: chipidea: udc: make use of new usb_endpoint_maxp_mult()

2016-11-01 Thread Peter Chen
On Tue, Nov 01, 2016 at 12:45:25PM +0200, Felipe Balbi wrote:
> 
> Hi,
> 
> Peter Chen  writes:
> > On Wed, Sep 28, 2016 at 04:05:24PM +0300, Felipe Balbi wrote:
> >> We have introduced a helper to calculate multiplier
> >> value from wMaxPacketSize. Start using it.
> >> 
> >> Cc: Peter Chen 
> >> Cc: 
> >> Signed-off-by: Felipe Balbi 
> >> ---
> >>  drivers/usb/chipidea/udc.c | 2 +-
> >>  1 file changed, 1 insertion(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> >> index 661f43fe0f9e..2b95ca887ca4 100644
> >> --- a/drivers/usb/chipidea/udc.c
> >> +++ b/drivers/usb/chipidea/udc.c
> >> @@ -1254,7 +1254,7 @@ static int ep_enable(struct usb_ep *ep,
> >>hwep->type = usb_endpoint_type(desc);
> >>  
> >>hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
> >> -  hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
> >> +  hwep->ep.mult = usb_endpoint_maxp_mult(desc);
> >>  
> >>if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
> >>cap |= QH_IOS;
> >> -- 
> >
> > You may need to change _ep_queue which uses hwep->ep.mult.
> 
> good catch, here's a new version:
> 
> 8<--
> From 576c3006a6e7bf0ea4ee150a9655e392fc0297cc Mon Sep 17 00:00:00 2001
> From: Felipe Balbi 
> Date: Wed, 28 Sep 2016 13:26:18 +0300
> Subject: [PATCH] usb: chipidea: udc: make use of new usb_endpoint_maxp_mult()
> 
> We have introduced a helper to calculate multiplier
> value from wMaxPacketSize. Start using it.
> 
> Cc: Peter Chen 
> Cc: 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/chipidea/udc.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> index 661f43fe0f9e..7a535be3024e 100644
> --- a/drivers/usb/chipidea/udc.c
> +++ b/drivers/usb/chipidea/udc.c
> @@ -821,7 +821,7 @@ static int _ep_queue(struct usb_ep *ep, struct 
> usb_request *req,
>   }
>  
>   if (usb_endpoint_xfer_isoc(hwep->ep.desc) &&
> - hwreq->req.length > (1 + hwep->ep.mult) * hwep->ep.maxpacket) {
> + hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) {
>   dev_err(hwep->ci->dev, "request length too big for 
> isochronous\n");
>   return -EMSGSIZE;
>   }
> @@ -1254,7 +1254,7 @@ static int ep_enable(struct usb_ep *ep,
>   hwep->type = usb_endpoint_type(desc);
>  
>   hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
> - hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
> + hwep->ep.mult = usb_endpoint_maxp_mult(desc);
>  
>   if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
>   cap |= QH_IOS;
> -- 
> 2.10.1
> 

Acked-by: Peter Chen 

-- 

Best Regards,
Peter Chen
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/6] Documentation: devicetree: dwc3: Add interrupt moderation

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
 John Youn  writes:
> Add interrupt moderation interval binding for dwc3.
>
> Signed-off-by: John Youn 
> ---
>  Documentation/devicetree/bindings/usb/dwc3.txt | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
> b/Documentation/devicetree/bindings/usb/dwc3.txt
> index e3e6983..17de9fc 100644
> --- a/Documentation/devicetree/bindings/usb/dwc3.txt
> +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
> @@ -53,6 +53,7 @@ Optional properties:
>   - snps,quirk-frame-length-adjustment: Value for GFLADJ_30MHZ field of 
> GFLADJ
>   register for post-silicon frame length adjustment when the
>   fladj_30mhz_sdbnd signal is invalid or incorrect.
> + - snps,imod_interval: the interrupt moderation interval.

 on top of all other comments, what's the unit here? nanoseconds? clock 
 cycles?

>>>
>>> Number of 250 ns intervals. I'll update the description to clarify.
>> 
>> it's probably better to add it in nanoseconds itself, then let driver
>> compute register value with DIV_ROUND_UP()
>> 
>
> I'm fine with it either way, but I think "increments of 250 ns" is
> slightly cleaner in that it reflects the exact settings that are
> possible and documented, and also fits neatly into a u16.

I don't know, I'll leave this to Mark and the other devicetree folks,
but I remember there was a preference of not passing register values via
devicetree. What if a following HW revision decides to change 250ns
increments to 125ns increments?

Mark?

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH 3/6] Documentation: devicetree: dwc3: Add interrupt moderation

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
>> I'm not sure that it makes sense for this to be in the DT, though I may
>> have misunderstood.
>
> I'm ok omitting the DT binding until it is needed by someone. Since we
> currently only need it for the workaround, which is detected
> automatically.
>
> Felipe, are you ok with this?

certainly. No problems whatsoever :-)

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH v2] usb: dwc3: gadget: wait for End Transfer to complete

2016-11-01 Thread Baolin Wang
Hi,

On 1 November 2016 at 19:01, Felipe Balbi  wrote:
>
> Hi,
>
> Baolin Wang  writes:
>> Changes since v1:
>>  - Move the suspend checking to right place to avoid checking twice.
>
> there is still one problem
>
>> @@ -1736,12 +1739,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>>  {
>>   struct dwc3 *dwc = gadget_to_dwc(g);
>>   unsigned long   flags;
>> + int epnum;
>>
>>   spin_lock_irqsave(&dwc->lock, flags);
>>   __dwc3_gadget_stop(dwc);
>
> this tries to access registers. If __dwc3_gadget_stop() runs while
> clocks are gated, we will get Data Abort exception.

We have suspend checking in __dwc3_gadget_stop(), thus it will not
access registers if clocks are disabled.

>
> How about this version, instead?

I think it is OK except we missed set 'dwc->gadget_driver = NULL'.

>
> 8<--
> From e21260f349271ff1d12e919be20a9ee47e29e4b4 Mon Sep 17 00:00:00 2001
> From: Baolin Wang 
> Date: Mon, 31 Oct 2016 19:38:36 +0800
> Subject: [PATCH] usb: dwc3: gadget: wait for End Transfer to complete
>
> Instead of just delaying for 100us, we should
> actually wait for End Transfer Command Complete
> interrupt before moving on. Note that this should
> only be done if we're dealing with one of the core
> revisions that actually require the interrupt before
> moving on.
>
> [ felipe.ba...@linux.intel.com: minor improvements ]
>
> Signed-off-by: Baolin Wang 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/dwc3/core.h   |  8 
>  drivers/usb/dwc3/gadget.c | 49 
> +++
>  2 files changed, 49 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 5fc437021ac7..c2b86856e85d 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -26,6 +26,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include 
>  #include 
> @@ -505,6 +506,7 @@ struct dwc3_event_buffer {
>   * @endpoint: usb endpoint
>   * @pending_list: list of pending requests for this endpoint
>   * @started_list: list of started requests on this endpoint
> + * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
>   * @lock: spinlock for endpoint request queue traversal
>   * @regs: pointer to first endpoint register
>   * @trb_pool: array of transaction buffers
> @@ -530,6 +532,8 @@ struct dwc3_ep {
> struct list_headpending_list;
> struct list_headstarted_list;
>
> +   wait_queue_head_t   wait_end_transfer;
> +
> spinlock_t  lock;
> void __iomem*regs;
>
> @@ -546,6 +550,7 @@ struct dwc3_ep {
>  #define DWC3_EP_BUSY   (1 << 4)
>  #define DWC3_EP_PENDING_REQUEST(1 << 5)
>  #define DWC3_EP_MISSED_ISOC(1 << 6)
> +#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
>
> /* This last one is specific to EP0 */
>  #define DWC3_EP0_DIR_IN(1 << 31)
> @@ -1050,6 +1055,9 @@ struct dwc3_event_depevt {
>  #define DEPEVT_TRANSFER_BUS_EXPIRY 2
>
> u32 parameters:16;
> +
> +/* For Command Complete Events */
> +#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
>  } __packed;
>
>  /**
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 4743e53cc295..a375fd28ed96 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -593,11 +593,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
> dep->comp_desc = comp_desc;
> dep->type = usb_endpoint_type(desc);
> dep->flags |= DWC3_EP_ENABLED;
> +   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
>
> reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
> reg |= DWC3_DALEPENA_EP(dep->number);
> dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
>
> +   init_waitqueue_head(&dep->wait_end_transfer);
> +
> if (usb_endpoint_xfer_control(desc))
> return 0;
>
> @@ -699,7 +702,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
> dep->endpoint.desc = NULL;
> dep->comp_desc = NULL;
> dep->type = 0;
> -   dep->flags = 0;
> +   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
>
> return 0;
>  }
> @@ -1783,9 +1786,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
>
>  static void __dwc3_gadget_stop(struct dwc3 *dwc)
>  {
> -   if (pm_runtime_suspended(dwc->dev))
> -   return;
> -
> dwc3_gadget_disable_irq(dwc);
> __dwc3_gadget_ep_disable(dwc->eps[0]);
> __dwc3_gadget_ep_disable(dwc->eps[1]);
> @@ -1795,10 +1795,31 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>  {
> struct dwc3 *dwc = gadget_to_dwc(g);
> unsigned long   flags;
> +   int epnum;
>
> spin_

Re: [PATCH] usb: dwc2: gadget: Update for new usb_endpoint_maxp()

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
> From: Vardan Mikayelyan 
>
> Update the dwc2 driver for the new behavior of the usb_endpoint_maxp()
> and also use the new usb_endpoint_maxp_mult() helper function.
>
> This commit fixes failures in high-badwith ISOC transfer tests.
>
> Signed-off-by: Vardan Mikayelyan 
> Signed-off-by: John Youn 
> ---
>  drivers/usb/dwc2/gadget.c | 38 --
>  1 file changed, 20 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 8a7fd73..a505bbf 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -1812,17 +1812,17 @@ static u32 dwc2_hsotg_ep0_mps(unsigned int mps)
>   * @hsotg: The driver state.
>   * @ep: The index number of the endpoint
>   * @mps: The maximum packet size in bytes
> + * @mc: The multicount value
>   *
>   * Configure the maximum packet size for the given endpoint, updating
>   * the hardware control registers to reflect this.
>   */
>  static void dwc2_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg,
> - unsigned int ep, unsigned int mps, unsigned int dir_in)
> + unsigned int ep, unsigned int mps,
> + unsigned int mc, unsigned int dir_in)

this has an odd set of arguments. You pass the ep index, mps, direction
and mult value, when you could just pass hsotg_ep and descriptor instead.

Anyway, this is in my testing/next now.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH] uwb: fix device reference leaks

2016-11-01 Thread Johan Hovold
This subsystem consistently fails to drop the device reference taken by
class_find_device().

Note that some of these lookup functions already take a reference to the
returned data, while others claim no reference is needed (or does not
seem need one).

Fixes: 183b9b592a62 ("uwb: add the UWB stack (core files)")
Signed-off-by: Johan Hovold 
---
 drivers/uwb/lc-rc.c | 16 +---
 drivers/uwb/pal.c   |  2 ++
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/uwb/lc-rc.c b/drivers/uwb/lc-rc.c
index d059ad4d0dbd..97ee1b46db69 100644
--- a/drivers/uwb/lc-rc.c
+++ b/drivers/uwb/lc-rc.c
@@ -56,8 +56,11 @@ static struct uwb_rc *uwb_rc_find_by_index(int index)
struct uwb_rc *rc = NULL;
 
dev = class_find_device(&uwb_rc_class, NULL, &index, 
uwb_rc_index_match);
-   if (dev)
+   if (dev) {
rc = dev_get_drvdata(dev);
+   put_device(dev);
+   }
+
return rc;
 }
 
@@ -467,7 +470,9 @@ struct uwb_rc *__uwb_rc_try_get(struct uwb_rc *target_rc)
if (dev) {
rc = dev_get_drvdata(dev);
__uwb_rc_get(rc);
+   put_device(dev);
}
+
return rc;
 }
 EXPORT_SYMBOL_GPL(__uwb_rc_try_get);
@@ -520,8 +525,11 @@ struct uwb_rc *uwb_rc_get_by_grandpa(const struct device 
*grandpa_dev)
 
dev = class_find_device(&uwb_rc_class, NULL, grandpa_dev,
find_rc_grandpa);
-   if (dev)
+   if (dev) {
rc = dev_get_drvdata(dev);
+   put_device(dev);
+   }
+
return rc;
 }
 EXPORT_SYMBOL_GPL(uwb_rc_get_by_grandpa);
@@ -553,8 +561,10 @@ struct uwb_rc *uwb_rc_get_by_dev(const struct uwb_dev_addr 
*addr)
struct uwb_rc *rc = NULL;
 
dev = class_find_device(&uwb_rc_class, NULL, addr, find_rc_dev);
-   if (dev)
+   if (dev) {
rc = dev_get_drvdata(dev);
+   put_device(dev);
+   }
 
return rc;
 }
diff --git a/drivers/uwb/pal.c b/drivers/uwb/pal.c
index c1304b8d4985..678e93741ae1 100644
--- a/drivers/uwb/pal.c
+++ b/drivers/uwb/pal.c
@@ -97,6 +97,8 @@ static bool uwb_rc_class_device_exists(struct uwb_rc 
*target_rc)
 
dev = class_find_device(&uwb_rc_class, NULL, target_rc, find_rc);
 
+   put_device(dev);
+
return (dev != NULL);
 }
 
-- 
2.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] usb: dwc3: gadget: wait for End Transfer to complete

2016-11-01 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> Changes since v1:
>  - Move the suspend checking to right place to avoid checking twice.

there is still one problem

> @@ -1736,12 +1739,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
>  {
>   struct dwc3 *dwc = gadget_to_dwc(g);
>   unsigned long   flags;
> + int epnum;
>  
>   spin_lock_irqsave(&dwc->lock, flags);
>   __dwc3_gadget_stop(dwc);

this tries to access registers. If __dwc3_gadget_stop() runs while
clocks are gated, we will get Data Abort exception.

How about this version, instead?

8<--
From e21260f349271ff1d12e919be20a9ee47e29e4b4 Mon Sep 17 00:00:00 2001
From: Baolin Wang 
Date: Mon, 31 Oct 2016 19:38:36 +0800
Subject: [PATCH] usb: dwc3: gadget: wait for End Transfer to complete

Instead of just delaying for 100us, we should
actually wait for End Transfer Command Complete
interrupt before moving on. Note that this should
only be done if we're dealing with one of the core
revisions that actually require the interrupt before
moving on.

[ felipe.ba...@linux.intel.com: minor improvements ]

Signed-off-by: Baolin Wang 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h   |  8 
 drivers/usb/dwc3/gadget.c | 49 +++
 2 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 5fc437021ac7..c2b86856e85d 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -505,6 +506,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  * @lock: spinlock for endpoint request queue traversal
  * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
@@ -530,6 +532,8 @@ struct dwc3_ep {
struct list_headpending_list;
struct list_headstarted_list;
 
+   wait_queue_head_t   wait_end_transfer;
+
spinlock_t  lock;
void __iomem*regs;
 
@@ -546,6 +550,7 @@ struct dwc3_ep {
 #define DWC3_EP_BUSY   (1 << 4)
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
+#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
@@ -1050,6 +1055,9 @@ struct dwc3_event_depevt {
 #define DEPEVT_TRANSFER_BUS_EXPIRY 2
 
u32 parameters:16;
+
+/* For Command Complete Events */
+#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
 } __packed;
 
 /**
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4743e53cc295..a375fd28ed96 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -593,11 +593,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
dep->comp_desc = comp_desc;
dep->type = usb_endpoint_type(desc);
dep->flags |= DWC3_EP_ENABLED;
+   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
 
reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
reg |= DWC3_DALEPENA_EP(dep->number);
dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
 
+   init_waitqueue_head(&dep->wait_end_transfer);
+
if (usb_endpoint_xfer_control(desc))
return 0;
 
@@ -699,7 +702,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
dep->endpoint.desc = NULL;
dep->comp_desc = NULL;
dep->type = 0;
-   dep->flags = 0;
+   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
 
return 0;
 }
@@ -1783,9 +1786,6 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 
 static void __dwc3_gadget_stop(struct dwc3 *dwc)
 {
-   if (pm_runtime_suspended(dwc->dev))
-   return;
-
dwc3_gadget_disable_irq(dwc);
__dwc3_gadget_ep_disable(dwc->eps[0]);
__dwc3_gadget_ep_disable(dwc->eps[1]);
@@ -1795,10 +1795,31 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 {
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long   flags;
+   int epnum;
 
spin_lock_irqsave(&dwc->lock, flags);
+
+   if (pm_runtime_suspended(dwc->dev))
+   goto out;
+
__dwc3_gadget_stop(dwc);
dwc->gadget_driver  = NULL;
+
+   for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+   struct dwc3_ep  *dep = dwc->eps[epnum];
+
+   if (!dep)
+   continue;
+
+   if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
+   continue;

Re: [RFC/PATCH 27/45] usb: musb: make use of new usb_endpoint_maxp_mult()

2016-11-01 Thread Felipe Balbi

Hi,

Bin Liu  writes:
> On Wed, Sep 28, 2016 at 04:05:36PM +0300, Felipe Balbi wrote:
>> We have introduced a helper to calculate multiplier
>> value from wMaxPacketSize. Start using it.
>> 
>> Cc: Bin Liu 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/musb/musb_gadget.c | 6 +++---
>>  drivers/usb/musb/musb_host.c   | 2 +-
>>  2 files changed, 4 insertions(+), 4 deletions(-)
>> 
>> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
>> index bff4869a57cd..8a0882cc446d 100644
>> --- a/drivers/usb/musb/musb_gadget.c
>> +++ b/drivers/usb/musb/musb_gadget.c
>> @@ -974,8 +974,8 @@ static int musb_gadget_enable(struct usb_ep *ep,
>>  goto fail;
>>  
>>  /* REVISIT this rules out high bandwidth periodic transfers */
>> -tmp = usb_endpoint_maxp(desc);
>
> The bit 10~0 in tmp is also needed in the original code, 

no it's not

>> -if (tmp & ~0x07ff) {
>> +tmp = usb_endpoint_maxp_mult(desc) - 1;
>
> but here bit 10~0 is lost.

here's the whole thing unpatched:

> /* REVISIT this rules out high bandwidth periodic transfers */
> tmp = usb_endpoint_maxp(desc);
> if (tmp & ~0x07ff) {

so, if we have a mult setting

>   int ok;
>
>   if (usb_endpoint_dir_in(desc))
>   ok = musb->hb_iso_tx;
>   else
>   ok = musb->hb_iso_rx;
>
>   if (!ok) {
>   musb_dbg(musb, "no support for high bandwidth ISO");
>   goto fail;
>   }
>   musb_ep->hb_mult = (tmp >> 11) & 3;

then we save the zero-based value in hb_mult

> } else {
>   musb_ep->hb_mult = 0;

otherwise, set it to 0.

IOW, this could be rewritten as:

int ok;

[...]

/* REVISIT this rules out high bandwidth periodic transfers */
tmp = usb_endpoint_maxp_mult(desc) - 1;
if (usb_endpoint_dir_in(desc))
ok = musb->hb_iso_tx & tmp;
else
ok = musb->hb_iso_rx & tmp;

if (!ok) {
musb_dbg(musb, "no support for high bandwidth ISO");
goto fail;
}
musb_ep->hb_mult = tmp;

And nothing would change. There is, however, one small problem with this
patch, but that's a few lines after this chunk. Here's the incremental
patch to fix it:

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 0e3404ce9465..47304560f105 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -992,7 +992,7 @@ static int musb_gadget_enable(struct usb_ep *ep,
musb_ep->hb_mult = 0;
}
 
-   musb_ep->packet_sz = tmp & 0x7ff;
+   musb_ep->packet_sz = usb_endpoint_maxp(desc);
tmp = musb_ep->packet_sz * (musb_ep->hb_mult + 1);
 
/* enable the interrupts for the endpoint, set the endpoint

And here's an entire new version:

8<--
From 9eec4692ab28bfd4336e2a5846f7fc5d90cd66e8 Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Wed, 28 Sep 2016 13:40:40 +0300
Subject: [PATCH] usb: musb: make use of new usb_endpoint_maxp_mult()

We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Bin Liu 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/musb/musb_gadget.c | 8 
 drivers/usb/musb/musb_host.c   | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index 4042ea017985..47304560f105 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -974,8 +974,8 @@ static int musb_gadget_enable(struct usb_ep *ep,
goto fail;
 
/* REVISIT this rules out high bandwidth periodic transfers */
-   tmp = usb_endpoint_maxp(desc);
-   if (tmp & ~0x07ff) {
+   tmp = usb_endpoint_maxp_mult(desc) - 1;
+   if (tmp) {
int ok;
 
if (usb_endpoint_dir_in(desc))
@@ -987,12 +987,12 @@ static int musb_gadget_enable(struct usb_ep *ep,
musb_dbg(musb, "no support for high bandwidth ISO");
goto fail;
}
-   musb_ep->hb_mult = (tmp >> 11) & 3;
+   musb_ep->hb_mult = tmp;
} else {
musb_ep->hb_mult = 0;
}
 
-   musb_ep->packet_sz = tmp & 0x7ff;
+   musb_ep->packet_sz = usb_endpoint_maxp(desc);
tmp = musb_ep->packet_sz * (musb_ep->hb_mult + 1);
 
/* enable the interrupts for the endpoint, set the endpoint
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 53bc4ceefe89..f6cdbad00dac 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2237,7 +2237,7 @@ static int musb_urb_enqueue(
 * Some musb cores don't support high bandwidth ISO transfers; and
 * we 

Re: [RFC/PATCH 15/45] usb: chipidea: udc: make use of new usb_endpoint_maxp_mult()

2016-11-01 Thread Felipe Balbi

Hi,

Peter Chen  writes:
> On Wed, Sep 28, 2016 at 04:05:24PM +0300, Felipe Balbi wrote:
>> We have introduced a helper to calculate multiplier
>> value from wMaxPacketSize. Start using it.
>> 
>> Cc: Peter Chen 
>> Cc: 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/chipidea/udc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
>> index 661f43fe0f9e..2b95ca887ca4 100644
>> --- a/drivers/usb/chipidea/udc.c
>> +++ b/drivers/usb/chipidea/udc.c
>> @@ -1254,7 +1254,7 @@ static int ep_enable(struct usb_ep *ep,
>>  hwep->type = usb_endpoint_type(desc);
>>  
>>  hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
>> -hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
>> +hwep->ep.mult = usb_endpoint_maxp_mult(desc);
>>  
>>  if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
>>  cap |= QH_IOS;
>> -- 
>
> You may need to change _ep_queue which uses hwep->ep.mult.

good catch, here's a new version:

8<--
From 576c3006a6e7bf0ea4ee150a9655e392fc0297cc Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Wed, 28 Sep 2016 13:26:18 +0300
Subject: [PATCH] usb: chipidea: udc: make use of new usb_endpoint_maxp_mult()

We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Peter Chen 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/chipidea/udc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 661f43fe0f9e..7a535be3024e 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -821,7 +821,7 @@ static int _ep_queue(struct usb_ep *ep, struct usb_request 
*req,
}
 
if (usb_endpoint_xfer_isoc(hwep->ep.desc) &&
-   hwreq->req.length > (1 + hwep->ep.mult) * hwep->ep.maxpacket) {
+   hwreq->req.length > hwep->ep.mult * hwep->ep.maxpacket) {
dev_err(hwep->ci->dev, "request length too big for 
isochronous\n");
return -EMSGSIZE;
}
@@ -1254,7 +1254,7 @@ static int ep_enable(struct usb_ep *ep,
hwep->type = usb_endpoint_type(desc);
 
hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
-   hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
+   hwep->ep.mult = usb_endpoint_maxp_mult(desc);
 
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
cap |= QH_IOS;
-- 
2.10.1



-- 
balbi


signature.asc
Description: PGP signature


[PATCH] USB: phy: am335x-control: fix device and of_node leaks

2016-11-01 Thread Johan Hovold
Make sure to drop the references taken by of_parse_phandle() and
bus_find_device() before returning from am335x_get_phy_control().

Note that there is no guarantee that the devres-managed struct
phy_control will be valid for the lifetime of the sibling phy device
regardless of this change.

Fixes: 3bb869c8b3f1 ("usb: phy: Add AM335x PHY driver")
Signed-off-by: Johan Hovold 
---
 drivers/usb/phy/phy-am335x-control.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/phy/phy-am335x-control.c 
b/drivers/usb/phy/phy-am335x-control.c
index 42a1afe36a90..5f5f19813fde 100644
--- a/drivers/usb/phy/phy-am335x-control.c
+++ b/drivers/usb/phy/phy-am335x-control.c
@@ -134,10 +134,12 @@ struct phy_control *am335x_get_phy_control(struct device 
*dev)
return NULL;
 
dev = bus_find_device(&platform_bus_type, NULL, node, match);
+   of_node_put(node);
if (!dev)
return NULL;
 
ctrl_usb = dev_get_drvdata(dev);
+   put_device(dev);
if (!ctrl_usb)
return NULL;
return &ctrl_usb->phy_ctrl;
-- 
2.7.3

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 53/82] usb: dwc3: ep0: simplify dwc3_ep0_handle_feature()

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
>> +static int dwc3_ep0_handle_device(struct dwc3 *dwc,
>>  struct usb_ctrlrequest *ctrl, int set)
>>  {
>> -struct dwc3_ep  *dep;
>> -u32 recip;
>> +enum usb_device_state   state;
>>  u32 wValue;
>>  u32 wIndex;
>> -u32 reg;
>> -int ret;
>> -enum usb_device_state   state;
>> +int ret = 0;
>>  
>>  wValue = le16_to_cpu(ctrl->wValue);
>>  wIndex = le16_to_cpu(ctrl->wIndex);
>> -recip = ctrl->bRequestType & USB_RECIP_MASK;
>>  state = dwc->gadget.state;
>>  
>> -switch (recip) {
>> -case USB_RECIP_DEVICE:
>> +switch (wValue) {
>> +case USB_DEVICE_REMOTE_WAKEUP:
>> +break;
>> +/*
>> + * 9.4.1 says only only for SS, in AddressState only for
>> + * default control pipe
>> + */
>> +case USB_DEVICE_U1_ENABLE:
>> +ret = dwc3_ep0_handle_u1(dwc, state, set);
>> +break;
>> +case USB_DEVICE_U2_ENABLE:
>> +ret = dwc3_ep0_handle_u2(dwc, state, set);
>> +break;
>> +case USB_DEVICE_LTM_ENABLE:
>> +ret = -EINVAL;
>> +break;
>> +case USB_DEVICE_TEST_MODE:
>> +ret = dwc3_ep0_handle_test(dwc, state, wIndex, set);
>
> Need a break here.
>
> Found with coverity.

nice!! :-) thanks for letting me know. Here's a new version:

8<--
From a9f78f9dcb6698bee03ec9a8eb0c73f08f49c2ee Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Mon, 3 Oct 2016 12:55:29 +0300
Subject: [PATCH] usb: dwc3: ep0: simplify dwc3_ep0_handle_feature()

By extracting smaller functions from
dwc3_ep0_handle_feature(), it becomes far easier to
understand what's going on. Cleanup only, no
functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/ep0.c | 257 +++--
 1 file changed, 164 insertions(+), 93 deletions(-)

diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index c562613ccd1a..a1f7c2b4b000 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -371,126 +371,197 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
return __dwc3_gadget_ep0_queue(dep, &dwc->ep0_usb_req);
 }
 
-static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
+static int dwc3_ep0_handle_u1(struct dwc3 *dwc, enum usb_device_state state,
+   int set)
+{
+   u32 reg;
+
+   if (state != USB_STATE_CONFIGURED)
+   return -EINVAL;
+   if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
+   (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS))
+   return -EINVAL;
+
+   reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+   if (set)
+   reg |= DWC3_DCTL_INITU1ENA;
+   else
+   reg &= ~DWC3_DCTL_INITU1ENA;
+   dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+   return 0;
+}
+
+static int dwc3_ep0_handle_u2(struct dwc3 *dwc, enum usb_device_state state,
+   int set)
+{
+   u32 reg;
+
+
+   if (state != USB_STATE_CONFIGURED)
+   return -EINVAL;
+   if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
+   (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS))
+   return -EINVAL;
+
+   reg = dwc3_readl(dwc->regs, DWC3_DCTL);
+   if (set)
+   reg |= DWC3_DCTL_INITU2ENA;
+   else
+   reg &= ~DWC3_DCTL_INITU2ENA;
+   dwc3_writel(dwc->regs, DWC3_DCTL, reg);
+
+   return 0;
+}
+
+static int dwc3_ep0_handle_test(struct dwc3 *dwc, enum usb_device_state state,
+   u32 wIndex, int set)
+{
+   if ((wIndex & 0xff) != 0)
+   return -EINVAL;
+   if (!set)
+   return -EINVAL;
+
+   switch (wIndex >> 8) {
+   case TEST_J:
+   case TEST_K:
+   case TEST_SE0_NAK:
+   case TEST_PACKET:
+   case TEST_FORCE_EN:
+   dwc->test_mode_nr = wIndex >> 8;
+   dwc->test_mode = true;
+   break;
+   default:
+   return -EINVAL;
+   }
+
+   return 0;
+}
+
+static int dwc3_ep0_handle_device(struct dwc3 *dwc,
struct usb_ctrlrequest *ctrl, int set)
 {
-   struct dwc3_ep  *dep;
-   u32 recip;
+   enum usb_device_state   state;
u32 wValue;
u32 wIndex;
-   u32 reg;
-   int ret;
-   enum usb_device_state   state;
+   int ret = 0;
 
wValue = le16_to_cpu(ctrl->wValue);
wIndex = le16_to_cpu(ctrl->wIndex);
-   recip = ctrl->bRequestType & USB_RECIP_MASK;
state = dwc->gadget.state;
 
-   switch (recip) {
-   case USB_RECIP_DEVICE:
+   switch (wValue) {
+   case USB_DEVICE_REMOTE_WAKEUP:
+   break;
+

Re: [PATCH 52/82] usb: dwc3: host: extract dwc3_host_get_irq()

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
> On 10/31/2016 3:51 AM, Felipe Balbi wrote:
>> Cleanup only, no functional changes.
>> 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/dwc3/host.c | 68 
>> +
>>  1 file changed, 35 insertions(+), 33 deletions(-)
>> 
>> diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
>> index f6533c68fed1..ed824647ead8 100644
>> --- a/drivers/usb/dwc3/host.c
>> +++ b/drivers/usb/dwc3/host.c
>> @@ -19,48 +19,50 @@
>>  
>>  #include "core.h"
>>  
>> +static int dwc3_host_get_irq(struct dwc3 *dwc)
>> +{
>> +struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
>> +int irq;
>> +
>> +irq = platform_get_irq_byname(dwc3_pdev, "host");
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq == -EPROBE_DEFER)
>> +goto out;
>> +
>> +irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq == -EPROBE_DEFER)
>> +goto out;
>> +
>> +irq = platform_get_irq(dwc3_pdev, 0);
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq != -EPROBE_DEFER)
>> +dev_err(dwc->dev, "missing host IRQ\n");
>> +
>> +if (!irq)
>> +irq = -EINVAL;
>> +
>> +out:
>> +return irq;
>> +}
>> +
>>  int dwc3_host_init(struct dwc3 *dwc)
>>  {
>>  struct property_entry   props[2];
>>  struct platform_device  *xhci;
>>  int ret, irq;
>>  struct resource *res;
>> -struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
>>  
>> -irq = platform_get_irq_byname(dwc3_pdev, "host");
>> -if (irq == -EPROBE_DEFER)
>> +irq = dwc3_host_get_irq(dwc);
>> +if (irq < 0)
>>  return irq;
>>  
>> -if (irq <= 0) {
>> -irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
>> -if (irq == -EPROBE_DEFER)
>> -return irq;
>> -
>> -if (irq <= 0) {
>> -irq = platform_get_irq(dwc3_pdev, 0);
>> -if (irq <= 0) {
>> -if (irq != -EPROBE_DEFER) {
>> -dev_err(dwc->dev,
>> -"missing host IRQ\n");
>> -}
>> -if (!irq)
>> -irq = -EINVAL;
>> -return irq;
>> -} else {
>> -res = platform_get_resource(dwc3_pdev,
>> -IORESOURCE_IRQ, 0);
>> -}
>> -} else {
>> -res = platform_get_resource_byname(dwc3_pdev,
>> -   IORESOURCE_IRQ,
>> -   "dwc_usb3");
>> -}
>> -
>> -} else {
>> -res = platform_get_resource_byname(dwc3_pdev, IORESOURCE_IRQ,
>> -   "host");
>> -}
>> -
>>  dwc->xhci_resources[1].start = irq;
>>  dwc->xhci_resources[1].end = irq;
>>  dwc->xhci_resources[1].flags = res->flags;
>
> Similar to patch 51.
>
> Lost the initialization of 'res' and then used uninitialized
> here.

completely missed that and GCC didn't tell me about it :-) Thanks,
here's another version

8<--
From 7a1e5968b7d42ff4524c9841bb139f499ce7cae6 Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Mon, 3 Oct 2016 12:31:48 +0300
Subject: [PATCH] usb: dwc3: host: extract dwc3_host_get_irq()

Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/host.c | 73 -
 1 file changed, 42 insertions(+), 31 deletions(-)

diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c
index f6533c68fed1..c39b826c17ba 100644
--- a/drivers/usb/dwc3/host.c
+++ b/drivers/usb/dwc3/host.c
@@ -19,47 +19,58 @@
 
 #include "core.h"
 
+static int dwc3_host_get_irq(struct dwc3 *dwc)
+{
+   struct platform_device  *dwc3_pdev = to_platform_device(dwc->dev);
+   int irq;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "host");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq(dwc3_pdev, 0);
+   if (irq > 0)
+   goto out;
+
+   if (irq != -EPROBE_DEFER)
+   dev_err(dwc->dev, "missing host IRQ\n");
+
+   if (!irq)
+   irq = -EINVAL;
+
+out:
+   return irq;
+}
+
 int dwc3_host_init(struct dwc3 *dwc)
 {
struct property_entry   props[2];
struct platform_device  *xh

Re: usb: dwc2: NMI watchdog: BUG: soft lockup - CPU#0 stuck for 146s

2016-11-01 Thread Michael Zoran
On Mon, 2016-10-31 at 21:34 +0100, Stefan Wahren wrote:
> I inspired by this issue [1] i build up a slightly modified setup
> with a
> Raspberry Pi B (mainline kernel 4.9rc3), a powered 7 port USB hub and
> 5 Prolific
> PL2303 USB to serial convertors. I modified the usb_test for dwc2
> [2], which
> only tries to open all ttyUSB devices one after the other. 
> 
> Unfortunately the complete system stuck after opening the first
> ttyUSB device (
> heartbeat LED stop blinking, no reaction to debug UART). The only way
> to
> reanimate the system is to powerdown the USB hub with the USB to
> serial
> convertors.
> 
> [1] - https://github.com/raspberrypi/linux/issues/1692
> [2] - https://gist.github.com/lategoodbye/dd0d30af27b6f101b03d5923b27
> 9dbaa
> 
> pi@raspberrypi:~$ lsusb -t
> /:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
> |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/3p, 480M
> |__ Port 1: Dev 3, If 0, Class=Vendor Specific Class,
> Driver=smsc95xx,
> 480M
> |__ Port 2: Dev 11, If 0, Class=Hub, Driver=hub/4p, 480M
> |__ Port 3: Dev 15, If 0, Class=Vendor Specific Class,
> Driver=pl2303, 12M
> |__ Port 1: Dev 12, If 0, Class=Hub, Driver=hub/4p, 480M
> |__ Port 2: Dev 14, If 0, Class=Vendor Specific
> Class,
> Driver=pl2303, 12M
> |__ Port 3: Dev 16, If 0, Class=Vendor Specific
> Class,
> Driver=pl2303, 12M
> |__ Port 4: Dev 17, If 0, Class=Vendor Specific Class,
> Driver=pl2303, 12M
> |__ Port 2: Dev 13, If 0, Class=Vendor Specific Class,
> Driver=pl2303, 12M
> 

Since I didn't see a response, I'll go ahead and add my two cents. 
Hopefully nobody minds me chiming in here.

I see these kinds of issues with USB on the RPI all the time. 
Typically, it's just the USB that breaks down not a hang in the CPU.

The issue is that I think the USB controller in the RPI chipset was
designed for the cellphone/set top box market.  In those markets, the
USB port is only used to connect to one device at a time.  For example,
with a cell phone you might connect it to a PC to transfer data.  On a
set top box, you might plug in a USB flash drive with video to play.

The RPI doesn't have a proper USB controller like you find in a PC. 
Instead it has a fixed number of hardware slots(I think the number is
between 5-7) that are used for pending transfers. Once the slots are
full, very little can be done.  And because USB 2.0 is based on
polling, the connected USB devices are constantly polled even if
nothing is happening.

The DWC_OTG driver works a bit better even though it's not perfect. 
That driver makes an attempt to schedule USB activity and send it to
the hardware a bit at a time just like a PC USB controller does. 
Unfortunatly, to get the precision required on some of the lower end
RPIs, it's necessary to use FIQ which is somewhat outside the Linux
driver model.

Although I don't completely agree that FIQ is necessary on the high end
RPIs with multiple cores.   In fact, I have a few local modifications
to the interrupt controller driver to round robin dispatch IRQs between
core to get more concurrency at the expense of more CPU cache misses. I
think this reduces the need for FIQ, but some other disagree...

  

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 51/82] usb: dwc3: gadget: extract dwc3_gadget_get_irq()

2016-11-01 Thread Felipe Balbi

Hi,

John Youn  writes:
> On 10/31/2016 3:51 AM, Felipe Balbi wrote:
>> Cleanup only, no functional changes.
>> 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/dwc3/gadget.c | 62 
>> +--
>>  1 file changed, 38 insertions(+), 24 deletions(-)
>> 
>> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
>> index c692aafa7397..c0011174a1f1 100644
>> --- a/drivers/usb/dwc3/gadget.c
>> +++ b/drivers/usb/dwc3/gadget.c
>> @@ -2871,6 +2871,39 @@ static irqreturn_t dwc3_interrupt(int irq, void *_evt)
>>  return dwc3_check_event_buf(evt);
>>  }
>>  
>> +static int dwc3_gadget_get_irq(struct dwc3 *dwc)
>> +{
>> +struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
>> +int irq;
>> +
>> +irq = platform_get_irq_byname(dwc3_pdev, "peripheral");
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq == -EPROBE_DEFER)
>> +goto out;
>> +
>> +irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq == -EPROBE_DEFER)
>> +goto out;
>> +
>> +irq = platform_get_irq(dwc3_pdev, 0);
>> +if (irq > 0)
>> +goto out;
>> +
>> +if (irq != -EPROBE_DEFER)
>> +dev_err(dwc->dev, "missing peripheral IRQ\n");
>> +
>> +if (!irq)
>> +irq = -EINVAL;
>> +
>> +out:
>> +return irq;
>> +}
>> +
>>  /**
>>   * dwc3_gadget_init - Initializes gadget related registers
>>   * @dwc: pointer to our controller context structure
>> @@ -2879,31 +2912,12 @@ static irqreturn_t dwc3_interrupt(int irq, void 
>> *_evt)
>>   */
>>  int dwc3_gadget_init(struct dwc3 *dwc)
>>  {
>> -int ret, irq;
>> -struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
>> +int ret;
>
> 'ret' is returned uninitialized in the error handling path.
>
> Found in coverity.

Thanks for letting me know. Here's another version:

8<--
From 6a92a7120c5b7c35e7ff8d80a8dcbd7e67ec5f09 Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Mon, 3 Oct 2016 11:27:01 +0300
Subject: [PATCH] usb: dwc3: gadget: extract dwc3_gadget_get_irq()

Cleanup only, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 62 +--
 1 file changed, 39 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c692aafa7397..45a3325ff5b1 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2871,6 +2871,39 @@ static irqreturn_t dwc3_interrupt(int irq, void *_evt)
return dwc3_check_event_buf(evt);
 }
 
+static int dwc3_gadget_get_irq(struct dwc3 *dwc)
+{
+   struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
+   int irq;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "peripheral");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
+   if (irq > 0)
+   goto out;
+
+   if (irq == -EPROBE_DEFER)
+   goto out;
+
+   irq = platform_get_irq(dwc3_pdev, 0);
+   if (irq > 0)
+   goto out;
+
+   if (irq != -EPROBE_DEFER)
+   dev_err(dwc->dev, "missing peripheral IRQ\n");
+
+   if (!irq)
+   irq = -EINVAL;
+
+out:
+   return irq;
+}
+
 /**
  * dwc3_gadget_init - Initializes gadget related registers
  * @dwc: pointer to our controller context structure
@@ -2879,30 +2912,13 @@ static irqreturn_t dwc3_interrupt(int irq, void *_evt)
  */
 int dwc3_gadget_init(struct dwc3 *dwc)
 {
-   int ret, irq;
-   struct platform_device *dwc3_pdev = to_platform_device(dwc->dev);
+   int ret;
+   int irq;
 
-   irq = platform_get_irq_byname(dwc3_pdev, "peripheral");
-   if (irq == -EPROBE_DEFER)
-   return irq;
-
-   if (irq <= 0) {
-   irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
-   if (irq == -EPROBE_DEFER)
-   return irq;
-
-   if (irq <= 0) {
-   irq = platform_get_irq(dwc3_pdev, 0);
-   if (irq <= 0) {
-   if (irq != -EPROBE_DEFER) {
-   dev_err(dwc->dev,
-   "missing peripheral IRQ\n");
-   }
-   if (!irq)
-   irq = -EINVAL;
-   return irq;
-   }
-   }
+   irq = dwc3_gadget_get_irq(dwc);
+   if (irq < 0) {
+   ret = irq;
+   goto err0;
}
 
dwc->irq_gadget = irq;
-- 
2.10.1



-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH 00/82] usb: patch bomb

2016-11-01 Thread Felipe Balbi

Hi,

Bin Liu  writes:
> Hi Felipe,
>
> On Mon, Oct 31, 2016 at 12:47:52PM +0200, Felipe Balbi wrote:
>> Hi guys,
>> 
>> Sorry for the patch bomb, but I wanted to make sure everyoby knows which
>> patches are already queued up for the next window. They are still
>> sitting in my testing/next branch, so I can still change any of them.
>> 
>> Please make sure to go through each one of them. This very branch has
>> been tested on Intel SKL and I couldn't find any problems so far.
>
> It seems you missed my comments in the RFC set, basically the set breaks
> MUSB and other controllers.

Okay, I'll go look for the original comments.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v2] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-01 Thread Yoshihiro Shimoda
This patch adds sysfs "otg_inputs" for usb role swap. This parameter
is write-only and if you use them as the following, you can swap
the usb role.

For example:
 1) connect a usb cable using 2 salvator-x boards
 2) On A-device (as host), you input the following command:
   # echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
 3) On B-device (as peripheral), you input the following command:
   # echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Then, the A-device acts as a peripheral (A-peripheral) and the B-device
acts as a host (B-host).
Please note that A-device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the condition keeps "A-peripheral".)
 # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Also you can use the following command if you want the B-device board to
act as a peripheral again.
 # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Signed-off-by: Yoshihiro Shimoda 
---
 This patch is based on the latest linux-phy.git / next branch.
 (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)

 Since this patch is related to usb, I added email addresses of Greg, Felipe,
 Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)

 Changed from v1:
  - rebase the latest next branch.

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
 drivers/phy/phy-rcar-gen3-usb2.c   | 124 -
 2 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..c7e715af
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,11 @@
+What:  /sys/devices/platform//otg-inputs
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda 
+Description:
+   This write-only file changes the phy mode for role swap of usb.
+   This file accepts the following strings:
+"a_bus_req/" - switching from A-Host to A-Peripheral
+"a_bus_drop" - switching from A-Peripheral to A-Host
+"b_bus_req"  - switching from B-Peripheral to B-Host
+"b_bus_req/" - switching from B-Host to B-Peripheral
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..80f5bcc 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(&ch->work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
rcar_gen3_init_for_peri(ch);
 }
 
+/*
+ * The following table is a state transition for usb phy mode:
+ * State   Event   Next state
+ * disconnected:   E1  a_host
+ * E2  b_peripheral
+ * A-Device - a_host:  E2  b_peripheral
+ * E3  disconnected
+ * E4  a_suspend
+ * A-Device - a_suspend:   E2  b_peripheral
+ *