Re: [PATCH v2] usb: dwc3: Prevent indefinite sleep in _dwc3_set_mode during suspend/resume

2018-04-09 Thread Minas Harutyunyan
Hi Filipe,

On 3/19/2018 5:53 PM, Minas Harutyunyan wrote:
> Hi,
> 
> On 3/19/2018 3:36 PM, Minas Harutyunyan wrote:
>> Hi,
>>
>> On 3/19/2018 12:55 PM, Felipe Balbi wrote:
>>>
>>> Hi,
>>>
>>> Minas Harutyunyan  writes:
> Thanks for picking this for -next.
> Is it better to have this in v4.16-rc fixes?
> and also stable? v4.12+

 Well, there was no "Fixes: foobar" or "Cc: stable" lines in the commit
 log ;-)

 The best we can do now, is wait for -rc1 and manually send the commit 
 to
 stable.

>>>
>>> That's fine. Thanks.
>>>
>>
>> Same issue seen in dwc3_gadget_ep_dequeue() function where also used
>> wait_event_lock_irq() - as result infinite loop.
>
> how did this happen? During rmmod dwc3? Or, perhaps, after you unloaded
> a gadget driver?
>
 No, not during rmmod's.
 We using our internal USB testing tool. Test case; ISOC OUT, transfer
 size N frames. When host starts ISOC OUT traffic then the dwc3 based on
 "Transfer not ready" event in frame F starts transfers staring from
 frame F+4 (for bInterval=1) as result 4 requests, which already queued
 on device side, remain incomplete. Function driver on some timeout
 trying dequeue these 4 requests (without disabling EP) to complete test.
 For IN ISOC's these requests completed on MISSED ISOC event, but for
 ISOC OUT required call dequeue on some timeout.
>>>
>>> okay
>>>
>> Actually to fix this issue I updated condition of wait function
>> from:
>> !(dep->flags & DWC3_EP_END_TRANSFER_PENDING)
>> to:
>> !(dep->flags & DWC3_EP_END_TRANSFER_PENDING & DWC3_EP_ENABLED)
>
> you're not fixing anything. You're, essentially, removing the entire
> end transfer pending logic.
 yes, you are right, but how to overcome this infinite loop? Replace
 wait_event_lock_irq() by  wait_event_interruptible_lock_irq_timeout()?
>>>
>>> The best way here would be to figure why we're missing command complete
>>> IRQ in those cases. According to documentation, we *should* receive that
>>> interrupt, so why is it missing?
>>>
>>
>> Additional info on test. Core configuration is HS only mode, test speed
>> HS, core version v2.90a. Maybe it will help to understand cause of issue.
>> BTW, currently to pass above describe ISOC OUT test we just commented
>> wait_event_lock_irq() in dwc3_gadget_ep_dequeue() function and
>> successfully received request completion in function driver.
>> Thanks,
>> Minas
>>
> 
> One more info: while function driver call dequeue, host periodically
> send control read command to get status of test from function - test In
> Progress or Finished.
> Thanks,
> Minas
> 

Your last dwc3 patch series allow us to successfully dequeuing remaining 
requests without falling in to infinite loop.

Thank you,
Minas
--
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: dwc2: Fix kernel doc's warnings.

2018-04-09 Thread Minas Harutyunyan
Hi,

On 4/3/2018 5:15 PM, Grigor Tovmasyan wrote:
> Added descriptions for all not described parameters.
> Fix all kernel doc's warnings.
> 
> Signed-off-by: Grigor Tovmasyan 
> ---
> Changes from version 1:
> 
> Fix minor kernel-doc style issue.
> 
> Changes from version 0:
> 
> Rebased to balbi/next.
> Fixed new kernel-doc warnings which cames from new patches.
> ---
>   drivers/usb/dwc2/core.c  |   7 ++
>   drivers/usb/dwc2/core.h  | 166 
> +++
>   drivers/usb/dwc2/debug.h |   2 +-
>   drivers/usb/dwc2/debugfs.c   |  19 ++---
>   drivers/usb/dwc2/gadget.c|  29 +---
>   drivers/usb/dwc2/hcd.c   |   3 +-
>   drivers/usb/dwc2/hcd.h   |  14 ++--
>   drivers/usb/dwc2/hcd_ddma.c  |   1 +
>   drivers/usb/dwc2/hcd_intr.c  |  12 
>   drivers/usb/dwc2/hcd_queue.c |   5 +-
>   drivers/usb/dwc2/params.c|   8 +++
>   drivers/usb/dwc2/pci.c   |   6 ++
>   12 files changed, 213 insertions(+), 59 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index 18a0a1771289..1c36a6a9dd63 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -419,6 +419,8 @@ static void dwc2_wait_for_mode(struct dwc2_hsotg *hsotg,
>   /**
>* dwc2_iddig_filter_enabled() - Returns true if the IDDIG debounce
>* filter is enabled.
> + *
> + * @hsotg: Programming view of DWC_otg controller
>*/
>   static bool dwc2_iddig_filter_enabled(struct dwc2_hsotg *hsotg)
>   {
> @@ -564,6 +566,9 @@ int dwc2_core_reset(struct dwc2_hsotg *hsotg, bool 
> skip_wait)
>* If a force is done, it requires a IDDIG debounce filter delay if
>* the filter is configured and enabled. We poll the current mode of
>* the controller to account for this delay.
> + *
> + * @hsotg: Programming view of DWC_otg controller
> + * @host: Host mode flag
>*/
>   void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
>   {
> @@ -610,6 +615,8 @@ void dwc2_force_mode(struct dwc2_hsotg *hsotg, bool host)
>* or not because the value of the connector ID status is affected by
>* the force mode. We only need to call this once during probe if
>* dr_mode == OTG.
> + *
> + * @hsotg: Programming view of DWC_otg controller
>*/
>   static void dwc2_clear_force_mode(struct dwc2_hsotg *hsotg)
>   {
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index d83be5651f87..c2c08cbbc19b 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -164,12 +164,11 @@ struct dwc2_hsotg_req;
>*   and has yet to be completed (maybe due to data move, or simply
>*   awaiting an ack from the core all the data has been completed).
>* @debugfs: File entry for debugfs file for this endpoint.
> - * @lock: State lock to protect contents of endpoint.
>* @dir_in: Set to true if this endpoint is of the IN direction, which
>*  means that it is sending data to the Host.
>* @index: The index for the endpoint registers.
>* @mc: Multi Count - number of transactions per microframe
> - * @interval - Interval for periodic endpoints, in frames or microframes.
> + * @interval: Interval for periodic endpoints, in frames or microframes.
>* @name: The name array passed to the USB core.
>* @halted: Set if the endpoint has been halted.
>* @periodic: Set if this is a periodic ep, such as Interrupt
> @@ -182,6 +181,7 @@ struct dwc2_hsotg_req;
>* @next_desc: index of next free descriptor in the ISOC chain under SW 
> control.
>* @total_data: The total number of data bytes done.
>* @fifo_size: The size of the FIFO (for periodic IN endpoints)
> + * @fifo_index: For Dedicated FIFO operation, only FIFO0 can be used for EP0.
>* @fifo_load: The amount of data loaded into the FIFO (periodic IN)
>* @last_load: The offset of data for the last start of request.
>* @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
> @@ -380,6 +380,9 @@ enum dwc2_ep0_state {
>*  is FS.
>*   0 - No (default)
>*   1 - Yes
> + * @acg_enable:  For enabling Active Clock Gating in the 
> controller
> + *   0 - No
> + *   1 - Yes
>* @ulpi_fs_ls: Make ULPI phy operate in FS/LS mode only
>*   0 - No (default)
>*   1 - Yes
> @@ -548,7 +551,7 @@ struct dwc2_core_params {
>*
>* The values that are not in dwc2_core_params are documented below.
>*
> - * @op_mode Mode of Operation
> + * @op_mode: Mode of Operation
>*   0 - HNP- and SRP-Capable OTG (Host & Device)
>*   1 - SRP-Capable OTG (Host & Device)
>*   2 - Non-HNP and Non-SRP Capable OTG (Host & Device)
> @@ -556,43 +559,96 @@ struct dwc2_core_params {
>*   4 - Non-OTG Device
>*   5 - SRP-Capable 

[PATCH v2 5/6] usb: gadget: udc: renesas_usb3: should fail if devm_phy_get() returns error

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver ignores errors other than
the non-existence of the device, f.e. a memory allocation failure
in devm_phy_get(). So, this patch replaces devm_phy_get() with
devm_phy_optional_get().

Reported-by: Simon Horman 
Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for generic 
phy")
Cc:  # v4.15+
Signed-off-by: Yoshihiro Shimoda 
---
Remarks:
 - A new file in v2

 drivers/usb/gadget/udc/renesas_usb3.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 233bc04..0e70163 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2636,9 +2636,11 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
 * This is optional. So, if this driver cannot get a phy,
 * this driver will not handle a phy anymore.
 */
-   usb3->phy = devm_phy_get(&pdev->dev, "usb");
-   if (IS_ERR(usb3->phy))
-   usb3->phy = NULL;
+   usb3->phy = devm_phy_optional_get(&pdev->dev, "usb");
+   if (IS_ERR(usb3->phy)) {
+   ret = PTR_ERR(usb3->phy);
+   goto err_add_udc;
+   }
 
pm_runtime_enable(&pdev->dev);
ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget);
-- 
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 v2 0/6] usb: gadget: udc: renesas_usb3: fix some major issues

2018-04-09 Thread Yoshihiro Shimoda
This patch set is based on v4.16.

Changes from v1:
 - Add Reviewed-by in patch 1, 2, 3 and 4.
 - Revise typo in patch 4.
 - Add new patches as patch 5 and 6.

Yoshihiro Shimoda (6):
  usb: gadget: udc: renesas_usb3: fix double phy_put()
  usb: gadget: udc: renesas_usb3: should remove debugfs
  usb: gadget: udc: renesas_usb3: should call pm_runtime_enable() before
add udc
  usb: gadget: udc: renesas_usb3: should call devm_phy_get() before add
udc
  usb: gadget: udc: renesas_usb3: should fail if devm_phy_get() returns
error
  usb: gadget: udc: renesas_usb3: disable the controller's irqs for
reconnecting

 drivers/usb/gadget/udc/renesas_usb3.c | 37 +++
 1 file changed, 25 insertions(+), 12 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


[PATCH v2 3/6] usb: gadget: udc: renesas_usb3: should call pm_runtime_enable() before add udc

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver causes panic if a gadget
driver is already loaded because usb_add_gadget_udc() might call
renesas_usb3_start() via .udc_start, and then pm_runtime_get_sync()
in renesas_usb3_start() doesn't work correctly.
Note that the usb3_to_dev() macro should not be called at this timing
because the macro uses the gadget structure.

Fixes: cf06df3fae28 ("usb: gadget: udc: renesas_usb3: move 
pm_runtime_{en,dis}able()")
Cc:  # v4.15+
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Simon Horman 
---
Changes from v1:
 - Add Reviewed-by.

 drivers/usb/gadget/udc/renesas_usb3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 1c54a77..738b734 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2632,6 +2632,7 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
if (ret < 0)
goto err_alloc_prd;
 
+   pm_runtime_enable(&pdev->dev);
ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget);
if (ret < 0)
goto err_add_udc;
@@ -2653,7 +2654,6 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
renesas_usb3_debugfs_init(usb3, &pdev->dev);
 
dev_info(&pdev->dev, "probed%s\n", usb3->phy ? " with phy" : "");
-   pm_runtime_enable(usb3_to_dev(usb3));
 
return 0;
 
-- 
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 v2 6/6] usb: gadget: udc: renesas_usb3: disable the controller's irqs for reconnecting

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that reconnection is possible to fail
because unexpected state handling happens by the irqs. To fix the issue,
the driver disables the controller's irqs when disconnected.

Fixes: 746bfe63bba3 ("usb: gadget: renesas_usb3: add support for Renesas USB3.0 
peripheral controller")
Cc:  # v4.5+
Signed-off-by: Yoshihiro Shimoda 
---

Remarks:
 - A new file in v2

 drivers/usb/gadget/udc/renesas_usb3.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 0e70163..5caf78b 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -623,6 +623,13 @@ static void usb3_disconnect(struct renesas_usb3 *usb3)
usb3_usb2_pullup(usb3, 0);
usb3_clear_bit(usb3, USB30_CON_B3_CONNECT, USB3_USB30_CON);
usb3_reset_epc(usb3);
+   usb3_disable_irq_1(usb3, USB_INT_1_B2_RSUM | USB_INT_1_B3_PLLWKUP |
+  USB_INT_1_B3_LUPSUCS | USB_INT_1_B3_DISABLE |
+  USB_INT_1_SPEED | USB_INT_1_B3_WRMRST |
+  USB_INT_1_B3_HOTRST | USB_INT_1_B2_SPND |
+  USB_INT_1_B2_L1SPND | USB_INT_1_B2_USBRST);
+   usb3_clear_bit(usb3, USB_COM_CON_SPD_MODE, USB3_USB_COM_CON);
+   usb3_init_epc_registers(usb3);
 
if (usb3->driver)
usb3->driver->disconnect(&usb3->gadget);
-- 
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 v2 1/6] usb: gadget: udc: renesas_usb3: fix double phy_put()

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver cause double phy_put()
calling. This driver must not call phy_put() in the remove because
the driver calls devm_phy_get() in the probe.

Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for generic 
phy")
Cc:  # v4.15+
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Simon Horman 
---
Changes from v1:
 - Add Reviewed-by.

 drivers/usb/gadget/udc/renesas_usb3.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 409cde4..78a12a5 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2408,8 +2408,6 @@ static int renesas_usb3_remove(struct platform_device 
*pdev)
renesas_usb3_dma_free_prd(usb3, &pdev->dev);
 
__renesas_usb3_ep_free_request(usb3->ep0_req);
-   if (usb3->phy)
-   phy_put(usb3->phy);
pm_runtime_disable(&pdev->dev);
 
return 0;
-- 
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 v2 4/6] usb: gadget: udc: renesas_usb3: should call devm_phy_get() before add udc

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver cannot call phy_init()
if a gadget driver is alreadly loaded because usb_add_gadget_udc()
might call renesas_usb3_start() via .udc_start.
This patch also revises the typo (s/an optional/optional/).

Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for generic 
phy")
Cc:  # v4.15+
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Simon Horman 
---
Changes from v1:
 - Add Reviewed-by.
 - Revise typo in the comment.

 drivers/usb/gadget/udc/renesas_usb3.c | 16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 738b734..233bc04 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2632,6 +2632,14 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
if (ret < 0)
goto err_alloc_prd;
 
+   /*
+* This is optional. So, if this driver cannot get a phy,
+* this driver will not handle a phy anymore.
+*/
+   usb3->phy = devm_phy_get(&pdev->dev, "usb");
+   if (IS_ERR(usb3->phy))
+   usb3->phy = NULL;
+
pm_runtime_enable(&pdev->dev);
ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget);
if (ret < 0)
@@ -2641,14 +2649,6 @@ static int renesas_usb3_probe(struct platform_device 
*pdev)
if (ret < 0)
goto err_dev_create;
 
-   /*
-* This is an optional. So, if this driver cannot get a phy,
-* this driver will not handle a phy anymore.
-*/
-   usb3->phy = devm_phy_get(&pdev->dev, "usb");
-   if (IS_ERR(usb3->phy))
-   usb3->phy = NULL;
-
usb3->workaround_for_vbus = priv->workaround_for_vbus;
 
renesas_usb3_debugfs_init(usb3, &pdev->dev);
-- 
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 v2 2/6] usb: gadget: udc: renesas_usb3: should remove debugfs

2018-04-09 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver doesn't remove its debugfs.

Fixes: 43ba968b00ea ("usb: gadget: udc: renesas_usb3: add debugfs to set the 
b-device mode")
Cc:  # v4.14+
Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Simon Horman 
---
Changes from v1:
 - Add Reviewed-by.

 drivers/usb/gadget/udc/renesas_usb3.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 78a12a5..1c54a77 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -333,6 +333,7 @@ struct renesas_usb3 {
struct extcon_dev *extcon;
struct work_struct extcon_work;
struct phy *phy;
+   struct dentry *dentry;
 
struct renesas_usb3_ep *usb3_ep;
int num_usb3_eps;
@@ -2393,8 +2394,12 @@ static void renesas_usb3_debugfs_init(struct 
renesas_usb3 *usb3,
 
file = debugfs_create_file("b_device", 0644, root, usb3,
   &renesas_usb3_b_device_fops);
-   if (!file)
+   if (!file) {
dev_info(dev, "%s: Can't create debugfs mode\n", __func__);
+   debugfs_remove_recursive(root);
+   } else {
+   usb3->dentry = root;
+   }
 }
 
 /*--- platform_driver */
@@ -2402,6 +2407,7 @@ static int renesas_usb3_remove(struct platform_device 
*pdev)
 {
struct renesas_usb3 *usb3 = platform_get_drvdata(pdev);
 
+   debugfs_remove_recursive(usb3->dentry);
device_remove_file(&pdev->dev, &dev_attr_role);
 
usb_del_gadget_udc(&usb3->gadget);
-- 
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: [PATCH] xhci: Fix USB ports for Dell Inspiron 5775

2018-04-09 Thread Kai Heng Feng

Hi Matthias,

On Mar 18, 2018, at 11:11 PM, Kai-Heng Feng   
wrote:


The Dell Inspiron 5775 is a Raven Ridge. The Enable Slot command timed
out when a USB device gets plugged:
[ 212.156326] xhci_hcd :03:00.3: Error while assigning device slot ID
[ 212.156340] xhci_hcd :03:00.3: Max number of devices this xHCI host  
supports is 64.

[ 212.156348] usb usb2-port3: couldn't allocate usb_device

AMD suggests that a delay before xHC suspends can fix the issue.

I can confirm it fixes the issue, so use the suspend delay quirk for
Raven Ridge's xHC.


I am hoping this patch can get merged in v4.17...

Thanks,
Kai-Heng



Cc: sta...@vger.kernel.org
Signed-off-by: Kai-Heng Feng 
---
 drivers/usb/host/xhci-pci.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index d9f831b67e57..93ce34bce7b5 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -126,7 +126,10 @@ static void xhci_pci_quirks(struct device *dev,  
struct xhci_hcd *xhci)

if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info())
xhci->quirks |= XHCI_AMD_PLL_FIX;

-   if (pdev->vendor == PCI_VENDOR_ID_AMD && pdev->device == 0x43bb)
+   if (pdev->vendor == PCI_VENDOR_ID_AMD &&
+   (pdev->device == 0x15e0 ||
+pdev->device == 0x15e1 ||
+pdev->device == 0x43bb))
xhci->quirks |= XHCI_SUSPEND_DELAY;

if (pdev->vendor == PCI_VENDOR_ID_AMD)
--
2.15.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: [PATCH usb v5 0/6] usb/core/phy fixes for v4.17

2018-04-09 Thread Keerthy


On Monday 09 April 2018 02:57 AM, Martin Blumenstingl wrote:
> This is a follow-up to my previous series "initialize (multiple) PHYs
> for a HCD": [0].
> 
> Roger Quadros reported [1] that it "is breaking low power cases on TI
> SoCs when USB is in host mode". He further explains that "Not doing the
> phy_exit() here [when entering suspend] leaves the clocks enabled on
> our SoC and we're no longer able to reach low power states on system
> suspend."
> Chunfeng Yun from Mediatek noted [2] that we cannot unconditionally call
> phy_exit while entering system suspend, because this would "disconnect
> plugged devices on MTK platforms, due to re-initialize u2 phys when
> resume"
> 
> In the discussion (which followed Roger's bug report: [1]) Roger,
> Chunfeng and me came to the conclusion that we can fix suspend on the
> TI SoCs without breaking it on the Mediatek SoCs by extending the
> suspend and resume code in usb/core/phy.c by checking whether the USB
> controller can wake up the system (which is the case for the Mediatek
> MTU3 controller, but now for the dwc3 controller used on the TI SoCs):
> - if the controller can wake up the system (Mediatek MTU3 use-case) we
>   only call usb_phy_roothub_power_off (which calls phy_power_off) when
>   entering system suspend
> - if the controller however cannot wake up the system (dwc3 on TI SoCs)
>   we additionally call usb_phy_roothub_exit (which calls phy_exit) when
>   entering system suspend
> - (we undo the previous steps during system resume)
> 
> The goal of this series is to fix the issue reported by Roger without
> breaking suspend/resume on the Mediatek SoCs.
> Since I neither have a TI nor a Mediatek device I am sending this as
> RFC. I have tested it on an Amlogic Meson GXM board (Khadas VIM2) which
> does NOT support suspend/resume yet.
> 
> Additionally Stefan Wahren reported [7] that booting on a Raspberry Pi
> with CONFIG_GENERIC_PHY being disabled (which is the case for
> bcm2835_defconfig) breaks USB. A fix for this is also included.
> 

FWIW

The series fixes suspend/resume on TI AM437X-GP-EVM platform.

Tested-by: Keerthy 

Regards,
Keerthy
> 
> changes since v4 at [8]
> - updated series title since it now includes fixes for other
>   functionality than suspend
> - rebased on top of f8cf2f16a7c95a from Linus' tree -> I will re-send
>   an updated version once v4.17-rc1 is out, I just sent it early to
>   get some feedback early!
> - included patch [3] "usb: core: phy: fix return value of
>   usb_phy_roothub_exit()" in this series
> - fix the logic if CONFIG_GENERIC_PHY is disabled (as reported by
>   Stefan Wahren, new patch #4)
> - two minor coding style fixes as suggested by Masahiro Yamada (new
>   patches #4 and #5)
> 
> changes since RFC v3 at [6]:
> - added Chunfeng Yun's Tested-by and Roger Quadros' Reviewed-by (thank
>   you!)
> - dropped RFC prefix
> 
> changes since RFC v2 at [5]:
> - add missing INIT_LIST_HEAD call in usb_phy_roothub_add_phy (affects
>   patch #1 - spotted by Roger Quadros, thank you!)
> - fixed swapped conditions using device_may_wakeup() in
>   usb_phy_roothub_resume because we need to call usb_phy_roothub_init
>   if the controller cannot wake up the device (affects patch #2, spotted
>   by Chunfeng Yun, thank you!)
> - simplified the error condition to "undo" usb_phy_roothub_init if
>   usb_phy_roothub_power_on failed in usb_phy_roothub_resume (suggested
>   by Chunfeng Yun)
> - updated the commit message (using Roger's wording) because (quote from
>   Roger "it doesn't prevent the system from entering suspend but just
>   prevents the system from reaching lowest power levels in the suspend
>   state."
> 
> Changes since RFC v1 (blob attachments) at [4]:
> - use device_may_wakeup instead of device_can_wakeup as suggested by
>   Roger Quadros
> - use the controller device from hcd->self.controller as suggested by
>   Chunfeng Yun
> - compile time fixes thanks to Roger Quadros
> - if usb_phy_roothub_power_on in usb_phy_roothub_resume failes then
>   we now call usb_phy_roothub_exit to keep the PHYs in the correct
>   state if usb_phy_roothub_resume partially failed
> 
> 
> [0] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006599.html
> [1] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006737.html
> [2] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006758.html
> [3] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006819.html
> [4] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006794.html
> [5] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006820.html
> [6] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006847.html
> [7] https://www.spinics.net/lists/linux-usb/msg167472.html
> [8] http://lists.infradead.org/pipermail/linux-amlogic/2018-March/006882.html
> 
> 
> Martin Blumenstingl (6):
>   usb: core: phy: fix return value of usb_phy_roothub_exit()
>   usb: core: split usb_phy_roothub_{init,alloc}
>   usb: cor

Re: [PATCH] usb: gadget: f_midi: Add configfs attrs for card and device

2018-04-09 Thread Jerry Zhang
I didn't realize that having function in func_inst was actually android
only. I think we can track card and device values in f_midi_opts in that
case, and update them as they change. I'll put up a fix soon.

On Mon, Apr 9, 2018 at 6:27 PM kbuild test robot  wrote:

> Hi Jerry,

> Thank you for the patch! Yet something to improve:

> [auto build test ERROR on balbi-usb/next]
> [also build test ERROR on v4.16 next-20180409]
> [if your patch is applied to the wrong git tree, please drop us a note to
help improve the system]

> url:
https://github.com/0day-ci/linux/commits/Jerry-Zhang/usb-gadget-f_midi-Add-configfs-attrs-for-card-and-device/20180410-061518
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
> config: x86_64-randconfig-x011-201814 (attached as .config)
> compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
> reproduce:
>   # save the attached .config to linux build tree
>   make ARCH=x86_64

> All errors (new ones prefixed by >>):

>  drivers/usb/gadget/function/f_midi.c: In function
'f_midi_opts_card_show':
> >> drivers/usb/gadget/function/f_midi.c:1188:22: error: 'struct
usb_function_instance' has no member named 'f'; did you mean 'fd'?
>if (opts->func_inst.f) {
>^
>fd
>  drivers/usb/gadget/function/f_midi.c:1189:39: error: 'struct
usb_function_instance' has no member named 'f'; did you mean 'fd'?
> midi = func_to_midi(opts->func_inst.f);
> ^
> fd
>  drivers/usb/gadget/function/f_midi.c: In function
'f_midi_opts_device_show':
>  drivers/usb/gadget/function/f_midi.c:1206:22: error: 'struct
usb_function_instance' has no member named 'f'; did you mean 'fd'?
>if (opts->func_inst.f) {
>^
>fd
>  drivers/usb/gadget/function/f_midi.c:1207:39: error: 'struct
usb_function_instance' has no member named 'f'; did you mean 'fd'?
> midi = func_to_midi(opts->func_inst.f);
> ^
> fd

> vim +1188 drivers/usb/gadget/function/f_midi.c

> 1181
> 1182  static ssize_t f_midi_opts_card_show(struct config_item *item,
char *page)
> 1183  {
> 1184  struct f_midi_opts *opts = to_f_midi_opts(item);
> 1185  int card = -1;
> 1186  struct f_midi *midi;
> 1187
> > 1188  if (opts->func_inst.f) {
> 1189  midi = func_to_midi(opts->func_inst.f);
> 1190  if (midi->rmidi && midi->rmidi->card) {
> 1191  card = midi->rmidi->card->number;
> 1192  }
> 1193  }
> 1194
> 1195  return sprintf(page, "%d\n", card);
> 1196  }
> 1197

> ---
> 0-DAY kernel test infrastructureOpen Source Technology
Center
> https://lists.01.org/pipermail/kbuild-all   Intel
Corporation
--
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: f_fs: Add compat_ioctl to ep0

2018-04-09 Thread kbuild test robot
Hi Jerry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.16 next-20180409]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jerry-Zhang/usb-gadget-f_fs-Add-compat_ioctl-to-ep0/20180410-060430
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-randconfig-x017-201814 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/usb/gadget/function/f_fs.c: In function 'ffs_ep0_compat_ioctl':
>> drivers/usb/gadget/function/f_fs.c:651:13: error: 'gadget' undeclared (first 
>> use in this function); did you mean 'bdget'?
 } else if (gadget && gadget->ops->compat_ioctl) {
^~
bdget
   drivers/usb/gadget/function/f_fs.c:651:13: note: each undeclared identifier 
is reported only once for each function it appears in

vim +651 drivers/usb/gadget/function/f_fs.c

   643  
   644  #ifdef CONFIG_COMPAT
   645  static long ffs_ep0_compat_ioctl(struct file *file, unsigned code, 
unsigned long value)
   646  {
   647  long ret;
   648  
   649  if (code == FUNCTIONFS_INTERFACE_REVMAP) {
   650  ret = ffs_ep0_ioctl(file, code, value);
 > 651  } else if (gadget && gadget->ops->compat_ioctl) {
   652  ret = gadget->ops->compat_ioctl(gadget, code, value);
   653  } else {
   654  ret = -ENOTTY;
   655  }
   656  
   657  return ret;
   658  }
   659  #endif
   660  

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


.config.gz
Description: application/gzip


[PATCH v2] usb: gadget: f_fs: Add compat_ioctl to ep0

2018-04-09 Thread Jerry Zhang
Functionfs ep0 ioctls can be handled in the
same way as a normal ioctl. Don't handle
underlying gadget ioctls since we don't know
whether they work with compat.

Signed-off-by: Jerry Zhang 
---
 v2 - fixed error, realized gadget_ops doesn't have compat_ioctl

 drivers/usb/gadget/function/f_fs.c | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c 
b/drivers/usb/gadget/function/f_fs.c
index 34d80cc2b667..8c6ed79f451d 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -641,6 +641,21 @@ static long ffs_ep0_ioctl(struct file *file, unsigned 
code, unsigned long value)
return ret;
 }
 
+#ifdef CONFIG_COMPAT
+static long ffs_ep0_compat_ioctl(struct file *file, unsigned code, unsigned 
long value)
+{
+   long ret;
+
+   if (code == FUNCTIONFS_INTERFACE_REVMAP) {
+   ret = ffs_ep0_ioctl(file, code, value);
+   } else {
+   ret = -ENOTTY;
+   }
+
+   return ret;
+}
+#endif
+
 static __poll_t ffs_ep0_poll(struct file *file, poll_table *wait)
 {
struct ffs_data *ffs = file->private_data;
@@ -691,6 +706,9 @@ static const struct file_operations ffs_ep0_operations = {
.release =  ffs_ep0_release,
.unlocked_ioctl =   ffs_ep0_ioctl,
.poll = ffs_ep0_poll,
+#ifdef CONFIG_COMPAT
+   .compat_ioctl = ffs_ep0_compat_ioctl,
+#endif
 };
 
 
-- 
2.17.0.484.g0c8726318c-goog

--
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] usb: storage: Replace mdelay with msleep in init_freecom

2018-04-09 Thread Jia-Ju Bai
init_freecom() is never called in atomic context.

init_freecom() is set as ".initFunction" through UNUSUAL_DEV().
And ->initFunction() is only called by usb_stor_acquire_resources(), 
which is only called by usb_stor_probe2().
usb_stor_probe2() is called by *_probe() functions (like alauda_probe()) 
for each USB driver.
*_probe() functions are set ".probe" in struct usb_driver.
These functions are not called in atomic context.

Despite never getting called from atomic context, init_freecom()
calls mdelay() to busily wait.
This is not necessary and can be replaced with msleep() to
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.
And I also manually check it.

Signed-off-by: Jia-Ju Bai 
---
 drivers/usb/storage/freecom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index c0a5d95..c7f886d 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -477,7 +477,7 @@ static int init_freecom(struct us_data *us)
usb_stor_dbg(us, "result from activate reset is %d\n", result);
 
/* wait 250ms */
-   mdelay(250);
+   msleep(250);
 
/* clear reset */
result = usb_stor_control_msg(us, us->send_ctrl_pipe,
@@ -485,7 +485,7 @@ static int init_freecom(struct us_data *us)
usb_stor_dbg(us, "result from clear reset is %d\n", result);
 
/* wait 3 seconds */
-   mdelay(3 * 1000);
+   msleep(3 * 1000);
 
return USB_STOR_TRANSPORT_GOOD;
 }
-- 
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: [PATCH 4/4] usb: gadget: udc: renesas_usb3: should call devm_phy_get() before add udc

2018-04-09 Thread Yoshihiro Shimoda
Hi Simon-san,

> From: Simon Horman, Sent: Monday, April 9, 2018 8:58 PM
> 
> On Mon, Apr 02, 2018 at 09:21:34PM +0900, Yoshihiro Shimoda wrote:
> > This patch fixes an issue that this driver cannot call phy_init()
> > if a gadget driver is alreadly loaded because usb_add_gadget_udc()
> > might call renesas_usb3_start() via .udc_start.
> >
> > Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for 
> > generic phy")
> > Cc:  # v4.15+
> > Signed-off-by: Yoshihiro Shimoda 
> > ---
> >  drivers/usb/gadget/udc/renesas_usb3.c | 16 
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> 
> Reviewed-by: Simon Horman 
> 
> 
> Please see some suggestions for follow-up lower-priority patches below.

Thank you for the review and suggestions!

> >
> > diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
> > b/drivers/usb/gadget/udc/renesas_usb3.c
> > index 738b734..671bac3 100644
> > --- a/drivers/usb/gadget/udc/renesas_usb3.c
> > +++ b/drivers/usb/gadget/udc/renesas_usb3.c
> > @@ -2632,6 +2632,14 @@ static int renesas_usb3_probe(struct platform_device 
> > *pdev)
> > if (ret < 0)
> > goto err_alloc_prd;
> >
> > +   /*
> > +* This is an optional. So, if this driver cannot get a phy,
> > +* this driver will not handle a phy anymore.
> > +*/
> 
> nit: s/an optional/optional/

Oops. I will fix and submit v2 patches.

> > +   usb3->phy = devm_phy_get(&pdev->dev, "usb");
> > +   if (IS_ERR(usb3->phy))
> > +   usb3->phy = NULL;
> 
> I think this will unintentionally ignore errors other than the
> non-existence of the device, f.e. a memory allocation failure
> in devm_phy_get().
> 
> So perhaps something like this, as per phy_optional_get(), would be better?
> 
>   usb3->phy = devm_phy_get(&pdev->dev, "usb");
>   if (IS_ERR(usb3->phy) && (PTR_ERR(usb3->phy) == -ENODEV))
>   usb3->phy = NULL;

Thank you for the suggestion. I agree with you.
I think I should use devm_phy_optional_get() instead of dev_phy_get(), as you 
mentioned :)
So, I will fix the code by using devm_phy_optional_get() first, and then fix 
this.

Best regards,
Yoshihiro Shimoda

> > +
> > pm_runtime_enable(&pdev->dev);
> > ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget);
> > if (ret < 0)
> > @@ -2641,14 +2649,6 @@ static int renesas_usb3_probe(struct platform_device 
> > *pdev)
> > if (ret < 0)
> > goto err_dev_create;
> >
> > -   /*
> > -* This is an optional. So, if this driver cannot get a phy,
> > -* this driver will not handle a phy anymore.
> > -*/
> > -   usb3->phy = devm_phy_get(&pdev->dev, "usb");
> > -   if (IS_ERR(usb3->phy))
> > -   usb3->phy = NULL;
> > -
> > usb3->workaround_for_vbus = priv->workaround_for_vbus;
> >
> > renesas_usb3_debugfs_init(usb3, &pdev->dev);
> > --
> > 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: [PATCH] usb: gadget: f_midi: Add configfs attrs for card and device

2018-04-09 Thread kbuild test robot
Hi Jerry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.16 next-20180409]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jerry-Zhang/usb-gadget-f_midi-Add-configfs-attrs-for-card-and-device/20180410-061518
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-randconfig-x011-201814 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/usb/gadget/function/f_midi.c: In function 'f_midi_opts_card_show':
>> drivers/usb/gadget/function/f_midi.c:1188:22: error: 'struct 
>> usb_function_instance' has no member named 'f'; did you mean 'fd'?
 if (opts->func_inst.f) {
 ^
 fd
   drivers/usb/gadget/function/f_midi.c:1189:39: error: 'struct 
usb_function_instance' has no member named 'f'; did you mean 'fd'?
  midi = func_to_midi(opts->func_inst.f);
  ^
  fd
   drivers/usb/gadget/function/f_midi.c: In function 'f_midi_opts_device_show':
   drivers/usb/gadget/function/f_midi.c:1206:22: error: 'struct 
usb_function_instance' has no member named 'f'; did you mean 'fd'?
 if (opts->func_inst.f) {
 ^
 fd
   drivers/usb/gadget/function/f_midi.c:1207:39: error: 'struct 
usb_function_instance' has no member named 'f'; did you mean 'fd'?
  midi = func_to_midi(opts->func_inst.f);
  ^
  fd

vim +1188 drivers/usb/gadget/function/f_midi.c

  1181  
  1182  static ssize_t f_midi_opts_card_show(struct config_item *item, char 
*page)
  1183  {
  1184  struct f_midi_opts *opts = to_f_midi_opts(item);
  1185  int card = -1;
  1186  struct f_midi *midi;
  1187  
> 1188  if (opts->func_inst.f) {
  1189  midi = func_to_midi(opts->func_inst.f);
  1190  if (midi->rmidi && midi->rmidi->card) {
  1191  card = midi->rmidi->card->number;
  1192  }
  1193  }
  1194  
  1195  return sprintf(page, "%d\n", card);
  1196  }
  1197  

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


.config.gz
Description: application/gzip


Re: [PATCH] usb: gadget: f_fs: Add compat_ioctl to ep0

2018-04-09 Thread kbuild test robot
Hi Jerry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.16 next-20180409]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Jerry-Zhang/usb-gadget-f_fs-Add-compat_ioctl-to-ep0/20180410-060430
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-randconfig-s3-04100757 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/usb/gadget/function/f_fs.c: In function 'ffs_ep0_compat_ioctl':
>> drivers/usb/gadget/function/f_fs.c:651:13: error: 'gadget' undeclared (first 
>> use in this function); did you mean 'dget'?
 } else if (gadget && gadget->ops->compat_ioctl) {
^~
dget
   drivers/usb/gadget/function/f_fs.c:651:13: note: each undeclared identifier 
is reported only once for each function it appears in

vim +651 drivers/usb/gadget/function/f_fs.c

   643  
   644  #ifdef CONFIG_COMPAT
   645  static long ffs_ep0_compat_ioctl(struct file *file, unsigned code, 
unsigned long value)
   646  {
   647  long ret;
   648  
   649  if (code == FUNCTIONFS_INTERFACE_REVMAP) {
   650  ret = ffs_ep0_ioctl(file, code, value);
 > 651  } else if (gadget && gadget->ops->compat_ioctl) {
   652  ret = gadget->ops->compat_ioctl(gadget, code, value);
   653  } else {
   654  ret = -ENOTTY;
   655  }
   656  
   657  return ret;
   658  }
   659  #endif
   660  

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


.config.gz
Description: application/gzip


Re: [RFT/PATCH 18/38] usb: dwc3: gadget: check for Missed Isoc from event status

2018-04-09 Thread Thinh Nguyen
Hi Felipe,

On 4/9/2018 4:28 AM, Felipe Balbi wrote:
> In case we get an event with status set to Missed Isoc, this means we
> have missed an isochronous interval and should issue End Transfer
> command and wait for the following XferNotReady.

Why does DWC3 need to issue End Transfer if there are still queued requests?

> 
> Let's do that early, rather than late.
> 
> Signed-off-by: Felipe Balbi 
> ---
>   drivers/usb/dwc3/core.h   |  5 +++--
>   drivers/usb/dwc3/gadget.c | 14 +++---
>   2 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 5ee895113906..8862118c3b79 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -1192,11 +1192,12 @@ struct dwc3_event_depevt {
>   /* Within XferNotReady */
>   #define DEPEVT_STATUS_TRANSFER_ACTIVE   BIT(3)
>   
> -/* Within XferComplete */
> +/* Within XferComplete or XferInProgress */
>   #define DEPEVT_STATUS_BUSERRBIT(0)
>   #define DEPEVT_STATUS_SHORT BIT(1)
>   #define DEPEVT_STATUS_IOC   BIT(2)
> -#define DEPEVT_STATUS_LSTBIT(3)
> +#define DEPEVT_STATUS_LSTBIT(3) /* XferComplete */
> +#define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
>   
>   /* Stream event only */
>   #define DEPEVT_STREAMEVT_FOUND  1
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 0b003367cc7c..ed44b85e59dc 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -2361,9 +2361,6 @@ static void 
> dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
>* entry is added into request list.
>*/
>   dep->flags = DWC3_EP_PENDING_REQUEST;
> - } else {
> - dwc3_stop_active_transfer(dep, true);
> - dep->flags = DWC3_EP_ENABLED;
>   }
>   }
>   }
> @@ -2383,14 +2380,25 @@ static void 
> dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
>   {
>   struct dwc3 *dwc = dep->dwc;
>   unsignedstatus = 0;
> + boolstop = false;
>   
>   dwc3_gadget_endpoint_frame_from_event(dep, event);
>   
>   if (event->status & DEPEVT_STATUS_BUSERR)
>   status = -ECONNRESET;
>   
> + if (event->status & DEPEVT_STATUS_MISSED_ISOC) {
> + status = -ECONNRESET;

Missed isoc shouldn't cause this error status or if it should return an 
error status at all. Maybe the status can be -EXDEV, similar to the host 
side (/Documentation/driver-api/usb/error-codes.rst).

> + stop = true;
> + }
> +
>   dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
>   
> + if (stop) {
> + dwc3_stop_active_transfer(dep, true);
> + dep->flags = DWC3_EP_ENABLED;
> + }
> +
>   /*
>* WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.
>* See dwc3_gadget_linksts_change_interrupt() for 1st half.
> 

BR,
Thinh
--
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/2] clk: at91: Fix for PLL set_rate changes not being actually written to PLL peripheral bits

2018-04-09 Thread Marcin Ziemianowicz
When a USB device is connected to the USB host port on the SAM9N12 then
you get "-62" error which seems to indicate USB replies from the device
are timing out. Looking around, I saw the USB bus was running at half
speed. Going further, it seems that in ..._set_rate() the PLL wasn't
actually being adjusted. Writing the multiplier and divider values to
the peripheral fixes the bus running at half speed.

Signed-off-by: Marcin Ziemianowicz 
---
 drivers/clk/at91/clk-pll.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c
index 534961766ae5..db7155fe9346 100644
--- a/drivers/clk/at91/clk-pll.c
+++ b/drivers/clk/at91/clk-pll.c
@@ -288,6 +288,14 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned 
long rate,
pll->div = div;
pll->mul = mul;
 
+   // Set the PLL as per above div and mil values.
+   regmap_update_bits(pll->regmap, AT91_CKGR_PLLBR,
+   AT91_PMC_DIV | AT91_PMC_MUL,
+   (div << 0) | (mul << 16));
+
+   pr_debug("clk-pll: setting new rate, (%lu hz / %u) * %u = %lu hz\n",
+   parent_rate, div, mul, rate);
+
return 0;
 }
 
-- 
2.17.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 1/2] clk: at91: Added more information logging.

2018-04-09 Thread Marcin Ziemianowicz
I noticed that when debugging some USB clocking issue that there weren't
many ways to tell what the state of the USB clocking system was. This
adds a few logging statements to see what the relevant code is trying to
do.

Signed-off-by: Marcin Ziemianowicz 
---
 drivers/clk/at91/clk-pll.c   |  6 +-
 drivers/clk/at91/clk-usb.c   | 10 --
 drivers/usb/host/ohci-at91.c | 16 ++--
 3 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c
index 7d3223fc7161..534961766ae5 100644
--- a/drivers/clk/at91/clk-pll.c
+++ b/drivers/clk/at91/clk-pll.c
@@ -133,6 +133,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
 {
struct clk_pll *pll = to_clk_pll(hw);
unsigned int pllr;
+   unsigned long recalcedrate;
u16 mul;
u8 div;
 
@@ -144,7 +145,10 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw *hw,
if (!div || !mul)
return 0;
 
-   return (parent_rate / div) * (mul + 1);
+   recalcedrate = (parent_rate / div) * (mul + 1);
+   pr_debug("clk-pll: calculating new rate, (%lu hz / %u) * %u = %lu hz\n",
+   parent_rate, div, mul, recalcedrate);
+   return recalcedrate;
 }
 
 static long clk_pll_get_best_div_mul(struct clk_pll *pll, unsigned long rate,
diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 791770a563fc..2fa877e99bac 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -48,11 +48,15 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct 
clk_hw *hw,
struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
unsigned int usbr;
u8 usbdiv;
+   unsigned int calcdclock;
 
regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
usbdiv = (usbr & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
 
-   return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
+   calcdclock = DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
+   pr_debug("clk-usb: calculating new rate, %lu hz / %u = %u hz\n",
+   parent_rate, usbdiv + 1, calcdclock);
+   return calcdclock;
 }
 
 static int at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw,
@@ -98,7 +102,6 @@ static int at91sam9x5_clk_usb_determine_rate(struct clk_hw 
*hw,
if (!best_diff)
break;
}
-
if (best_rate < 0)
return best_rate;
 
@@ -142,6 +145,9 @@ static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, 
unsigned long rate,
if (div > SAM9X5_USB_MAX_DIV + 1 || !div)
return -EINVAL;
 
+   pr_debug("clk-usb: setting USB clock divider to %lu hz / %lu = %lu 
hz\n",
+   parent_rate, div, rate);
+
regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_OHCIUSBDIV,
   (div - 1) << SAM9X5_USB_DIV_SHIFT);
 
diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 5ad9e9bdc8ee..c57a239918f9 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -70,11 +70,13 @@ static const struct ohci_driver_overrides 
ohci_at91_drv_overrides __initconst =
 
 /*-*/
 
-static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
+static void at91_start_clock(struct ohci_at91_priv *ohci_at91,
+   struct device *dev)
 {
if (ohci_at91->clocked)
return;
 
+   dev_dbg(dev, "Enabling hclk, iclk, and setting fclk to 48 Mhz\n");
clk_set_rate(ohci_at91->fclk, 4800);
clk_prepare_enable(ohci_at91->hclk);
clk_prepare_enable(ohci_at91->iclk);
@@ -82,11 +84,13 @@ static void at91_start_clock(struct ohci_at91_priv 
*ohci_at91)
ohci_at91->clocked = true;
 }
 
-static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
+static void at91_stop_clock(struct ohci_at91_priv *ohci_at91,
+   struct device *dev)
 {
if (!ohci_at91->clocked)
return;
 
+   dev_dbg(dev, "Disabling hclk, iclk, and fclk\n");
clk_disable_unprepare(ohci_at91->fclk);
clk_disable_unprepare(ohci_at91->iclk);
clk_disable_unprepare(ohci_at91->hclk);
@@ -104,7 +108,7 @@ static void at91_start_hc(struct platform_device *pdev)
/*
 * Start the USB clocks.
 */
-   at91_start_clock(ohci_at91);
+   at91_start_clock(ohci_at91, &pdev->dev);
 
/*
 * The USB host controller must remain in reset.
@@ -128,7 +132,7 @@ static void at91_stop_hc(struct platform_device *pdev)
/*
 * Stop the USB clocks.
 */
-   at91_stop_clock(ohci_at91);
+   at91_stop_clock(ohci_at91, &pdev->dev);
 }
 
 
@@ -623,7 +627,7 @@ ohci_hcd_at91_drv_suspend(struct device *dev)
 
/* flush the writes */
(void) ohci_readl (ohci, &ohci->regs->control);
-   at91_s

[PATCH v2 0/2] clk: at91: Added more information logging

2018-04-09 Thread Marcin Ziemianowicz
This is a series of patches which resolves set_rate() for the PLL not
having any effect and therefore the USB Host port not working. Also, a
few messages were added which may be helpful in the future when others
are working with USB clocking.

Changes since V1:
  Added patch set cover letter
  Shortened lines which were over >80 characters long
  > Comment by Greg Kroah-Hartman about "from" field in email addressed
  > Comment by Alan Stern about redundant debug lines addressed

hak8or (2):
  clk: at91: Added more information logging.
  clk: at91: Fix for PLL set_rate changes not being actually written to
PLL peripheral bits

 drivers/clk/at91/clk-pll.c   | 14 +-
 drivers/clk/at91/clk-usb.c   | 10 --
 drivers/usb/host/ohci-at91.c | 16 ++--
 3 files changed, 31 insertions(+), 9 deletions(-)

-- 
2.17.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 v3 3/3] usb: phy: Add Kconfig entry for Tegra PHY driver

2018-04-09 Thread Dmitry Osipenko
Tegra's EHCI driver has a build dependency on Tegra's PHY driver and
currently Tegra's PHY driver is built only when Tegra's EHCI driver is
built. Add own Kconfig entry for the Tegra's PHY driver so that drivers
other than ehci-tegra (like ChipIdea UDC) could work with ehci-tegra
driver being disabled in kernels config by allowing user to manually
select the PHY driver.

Signed-off-by: Dmitry Osipenko 
---
 drivers/usb/host/Kconfig | 4 +---
 drivers/usb/phy/Kconfig  | 9 +
 drivers/usb/phy/Makefile | 2 +-
 3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 5d958da8e1bc..9f0aeb068acb 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -234,9 +234,7 @@ config USB_EHCI_TEGRA
tristate "NVIDIA Tegra HCD support"
depends on ARCH_TEGRA
select USB_EHCI_ROOT_HUB_TT
-   select USB_PHY
-   select USB_ULPI
-   select USB_ULPI_VIEWPORT
+   select USB_TEGRA_PHY
help
  This driver enables support for the internal USB Host Controllers
  found in NVIDIA Tegra SoCs. The controllers are EHCI compliant.
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 0f8ab981d572..b9b0a44be679 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -159,6 +159,15 @@ config USB_MXS_PHY
 
  MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
 
+config USB_TEGRA_PHY
+   tristate "NVIDIA Tegra USB PHY Driver"
+   depends on ARCH_TEGRA
+   select USB_PHY
+   select USB_ULPI
+   help
+ This driver provides PHY support for the USB controllers found
+ on NVIDIA Tegra SoC's.
+
 config USB_ULPI
bool "Generic ULPI Transceiver Driver"
depends on ARM || ARM64
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 25e579fb92b8..df1d99010079 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -16,7 +16,7 @@ obj-$(CONFIG_AM335X_CONTROL_USB)  += phy-am335x-control.o
 obj-$(CONFIG_AM335X_PHY_USB)   += phy-am335x.o
 obj-$(CONFIG_OMAP_OTG) += phy-omap-otg.o
 obj-$(CONFIG_TWL6030_USB)  += phy-twl6030-usb.o
-obj-$(CONFIG_USB_EHCI_TEGRA)   += phy-tegra-usb.o
+obj-$(CONFIG_USB_TEGRA_PHY)+= phy-tegra-usb.o
 obj-$(CONFIG_USB_GPIO_VBUS)+= phy-gpio-vbus-usb.o
 obj-$(CONFIG_USB_ISP1301)  += phy-isp1301.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
-- 
2.16.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 v3 1/3] usb: phy: tegra: Cleanup error messages

2018-04-09 Thread Dmitry Osipenko
Tegra's PHY driver has a mix of pr_err() and dev_err(), let's switch to
dev_err() and use common errors message formatting across the driver for
consistency.

Signed-off-by: Dmitry Osipenko 
---
 drivers/usb/phy/phy-tegra-usb.c | 69 -
 1 file changed, 41 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index 0e8d23e51732..e46219e7fa93 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -236,10 +236,14 @@ static void set_phcd(struct tegra_usb_phy *phy, bool 
enable)
 
 static int utmip_pad_open(struct tegra_usb_phy *phy)
 {
+   int err;
+
phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads");
if (IS_ERR(phy->pad_clk)) {
-   pr_err("%s: can't get utmip pad clock\n", __func__);
-   return PTR_ERR(phy->pad_clk);
+   err = PTR_ERR(phy->pad_clk);
+   dev_err(phy->u_phy.dev,
+   "Failed to get UTMIP pad clock: %d\n", err);
+   return err;
}
 
return 0;
@@ -282,7 +286,7 @@ static int utmip_pad_power_off(struct tegra_usb_phy *phy)
void __iomem *base = phy->pad_regs;
 
if (!utmip_pad_count) {
-   pr_err("%s: utmip pad already powered off\n", __func__);
+   dev_err(phy->u_phy.dev, "UTMIP pad already powered off\n");
return -EINVAL;
}
 
@@ -338,7 +342,8 @@ static void utmi_phy_clk_disable(struct tegra_usb_phy *phy)
set_phcd(phy, true);
 
if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID, 0) < 0)
-   pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
+   dev_err(phy->u_phy.dev,
+   "Timeout waiting for PHY to stabilize on disable\n");
 }
 
 static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
@@ -370,7 +375,8 @@ static void utmi_phy_clk_enable(struct tegra_usb_phy *phy)
 
if (utmi_wait_register(base + USB_SUSP_CTRL, USB_PHY_CLK_VALID,
 USB_PHY_CLK_VALID))
-   pr_err("%s: timeout waiting for phy to stabilize\n", __func__);
+   dev_err(phy->u_phy.dev,
+   "Timeout waiting for PHY to stabilize on enable\n");
 }
 
 static int utmi_phy_power_on(struct tegra_usb_phy *phy)
@@ -617,15 +623,15 @@ static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
 
ret = gpio_direction_output(phy->reset_gpio, 0);
if (ret < 0) {
-   dev_err(phy->u_phy.dev, "gpio %d not set to 0\n",
-   phy->reset_gpio);
+   dev_err(phy->u_phy.dev, "GPIO %d not set to 0: %d\n",
+   phy->reset_gpio, ret);
return ret;
}
msleep(5);
ret = gpio_direction_output(phy->reset_gpio, 1);
if (ret < 0) {
-   dev_err(phy->u_phy.dev, "gpio %d not set to 1\n",
-   phy->reset_gpio);
+   dev_err(phy->u_phy.dev, "GPIO %d not set to 1: %d\n",
+   phy->reset_gpio, ret);
return ret;
}
 
@@ -661,13 +667,13 @@ static int ulpi_phy_power_on(struct tegra_usb_phy *phy)
/* Fix VbusInvalid due to floating VBUS */
ret = usb_phy_io_write(phy->ulpi, 0x40, 0x08);
if (ret) {
-   pr_err("%s: ulpi write failed\n", __func__);
+   dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", ret);
return ret;
}
 
ret = usb_phy_io_write(phy->ulpi, 0x80, 0x0B);
if (ret) {
-   pr_err("%s: ulpi write failed\n", __func__);
+   dev_err(phy->u_phy.dev, "ULPI write failed: %d\n", ret);
return ret;
}
 
@@ -728,28 +734,30 @@ static int ulpi_open(struct tegra_usb_phy *phy)
 
phy->clk = devm_clk_get(phy->u_phy.dev, "ulpi-link");
if (IS_ERR(phy->clk)) {
-   pr_err("%s: can't get ulpi clock\n", __func__);
-   return PTR_ERR(phy->clk);
+   err = PTR_ERR(phy->clk);
+   dev_err(phy->u_phy.dev, "Failed to get ULPI clock: %d\n", err);
+   return err;
}
 
err = devm_gpio_request(phy->u_phy.dev, phy->reset_gpio,
"ulpi_phy_reset_b");
if (err < 0) {
-   dev_err(phy->u_phy.dev, "request failed for gpio: %d\n",
-  phy->reset_gpio);
+   dev_err(phy->u_phy.dev, "Request failed for GPIO %d: %d\n",
+   phy->reset_gpio, err);
return err;
}
 
err = gpio_direction_output(phy->reset_gpio, 0);
if (err < 0) {
-   dev_err(phy->u_phy.dev, "gpio %d direction not set to output\n",
-  phy->reset_gpio);
+   dev_err(phy->u_phy.dev,
+   "GPIO %d direction not set to output: %d\n",
+   phy->res

[PATCH v3 2/3] usb: tegra: Move utmi-pads reset from ehci-tegra to tegra-phy

2018-04-09 Thread Dmitry Osipenko
UTMI pads are shared by USB controllers and reset of UTMI pads is shared
with the reset of USB1 controller. Currently reset of UTMI pads is done by
the EHCI driver and ChipIdea UDC works because EHCI driver always happen
to be probed first. Move reset controls from ehci-tegra to tegra-phy in
order to resolve the problem.

Signed-off-by: Dmitry Osipenko 
---
 drivers/usb/host/ehci-tegra.c | 87 ++-
 drivers/usb/phy/phy-tegra-usb.c   | 79 ---
 include/linux/usb/tegra_usb_phy.h |  2 +
 3 files changed, 115 insertions(+), 53 deletions(-)

diff --git a/drivers/usb/host/ehci-tegra.c b/drivers/usb/host/ehci-tegra.c
index a6f4389f7e88..4d2cdec4cb78 100644
--- a/drivers/usb/host/ehci-tegra.c
+++ b/drivers/usb/host/ehci-tegra.c
@@ -36,7 +36,6 @@
 #define DRV_NAME "tegra-ehci"
 
 static struct hc_driver __read_mostly tegra_ehci_hc_driver;
-static bool usb1_reset_attempted;
 
 struct tegra_ehci_soc_config {
bool has_hostpc;
@@ -51,67 +50,54 @@ struct tegra_ehci_hcd {
enum tegra_usb_phy_port_speed port_speed;
 };
 
-/*
- * The 1st USB controller contains some UTMI pad registers that are global for
- * all the controllers on the chip. Those registers are also cleared when
- * reset is asserted to the 1st controller. This means that the 1st controller
- * can only be reset when no other controlled has finished probing. So we'll
- * reset the 1st controller before doing any other setup on any of the
- * controllers, and then never again.
- *
- * Since this is a PHY issue, the Tegra PHY driver should probably be doing
- * the resetting of the USB controllers. But to keep compatibility with old
- * device trees that don't have reset phandles in the PHYs, do it here.
- * Those old DTs will be vulnerable to total USB breakage if the 1st EHCI
- * device isn't the first one to finish probing, so warn them.
- */
 static int tegra_reset_usb_controller(struct platform_device *pdev)
 {
struct device_node *phy_np;
struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct tegra_ehci_hcd *tegra =
(struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv;
-   bool has_utmi_pad_registers = false;
+   struct reset_control *rst;
+   int err;
 
phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0);
if (!phy_np)
return -ENOENT;
 
-   if (of_property_read_bool(phy_np, "nvidia,has-utmi-pad-registers"))
-   has_utmi_pad_registers = true;
+   /*
+* The 1st USB controller contains some UTMI pad registers that are
+* global for all the controllers on the chip. Those registers are
+* also cleared when reset is asserted to the 1st controller.
+*/
+   rst = of_reset_control_get_shared(phy_np, "utmi-pads");
+   if (IS_ERR(rst)) {
+   dev_warn(&pdev->dev,
+"can't get utmi-pads reset from the PHY\n");
+   dev_warn(&pdev->dev,
+"continuing, but please update your DT\n");
+   } else {
+   /*
+* PHY driver performs UTMI-pads reset in a case of
+* non-legacy DT.
+*/
+   reset_control_put(rst);
+   }
 
-   if (!usb1_reset_attempted) {
-   struct reset_control *usb1_reset;
+   of_node_put(phy_np);
 
-   if (!has_utmi_pad_registers)
-   usb1_reset = of_reset_control_get(phy_np, "utmi-pads");
-   else
-   usb1_reset = tegra->rst;
-
-   if (IS_ERR(usb1_reset)) {
-   dev_warn(&pdev->dev,
-"can't get utmi-pads reset from the PHY\n");
-   dev_warn(&pdev->dev,
-"continuing, but please update your DT\n");
-   } else {
-   reset_control_assert(usb1_reset);
-   udelay(1);
-   reset_control_deassert(usb1_reset);
-
-   if (!has_utmi_pad_registers)
-   reset_control_put(usb1_reset);
-   }
+   /* reset control is shared, hence initialize it first */
+   err = reset_control_deassert(tegra->rst);
+   if (err)
+   return err;
 
-   usb1_reset_attempted = true;
-   }
+   err = reset_control_assert(tegra->rst);
+   if (err)
+   return err;
 
-   if (!has_utmi_pad_registers) {
-   reset_control_assert(tegra->rst);
-   udelay(1);
-   reset_control_deassert(tegra->rst);
-   }
+   udelay(1);
 
-   of_node_put(phy_np);
+   err = reset_control_deassert(tegra->rst);
+   if (err)
+   return err;
 
return 0;
 }
@@ -440,7 +426,7 @@ static int tegra_ehci_probe(struct platform_device *pdev)
goto cleanup_hcd_create;
}
 
-   te

[PATCH v3 0/3] Tegra's USB driver dependency fix

2018-04-09 Thread Dmitry Osipenko
Tegra uses two different USB drivers for host / device controllers, one is
tegra-ehci (host) and other is ChipIdea (UDC). Currently ChipIdea driver
implicitly (and incorrectly) depends on Tegra's EHCI driver because Tegra's
PHY driver is built only when host driver is built, also host controller
shares HW resets with the device controller and host driver manages the
resets solely. This small series fixes the dependency by moving out reset
controls to the PHY driver and making them shared, then the driver build
dependency is resolved.

Changelog:

v3:
Fixed Tegra's EHCI driver dependency on functions exported by the
Tegra's PHY driver (was reported by "kbuild test robot" for v2) by
making host driver to select the PHY driver in Kconfig.

v2:
Added missed USB_ULPI dependency to USB_TEGRA_PHY.

Corrected UTMI pads reset by moving reset assert/deassert to the
PHY's probe.

Removed function names as per Thierry's suggestion.

Dmitry Osipenko (3):
  usb: phy: tegra: Cleanup error messages
  usb: tegra: Move utmi-pads reset from ehci-tegra to tegra-phy
  usb: phy: Add Kconfig entry for Tegra PHY driver

 drivers/usb/host/Kconfig  |   4 +-
 drivers/usb/host/ehci-tegra.c |  87 +++
 drivers/usb/phy/Kconfig   |   9 +++
 drivers/usb/phy/Makefile  |   2 +-
 drivers/usb/phy/phy-tegra-usb.c   | 140 ++
 include/linux/usb/tegra_usb_phy.h |   2 +
 6 files changed, 163 insertions(+), 81 deletions(-)

-- 
2.16.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: dwc2: Memory leak in dwc2_gadget_init

2018-04-09 Thread Stefan Wahren
Hi Grigor,

> Grigor Tovmasyan  hat am 9. April 2018 um 
> 18:42 geschrieben:
> 
> 
> Hi Stefan,
> 
> On 4/2/2018 12:59 PM, Stefan Wahren wrote:
> > Hi Minas,
> > 
> > i noticed that in opposite to all allocations in dwc2_gadget_init() the 
> > function dwc2_hsotg_ep_alloc_request() uses kzalloc. So in case 
> > usb_add_gadget_udc() would fail, the memory of the USB request would be 
> > leaked:
> > 
> > Linux raspberrypi 4.16.0-rc7-next-20180327+ #2 SMP PREEMPT Sat Mar 31 
> > 13:24:47 CEST 2018 armv6l GNU/Linux
> 
> Sorry for late reply.
> Could you please tell me which tool you use for checking memory leak?

there is no additional tool required. Just enable the following settings in the 
kernel config:

Kernel hacking  --->
  Memory Debugging  --->
[*] Kernel memory leak detector (CONFIG_DEBUG_KMEMLEAK=y)
(1400) Maximum kmemleak early log entries 
(CONFIG_DEBUG_KMEMLEAK_EARLY_LOG_SIZE=1400)

The log entries depends on your system, these are the settings for an Raspberry 
Pi. The detector noticed only leaks that has been triggered AFTER 10 minutes.

> I prepared the patch and wanted to check it.

So in order to reproduce this issue you will need to make probing fail at the 
same point.

Please follow this patch [1] and this bootlog [2] for more context.

Thanks
Stefan

[1] - https://www.spinics.net/lists/linux-usb/msg167472.html
[2] - 
https://storage.kernelci.org/next/master/next-20180409/arm/bcm2835_defconfig/lab-baylibre/boot-bcm2837-rpi-3-b.txt

> 
> Thanks,
> Grigor.
> 
> > 
> > unreferenced object 0xd8703cc0 (size 64):
> >comm "kworker/0:1", pid 18, jiffies 4294937977 (age 2780.490s)
> >hex dump (first 32 bytes):
> >  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
> >  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
> >backtrace:
> >  [<09023b43>] kmemleak_alloc+0x78/0xc0
> >  [<60182b94>] kmem_cache_alloc_trace+0x150/0x398
> >  [] dwc2_hsotg_ep_alloc_request+0x34/0x58
> >  [<401a2371>] dwc2_gadget_init+0x32c/0x3ec
> >  [<2b1d6850>] dwc2_driver_probe+0x320/0x418
> >  [<765bc59d>] platform_drv_probe+0x60/0xac
> >  [<65e4f320>] driver_probe_device+0x2d4/0x46c
> >  [<57a8c266>] __device_attach_driver+0xb0/0x104
> >  [<14964192>] bus_for_each_drv+0x98/0xa0
> >  [<34c644b4>] __device_attach+0xb0/0x13c
> >  [] device_initial_probe+0x1c/0x20
> >  [] bus_probe_device+0x38/0x94
> >  [<550305ed>] deferred_probe_work_func+0x12c/0x14c
> >  [<681db7c3>] process_one_work+0x3c8/0x76c
> >  [<818bc895>] process_scheduled_works+0x38/0x3c
> >  [<0dd47435>] worker_thread+0x2c4/0x43c
> > 
> > Best regards
> > Stefan
> > --
> > 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  
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwICaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=K1ULVL1slpLXpMJJlAXSOxws4tRq0IkTBqxDkyW2hUQ&m=i65dP-5DLfIelHtOk6TiLygqXtfp5tcq2CKdocriNto&s=EijYUhFJlFmz34zKw20t_Hq5TQHZoWJIbNmjpj2H7N8&e=
> > 
>
--
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 02/13] dt-bindings: usb: add documentation for typec port controller(TCPCI)

2018-04-09 Thread Rob Herring
On Thu, Mar 29, 2018 at 12:06:07AM +0800, Li Jun wrote:
> TCPCI stands for typec port controller interface, its implementation
> has full typec port control with power delivery support, it's a
> standard i2c slave with GPIO input as irq interface, detail see spec
> "Universal Serial Bus Type-C Port Controller Interface Specification
> Revision 1.0, Version 1.1"
> 
> Signed-off-by: Li Jun 
> ---
>  .../devicetree/bindings/usb/typec-tcpci.txt| 33 
> ++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/typec-tcpci.txt 
> b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
> new file mode 100644
> index 000..7a7a8e0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/typec-tcpci.txt
> @@ -0,0 +1,33 @@
> +TCPCI(Typec port cotroller interface) binding
> +-
> +
> +Required properties:
> +- compatible:   should be "usb-tcpci,chip-specific-string".

Compatible strings should be in the form of ","

> +- reg:  the i2c slave address of typec port controller device.
> +- interrupt-parent: the phandle to the interrupt controller which provides
> +the interrupt.
> +- interrupts:   interrupt specification for tcpci alert.
> +
> +Required sub-node:
> +- connector: The "usb-c-connector" attached to the tcpci chip, the bindings
> +  of connector node are specified in
> +  Documentation/devicetree/bindings/connector/usb-connector.txt
> +
> +Example:
> +
> +ptn5110@50 {
> + compatible = "usb-tcpci,ptn5110";
> + reg = <0x50>;
> + interrupt-parent = <&gpio3>;
> + interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
> +
> + usb_con: connector {

How is the OF graph done in this case? You need some link to the USB 
controller.

> + compatible = "usb-c-connector";
> + label = "USB-C";
> + port-type = "dual";
> + try-power-role = "sink"
> + source-pdos = <0x380190c8>;
> + sink-pdos = <0x380190c8 0x3802d0c8>;
> + op-sink-microwatt-hours = <900>;
> + };
> +};
> -- 
> 2.7.4
> 
> --
> To unsubscribe from this list: send the line "unsubscribe devicetree" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
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] usb: gadget: f_fs: Add compat_ioctl to ep0

2018-04-09 Thread Jerry Zhang
Functionfs ep0 ioctls can be handled in the
same way as a normal ioctl. Underlying gadget
ioctls are passed to the underlying gadget's
compat_ioctl.

Signed-off-by: Jerry Zhang 
---
 drivers/usb/gadget/function/f_fs.c | 20 
 1 file changed, 20 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c 
b/drivers/usb/gadget/function/f_fs.c
index 34d80cc2b667..ef349bdde001 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -641,6 +641,23 @@ static long ffs_ep0_ioctl(struct file *file, unsigned 
code, unsigned long value)
return ret;
 }
 
+#ifdef CONFIG_COMPAT
+static long ffs_ep0_compat_ioctl(struct file *file, unsigned code, unsigned 
long value)
+{
+   long ret;
+
+   if (code == FUNCTIONFS_INTERFACE_REVMAP) {
+   ret = ffs_ep0_ioctl(file, code, value);
+   } else if (gadget && gadget->ops->compat_ioctl) {
+   ret = gadget->ops->compat_ioctl(gadget, code, value);
+   } else {
+   ret = -ENOTTY;
+   }
+
+   return ret;
+}
+#endif
+
 static __poll_t ffs_ep0_poll(struct file *file, poll_table *wait)
 {
struct ffs_data *ffs = file->private_data;
@@ -691,6 +708,9 @@ static const struct file_operations ffs_ep0_operations = {
.release =  ffs_ep0_release,
.unlocked_ioctl =   ffs_ep0_ioctl,
.poll = ffs_ep0_poll,
+#ifdef CONFIG_COMPAT
+   .compat_ioctl = ffs_ep0_compat_ioctl,
+#endif
 };
 
 
-- 
2.17.0.484.g0c8726318c-goog

--
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] usb: gadget: f_midi: Add configfs attrs for card and device

2018-04-09 Thread Jerry Zhang
An f_midi instance will have a corresponding native
device in /dev/snd/midiC%dD%d where the first number
is the number of the sound card and the second is the
number of the device. Expose both of these through
configfs so the user can find the correct sound device.

The configfs attrs are read only and will return the
appropriate value, or -1 if it is not available.

Signed-off-by: Jerry Zhang 
---
 drivers/usb/gadget/function/f_midi.c | 38 
 1 file changed, 38 insertions(+)

diff --git a/drivers/usb/gadget/function/f_midi.c 
b/drivers/usb/gadget/function/f_midi.c
index a89908eb035f..5d4a444ff073 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -1179,6 +1179,42 @@ static ssize_t f_midi_opts_id_store(struct config_item 
*item,
 
 CONFIGFS_ATTR(f_midi_opts_, id);
 
+static ssize_t f_midi_opts_card_show(struct config_item *item, char *page)
+{
+   struct f_midi_opts *opts = to_f_midi_opts(item);
+   int card = -1;
+   struct f_midi *midi;
+
+   if (opts->func_inst.f) {
+   midi = func_to_midi(opts->func_inst.f);
+   if (midi->rmidi && midi->rmidi->card) {
+   card = midi->rmidi->card->number;
+   }
+   }
+
+   return sprintf(page, "%d\n", card);
+}
+
+CONFIGFS_ATTR_RO(f_midi_opts_, card);
+
+static ssize_t f_midi_opts_device_show(struct config_item *item, char *page)
+{
+   struct f_midi_opts *opts = to_f_midi_opts(item);
+   int device = -1;
+   struct f_midi *midi;
+
+   if (opts->func_inst.f) {
+   midi = func_to_midi(opts->func_inst.f);
+   if (midi->rmidi) {
+   device = midi->rmidi->device;
+   }
+   }
+
+   return sprintf(page, "%d\n", device);
+}
+
+CONFIGFS_ATTR_RO(f_midi_opts_, device);
+
 static struct configfs_attribute *midi_attrs[] = {
&f_midi_opts_attr_index,
&f_midi_opts_attr_buflen,
@@ -1186,6 +1222,8 @@ static struct configfs_attribute *midi_attrs[] = {
&f_midi_opts_attr_in_ports,
&f_midi_opts_attr_out_ports,
&f_midi_opts_attr_id,
+   &f_midi_opts_attr_card,
+   &f_midi_opts_attr_device,
NULL,
 };
 
-- 
2.17.0.484.g0c8726318c-goog

--
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: dwc3: gadget: Fix list_del corruption in dwc3_ep_dequeue

2018-04-09 Thread Jack Pham
Hi Felipe,

Just wondering if you had a chance to look at this. This fixes a
potential double-delete error which was caught when CONFIG_DEBUG_LIST=y
&& CONFIG_BUG_ON_DATA_CORRUPTION==y.

On Fri, Mar 23, 2018 at 10:05:33AM -0700, Jack Pham wrote:
> From: Mayank Rana 
> 
> dwc3_ep_dequeue() waits for completion of End Transfer command
> using wait_event_lock_irq(), which will release the dwc3->lock
> while waiting and reacquire after completion. This allows a
> potential race condition with ep_disable() which also removes
> all requests from started_list and pending_list. The check for
> NULL r->trb should catch this but currently it exits to the
> wrong 'out1' label which calls dwc3_gadget_giveback(). Since
> its list entry was already removed, if CONFIG_DEBUG_LIST is
> enabled a 'list_del corruption' bug is thrown since its
> next/prev pointers are already LIST_POISON1/2. If r->trb is
> NULL it should simply exit to 'out0'.
> 
> Fixes: cf3113d893d4 ("usb: dwc3: gadget: properly increment dequeue pointer 
> on ep_dequeue")
> Cc: sta...@vger.kernel.org
> Signed-off-by: Mayank Rana 
> Signed-off-by: Jack Pham 
> ---
>  drivers/usb/dwc3/gadget.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index 2bda4eb..1238a97 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -1417,7 +1417,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
>   dwc->lock);
>  
>   if (!r->trb)
> - goto out1;
> + goto out0;
>  
>   if (r->num_pending_sgs) {
>   struct dwc3_trb *trb;

Thanks,
Jack
--
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: dwc2: Memory leak in dwc2_gadget_init

2018-04-09 Thread Grigor Tovmasyan
Hi Stefan,

On 4/2/2018 12:59 PM, Stefan Wahren wrote:
> Hi Minas,
> 
> i noticed that in opposite to all allocations in dwc2_gadget_init() the 
> function dwc2_hsotg_ep_alloc_request() uses kzalloc. So in case 
> usb_add_gadget_udc() would fail, the memory of the USB request would be 
> leaked:
> 
> Linux raspberrypi 4.16.0-rc7-next-20180327+ #2 SMP PREEMPT Sat Mar 31 
> 13:24:47 CEST 2018 armv6l GNU/Linux

Sorry for late reply.
Could you please tell me which tool you use for checking memory leak?
I prepared the patch and wanted to check it.

Thanks,
Grigor.

> 
> unreferenced object 0xd8703cc0 (size 64):
>comm "kworker/0:1", pid 18, jiffies 4294937977 (age 2780.490s)
>hex dump (first 32 bytes):
>  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
>  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  
>backtrace:
>  [<09023b43>] kmemleak_alloc+0x78/0xc0
>  [<60182b94>] kmem_cache_alloc_trace+0x150/0x398
>  [] dwc2_hsotg_ep_alloc_request+0x34/0x58
>  [<401a2371>] dwc2_gadget_init+0x32c/0x3ec
>  [<2b1d6850>] dwc2_driver_probe+0x320/0x418
>  [<765bc59d>] platform_drv_probe+0x60/0xac
>  [<65e4f320>] driver_probe_device+0x2d4/0x46c
>  [<57a8c266>] __device_attach_driver+0xb0/0x104
>  [<14964192>] bus_for_each_drv+0x98/0xa0
>  [<34c644b4>] __device_attach+0xb0/0x13c
>  [] device_initial_probe+0x1c/0x20
>  [] bus_probe_device+0x38/0x94
>  [<550305ed>] deferred_probe_work_func+0x12c/0x14c
>  [<681db7c3>] process_one_work+0x3c8/0x76c
>  [<818bc895>] process_scheduled_works+0x38/0x3c
>  [<0dd47435>] worker_thread+0x2c4/0x43c
> 
> Best regards
> Stefan
> --
> 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  
> https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwICaQ&c=DPL6_X_6JkXFx7AXWqB0tg&r=K1ULVL1slpLXpMJJlAXSOxws4tRq0IkTBqxDkyW2hUQ&m=i65dP-5DLfIelHtOk6TiLygqXtfp5tcq2CKdocriNto&s=EijYUhFJlFmz34zKw20t_Hq5TQHZoWJIbNmjpj2H7N8&e=
> 

--
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] USB: serial: cp210x: Add ID for NI USB serial console

2018-04-09 Thread Kyle Roeschley
Added the USB VID and PID for the USB serial console on some National
Instruments devices.

Signed-off-by: Kyle Roeschley 
---
 drivers/usb/serial/cp210x.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index 06d502b3e913..cc5b2d0d340d 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -213,6 +213,7 @@ static const struct usb_device_id id_table[] = {
{ USB_DEVICE(0x3195, 0xF190) }, /* Link Instruments MSO-19 */
{ USB_DEVICE(0x3195, 0xF280) }, /* Link Instruments MSO-28 */
{ USB_DEVICE(0x3195, 0xF281) }, /* Link Instruments MSO-28 */
+   { USB_DEVICE(0x3923, 0x7A0B) }, /* National Instruments USB Serial 
Console */
{ USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */
{ } /* Terminating Entry */
 };
-- 
2.16.2

--
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: [RFT/PATCH 35/38] usb: dwc3: gadget: combine modify & restore into single argument

2018-04-09 Thread kbuild test robot
Hi Felipe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on balbi-usb/next]
[also build test WARNING on next-20180409]
[cannot apply to v4.16]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/Felipe-Balbi/usb-dwc3-gadget-Rework-Refactoring/20180409-204052
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
reproduce: make htmldocs

All warnings (new ones prefixed by >>):

   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   include/net/mac80211.h:2083: warning: bad line: >
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'rx_stats_avg' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'rx_stats_avg.signal' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'rx_stats_avg.chain_signal' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.filtered' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.retry_failed' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.retry_count' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.lost_packets' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.last_tdls_pkt_time' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.msdu_retries' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.msdu_failed' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.last_ack' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.last_ack_signal' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'status_stats.ack_signal_filled' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'tx_stats.packets' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'tx_stats.bytes' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'tx_stats.last_rate' not described in 'sta_info'
   net/mac80211/sta_info.h:586: warning: Function parameter or member 
'tx_stats.msdu' not described in 'sta_info'
   kernel/sched/fair.c:3731: warning: Function parameter or member 'flags' not 
described in 'attach_entity_load_avg'
   include/linux/dma-buf.h:307: warning: Function parameter or member 
'cb_e

Re: [PATCH 2/2] usb: dwc3: add clock and resets

2018-04-09 Thread Rob Herring
On Wed, Mar 28, 2018 at 11:32 PM, Masahiro Yamada
 wrote:
> 2018-03-19 7:37 GMT+09:00 Masahiro Yamada :
>> Hi Rob,
>>
>> 2018-03-18 21:52 GMT+09:00 Rob Herring :
>>> On Thu, Mar 15, 2018 at 08:39:58PM +0900, Masahiro Yamada wrote:
 dwc3-of-simple.c only handles arbitrary number of clocks and resets.
 They are both generic enough to be put into the dwc3 core.  For simple
 cases, a nested node structure like follows:

   dwc3-glue {
   compatible = "foo,dwc3";
   clocks = ...;
   resets = ...;
   ...

   dwc3 {
   compatible = "snps,dwc3";
   ...
   };
>>>
>>> I'm not a fan of how this was done.
>>>
>>>
   }

 would be turned into a single node:

   dwc3 {
   compatible = "foo,dwc3", "snps,dwc3";
   clocks = ...;
   resets = ...;
   ...
   }
>>>
>>> And yes, this is what I'd prefer.
>>
>>
>>
>> Not only dwc3-of-simple.c, but all dwc3 nodes are
>> written like this.
>>
>>
>> omap_dwc3_1: omap_dwc3_1@4888 {
>> compatible = "ti,dwc3";
>> reg = <0x4888 0x1>;
>> #address-cells = <1>;
>> #size-cells = <1>;
>> ranges;
>> ...
>>
>> usb1: usb@4889 {
>> compatible = "snps,dwc3";
>> reg = <0x4889 0x17000>;
>> ...
>> };
>> };
>>
>>
>> The glue layer initializes SoC-specific things,
>> then populates the child "snps,dwc3".
>>
>>
>> I think the following structure should work
>> by handling EPROBE_DEFER properly.
>>
>> omap_dwc3_1: omap_dwc3_1@4888 {
>> compatible = "ti,dwc3"; (should be "ti,dwc3-glue" or something)
>> reg = <0x4888 0x1>;
>> ...
>> };
>>
>> usb1: usb@4889 {
>> compatible = "snps,dwc3";
>> reg = <0x4889 0x17000>;
>> ...
>> };
>>
>>
>>

 I inserted reset_control_deassert() and clk_enable() before the first
 register access, i.e. dwc3_cache_hwparams().

 Signed-off-by: Masahiro Yamada 
 ---

  Documentation/devicetree/bindings/usb/dwc3.txt |   2 +
  drivers/usb/dwc3/core.c| 127 
 -
  drivers/usb/dwc3/core.h|   5 +
  3 files changed, 132 insertions(+), 2 deletions(-)

 diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
 b/Documentation/devicetree/bindings/usb/dwc3.txt
 index 44e8bab..67e9cfb 100644
 --- a/Documentation/devicetree/bindings/usb/dwc3.txt
 +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
 @@ -9,12 +9,14 @@ Required properties:
   - interrupts: Interrupts used by the dwc3 controller.

  Optional properties:
 + - clocks: list of phandle and clock specifier pairs
>>>
>>> However, this should be specific as to how many clocks and their
>>> function. This should be readily available to someone with access to
>>> Synopsys datasheet. The number of clocks should generally be the same
>>> across SoCs, it is just some SoCs either tie clocks together or don't
>>> provide s/w control of some of the clocks.
>>
>>
>> Make sense.
>> You also implies this property is mandatory.
>> The number of clocks should be available in the datasheet
>> and no hardware can work with zero clock.
>>
>> However, making it mandatory breaks the binding
>> since the existing DT files do not specify clocks at all
>> in the "snps,dwc3" node.

Because of this it has to be optional. We could list what compatibles
it is optional for and that it is mandatory for new users.

>>
>> Anyway, our current situation:
>>
>> - We have the dwc3-core under the glue layer node
>>   despite they are independent in the CPU address view
>> - We add all sorts of clocks and resets in the glue layer node,
>>   and nothing in the dwc3-core node.
>>
>> If these are design mistake, what should we do?
>>
>> Continue development based on it?
>> If we fix it, how to change the course?
>>
>
> Any insight about this?

We just need to reject new bindings that do things the old way. The
driver will have to support both cases for some time period.


> I think this is rather a general question.
>
> If somebody upstreams a driver without clocks,
> then later it turns out clocks are necessary,
> adding required clocks would break existing platforms
> since clk_get() fails.

We should try to prevent that, but of course that is not always
possible. Unless that platform is deemed unstable and we break
compatibility, we'd have to handle both cases in the driver.

Rob
--
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 4/4] usb: gadget: udc: renesas_usb3: should call devm_phy_get() before add udc

2018-04-09 Thread Simon Horman
On Mon, Apr 02, 2018 at 09:21:34PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that this driver cannot call phy_init()
> if a gadget driver is alreadly loaded because usb_add_gadget_udc()
> might call renesas_usb3_start() via .udc_start.
> 
> Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for generic 
> phy")
> Cc:  # v4.15+
> Signed-off-by: Yoshihiro Shimoda 
> ---
>  drivers/usb/gadget/udc/renesas_usb3.c | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)

Reviewed-by: Simon Horman 


Please see some suggestions for follow-up lower-priority patches below.

> 
> diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
> b/drivers/usb/gadget/udc/renesas_usb3.c
> index 738b734..671bac3 100644
> --- a/drivers/usb/gadget/udc/renesas_usb3.c
> +++ b/drivers/usb/gadget/udc/renesas_usb3.c
> @@ -2632,6 +2632,14 @@ static int renesas_usb3_probe(struct platform_device 
> *pdev)
>   if (ret < 0)
>   goto err_alloc_prd;
>  
> + /*
> +  * This is an optional. So, if this driver cannot get a phy,
> +  * this driver will not handle a phy anymore.
> +  */

nit: s/an optional/optional/

> + usb3->phy = devm_phy_get(&pdev->dev, "usb");
> + if (IS_ERR(usb3->phy))
> + usb3->phy = NULL;

I think this will unintentionally ignore errors other than the
non-existence of the device, f.e. a memory allocation failure
in devm_phy_get().

So perhaps something like this, as per phy_optional_get(), would be better?

usb3->phy = devm_phy_get(&pdev->dev, "usb");
if (IS_ERR(usb3->phy) && (PTR_ERR(usb3->phy) == -ENODEV))
usb3->phy = NULL;

> +
>   pm_runtime_enable(&pdev->dev);
>   ret = usb_add_gadget_udc(&pdev->dev, &usb3->gadget);
>   if (ret < 0)
> @@ -2641,14 +2649,6 @@ static int renesas_usb3_probe(struct platform_device 
> *pdev)
>   if (ret < 0)
>   goto err_dev_create;
>  
> - /*
> -  * This is an optional. So, if this driver cannot get a phy,
> -  * this driver will not handle a phy anymore.
> -  */
> - usb3->phy = devm_phy_get(&pdev->dev, "usb");
> - if (IS_ERR(usb3->phy))
> - usb3->phy = NULL;
> -
>   usb3->workaround_for_vbus = priv->workaround_for_vbus;
>  
>   renesas_usb3_debugfs_init(usb3, &pdev->dev);
> -- 
> 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: [PATCH 3/4] usb: gadget: udc: renesas_usb3: should call pm_runtime_enable() before add udc

2018-04-09 Thread Simon Horman
On Mon, Apr 02, 2018 at 09:21:33PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that this driver causes panic if a gadget
> driver is already loaded because usb_add_gadget_udc() might call
> renesas_usb3_start() via .udc_start, and then pm_runtime_get_sync()
> in renesas_usb3_start() doesn't work correctly.
> Note that the usb3_to_dev() macro should not be called at this timing
> because the macro uses the gadget structure.
> 
> Fixes: cf06df3fae28 ("usb: gadget: udc: renesas_usb3: move 
> pm_runtime_{en,dis}able()")
> Cc:  # v4.15+
> Signed-off-by: Yoshihiro Shimoda 

Reviewed-by: Simon Horman 

--
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 2/4] usb: gadget: udc: renesas_usb3: should remove debugfs

2018-04-09 Thread Simon Horman
On Mon, Apr 02, 2018 at 09:21:32PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that this driver doesn't remove its debugfs.
> 
> Fixes: 43ba968b00ea ("usb: gadget: udc: renesas_usb3: add debugfs to set the 
> b-device mode")
> Cc:  # v4.14+
> Signed-off-by: Yoshihiro Shimoda 

Reviewed-by: Simon Horman 

--
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: typec: ucsi: fix tracepoint related build error

2018-04-09 Thread Tobias Regnery
On 09.04.18, Heikki Krogerus wrote:
> On Mon, Apr 09, 2018 at 09:55:17AM +0200, Tobias Regnery wrote:
> > The ucsi driver defines several tracepoints, but the header file with the
> > tracepoint definition trace.h is only conditionally built depending on
> > CONFIG_FTRACE.
> 
> You mean trace.c, right? The definitions are indeed in the header,
> trace.h, so I'm a bit confused what is actually the problem?

Right.

> 
> > This leads to the following build error with CONFIG_FTRACE=n and
> > CONFIG_TYPEC_UCSI=m:
> 
> That alone should not cause any problems.
> 
> > ERROR: "__tracepoint_ucsi_command" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> > undefined!
> > ERROR: "__tracepoint_ucsi_register_port" 
> > [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
> > ERROR: "__tracepoint_ucsi_notify" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> > undefined!
> > ERROR: "__tracepoint_ucsi_reset_ppm" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> > undefined!
> > ERROR: "__tracepoint_ucsi_run_command" 
> > [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
> > ERROR: "__tracepoint_ucsi_ack" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> > undefined!
> > ERROR: "__tracepoint_ucsi_connector_change" 
> > [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
> > 
> > With CONFIG_TYPEC_UCSI=y the build fails with several link errors.
> > 
> > Fix this by changing the Makefile to unconditionally build trace.o.
> > Tracepints are a runtime contruct and no other user of tracepoints depends
> > on CONFIG_FTRACE.
> > 
> > Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
> > Signed-off-by: Tobias Regnery 
> > ---
> >  drivers/usb/typec/ucsi/Makefile | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> > 
> > diff --git a/drivers/usb/typec/ucsi/Makefile 
> > b/drivers/usb/typec/ucsi/Makefile
> > index b57891c1fd31..971befbbc2a8 100644
> > --- a/drivers/usb/typec/ucsi/Makefile
> > +++ b/drivers/usb/typec/ucsi/Makefile
> > @@ -3,8 +3,6 @@ CFLAGS_trace.o  := -I$(src)
> >  
> >  obj-$(CONFIG_TYPEC_UCSI)   += typec_ucsi.o
> >  
> > -typec_ucsi-y   := ucsi.o
> > -
> > -typec_ucsi-$(CONFIG_FTRACE)+= trace.o
> > +typec_ucsi-y   := ucsi.o trace.o
> >  
> >  obj-$(CONFIG_UCSI_ACPI)+= ucsi_acpi.o
> 
> I would like to understand what is the root cause for the problem you
> are seeing? CONFIG_FTRACE=n with CONFIG_TYPEC_UCSI=m alone compiles
> just fine for me.
> 
> Using FTRACE as the condition here is indeed wrong, but changing that
> so that we unconditionally compile trace.c is also wrong. We should
> probable use CONFIG_TRACING instead of CONFIG_FTRACE. Can you check if
> that works for you?
> 
> 
> Thanks,
> 
> -- 
> heikki

You are right, building a defconfig, enable the UCSI driver and disable
CONFIG_FTRACE indeed builds without problems. So it must be some other
combination of config options. Attached is the randconfig which triggers
the problem with linux-next from today.

Regardless of the root cause, building trace.c conditionally on
CONFIG_TRACING works and the build failure goes away. Grepping through
the tree this seems to be the right option to depend on, as other users
of tracepoints are doing the same.

--
Tobias

#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 4.16.0 Kernel Configuration
#
# CONFIG_64BIT is not set
CONFIG_X86_32=y
CONFIG_X86=y
CONFIG_INSTRUCTION_DECODER=y
CONFIG_OUTPUT_FORMAT="elf32-i386"
CONFIG_ARCH_DEFCONFIG="arch/x86/configs/i386_defconfig"
CONFIG_LOCKDEP_SUPPORT=y
CONFIG_STACKTRACE_SUPPORT=y
CONFIG_MMU=y
CONFIG_ARCH_MMAP_RND_BITS_MIN=8
CONFIG_ARCH_MMAP_RND_BITS_MAX=16
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN=8
CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX=16
CONFIG_NEED_DMA_MAP_STATE=y
CONFIG_NEED_SG_DMA_LENGTH=y
CONFIG_GENERIC_ISA_DMA=y
CONFIG_GENERIC_BUG=y
CONFIG_GENERIC_HWEIGHT=y
CONFIG_ARCH_MAY_HAVE_PC_FDC=y
CONFIG_RWSEM_XCHGADD_ALGORITHM=y
CONFIG_GENERIC_CALIBRATE_DELAY=y
CONFIG_ARCH_HAS_CPU_RELAX=y
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
CONFIG_HAVE_SETUP_PER_CPU_AREA=y
CONFIG_NEED_PER_CPU_EMBED_FIRST_CHUNK=y
CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK=y
CONFIG_ARCH_HIBERNATION_POSSIBLE=y
CONFIG_ARCH_SUSPEND_POSSIBLE=y
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
CONFIG_ARCH_WANT_GENERAL_HUGETLB=y
CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING=y
CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC=y
CONFIG_ARCH_SUPPORTS_UPROBES=y
CONFIG_FIX_EARLYCON_MEM=y
CONFIG_PGTABLE_LEVELS=2
CONFIG_IRQ_WORK=y
CONFIG_BUILDTIME_EXTABLE_SORT=y
CONFIG_THREAD_INFO_IN_TASK=y

#
# General setup
#
CONFIG_BROKEN_ON_SMP=y
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE=""
# CONFIG_COMPILE_TEST is not set
CONFIG_LOCALVERSION=""
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_HAVE_KERNEL_GZIP=y
CONFIG_HAVE_KERNEL_BZIP2=y
CONFIG_HAVE_KERNEL_LZMA=y
CONFIG_HAVE_KERNEL_XZ=y
CONFIG_HAVE_KERNEL_LZO=y
CONFIG_HAVE_KERNEL_LZ4=y
# CONFIG_KERNEL_GZIP is not set
# CONFIG_KERNEL_BZIP2 is not set
# CONFIG_KERNEL_LZMA is not set
# CONFIG_KERNEL_XZ is not set
CONFIG_KERNEL_LZO=y
# CONFIG_KERNEL_LZ4 is not

Re: [PATCH 1/4] usb: gadget: udc: renesas_usb3: fix double phy_put()

2018-04-09 Thread Simon Horman
On Mon, Apr 02, 2018 at 09:21:31PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that this driver cause double phy_put()
> calling. This driver must not call phy_put() in the remove because
> the driver calls devm_phy_get() in the probe.
> 
> Fixes: 279d4bc64060 ("usb: gadget: udc: renesas_usb3: add support for generic 
> phy")
> Cc:  # v4.15+
> Signed-off-by: Yoshihiro Shimoda 

Reviewed-by: Simon Horman 

--
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


[RFT/PATCH 21/38] usb: dwc3: gadget: simplify isoc case on cleanup_completed_requests

2018-04-09 Thread Felipe Balbi
Just a minor simplification, no functional changes.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 1c15b87c2d84..fea515e4efec 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2316,16 +2316,9 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
return;
 
if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
-   list_empty(&dep->started_list)) {
-   if (list_empty(&dep->pending_list)) {
-   /*
-* If there is no entry in request list then do
-* not issue END TRANSFER now. Just set PENDING
-* flag, so that END TRANSFER is issued when an
-* entry is added into request list.
-*/
-   dep->flags = DWC3_EP_PENDING_REQUEST;
-   }
+   list_empty(&dep->started_list) &&
+   list_empty(&dep->pending_list)) {
+   dep->flags = DWC3_EP_PENDING_REQUEST;
}
 }
 
-- 
2.16.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


[RFT/PATCH 29/38] usb: dwc3: gadget: add a helper to test if a request is completed

2018-04-09 Thread Felipe Balbi
This will allow us to remove an unnecessary variable

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index f0fd655c4fac..763304194ca4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2278,6 +2278,11 @@ static int dwc3_gadget_ep_reclaim_trb_linear(struct 
dwc3_ep *dep,
event, status, false);
 }
 
+static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req)
+{
+   return req->request.actual == req->request.length;
+}
+
 static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
@@ -2304,7 +2309,8 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
req->request.actual = length - req->remaining;
 
-   if ((req->request.actual < length) && req->num_pending_sgs) {
+   if (!dwc3_gadget_ep_request_completed(req) &&
+   req->num_pending_sgs) {
__dwc3_gadget_kick_transfer(dep);
break;
}
-- 
2.16.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


[RFT/PATCH 30/38] usb: dwc3: gadget: one declaration per line

2018-04-09 Thread Felipe Balbi
Misc cleanup. No functional changes.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 763304194ca4..99962de67715 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2286,10 +2286,11 @@ static bool dwc3_gadget_ep_request_completed(struct 
dwc3_request *req)
 static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
-   struct dwc3_request *req, *n;
+   struct dwc3_request *req;
+   struct dwc3_request *tmp;
int ret = 0;
 
-   list_for_each_entry_safe(req, n, &dep->started_list, list) {
+   list_for_each_entry_safe(req, tmp, &dep->started_list, list) {
unsigned length;
 
length = req->request.length;
-- 
2.16.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


[RFT/PATCH 27/38] usb: dwc3: gadget: simplify short packet event

2018-04-09 Thread Felipe Balbi
We know that only OUT endpoints can trigger SHORT. We also know that
count MUST be > 0 whenever SHORT triggers.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 8 +---
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c43d1d4b7bb5..c3dd569786db 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2196,7 +2196,6 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status, int chain)
 {
unsigned intcount;
-   unsigned ints_pkt = 0;
 
dwc3_ep_inc_deq(dep);
 
@@ -2231,12 +2230,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
return 1;
 
-   if (!dep->direction) {
-   if (count && (event->status & DEPEVT_STATUS_SHORT))
-   s_pkt = 1;
-   }
-
-   if (s_pkt && !chain)
+   if (event->status & DEPEVT_STATUS_SHORT && !chain)
return 1;
 
if ((event->status & DEPEVT_STATUS_IOC) &&
-- 
2.16.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


[RFT/PATCH 19/38] usb: dwc3: gadget: remove duplicated missed isoc handling

2018-04-09 Thread Felipe Balbi
Now, this part of the code is duplicated and brings no extra value to
the driver. Let's remove it.

Signed-off-by: Felipe Balbi 
---
 Documentation/driver-api/usb/dwc3.rst |  1 -
 drivers/usb/dwc3/core.h   |  1 -
 drivers/usb/dwc3/gadget.c | 34 ++
 drivers/usb/dwc3/trace.h  |  3 +--
 4 files changed, 3 insertions(+), 36 deletions(-)

diff --git a/Documentation/driver-api/usb/dwc3.rst 
b/Documentation/driver-api/usb/dwc3.rst
index 33f65d263087..8b36ff11cef9 100644
--- a/Documentation/driver-api/usb/dwc3.rst
+++ b/Documentation/driver-api/usb/dwc3.rst
@@ -676,7 +676,6 @@ operations, both of which can be traced. Format is::
__entry->flags & DWC3_EP_WEDGE ? 'W' : 'w',
__entry->flags & DWC3_EP_TRANSFER_STARTED ? 'B' : 'b',
__entry->flags & DWC3_EP_PENDING_REQUEST ? 'P' : 'p',
-   __entry->flags & DWC3_EP_MISSED_ISOC ? 'M' : 'm',
__entry->flags & DWC3_EP_END_TRANSFER_PENDING ? 'E' : 'e',
__entry->direction ? '<' : '>'
   )
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 8862118c3b79..b0ab6128beae 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -664,7 +664,6 @@ struct dwc3_ep {
 #define DWC3_EP_WEDGE  BIT(2)
 #define DWC3_EP_TRANSFER_STARTED BIT(3)
 #define DWC3_EP_PENDING_REQUESTBIT(5)
-#define DWC3_EP_MISSED_ISOCBIT(6)
 #define DWC3_EP_END_TRANSFER_PENDING   BIT(7)
 
/* This last one is specific to EP0 */
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ed44b85e59dc..db4c93ddb72b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1308,8 +1308,7 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
return 0;
}
 
-   if ((dep->flags & DWC3_EP_TRANSFER_STARTED) &&
-   !(dep->flags & DWC3_EP_MISSED_ISOC))
+   if (dep->flags & DWC3_EP_TRANSFER_STARTED)
goto out;
 
return 0;
@@ -2204,7 +2203,6 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
 {
unsigned intcount;
unsigned ints_pkt = 0;
-   unsigned inttrb_status;
 
dwc3_ep_inc_deq(dep);
 
@@ -2239,35 +2237,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
if ((trb->ctrl & DWC3_TRB_CTRL_HWO) && status != -ESHUTDOWN)
return 1;
 
-   if (dep->direction) {
-   if (count) {
-   trb_status = DWC3_TRB_SIZE_TRBSTS(trb->size);
-   if (trb_status == DWC3_TRBSTS_MISSED_ISOC) {
-   /*
-* If missed isoc occurred and there is
-* no request queued then issue END
-* TRANSFER, so that core generates
-* next xfernotready and we will issue
-* a fresh START TRANSFER.
-* If there are still queued request
-* then wait, do not issue either END
-* or UPDATE TRANSFER, just attach next
-* request in pending_list during
-* giveback.If any future queued request
-* is successfully transferred then we
-* will issue UPDATE TRANSFER for all
-* request in the pending_list.
-*/
-   dep->flags |= DWC3_EP_MISSED_ISOC;
-   } else {
-   dev_err(dep->dwc->dev, "incomplete IN transfer 
%s\n",
-   dep->name);
-   status = -ECONNRESET;
-   }
-   } else {
-   dep->flags &= ~DWC3_EP_MISSED_ISOC;
-   }
-   } else {
+   if (!dep->direction) {
if (count && (event->status & DEPEVT_STATUS_SHORT))
s_pkt = 1;
}
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index f91461bc53fe..f22714cce070 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -303,7 +303,7 @@ DECLARE_EVENT_CLASS(dwc3_log_ep,
__entry->trb_enqueue = dep->trb_enqueue;
__entry->trb_dequeue = dep->trb_dequeue;
),
-   TP_printk("%s: mps %d/%d streams %d burst %d ring %d/%d flags 
%c:%c%c%c%c%c:%c:%c",
+   TP_printk("%s: mps %d/%d streams %d burst %d ring %d/%d flags 
%c:%c%c%c%c:%c:%c",
__get_str(name), __entry->maxpacket,
__entry->maxpacket_limit, __entry->max_streams,
__entry->maxburst, __entry->trb_enqueue,
@@ -313,7 +313,6 @@ DEC

[RFT/PATCH 31/38] usb: dwc3: gadget: reduce scope of ret variable

2018-04-09 Thread Felipe Balbi
We can declare it inside list_for_each_entry_safe() loop and reduce
its scope.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 99962de67715..3a4013bc61d8 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2288,10 +2288,10 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 {
struct dwc3_request *req;
struct dwc3_request *tmp;
-   int ret = 0;
 
list_for_each_entry_safe(req, tmp, &dep->started_list, list) {
unsigned length;
+   int ret;
 
length = req->request.length;
if (req->num_pending_sgs)
-- 
2.16.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


[RFT/PATCH 24/38] usb: dwc3: gadget: remove unnecessary 'chain' variable

2018-04-09 Thread Felipe Balbi
Minor cleanup, no functional changes.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index e4bd902a1e76..63e74a8964d7 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2294,11 +2294,9 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
list_for_each_entry_safe(req, n, &dep->started_list, list) {
unsigned length;
-   int chain;
 
length = req->request.length;
-   chain = req->num_pending_sgs > 0;
-   if (chain)
+   if (req->num_pending_sgs)
ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
status);
else
-- 
2.16.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


[RFT/PATCH 14/38] usb: dwc3: gadget: start removing BUSY flag

2018-04-09 Thread Felipe Balbi
By now, it has the same semantics as DWC3_EP_TRANSFER_STARTED, but
that has a much more descriptive name.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index e982cdec8a5d..0c6db0de3fd1 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1196,7 +1196,7 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep 
*dep)
if (!dwc3_calc_trbs_left(dep))
return 0;
 
-   starting = !(dep->flags & DWC3_EP_BUSY);
+   starting = !(dep->flags & DWC3_EP_TRANSFER_STARTED);
 
dwc3_prepare_trbs(dep);
req = next_request(&dep->started_list);
@@ -1312,7 +1312,7 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
return 0;
}
 
-   if ((dep->flags & DWC3_EP_BUSY) &&
+   if ((dep->flags & DWC3_EP_TRANSFER_STARTED) &&
!(dep->flags & DWC3_EP_MISSED_ISOC))
goto out;
 
-- 
2.16.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


[RFT/PATCH 32/38] usb: dwc3: gadget: get rid of the length variable

2018-04-09 Thread Felipe Balbi
Code is just as readable without it.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3a4013bc61d8..c515104ba86d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2290,10 +2290,8 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
struct dwc3_request *tmp;
 
list_for_each_entry_safe(req, tmp, &dep->started_list, list) {
-   unsigned length;
int ret;
 
-   length = req->request.length;
if (req->num_pending_sgs)
ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
status);
@@ -2308,7 +2306,7 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
req->zero = false;
}
 
-   req->request.actual = length - req->remaining;
+   req->request.actual = req->request.length - req->remaining;
 
if (!dwc3_gadget_ep_request_completed(req) &&
req->num_pending_sgs) {
-- 
2.16.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


[RFT/PATCH 33/38] usb: dwc3: gadget: split dwc3_gadget_ep_cleanup_completed_requests()

2018-04-09 Thread Felipe Balbi
No functional changes, it just makes the code slightly easier to read.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c515104ba86d..79d0e48c612b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2283,6 +2283,40 @@ static bool dwc3_gadget_ep_request_completed(struct 
dwc3_request *req)
return req->request.actual == req->request.length;
 }
 
+static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
+   const struct dwc3_event_depevt *event,
+   struct dwc3_request *req, int status)
+{
+   int ret;
+
+   if (req->num_pending_sgs)
+   ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
+   status);
+   else
+   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
+   status);
+
+   if (req->unaligned || req->zero) {
+   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
+   status);
+   req->unaligned = false;
+   req->zero = false;
+   }
+
+   req->request.actual = req->request.length - req->remaining;
+
+   if (!dwc3_gadget_ep_request_completed(req) &&
+   req->num_pending_sgs) {
+   __dwc3_gadget_kick_transfer(dep);
+   goto out;
+   }
+
+   dwc3_gadget_giveback(dep, req, status);
+
+out:
+   return ret;
+}
+
 static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
@@ -2292,30 +2326,8 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
list_for_each_entry_safe(req, tmp, &dep->started_list, list) {
int ret;
 
-   if (req->num_pending_sgs)
-   ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
-   status);
-   else
-   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
-   status);
-
-   if (req->unaligned || req->zero) {
-   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
-   status);
-   req->unaligned = false;
-   req->zero = false;
-   }
-
-   req->request.actual = req->request.length - req->remaining;
-
-   if (!dwc3_gadget_ep_request_completed(req) &&
-   req->num_pending_sgs) {
-   __dwc3_gadget_kick_transfer(dep);
-   break;
-   }
-
-   dwc3_gadget_giveback(dep, req, status);
-
+   ret = dwc3_gadget_ep_cleanup_completed_request(dep, event,
+   req, status);
if (ret)
break;
}
-- 
2.16.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


[RFT/PATCH 25/38] usb: dwc3: gadget: simplify unaligned and zlp handling

2018-04-09 Thread Felipe Balbi
We can just call reclaim_trb_linear instead of reimplementing it.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 63e74a8964d7..c43d1d4b7bb5 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2289,7 +2289,6 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
struct dwc3_request *req, *n;
-   struct dwc3_trb *trb;
int ret = 0;
 
list_for_each_entry_safe(req, n, &dep->started_list, list) {
@@ -2304,9 +2303,8 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
status);
 
if (req->unaligned || req->zero) {
-   trb = &dep->trb_pool[dep->trb_dequeue];
-   ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
-   trb, event, status, false);
+   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
+   status);
req->unaligned = false;
req->zero = false;
}
-- 
2.16.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


[RFT/PATCH 34/38] usb: dwc3: gadget: refactor dwc3_gadget_init_endpoints()

2018-04-09 Thread Felipe Balbi
This just makes it slightly easier to read. No functional changes.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 79d0e48c612b..0cf0cd35cb4d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2050,113 +2050,142 @@ static const struct usb_gadget_ops dwc3_gadget_ops = {
 
 /* -- 
*/
 
-static int dwc3_gadget_init_endpoints(struct dwc3 *dwc, u8 total)
+static int dwc3_gadget_init_control_endpoint(struct dwc3_ep *dep)
 {
-   struct dwc3_ep  *dep;
-   u8  epnum;
+   struct dwc3 *dwc = dep->dwc;
 
-   INIT_LIST_HEAD(&dwc->gadget.ep_list);
+   usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
+   dep->endpoint.maxburst = 1;
+   dep->endpoint.ops = &dwc3_gadget_ep0_ops;
+   if (!dep->direction)
+   dwc->gadget.ep0 = &dep->endpoint;
 
-   for (epnum = 0; epnum < total; epnum++) {
-   booldirection = epnum & 1;
-   u8  num = epnum >> 1;
+   dep->endpoint.caps.type_control = true;
 
-   dep = kzalloc(sizeof(*dep), GFP_KERNEL);
-   if (!dep)
-   return -ENOMEM;
+   return 0;
+}
 
-   dep->dwc = dwc;
-   dep->number = epnum;
-   dep->direction = direction;
-   dep->regs = dwc->regs + DWC3_DEP_BASE(epnum);
-   dwc->eps[epnum] = dep;
+static int dwc3_gadget_init_in_endpoint(struct dwc3_ep *dep)
+{
+   struct dwc3 *dwc = dep->dwc;
+   int mdwidth;
+   int kbytes;
+   int size;
 
-   snprintf(dep->name, sizeof(dep->name), "ep%u%s", num,
-   direction ? "in" : "out");
+   mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
+   /* MDWIDTH is represented in bits, we need it in bytes */
+   mdwidth /= 8;
 
-   dep->endpoint.name = dep->name;
+   size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(dep->number >> 1));
+   if (dwc3_is_usb31(dwc))
+   size = DWC31_GTXFIFOSIZ_TXFDEF(size);
+   else
+   size = DWC3_GTXFIFOSIZ_TXFDEF(size);
 
-   if (!(dep->number > 1)) {
-   dep->endpoint.desc = &dwc3_gadget_ep0_desc;
-   dep->endpoint.comp_desc = NULL;
-   }
+   /* FIFO Depth is in MDWDITH bytes. Multiply */
+   size *= mdwidth;
 
-   spin_lock_init(&dep->lock);
-
-   if (num == 0) {
-   usb_ep_set_maxpacket_limit(&dep->endpoint, 512);
-   dep->endpoint.maxburst = 1;
-   dep->endpoint.ops = &dwc3_gadget_ep0_ops;
-   if (!direction)
-   dwc->gadget.ep0 = &dep->endpoint;
-   } else if (direction) {
-   int mdwidth;
-   int kbytes;
-   int size;
-   int ret;
-
-   mdwidth = DWC3_MDWIDTH(dwc->hwparams.hwparams0);
-   /* MDWIDTH is represented in bits, we need it in bytes 
*/
-   mdwidth /= 8;
-
-   size = dwc3_readl(dwc->regs, DWC3_GTXFIFOSIZ(num));
-   if (dwc3_is_usb31(dwc))
-   size = DWC31_GTXFIFOSIZ_TXFDEF(size);
-   else
-   size = DWC3_GTXFIFOSIZ_TXFDEF(size);
+   kbytes = size / 1024;
+   if (kbytes == 0)
+   kbytes = 1;
 
-   /* FIFO Depth is in MDWDITH bytes. Multiply */
-   size *= mdwidth;
+   /*
+* FIFO sizes account an extra MDWIDTH * (kbytes + 1) bytes for
+* internal overhead. We don't really know how these are used,
+* but documentation say it exists.
+*/
+   size -= mdwidth * (kbytes + 1);
+   size /= kbytes;
 
-   kbytes = size / 1024;
-   if (kbytes == 0)
-   kbytes = 1;
+   usb_ep_set_maxpacket_limit(&dep->endpoint, size);
 
-   /*
-* FIFO sizes account an extra MDWIDTH * (kbytes + 1) 
bytes for
-* internal overhead. We don't really know how these 
are used,
-* but documentation say it exists.
-*/
-   size -= mdwidth * (kbytes + 1);
-   size /= kbytes;
+   dep->endpoint.max_streams = 15;
+   dep->endpoint.ops = &dwc3_gadget_ep_ops;
+   list_add_tail(&dep->endpoint.ep_list,
+   &dwc->gadget.ep_list);
+   dep->endpoint.caps.type_iso = true;
+  

[RFT/PATCH 15/38] usb: dwc3: gadget: remove DWC3_EP_BUSY flag

2018-04-09 Thread Felipe Balbi
It has no use anymore.

Signed-off-by: Felipe Balbi 
---
 Documentation/driver-api/usb/dwc3.rst |  2 +-
 drivers/usb/dwc3/core.h   |  3 +--
 drivers/usb/dwc3/ep0.c|  5 ++---
 drivers/usb/dwc3/gadget.c | 14 ++
 drivers/usb/dwc3/trace.h  |  2 +-
 5 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/Documentation/driver-api/usb/dwc3.rst 
b/Documentation/driver-api/usb/dwc3.rst
index c3dc84a50ce5..33f65d263087 100644
--- a/Documentation/driver-api/usb/dwc3.rst
+++ b/Documentation/driver-api/usb/dwc3.rst
@@ -674,7 +674,7 @@ operations, both of which can be traced. Format is::
__entry->flags & DWC3_EP_ENABLED ? 'E' : 'e',
__entry->flags & DWC3_EP_STALL ? 'S' : 's',
__entry->flags & DWC3_EP_WEDGE ? 'W' : 'w',
-   __entry->flags & DWC3_EP_BUSY ? 'B' : 'b',
+   __entry->flags & DWC3_EP_TRANSFER_STARTED ? 'B' : 'b',
__entry->flags & DWC3_EP_PENDING_REQUEST ? 'P' : 'p',
__entry->flags & DWC3_EP_MISSED_ISOC ? 'M' : 'm',
__entry->flags & DWC3_EP_END_TRANSFER_PENDING ? 'E' : 'e',
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 2baa6caeffa6..5ee895113906 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -662,11 +662,10 @@ struct dwc3_ep {
 #define DWC3_EP_ENABLEDBIT(0)
 #define DWC3_EP_STALL  BIT(1)
 #define DWC3_EP_WEDGE  BIT(2)
-#define DWC3_EP_BUSY   BIT(4)
+#define DWC3_EP_TRANSFER_STARTED BIT(3)
 #define DWC3_EP_PENDING_REQUESTBIT(5)
 #define DWC3_EP_MISSED_ISOCBIT(6)
 #define DWC3_EP_END_TRANSFER_PENDING   BIT(7)
-#define DWC3_EP_TRANSFER_STARTED BIT(8)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_INBIT(31)
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 5a991bca8ed7..826fee2bc8cc 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -66,7 +66,7 @@ static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
struct dwc3 *dwc;
int ret;
 
-   if (dep->flags & DWC3_EP_BUSY)
+   if (dep->flags & DWC3_EP_TRANSFER_STARTED)
return 0;
 
dwc = dep->dwc;
@@ -79,7 +79,6 @@ static int dwc3_ep0_start_trans(struct dwc3_ep *dep)
if (ret < 0)
return ret;
 
-   dep->flags |= DWC3_EP_BUSY;
dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
dwc->ep0_next_event = DWC3_EP0_COMPLETE;
 
@@ -913,7 +912,7 @@ static void dwc3_ep0_xfer_complete(struct dwc3 *dwc,
 {
struct dwc3_ep  *dep = dwc->eps[event->endpoint_number];
 
-   dep->flags &= ~DWC3_EP_BUSY;
+   dep->flags &= ~DWC3_EP_TRANSFER_STARTED;
dep->resource_index = 0;
dwc->setup_packet_pending = false;
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0c6db0de3fd1..83f386bd65e0 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -691,8 +691,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
if (ret < 0)
return ret;
 
-   dep->flags |= DWC3_EP_BUSY;
-
dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
WARN_ON_ONCE(!dep->resource_index);
}
@@ -1232,8 +1230,6 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep 
*dep)
return ret;
}
 
-   dep->flags |= DWC3_EP_BUSY;
-
if (starting) {
dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
WARN_ON_ONCE(!dep->resource_index);
@@ -2353,7 +2349,7 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
/*
 * Our endpoint might get disabled by another thread during
 * dwc3_gadget_giveback(). If that happens, we're just gonna return 1
-* early on so DWC3_EP_BUSY flag gets cleared
+* early.
 */
if (!dep->endpoint.desc)
return 1;
@@ -2396,18 +2392,13 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
 {
struct dwc3 *dwc = dep->dwc;
unsignedstatus = 0;
-   int clean_busy;
 
dwc3_gadget_endpoint_frame_from_event(dep, event);
 
if (event->status & DEPEVT_STATUS_BUSERR)
status = -ECONNRESET;
 
-   clean_busy = dwc3_gadget_ep_cleanup_completed_requests(dep, event,
-   status);
-   if (clean_busy && (!dep->endpoint.desc ||
-   usb_endpoint_xfer_isoc(dep->endpoint.desc)))
-   dep->flags &= ~DWC3_EP_BUSY;
+   dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
 
/*
 * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.
@@ -2576,7 +2567,6 @@ static void dwc3_stop_active_transfer(struct dwc3_ep 
*dep, bool force)
ret = dw

[RFT/PATCH 28/38] usb: dwc3: gadget: simplify IOC handling

2018-04-09 Thread Felipe Balbi
We will only have event status of IOC when IOC bit is set in
TRB. There's no need to check both bits.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c3dd569786db..f0fd655c4fac 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2233,8 +2233,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
if (event->status & DEPEVT_STATUS_SHORT && !chain)
return 1;
 
-   if ((event->status & DEPEVT_STATUS_IOC) &&
-   (trb->ctrl & DWC3_TRB_CTRL_IOC))
+   if (event->status & DEPEVT_STATUS_IOC)
return 1;
 
return 0;
-- 
2.16.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


[RFT/PATCH 26/38] usb: dwc3: trace: print out event status too

2018-04-09 Thread Felipe Balbi
This will make it easier to figure out the reason for the event. That
information really helps debugging certain problems.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debug.h | 20 
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index bfb90c52d8fc..0be6a554be57 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -475,21 +475,33 @@ dwc3_ep_event_string(char *str, const struct 
dwc3_event_depevt *event,
if (ret < 0)
return "UNKNOWN";
 
+   status = event->status;
+
switch (event->endpoint_event) {
case DWC3_DEPEVT_XFERCOMPLETE:
-   strcat(str, "Transfer Complete");
+   len = strlen(str);
+   sprintf(str + len, "Transfer Complete (%c%c%c)",
+   status & DEPEVT_STATUS_SHORT ? 'S' : 's',
+   status & DEPEVT_STATUS_IOC ? 'I' : 'i',
+   status & DEPEVT_STATUS_LST ? 'L' : 'l');
+
len = strlen(str);
 
if (epnum <= 1)
sprintf(str + len, " [%s]", 
dwc3_ep0_state_string(ep0state));
break;
case DWC3_DEPEVT_XFERINPROGRESS:
-   strcat(str, "Transfer In-Progress");
+   len = strlen(str);
+
+   sprintf(str + len, "Transfer In Progress (%c%c%c)",
+   status & DEPEVT_STATUS_SHORT ? 'S' : 's',
+   status & DEPEVT_STATUS_IOC ? 'I' : 'i',
+   status & DEPEVT_STATUS_LST ? 'M' : 'm');
break;
case DWC3_DEPEVT_XFERNOTREADY:
strcat(str, "Transfer Not Ready");
-   status = event->status & DEPEVT_STATUS_TRANSFER_ACTIVE;
-   strcat(str, status ? " (Active)" : " (Not Active)");
+   strcat(str, status & DEPEVT_STATUS_TRANSFER_ACTIVE ?
+   " (Active)" : " (Not Active)");
 
/* Control Endpoints */
if (epnum <= 1) {
-- 
2.16.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


[RFT/PATCH 35/38] usb: dwc3: gadget: combine modify & restore into single argument

2018-04-09 Thread Felipe Balbi
Those two arguments refer to a single bitfield in the register. In
order to simplify the code, we can combine them into a single argument
and expect caller to pass the correct action argument at all times.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0cf0cd35cb4d..fc68390a02e4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -523,16 +523,12 @@ static int dwc3_gadget_start_config(struct dwc3 *dwc, 
struct dwc3_ep *dep)
 }
 
 static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
-   bool modify, bool restore)
+   unsigned int action)
 {
const struct usb_ss_ep_comp_descriptor *comp_desc;
const struct usb_endpoint_descriptor *desc;
struct dwc3_gadget_ep_cmd_params params;
 
-   if (dev_WARN_ONCE(dwc->dev, modify && restore,
-   "Can't modify and restore\n"))
-   return -EINVAL;
-
comp_desc = dep->endpoint.comp_desc;
desc = dep->endpoint.desc;
 
@@ -547,14 +543,9 @@ static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, 
struct dwc3_ep *dep,
params.param0 |= DWC3_DEPCFG_BURST_SIZE(burst - 1);
}
 
-   if (modify) {
-   params.param0 |= DWC3_DEPCFG_ACTION_MODIFY;
-   } else if (restore) {
-   params.param0 |= DWC3_DEPCFG_ACTION_RESTORE;
+   params.param0 |= action;
+   if (action == DWC3_DEPCFG_ACTION_RESTORE)
params.param2 |= dep->saved_state;
-   } else {
-   params.param0 |= DWC3_DEPCFG_ACTION_INIT;
-   }
 
if (usb_endpoint_xfer_control(desc))
params.param1 = DWC3_DEPCFG_XFER_COMPLETE_EN;
@@ -615,8 +606,7 @@ static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, 
struct dwc3_ep *dep)
  * Caller should take care of locking. Execute all necessary commands to
  * initialize a HW endpoint so it can be used by a gadget driver.
  */
-static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
-   bool modify, bool restore)
+static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, unsigned int action)
 {
const struct usb_endpoint_descriptor *desc = dep->endpoint.desc;
struct dwc3 *dwc = dep->dwc;
@@ -630,7 +620,7 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
return ret;
}
 
-   ret = dwc3_gadget_set_ep_config(dwc, dep, modify, restore);
+   ret = dwc3_gadget_set_ep_config(dwc, dep, action);
if (ret)
return ret;
 
@@ -804,7 +794,7 @@ static int dwc3_gadget_ep_enable(struct usb_ep *ep,
return 0;
 
spin_lock_irqsave(&dwc->lock, flags);
-   ret = __dwc3_gadget_ep_enable(dep, false, false);
+   ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT);
spin_unlock_irqrestore(&dwc->lock, flags);
 
return ret;
@@ -1846,14 +1836,14 @@ static int __dwc3_gadget_start(struct dwc3 *dwc)
dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
 
dep = dwc->eps[0];
-   ret = __dwc3_gadget_ep_enable(dep, false, false);
+   ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT);
if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name);
goto err0;
}
 
dep = dwc->eps[1];
-   ret = __dwc3_gadget_ep_enable(dep, false, false);
+   ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_INIT);
if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name);
goto err1;
@@ -2764,14 +2754,14 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 
*dwc)
}
 
dep = dwc->eps[0];
-   ret = __dwc3_gadget_ep_enable(dep, true, false);
+   ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_MODIFY);
if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name);
return;
}
 
dep = dwc->eps[1];
-   ret = __dwc3_gadget_ep_enable(dep, true, false);
+   ret = __dwc3_gadget_ep_enable(dep, DWC3_DEPCFG_ACTION_MODIFY);
if (ret) {
dev_err(dwc->dev, "failed to enable %s\n", dep->name);
return;
-- 
2.16.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


[RFT/PATCH 20/38] usb: dwc3: gadget: simplify queueing of isoc transfers

2018-04-09 Thread Felipe Balbi
After all the previous changes, it's now a lot clearer how isoc
transfers should be managed. We don't need to try to End Transfers
from ep_queue since that's already done by cleanup_requests.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index db4c93ddb72b..1c15b87c2d84 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1297,24 +1297,18 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
 * errors which will force us issue EndTransfer command.
 */
if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+   if (!(dep->flags & DWC3_EP_PENDING_REQUEST) &&
+   !(dep->flags & DWC3_EP_TRANSFER_STARTED))
+   return 0;
+
if ((dep->flags & DWC3_EP_PENDING_REQUEST)) {
-   if (dep->flags & DWC3_EP_TRANSFER_STARTED) {
-   dwc3_stop_active_transfer(dep, true);
-   dep->flags = DWC3_EP_ENABLED;
-   } else {
+   if (!(dep->flags & DWC3_EP_TRANSFER_STARTED)) {
__dwc3_gadget_start_isoc(dep);
-   dep->flags &= ~DWC3_EP_PENDING_REQUEST;
+   return 0;
}
-   return 0;
}
-
-   if (dep->flags & DWC3_EP_TRANSFER_STARTED)
-   goto out;
-
-   return 0;
}
 
-out:
return __dwc3_gadget_kick_transfer(dep);
 }
 
-- 
2.16.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


[RFT/PATCH 36/38] usb: dwc3: gadget: remove a few more dwc arguments

2018-04-09 Thread Felipe Balbi
In a few places, the argument is completely unnecessary. On places
where it's needed, we can get it from dep->dwc.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index fc68390a02e4..cc7f05603d15 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -455,7 +455,7 @@ static void dwc3_free_trb_pool(struct dwc3_ep *dep)
dep->trb_pool_dma = 0;
 }
 
-static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep 
*dep);
+static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep);
 
 /**
  * dwc3_gadget_start_config - configure ep resources
@@ -491,9 +491,10 @@ static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, 
struct dwc3_ep *dep);
  * triggered only when called for EP0-out, which always happens first, and 
which
  * should only happen in one of the above conditions.
  */
-static int dwc3_gadget_start_config(struct dwc3 *dwc, struct dwc3_ep *dep)
+static int dwc3_gadget_start_config(struct dwc3_ep *dep)
 {
struct dwc3_gadget_ep_cmd_params params;
+   struct dwc3 *dwc;
u32 cmd;
int i;
int ret;
@@ -503,6 +504,7 @@ static int dwc3_gadget_start_config(struct dwc3 *dwc, 
struct dwc3_ep *dep)
 
memset(¶ms, 0x00, sizeof(params));
cmd = DWC3_DEPCMD_DEPSTARTCFG;
+   dwc = dep->dwc;
 
ret = dwc3_send_gadget_ep_cmd(dep, cmd, ¶ms);
if (ret)
@@ -514,7 +516,7 @@ static int dwc3_gadget_start_config(struct dwc3 *dwc, 
struct dwc3_ep *dep)
if (!dep)
continue;
 
-   ret = dwc3_gadget_set_xfer_resource(dwc, dep);
+   ret = dwc3_gadget_set_xfer_resource(dep);
if (ret)
return ret;
}
@@ -522,12 +524,12 @@ static int dwc3_gadget_start_config(struct dwc3 *dwc, 
struct dwc3_ep *dep)
return 0;
 }
 
-static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, struct dwc3_ep *dep,
-   unsigned int action)
+static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, unsigned int action)
 {
const struct usb_ss_ep_comp_descriptor *comp_desc;
const struct usb_endpoint_descriptor *desc;
struct dwc3_gadget_ep_cmd_params params;
+   struct dwc3 *dwc = dep->dwc;
 
comp_desc = dep->endpoint.comp_desc;
desc = dep->endpoint.desc;
@@ -585,7 +587,7 @@ static int dwc3_gadget_set_ep_config(struct dwc3 *dwc, 
struct dwc3_ep *dep,
return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, ¶ms);
 }
 
-static int dwc3_gadget_set_xfer_resource(struct dwc3 *dwc, struct dwc3_ep *dep)
+static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep)
 {
struct dwc3_gadget_ep_cmd_params params;
 
@@ -615,12 +617,12 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep, 
unsigned int action)
int ret;
 
if (!(dep->flags & DWC3_EP_ENABLED)) {
-   ret = dwc3_gadget_start_config(dwc, dep);
+   ret = dwc3_gadget_start_config(dep);
if (ret)
return ret;
}
 
-   ret = dwc3_gadget_set_ep_config(dwc, dep, action);
+   ret = dwc3_gadget_set_ep_config(dep, action);
if (ret)
return ret;
 
-- 
2.16.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


[RFT/PATCH 38/38] usb: dwc3: gadget: move dwc3_calc_trbs_left() in place of prototype

2018-04-09 Thread Felipe Balbi
Avoid a prototype when the function can be defined earlier. No
functional changes, cleanup only.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8c0e297bb833..c3809cf00288 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -854,7 +854,53 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
kfree(req);
 }
 
-static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep);
+/**
+ * dwc3_ep_prev_trb - returns the previous TRB in the ring
+ * @dep: The endpoint with the TRB ring
+ * @index: The index of the current TRB in the ring
+ *
+ * Returns the TRB prior to the one pointed to by the index. If the
+ * index is 0, we will wrap backwards, skip the link TRB, and return
+ * the one just before that.
+ */
+static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index)
+{
+   u8 tmp = index;
+
+   if (!tmp)
+   tmp = DWC3_TRB_NUM - 1;
+
+   return &dep->trb_pool[tmp - 1];
+}
+
+static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
+{
+   struct dwc3_trb *tmp;
+   u8  trbs_left;
+
+   /*
+* If enqueue & dequeue are equal than it is either full or empty.
+*
+* One way to know for sure is if the TRB right before us has HWO bit
+* set or not. If it has, then we're definitely full and can't fit any
+* more transfers in our ring.
+*/
+   if (dep->trb_enqueue == dep->trb_dequeue) {
+   tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue);
+   if (tmp->ctrl & DWC3_TRB_CTRL_HWO)
+   return 0;
+
+   return DWC3_TRB_NUM - 1;
+   }
+
+   trbs_left = dep->trb_dequeue - dep->trb_enqueue;
+   trbs_left &= (DWC3_TRB_NUM - 1);
+
+   if (dep->trb_dequeue < dep->trb_enqueue)
+   trbs_left--;
+
+   return trbs_left;
+}
 
 static void __dwc3_prepare_one_trb(struct dwc3_ep *dep, struct dwc3_trb *trb,
dma_addr_t dma, unsigned length, unsigned chain, unsigned node,
@@ -987,54 +1033,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
stream_id, short_not_ok, no_interrupt);
 }
 
-/**
- * dwc3_ep_prev_trb - returns the previous TRB in the ring
- * @dep: The endpoint with the TRB ring
- * @index: The index of the current TRB in the ring
- *
- * Returns the TRB prior to the one pointed to by the index. If the
- * index is 0, we will wrap backwards, skip the link TRB, and return
- * the one just before that.
- */
-static struct dwc3_trb *dwc3_ep_prev_trb(struct dwc3_ep *dep, u8 index)
-{
-   u8 tmp = index;
-
-   if (!tmp)
-   tmp = DWC3_TRB_NUM - 1;
-
-   return &dep->trb_pool[tmp - 1];
-}
-
-static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
-{
-   struct dwc3_trb *tmp;
-   u8  trbs_left;
-
-   /*
-* If enqueue & dequeue are equal than it is either full or empty.
-*
-* One way to know for sure is if the TRB right before us has HWO bit
-* set or not. If it has, then we're definitely full and can't fit any
-* more transfers in our ring.
-*/
-   if (dep->trb_enqueue == dep->trb_dequeue) {
-   tmp = dwc3_ep_prev_trb(dep, dep->trb_enqueue);
-   if (tmp->ctrl & DWC3_TRB_CTRL_HWO)
-   return 0;
-
-   return DWC3_TRB_NUM - 1;
-   }
-
-   trbs_left = dep->trb_dequeue - dep->trb_enqueue;
-   trbs_left &= (DWC3_TRB_NUM - 1);
-
-   if (dep->trb_dequeue < dep->trb_enqueue)
-   trbs_left--;
-
-   return trbs_left;
-}
-
 static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
struct dwc3_request *req)
 {
-- 
2.16.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


[RFT/PATCH 37/38] usb: dwc3: gadget: move set_xfer_resource() in place of prototype

2018-04-09 Thread Felipe Balbi
Instead of having a prototype for a function that's defined a few
lines down, let's just move definition to the place where prototype
was.

No functional changes, cleanup only.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index cc7f05603d15..8c0e297bb833 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -455,7 +455,17 @@ static void dwc3_free_trb_pool(struct dwc3_ep *dep)
dep->trb_pool_dma = 0;
 }
 
-static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep);
+static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep)
+{
+   struct dwc3_gadget_ep_cmd_params params;
+
+   memset(¶ms, 0x00, sizeof(params));
+
+   params.param0 = DWC3_DEPXFERCFG_NUM_XFER_RES(1);
+
+   return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE,
+   ¶ms);
+}
 
 /**
  * dwc3_gadget_start_config - configure ep resources
@@ -587,18 +597,6 @@ static int dwc3_gadget_set_ep_config(struct dwc3_ep *dep, 
unsigned int action)
return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETEPCONFIG, ¶ms);
 }
 
-static int dwc3_gadget_set_xfer_resource(struct dwc3_ep *dep)
-{
-   struct dwc3_gadget_ep_cmd_params params;
-
-   memset(¶ms, 0x00, sizeof(params));
-
-   params.param0 = DWC3_DEPXFERCFG_NUM_XFER_RES(1);
-
-   return dwc3_send_gadget_ep_cmd(dep, DWC3_DEPCMD_SETTRANSFRESOURCE,
-   ¶ms);
-}
-
 /**
  * __dwc3_gadget_ep_enable - initializes a hw endpoint
  * @dep: endpoint to be initialized
-- 
2.16.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


[RFT/PATCH 23/38] usb: dwc3: gadget: remove PENDING handling from cleanup_completed

2018-04-09 Thread Felipe Balbi
We are trying to kick transfers on Isochronous endpoints in a more
controlled manner now. And this ended up rendering this piece of code
unnecessary.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 16 +---
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 040c4fea2700..e4bd902a1e76 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2317,7 +2317,7 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
if ((req->request.actual < length) && req->num_pending_sgs) {
__dwc3_gadget_kick_transfer(dep);
-   return;
+   break;
}
 
dwc3_gadget_giveback(dep, req, status);
@@ -2325,20 +2325,6 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
if (ret)
break;
}
-
-   /*
-* Our endpoint might get disabled by another thread during
-* dwc3_gadget_giveback(). If that happens, we're just gonna return 1
-* early.
-*/
-   if (!dep->endpoint.desc)
-   return;
-
-   if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
-   list_empty(&dep->started_list) &&
-   list_empty(&dep->pending_list)) {
-   dep->flags = DWC3_EP_PENDING_REQUEST;
-   }
 }
 
 static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep,
-- 
2.16.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


[RFT/PATCH 22/38] usb: dwc3: gadget: split scatterlist and linear handlers

2018-04-09 Thread Felipe Balbi
instead of having one big loop, let's split it down into two smaller
handlers: one for linear buffers and one for scatterlist.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index fea515e4efec..040c4fea2700 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2246,6 +2246,45 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
return 0;
 }
 
+static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep,
+   struct dwc3_request *req, const struct dwc3_event_depevt *event,
+   int status)
+{
+   struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue];
+   struct scatterlist *sg = req->sg;
+   struct scatterlist *s;
+   unsigned int pending = req->num_pending_sgs;
+   unsigned int i;
+   int ret = 0;
+
+   for_each_sg(sg, s, pending, i) {
+   trb = &dep->trb_pool[dep->trb_dequeue];
+
+   if (trb->ctrl & DWC3_TRB_CTRL_HWO)
+   break;
+
+   req->sg = sg_next(s);
+   req->num_pending_sgs--;
+
+   ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
+   trb, event, status, true);
+   if (ret)
+   break;
+   }
+
+   return ret;
+}
+
+static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep,
+   struct dwc3_request *req, const struct dwc3_event_depevt *event,
+   int status)
+{
+   struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue];
+
+   return dwc3_gadget_ep_reclaim_completed_trb(dep, req, trb,
+   event, status, false);
+}
+
 static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
@@ -2259,32 +2298,12 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
length = req->request.length;
chain = req->num_pending_sgs > 0;
-   if (chain) {
-   struct scatterlist *sg = req->sg;
-   struct scatterlist *s;
-   unsigned int pending = req->num_pending_sgs;
-   unsigned int i;
-
-   for_each_sg(sg, s, pending, i) {
-   trb = &dep->trb_pool[dep->trb_dequeue];
-
-   if (trb->ctrl & DWC3_TRB_CTRL_HWO)
-   break;
-
-   req->sg = sg_next(s);
-   req->num_pending_sgs--;
-
-   ret = dwc3_gadget_ep_reclaim_completed_trb(dep,
-   req, trb, event, status,
-   chain);
-   if (ret)
-   break;
-   }
-   } else {
-   trb = &dep->trb_pool[dep->trb_dequeue];
-   ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
-   trb, event, status, chain);
-   }
+   if (chain)
+   ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
+   status);
+   else
+   ret = dwc3_gadget_ep_reclaim_trb_linear(dep, req, event,
+   status);
 
if (req->unaligned || req->zero) {
trb = &dep->trb_pool[dep->trb_dequeue];
-- 
2.16.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


[RFT/PATCH 16/38] usb: dwc3: gadget: make cleanup_completed_requests() return nothing

2018-04-09 Thread Felipe Balbi
We don't need to return a value anymore here. Let's remove it.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 83f386bd65e0..afd916dbfbd2 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2282,7 +2282,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3_ep *dep,
return 0;
 }
 
-static int dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
+static void dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
struct dwc3_request *req, *n;
@@ -2333,8 +2333,10 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
req->request.actual = length - req->remaining;
 
-   if ((req->request.actual < length) && req->num_pending_sgs)
-   return __dwc3_gadget_kick_transfer(dep);
+   if ((req->request.actual < length) && req->num_pending_sgs) {
+   __dwc3_gadget_kick_transfer(dep);
+   return;
+   }
 
dwc3_gadget_giveback(dep, req, status);
 
@@ -2352,7 +2354,7 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 * early.
 */
if (!dep->endpoint.desc)
-   return 1;
+   return;
 
if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
list_empty(&dep->started_list)) {
@@ -2368,13 +2370,7 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
dwc3_stop_active_transfer(dep, true);
dep->flags = DWC3_EP_ENABLED;
}
-   return 1;
}
-
-   if (usb_endpoint_xfer_isoc(dep->endpoint.desc) && ioc)
-   return 0;
-
-   return 1;
 }
 
 static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep,
-- 
2.16.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


[RFT/PATCH 09/38] usb: dwc3: gadget: renable dwc3_gadget_start_isoc()

2018-04-09 Thread Felipe Balbi
Cleanup only, no functional changes. This just matches the event name
with its handler.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8ea180373423..fb2dc07edcaf 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1268,7 +1268,7 @@ static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
__dwc3_gadget_kick_transfer(dep);
 }
 
-static void dwc3_gadget_start_isoc(struct dwc3 *dwc,
+static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3 *dwc,
struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
 {
u32 cur_uf, mask;
@@ -2467,7 +2467,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
dwc3_gadget_endpoint_transfer_in_progress(dwc, dep, event);
break;
case DWC3_DEPEVT_XFERNOTREADY:
-   dwc3_gadget_start_isoc(dwc, dep, event);
+   dwc3_gadget_endpoint_transfer_not_ready(dwc, dep, event);
break;
case DWC3_DEPEVT_EPCMDCMPLT:
cmd = DEPEVT_PARAMETER_CMD(event->parameters);
-- 
2.16.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


[RFT/PATCH 18/38] usb: dwc3: gadget: check for Missed Isoc from event status

2018-04-09 Thread Felipe Balbi
In case we get an event with status set to Missed Isoc, this means we
have missed an isochronous interval and should issue End Transfer
command and wait for the following XferNotReady.

Let's do that early, rather than late.

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

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 5ee895113906..8862118c3b79 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1192,11 +1192,12 @@ struct dwc3_event_depevt {
 /* Within XferNotReady */
 #define DEPEVT_STATUS_TRANSFER_ACTIVE  BIT(3)
 
-/* Within XferComplete */
+/* Within XferComplete or XferInProgress */
 #define DEPEVT_STATUS_BUSERR   BIT(0)
 #define DEPEVT_STATUS_SHORTBIT(1)
 #define DEPEVT_STATUS_IOC  BIT(2)
-#define DEPEVT_STATUS_LST  BIT(3)
+#define DEPEVT_STATUS_LST  BIT(3) /* XferComplete */
+#define DEPEVT_STATUS_MISSED_ISOC BIT(3) /* XferInProgress */
 
 /* Stream event only */
 #define DEPEVT_STREAMEVT_FOUND 1
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0b003367cc7c..ed44b85e59dc 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2361,9 +2361,6 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 * entry is added into request list.
 */
dep->flags = DWC3_EP_PENDING_REQUEST;
-   } else {
-   dwc3_stop_active_transfer(dep, true);
-   dep->flags = DWC3_EP_ENABLED;
}
}
 }
@@ -2383,14 +2380,25 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
 {
struct dwc3 *dwc = dep->dwc;
unsignedstatus = 0;
+   boolstop = false;
 
dwc3_gadget_endpoint_frame_from_event(dep, event);
 
if (event->status & DEPEVT_STATUS_BUSERR)
status = -ECONNRESET;
 
+   if (event->status & DEPEVT_STATUS_MISSED_ISOC) {
+   status = -ECONNRESET;
+   stop = true;
+   }
+
dwc3_gadget_ep_cleanup_completed_requests(dep, event, status);
 
+   if (stop) {
+   dwc3_stop_active_transfer(dep, true);
+   dep->flags = DWC3_EP_ENABLED;
+   }
+
/*
 * WORKAROUND: This is the 2nd half of U1/U2 -> U0 workaround.
 * See dwc3_gadget_linksts_change_interrupt() for 1st half.
-- 
2.16.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


[RFT/PATCH 11/38] usb: dwc3: gadget: remove unnecessary 'dwc' parameter

2018-04-09 Thread Felipe Balbi
Endpoint handlers need to know about endpoints, not dwc. If they
really need access to dwc (e.g. for printing error messages) we have a
reference to it tucked inside the endpoint.

This patch has no functional changes, it's simply moving things around.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 17d2ece96068..97ae480e4999 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -703,12 +703,12 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
return 0;
 }
 
-static void dwc3_stop_active_transfer(struct dwc3 *dwc, u32 epnum, bool force);
+static void dwc3_stop_active_transfer(struct dwc3_ep *dep, bool force);
 static void dwc3_remove_requests(struct dwc3 *dwc, struct dwc3_ep *dep)
 {
struct dwc3_request *req;
 
-   dwc3_stop_active_transfer(dwc, dep->number, true);
+   dwc3_stop_active_transfer(dep, true);
 
/* - giveback all requests to gadget driver */
while (!list_empty(&dep->started_list)) {
@@ -1250,11 +1250,10 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)
return DWC3_DSTS_SOFFN(reg);
 }
 
-static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
-   struct dwc3_ep *dep, u32 cur_uf)
+static void __dwc3_gadget_start_isoc(struct dwc3_ep *dep, u32 cur_uf)
 {
if (list_empty(&dep->pending_list)) {
-   dev_info(dwc->dev, "%s: ran out of requests\n",
+   dev_info(dep->dwc->dev, "%s: ran out of requests\n",
dep->name);
dep->flags |= DWC3_EP_PENDING_REQUEST;
return;
@@ -1304,13 +1303,13 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
if ((dep->flags & DWC3_EP_PENDING_REQUEST)) {
if (dep->flags & DWC3_EP_TRANSFER_STARTED) {
-   dwc3_stop_active_transfer(dwc, dep->number, 
true);
+   dwc3_stop_active_transfer(dep, true);
dep->flags = DWC3_EP_ENABLED;
} else {
u32 cur_uf;
 
cur_uf = __dwc3_gadget_get_frame(dwc);
-   __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
+   __dwc3_gadget_start_isoc(dep, cur_uf);
dep->flags &= ~DWC3_EP_PENDING_REQUEST;
}
return 0;
@@ -1373,7 +1372,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
}
if (r == req) {
/* wait until it is processed */
-   dwc3_stop_active_transfer(dwc, dep->number, true);
+   dwc3_stop_active_transfer(dep, true);
 
/*
 * If request was already started, this means we had to
@@ -2206,10 +2205,9 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
 
 /* -- 
*/
 
-static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3 *dwc,
-   struct dwc3_ep *dep, struct dwc3_request *req,
-   struct dwc3_trb *trb, const struct dwc3_event_depevt *event,
-   int status, int chain)
+static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3_ep *dep,
+   struct dwc3_request *req, struct dwc3_trb *trb,
+   const struct dwc3_event_depevt *event, int status, int chain)
 {
unsigned intcount;
unsigned ints_pkt = 0;
@@ -2269,7 +2267,7 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3 *dwc,
 */
dep->flags |= DWC3_EP_MISSED_ISOC;
} else {
-   dev_err(dwc->dev, "incomplete IN transfer %s\n",
+   dev_err(dep->dwc->dev, "incomplete IN transfer 
%s\n",
dep->name);
status = -ECONNRESET;
}
@@ -2291,9 +2289,8 @@ static int dwc3_gadget_ep_reclaim_completed_trb(struct 
dwc3 *dwc,
return 0;
 }
 
-static int dwc3_gadget_ep_cleanup_completed_requests(struct dwc3 *dwc,
-   struct dwc3_ep *dep, const struct dwc3_event_depevt *event,
-   int status)
+static int dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
+   const struct dwc3_event_depevt *event, int status)
 {
struct dwc3_request *req, *n;
struct dwc3_trb *trb;
@@ -2321,22 +2318,22 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3 *dwc

[RFT/PATCH 07/38] usb: dwc3: gadget: remove allocated/queued request tracking

2018-04-09 Thread Felipe Balbi
That has never proven useful in any way. Just remove it.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h   |  4 
 drivers/usb/dwc3/gadget.c | 21 ++---
 drivers/usb/dwc3/trace.h  |  7 ++-
 3 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 4f3b43809917..2baa6caeffa6 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -639,8 +639,6 @@ struct dwc3_event_buffer {
  * @resource_index: Resource transfer index
  * @frame_number: set to the frame number we want this transfer to start (ISOC)
  * @interval: the interval on which the ISOC transfer is started
- * @allocated_requests: number of requests allocated
- * @queued_requests: number of requests queued for transfer
  * @name: a human readable name e.g. ep1out-bulk
  * @direction: true for TX, false for RX
  * @stream_capable: true when streams are enabled
@@ -688,8 +686,6 @@ struct dwc3_ep {
u8  number;
u8  type;
u8  resource_index;
-   u32 allocated_requests;
-   u32 queued_requests;
u32 frame_number;
u32 interval;
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index cbe390d17386..a77458e3996a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -840,7 +840,7 @@ static int dwc3_gadget_ep_disable(struct usb_ep *ep)
 }
 
 static struct usb_request *dwc3_gadget_ep_alloc_request(struct usb_ep *ep,
-   gfp_t gfp_flags)
+   gfp_t gfp_flags)
 {
struct dwc3_request *req;
struct dwc3_ep  *dep = to_dwc3_ep(ep);
@@ -852,8 +852,6 @@ static struct usb_request 
*dwc3_gadget_ep_alloc_request(struct usb_ep *ep,
req->epnum  = dep->number;
req->dep= dep;
 
-   dep->allocated_requests++;
-
trace_dwc3_alloc_request(req);
 
return &req->request;
@@ -863,9 +861,7 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
struct usb_request *request)
 {
struct dwc3_request *req = to_dwc3_request(request);
-   struct dwc3_ep  *dep = to_dwc3_ep(ep);
 
-   dep->allocated_requests--;
trace_dwc3_free_request(req);
kfree(req);
 }
@@ -997,7 +993,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
dwc3_gadget_move_started_request(req);
req->trb = trb;
req->trb_dma = dwc3_trb_dma_offset(dep, trb);
-   dep->queued_requests++;
}
 
__dwc3_prepare_one_trb(dep, trb, dma, length, chain, node,
@@ -1233,7 +1228,6 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep 
*dep)
 */
if (req->trb)
memset(req->trb, 0, sizeof(struct dwc3_trb));
-   dep->queued_requests--;
dwc3_gadget_del_and_unmap_request(dep, req, ret);
return ret;
}
@@ -1463,7 +1457,7 @@ static int dwc3_gadget_ep_dequeue(struct usb_ep *ep,
 
 out1:
/* giveback the request */
-   dep->queued_requests--;
+
dwc3_gadget_giveback(dep, req, -ECONNRESET);
 
 out0:
@@ -2223,7 +2217,7 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
 
 /* -- 
*/
 
-static int dwc3_gadget_ep_reclaim_completed_trbs(struct dwc3 *dwc,
+static int dwc3_gadget_ep_reclaim_completed_trb(struct dwc3 *dwc,
struct dwc3_ep *dep, struct dwc3_request *req,
struct dwc3_trb *trb, const struct dwc3_event_depevt *event,
int status, int chain)
@@ -2234,9 +2228,6 @@ static int dwc3_gadget_ep_reclaim_completed_trbs(struct 
dwc3 *dwc,
 
dwc3_ep_inc_deq(dep);
 
-   if (req->trb == trb)
-   dep->queued_requests--;
-
trace_dwc3_complete_trb(dep, trb);
 
/*
@@ -2341,7 +2332,7 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3 *dwc,
req->sg = sg_next(s);
req->num_pending_sgs--;
 
-   ret = dwc3_gadget_ep_reclaim_completed_trbs(dwc,
+   ret = dwc3_gadget_ep_reclaim_completed_trb(dwc,
dep, req, trb, event, status,
chain);
if (ret)
@@ -2349,13 +2340,13 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3 *dwc,
}
} else {
trb = &dep->trb_pool[dep->trb_dequeue];
-   ret = dwc3_gadget_ep_reclaim_completed_trbs(dwc, dep,
+   ret = dwc3_gadget_ep_reclaim_completed_trb(dwc, dep,

[RFT/PATCH 05/38] usb: dwc3: gadget: don't kick transfer all the time

2018-04-09 Thread Felipe Balbi
Instead of constantly calling kick transfer everything some event
shows up, let's just rely on the fact that we send Update Transfer
every time a new request is queued.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4d2af083c0f4..a494ae350fad 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2443,17 +2443,6 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3 *dwc,
 
dwc->u1u2 = 0;
}
-
-   /*
-* Our endpoint might get disabled by another thread during
-* dwc3_gadget_giveback(). If that happens, we're just gonna return 1
-* early on so DWC3_EP_BUSY flag gets cleared
-*/
-   if (!dep->endpoint.desc)
-   return;
-
-   if (!usb_endpoint_xfer_isoc(dep->endpoint.desc))
-   __dwc3_gadget_kick_transfer(dep);
 }
 
 static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
-- 
2.16.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


[RFT/PATCH 10/38] usb: dwc3: gadget: move handler closer to calling site

2018-04-09 Thread Felipe Balbi
Cleanup only, no functional changes. Just making code easier to
follow.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index fb2dc07edcaf..17d2ece96068 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1268,17 +1268,6 @@ static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
__dwc3_gadget_kick_transfer(dep);
 }
 
-static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3 *dwc,
-   struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
-{
-   u32 cur_uf, mask;
-
-   mask = ~(dep->interval - 1);
-   cur_uf = event->parameters & mask;
-
-   __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
-}
-
 static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, struct dwc3_request 
*req)
 {
struct dwc3 *dwc = dep->dwc;
@@ -2439,6 +2428,17 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3 *dwc,
}
 }
 
+static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3 *dwc,
+   struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
+{
+   u32 cur_uf, mask;
+
+   mask = ~(dep->interval - 1);
+   cur_uf = event->parameters & mask;
+
+   __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
+}
+
 static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
const struct dwc3_event_depevt *event)
 {
-- 
2.16.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


[RFT/PATCH 06/38] usb: dwc3: gadget: rename done_trbs and done_reqs

2018-04-09 Thread Felipe Balbi
This patch simply renames two functions to more descriptive names so
that it's easier to understand what they're doing.

Cleanup only, no functional changes.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index a494ae350fad..cbe390d17386 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2223,10 +2223,10 @@ static void dwc3_gadget_free_endpoints(struct dwc3 *dwc)
 
 /* -- 
*/
 
-static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, struct dwc3_ep *dep,
-   struct dwc3_request *req, struct dwc3_trb *trb,
-   const struct dwc3_event_depevt *event, int status,
-   int chain)
+static int dwc3_gadget_ep_reclaim_completed_trbs(struct dwc3 *dwc,
+   struct dwc3_ep *dep, struct dwc3_request *req,
+   struct dwc3_trb *trb, const struct dwc3_event_depevt *event,
+   int status, int chain)
 {
unsigned intcount;
unsigned ints_pkt = 0;
@@ -2311,8 +2311,9 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
return 0;
 }
 
-static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
-   const struct dwc3_event_depevt *event, int status)
+static int dwc3_gadget_ep_cleanup_completed_requests(struct dwc3 *dwc,
+   struct dwc3_ep *dep, const struct dwc3_event_depevt *event,
+   int status)
 {
struct dwc3_request *req, *n;
struct dwc3_trb *trb;
@@ -2340,21 +2341,22 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
req->sg = sg_next(s);
req->num_pending_sgs--;
 
-   ret = __dwc3_cleanup_done_trbs(dwc, dep, req, 
trb,
-   event, status, chain);
+   ret = dwc3_gadget_ep_reclaim_completed_trbs(dwc,
+   dep, req, trb, event, status,
+   chain);
if (ret)
break;
}
} else {
trb = &dep->trb_pool[dep->trb_dequeue];
-   ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
-   event, status, chain);
+   ret = dwc3_gadget_ep_reclaim_completed_trbs(dwc, dep,
+   req, trb, event, status, chain);
}
 
if (req->unaligned || req->zero) {
trb = &dep->trb_pool[dep->trb_dequeue];
-   ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
-   event, status, false);
+   ret = dwc3_gadget_ep_reclaim_completed_trbs(dwc, dep,
+   req, trb, event, status, false);
req->unaligned = false;
req->zero = false;
}
@@ -2414,7 +2416,8 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3 *dwc,
if (event->status & DEPEVT_STATUS_BUSERR)
status = -ECONNRESET;
 
-   clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status);
+   clean_busy = dwc3_gadget_ep_cleanup_completed_requests(dwc, dep, event,
+   status);
if (clean_busy && (!dep->endpoint.desc ||
usb_endpoint_xfer_isoc(dep->endpoint.desc)))
dep->flags &= ~DWC3_EP_BUSY;
-- 
2.16.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


[RFT/PATCH 17/38] usb: dwc3: gadget: remove unnecessary 'ioc' variable

2018-04-09 Thread Felipe Balbi
It's only written to, never read. We can remove it now.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 7 +--
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index afd916dbfbd2..0b003367cc7c 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2287,7 +2287,6 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 {
struct dwc3_request *req, *n;
struct dwc3_trb *trb;
-   boolioc = false;
int ret = 0;
 
list_for_each_entry_safe(req, n, &dep->started_list, list) {
@@ -2340,12 +2339,8 @@ static void 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
 
dwc3_gadget_giveback(dep, req, status);
 
-   if (ret) {
-   if ((event->status & DEPEVT_STATUS_IOC) &&
-   (trb->ctrl & DWC3_TRB_CTRL_IOC))
-   ioc = true;
+   if (ret)
break;
-   }
}
 
/*
-- 
2.16.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


[RFT/PATCH 08/38] usb: dwc3: gadget: remove some pointless checks

2018-04-09 Thread Felipe Balbi
We *KNOW* which events we enable for which endpoint types and
we *KNOW* when they'll trigger. The endpoint type checks are
pointless.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index a77458e3996a..8ea180373423 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2467,21 +2467,8 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
dwc3_gadget_endpoint_transfer_in_progress(dwc, dep, event);
break;
case DWC3_DEPEVT_XFERNOTREADY:
-   if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
-   dev_err(dwc->dev, "XferNotReady for non-Isoc %s\n",
-   dep->name);
-   return;
-   }
-
dwc3_gadget_start_isoc(dwc, dep, event);
break;
-   case DWC3_DEPEVT_STREAMEVT:
-   if (!usb_endpoint_xfer_bulk(dep->endpoint.desc)) {
-   dev_err(dwc->dev, "Stream event for non-Bulk %s\n",
-   dep->name);
-   return;
-   }
-   break;
case DWC3_DEPEVT_EPCMDCMPLT:
cmd = DEPEVT_PARAMETER_CMD(event->parameters);
 
@@ -2490,6 +2477,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
wake_up(&dep->wait_end_transfer);
}
break;
+   case DWC3_DEPEVT_STREAMEVT:
case DWC3_DEPEVT_XFERCOMPLETE:
case DWC3_DEPEVT_RXTXFIFOEVT:
break;
-- 
2.16.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


[RFT/PATCH 12/38] usb: dwc3: gadget: always use frame number from XferNotReady

2018-04-09 Thread Felipe Balbi
The core requires the extra two bits of information for properly
scheduling Isochronous transfers. This means that we can't rely on
__dwc3_gadget_get_frame(). Let's always cache uFrame number from
XferNotReady instead.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 97ae480e4999..00a429db158b 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1250,7 +1250,7 @@ static int __dwc3_gadget_get_frame(struct dwc3 *dwc)
return DWC3_DSTS_SOFFN(reg);
 }
 
-static void __dwc3_gadget_start_isoc(struct dwc3_ep *dep, u32 cur_uf)
+static void __dwc3_gadget_start_isoc(struct dwc3_ep *dep)
 {
if (list_empty(&dep->pending_list)) {
dev_info(dep->dwc->dev, "%s: ran out of requests\n",
@@ -1263,7 +1263,7 @@ static void __dwc3_gadget_start_isoc(struct dwc3_ep *dep, 
u32 cur_uf)
 * Schedule the first trb for one interval in the future or at
 * least 4 microframes.
 */
-   dep->frame_number = cur_uf + max_t(u32, 4, dep->interval);
+   dep->frame_number += max_t(u32, 4, dep->interval);
__dwc3_gadget_kick_transfer(dep);
 }
 
@@ -1306,10 +1306,7 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
dwc3_stop_active_transfer(dep, true);
dep->flags = DWC3_EP_ENABLED;
} else {
-   u32 cur_uf;
-
-   cur_uf = __dwc3_gadget_get_frame(dwc);
-   __dwc3_gadget_start_isoc(dep, cur_uf);
+   __dwc3_gadget_start_isoc(dep);
dep->flags &= ~DWC3_EP_PENDING_REQUEST;
}
return 0;
@@ -2433,8 +2430,9 @@ static void 
dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep,
 
mask = ~(dep->interval - 1);
cur_uf = event->parameters & mask;
+   dep->frame_number = cur_uf;
 
-   __dwc3_gadget_start_isoc(dep, cur_uf);
+   __dwc3_gadget_start_isoc(dep);
 }
 
 static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
-- 
2.16.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


[RFT/PATCH 13/38] usb: dwc3: gadget: update dep->frame_number from XferInprogress too

2018-04-09 Thread Felipe Balbi
We will need an up-to-date frame_number from XferInProgress too when
future patches improve our handling of Isoc endpoints.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 00a429db158b..e982cdec8a5d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2381,6 +2381,16 @@ static int 
dwc3_gadget_ep_cleanup_completed_requests(struct dwc3_ep *dep,
return 1;
 }
 
+static void dwc3_gadget_endpoint_frame_from_event(struct dwc3_ep *dep,
+   const struct dwc3_event_depevt *event)
+{
+   u32 cur_uf, mask;
+
+   mask = ~(dep->interval - 1);
+   cur_uf = event->parameters & mask;
+   dep->frame_number = cur_uf;
+}
+
 static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event)
 {
@@ -2388,6 +2398,8 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
unsignedstatus = 0;
int clean_busy;
 
+   dwc3_gadget_endpoint_frame_from_event(dep, event);
+
if (event->status & DEPEVT_STATUS_BUSERR)
status = -ECONNRESET;
 
@@ -2426,12 +2438,7 @@ static void 
dwc3_gadget_endpoint_transfer_in_progress(struct dwc3_ep *dep,
 static void dwc3_gadget_endpoint_transfer_not_ready(struct dwc3_ep *dep,
const struct dwc3_event_depevt *event)
 {
-   u32 cur_uf, mask;
-
-   mask = ~(dep->interval - 1);
-   cur_uf = event->parameters & mask;
-   dep->frame_number = cur_uf;
-
+   dwc3_gadget_endpoint_frame_from_event(dep, event);
__dwc3_gadget_start_isoc(dep);
 }
 
-- 
2.16.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


[RFT/PATCH 03/38] usb: dwc3: gadget: XferComplete only for EP0

2018-04-09 Thread Felipe Balbi
XferComplete is enabled only for the default control pipe, let's make
that clear in the code.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 11 +--
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index d48e9fa8284a..748c088f3b79 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2483,16 +2483,6 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
}
 
switch (event->endpoint_event) {
-   case DWC3_DEPEVT_XFERCOMPLETE:
-   dep->resource_index = 0;
-
-   if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
-   dev_err(dwc->dev, "XferComplete for Isochronous 
endpoint\n");
-   return;
-   }
-
-   dwc3_endpoint_transfer_complete(dwc, dep, event);
-   break;
case DWC3_DEPEVT_XFERINPROGRESS:
dwc3_endpoint_transfer_complete(dwc, dep, event);
break;
@@ -2520,6 +2510,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
wake_up(&dep->wait_end_transfer);
}
break;
+   case DWC3_DEPEVT_XFERCOMPLETE:
case DWC3_DEPEVT_RXTXFIFOEVT:
break;
}
-- 
2.16.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


[RFT/PATCH 00/38] usb: dwc3: gadget: Rework & Refactoring

2018-04-09 Thread Felipe Balbi
Hi guys,

I've been working on this series for a while now. I feels like after
this series the transfer management code is far easier to read and
understand.

Based on my tests, I have no regressions. Tested g_mass_storage and all
of testusb's tests (including ISOC).

Patches are also available on dwc3-improve-isoc-endpoints in my k.org
tree. Test reports would be VERY, VERY, VERY welcome. Please give this a
go so we avoid regressions on v4.18.

Cheers

Felipe Balbi (38):
  usb: dwc3: gadget: pre-issue Start Transfer for Interrupt EPs too
  usb: dwc3: gadget: XferNotReady is Isoc-only
  usb: dwc3: gadget: XferComplete only for EP0
  usb: dwc3: gadget: rename dwc3_endpoint_transfer_complete()
  usb: dwc3: gadget: don't kick transfer all the time
  usb: dwc3: gadget: rename done_trbs and done_reqs
  usb: dwc3: gadget: remove allocated/queued request tracking
  usb: dwc3: gadget: remove some pointless checks
  usb: dwc3: gadget: renable dwc3_gadget_start_isoc()
  usb: dwc3: gadget: move handler closer to calling site
  usb: dwc3: gadget: remove unnecessary 'dwc' parameter
  usb: dwc3: gadget: always use frame number from XferNotReady
  usb: dwc3: gadget: update dep->frame_number from XferInprogress too
  usb: dwc3: gadget: start removing BUSY flag
  usb: dwc3: gadget: remove DWC3_EP_BUSY flag
  usb: dwc3: gadget: make cleanup_completed_requests() return nothing
  usb: dwc3: gadget: remove unnecessary 'ioc' variable
  usb: dwc3: gadget: check for Missed Isoc from event status
  usb: dwc3: gadget: remove duplicated missed isoc handling
  usb: dwc3: gadget: simplify queueing of isoc transfers
  usb: dwc3: gadget: simplify isoc case on cleanup_completed_requests
  usb: dwc3: gadget: split scatterlist and linear handlers
  usb: dwc3: gadget: remove PENDING handling from cleanup_completed
  usb: dwc3: gadget: remove unnecessary 'chain' variable
  usb: dwc3: gadget: simplify unaligned and zlp handling
  usb: dwc3: trace: print out event status too
  usb: dwc3: gadget: simplify short packet event
  usb: dwc3: gadget: simplify IOC handling
  usb: dwc3: gadget: add a helper to test if a request is completed
  usb: dwc3: gadget: one declaration per line
  usb: dwc3: gadget: reduce scope of ret variable
  usb: dwc3: gadget: get rid of the length variable
  usb: dwc3: gadget: split dwc3_gadget_ep_cleanup_completed_requests()
  usb: dwc3: gadget: refactor dwc3_gadget_init_endpoints()
  usb: dwc3: gadget: combine modify & restore into single argument
  usb: dwc3: gadget: remove a few more dwc arguments
  usb: dwc3: gadget: move set_xfer_resource() in place of prototype
  usb: dwc3: gadget: move dwc3_calc_trbs_left() in place of prototype

 Documentation/driver-api/usb/dwc3.rst |   3 +-
 drivers/usb/dwc3/core.h   |  13 +-
 drivers/usb/dwc3/debug.h  |  20 +-
 drivers/usb/dwc3/ep0.c|   5 +-
 drivers/usb/dwc3/gadget.c | 712 --
 drivers/usb/dwc3/trace.h  |  12 +-
 6 files changed, 351 insertions(+), 414 deletions(-)

-- 
2.16.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


[RFT/PATCH 02/38] usb: dwc3: gadget: XferNotReady is Isoc-only

2018-04-09 Thread Felipe Balbi
We don't use XferNotReady for anything other than Default Control
Pipe, which is handled in ep0.c, and Isochronous endpoints. Let's make
that clear in the code.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ecf71c0b1d8e..d48e9fa8284a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2497,11 +2497,13 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
dwc3_endpoint_transfer_complete(dwc, dep, event);
break;
case DWC3_DEPEVT_XFERNOTREADY:
-   if (usb_endpoint_xfer_isoc(dep->endpoint.desc))
-   dwc3_gadget_start_isoc(dwc, dep, event);
-   else
-   __dwc3_gadget_kick_transfer(dep);
+   if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
+   dev_err(dwc->dev, "XferNotReady for non-Isoc %s\n",
+   dep->name);
+   return;
+   }
 
+   dwc3_gadget_start_isoc(dwc, dep, event);
break;
case DWC3_DEPEVT_STREAMEVT:
if (!usb_endpoint_xfer_bulk(dep->endpoint.desc)) {
-- 
2.16.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


[RFT/PATCH 01/38] usb: dwc3: gadget: pre-issue Start Transfer for Interrupt EPs too

2018-04-09 Thread Felipe Balbi
Interrupt endpoints behave much like Bulk endpoints with the exception
that they are periodic. We can pre-issue Start Transfer exactly as we
do for Bulk endpoints.

While at that, remove one trailing blank line which is unnecessary.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8796a5ee9bb9..ecf71c0b1d8e 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -671,7 +671,8 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
 * Issue StartTransfer here with no-op TRB so we can always rely on No
 * Response Update Transfer command.
 */
-   if (usb_endpoint_xfer_bulk(desc)) {
+   if (usb_endpoint_xfer_bulk(desc) ||
+   usb_endpoint_xfer_int(desc)) {
struct dwc3_gadget_ep_cmd_params params;
struct dwc3_trb *trb;
dma_addr_t trb_dma;
@@ -696,7 +697,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
WARN_ON_ONCE(!dep->resource_index);
}
 
-
 out:
trace_dwc3_gadget_ep_enable(dep);
 
-- 
2.16.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


[RFT/PATCH 04/38] usb: dwc3: gadget: rename dwc3_endpoint_transfer_complete()

2018-04-09 Thread Felipe Balbi
Now that we're making sure we don't have XferComplete events, we can
rename this function to what it actually handles:
dwc3_gadget_endpoint_transfer_in_progress()

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 748c088f3b79..4d2af083c0f4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2405,20 +2405,17 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
return 1;
 }
 
-static void dwc3_endpoint_transfer_complete(struct dwc3 *dwc,
+static void dwc3_gadget_endpoint_transfer_in_progress(struct dwc3 *dwc,
struct dwc3_ep *dep, const struct dwc3_event_depevt *event)
 {
unsignedstatus = 0;
int clean_busy;
-   u32 is_xfer_complete;
-
-   is_xfer_complete = (event->endpoint_event == DWC3_DEPEVT_XFERCOMPLETE);
 
if (event->status & DEPEVT_STATUS_BUSERR)
status = -ECONNRESET;
 
clean_busy = dwc3_cleanup_done_reqs(dwc, dep, event, status);
-   if (clean_busy && (!dep->endpoint.desc || is_xfer_complete ||
+   if (clean_busy && (!dep->endpoint.desc ||
usb_endpoint_xfer_isoc(dep->endpoint.desc)))
dep->flags &= ~DWC3_EP_BUSY;
 
@@ -2484,7 +2481,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
 
switch (event->endpoint_event) {
case DWC3_DEPEVT_XFERINPROGRESS:
-   dwc3_endpoint_transfer_complete(dwc, dep, event);
+   dwc3_gadget_endpoint_transfer_in_progress(dwc, dep, event);
break;
case DWC3_DEPEVT_XFERNOTREADY:
if (!usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
-- 
2.16.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: [PATCH] usb: typec: ucsi: fix tracepoint related build error

2018-04-09 Thread Heikki Krogerus
On Mon, Apr 09, 2018 at 09:55:17AM +0200, Tobias Regnery wrote:
> The ucsi driver defines several tracepoints, but the header file with the
> tracepoint definition trace.h is only conditionally built depending on
> CONFIG_FTRACE.

You mean trace.c, right? The definitions are indeed in the header,
trace.h, so I'm a bit confused what is actually the problem?

> This leads to the following build error with CONFIG_FTRACE=n and
> CONFIG_TYPEC_UCSI=m:

That alone should not cause any problems.

> ERROR: "__tracepoint_ucsi_command" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> undefined!
> ERROR: "__tracepoint_ucsi_register_port" 
> [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
> ERROR: "__tracepoint_ucsi_notify" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> undefined!
> ERROR: "__tracepoint_ucsi_reset_ppm" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> undefined!
> ERROR: "__tracepoint_ucsi_run_command" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> undefined!
> ERROR: "__tracepoint_ucsi_ack" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
> undefined!
> ERROR: "__tracepoint_ucsi_connector_change" 
> [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
> 
> With CONFIG_TYPEC_UCSI=y the build fails with several link errors.
> 
> Fix this by changing the Makefile to unconditionally build trace.o.
> Tracepints are a runtime contruct and no other user of tracepoints depends
> on CONFIG_FTRACE.
> 
> Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
> Signed-off-by: Tobias Regnery 
> ---
>  drivers/usb/typec/ucsi/Makefile | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile
> index b57891c1fd31..971befbbc2a8 100644
> --- a/drivers/usb/typec/ucsi/Makefile
> +++ b/drivers/usb/typec/ucsi/Makefile
> @@ -3,8 +3,6 @@ CFLAGS_trace.o:= -I$(src)
>  
>  obj-$(CONFIG_TYPEC_UCSI) += typec_ucsi.o
>  
> -typec_ucsi-y := ucsi.o
> -
> -typec_ucsi-$(CONFIG_FTRACE)  += trace.o
> +typec_ucsi-y := ucsi.o trace.o
>  
>  obj-$(CONFIG_UCSI_ACPI)  += ucsi_acpi.o

I would like to understand what is the root cause for the problem you
are seeing? CONFIG_FTRACE=n with CONFIG_TYPEC_UCSI=m alone compiles
just fine for me.

Using FTRACE as the condition here is indeed wrong, but changing that
so that we unconditionally compile trace.c is also wrong. We should
probable use CONFIG_TRACING instead of CONFIG_FTRACE. Can you check if
that works for you?


Thanks,

-- 
heikki
--
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 2/5] usb: typec: fusb302: remove max_snk_* for sink config

2018-04-09 Thread Jun Li

> -Original Message-
> From: Hans de Goede [mailto:hdego...@redhat.com]
> Sent: 2018年4月5日 4:13
> To: Mats Karrman ; Jun Li ;
> gre...@linuxfoundation.org; robh...@kernel.org; mark.rutl...@arm.com;
> heikki.kroge...@linux.intel.com
> Cc: li...@roeck-us.net; rmf...@gmail.com; yueyao@gmail.com;
> linux-usb@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> 
> Subject: Re: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink
> config
> 
> Hi,
> 
> On 04-04-18 14:06, Mats Karrman wrote:
> > Hi Li,
> >
> > On 2018-03-23 15:58, Li Jun wrote:
> >
> >> Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
> >> variable PDO for sink config.
> >>
> >> Signed-off-by: Li Jun 
> >> ---
> >>   drivers/usb/typec/fusb302/fusb302.c | 51
> >> +++--
> >>   1 file changed, 37 insertions(+), 14 deletions(-)
> >>
> >> diff --git a/drivers/usb/typec/fusb302/fusb302.c
> >> b/drivers/usb/typec/fusb302/fusb302.c
> >> index 7036171..db4d9cd 100644
> >> --- a/drivers/usb/typec/fusb302/fusb302.c
> >> +++ b/drivers/usb/typec/fusb302/fusb302.c
> >> @@ -120,6 +120,7 @@ struct fusb302_chip {
> >>   enum typec_cc_polarity cc_polarity;
> >>   enum typec_cc_status cc1;
> >>   enum typec_cc_status cc2;
> >> +    u32 snk_pdo[PDO_MAX_OBJECTS];
> >>   #ifdef CONFIG_DEBUG_FS
> >>   struct dentry *dentry;
> >> @@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
> >>   static const struct tcpc_config fusb302_tcpc_config = {
> >>   .src_pdo = src_pdo,
> >>   .nr_src_pdo = ARRAY_SIZE(src_pdo),
> >> -    .snk_pdo = snk_pdo,
> >> -    .nr_snk_pdo = ARRAY_SIZE(snk_pdo),
> >> -    .max_snk_mv = 5000,
> >> -    .max_snk_ma = 3000,
> >> -    .max_snk_mw = 15000,
> >>   .operating_snk_mw = 2500,
> >>   .type = TYPEC_PORT_DRP,
> >>   .data = TYPEC_PORT_DRD,
> >> @@ -1756,6 +1752,38 @@ static int init_gpio(struct fusb302_chip
> >> *chip)
> >>   return 0;
> >>   }
> >> +static int fusb302_composite_snk_pdo_array(struct fusb302_chip
> >> +*chip) {
> >> +    struct device *dev = chip->dev;
> >> +    u32 mv, ma, mw, min_mv;
> >> +    unsigned int i;
> >> +
> >> +    /* Copy the static snk pdo */
> >> +    for (i = 0; i < ARRAY_SIZE(snk_pdo); i++)
> >> +    chip->snk_pdo[i] = snk_pdo[i];
> >> +
> >> +    if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &mv)
> >> +||
> >> +    device_property_read_u32(dev, "fcs,max-sink-microamp", &ma)
> >> +||
> >> +    device_property_read_u32(dev, "fcs,max-sink-microwatt",
> >> +&mw))
> >> +    return i;
> >> +
> >> +    mv = mv / 1000;
> >> +    ma = ma / 1000;
> >> +    mw = mw / 1000;
> >> +
> >> +    min_mv = 1000 * chip->tcpc_config.operating_snk_mw / ma;
> >> +    if (pdo_type(snk_pdo[i-1] == PDO_TYPE_FIXED))
> >
> > You've got the parentheses wrong.
> >
> > Apart from that I don't like/understand why the PDO's should be fixed.
> > Every product should be able to have its own settings, including the
> > first PDO (e.g. it might need to specify a higher current and/or set the 
> > "Higher
> Capability" bit).
> >
> > I think this would be best solved the same way as in your TCPCI driver
> > patch series [1] with a list freely specified by a property.
> >
> > [1]
> > https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww
> > .spinics.net%2Flists%2Flinux-usb%2Fmsg167398.html&data=02%7C01%7Cjun.l
> >
> i%40nxp.com%7C678fb35afff542581d3808d59a68708b%7C686ea1d3bc2b4c6fa92c
> d
> >
> 99c5c301635%7C0%7C0%7C636584695710093111&sdata=ZyAJQUR8ZbAq8VWsZkF
> PGLg
> > F9P5j5QpvF3yeGyNoyH8%3D&reserved=0
> 
> Hmm, interesting, for the x86 use-case that would require updating the
> properties for the fusb302 defined in:
> 
> drivers/platform/x86/intel_cht_int33fe.c
> 
> In tandem, which is easily doable.
> 
> But what about other users of the fusb302 driver? Since this driver was added
> before I started using it for some x86 boards, I assume there are some non x86
> users, so we should preserve compatibility for DTB files which don't define 
> any
> sink PDOs in their properties, I guess we could fall to a default fixed 5V 
> sink pdo
> for those.

If we can't elaborate all existing users, we have to change the driver
like this to preserve compatibility.

Thanks
Jun
> 
> Regards,
> 
> Hans
> 
> 
> 
> >
> >> +    min_mv = max(min_mv, pdo_fixed_voltage(snk_pdo[i-1]));
> >> +    else
> >> +    min_mv = max(min_mv, pdo_max_voltage(snk_pdo[i-1]));
> >> +    ma = min(ma, 1000 * mw / min_mv);
> >> +
> >> +    /* Insert the new pdo to the end */
> >> +    chip->snk_pdo[i] = PDO_VAR(min_mv, mv, ma);
> >> +
> >> +    return i+1;
> >> +}
> >> +
> >>   static int fusb302_probe(struct i2c_client *client,
> >>    const struct i2c_device_id *id)
> >>   {
> >> @@ -1784,18 +1812,13 @@ static int fusb302_probe(struct i2c_client
> >> *client,
> >>   chip->tcpc_dev.config = &chip->tcpc_config;
> >>   mutex_init(&chip->lock);
> >> -    if (!device_property_read_u32(dev, "fcs

RE: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink config

2018-04-09 Thread Jun Li
Hi
> -Original Message-
> From: Mats Karrman [mailto:mats.dev.l...@gmail.com]
> Sent: 2018年4月4日 20:07
> To: Jun Li ; gre...@linuxfoundation.org; robh...@kernel.org;
> mark.rutl...@arm.com; heikki.kroge...@linux.intel.com;
> hdego...@redhat.com
> Cc: li...@roeck-us.net; rmf...@gmail.com; yueyao@gmail.com;
> linux-usb@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> 
> Subject: Re: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink
> config
> 
> Hi Li,
> 
> On 2018-03-23 15:58, Li Jun wrote:
> 
> > Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
> > variable PDO for sink config.
> >
> > Signed-off-by: Li Jun 
> > ---
> >   drivers/usb/typec/fusb302/fusb302.c | 51
> +++--
> >   1 file changed, 37 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/usb/typec/fusb302/fusb302.c
> > b/drivers/usb/typec/fusb302/fusb302.c
> > index 7036171..db4d9cd 100644
> > --- a/drivers/usb/typec/fusb302/fusb302.c
> > +++ b/drivers/usb/typec/fusb302/fusb302.c
> > @@ -120,6 +120,7 @@ struct fusb302_chip {
> > enum typec_cc_polarity cc_polarity;
> > enum typec_cc_status cc1;
> > enum typec_cc_status cc2;
> > +   u32 snk_pdo[PDO_MAX_OBJECTS];
> >
> >   #ifdef CONFIG_DEBUG_FS
> > struct dentry *dentry;
> > @@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
> >   static const struct tcpc_config fusb302_tcpc_config = {
> > .src_pdo = src_pdo,
> > .nr_src_pdo = ARRAY_SIZE(src_pdo),
> > -   .snk_pdo = snk_pdo,
> > -   .nr_snk_pdo = ARRAY_SIZE(snk_pdo),
> > -   .max_snk_mv = 5000,
> > -   .max_snk_ma = 3000,
> > -   .max_snk_mw = 15000,
> > .operating_snk_mw = 2500,
> > .type = TYPEC_PORT_DRP,
> > .data = TYPEC_PORT_DRD,
> > @@ -1756,6 +1752,38 @@ static int init_gpio(struct fusb302_chip *chip)
> > return 0;
> >   }
> >
> > +static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
> > +{
> > +   struct device *dev = chip->dev;
> > +   u32 mv, ma, mw, min_mv;
> > +   unsigned int i;
> > +
> > +   /* Copy the static snk pdo */
> > +   for (i = 0; i < ARRAY_SIZE(snk_pdo); i++)
> > +   chip->snk_pdo[i] = snk_pdo[i];
> > +
> > +   if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &mv) ||
> > +   device_property_read_u32(dev, "fcs,max-sink-microamp", &ma) ||
> > +   device_property_read_u32(dev, "fcs,max-sink-microwatt", &mw))
> > +   return i;
> > +
> > +   mv = mv / 1000;
> > +   ma = ma / 1000;
> > +   mw = mw / 1000;
> > +
> > +   min_mv = 1000 * chip->tcpc_config.operating_snk_mw / ma;
> > +   if (pdo_type(snk_pdo[i-1] == PDO_TYPE_FIXED))
> 
> You've got the parentheses wrong.

Good catch.

> 
> Apart from that I don't like/understand why the PDO's should be fixed.

This is only for legacy setting(a fixed PDO) and properties(fcs,max-sink-*),
to make it can still work after using the new PDO matching policy.

> Every product should be able to have its own settings, including the first 
> PDO (e.g.
> it might need to specify a higher current and/or set the "Higher Capability" 
> bit).
> 
> I think this would be best solved the same way as in your TCPCI driver patch
> series [1] with a list freely specified by a property.
> 
> [1]
> https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.s
> pinics.net%2Flists%2Flinux-usb%2Fmsg167398.html&data=02%7C01%7Cjun.li%40
> nxp.com%7C94bfdd71fa87479f54c808d59a24873a%7C686ea1d3bc2b4c6fa92cd99c
> 5c301635%7C0%7C0%7C636584404043415663&sdata=RbOoMtJM9XtmvhHYNQ9a
> nhPMn%2BJpdqwY3UagRPCgM9k%3D&reserved=0

Agreed, new code(dt) should use[1] to describe the power properties.
Fusb302 driver just need pass a fwnode at init, tcpm will read and parse
all the properties when register port.

Thanks
Jun
> 
> > +   min_mv = max(min_mv, pdo_fixed_voltage(snk_pdo[i-1]));
> > +   else
> > +   min_mv = max(min_mv, pdo_max_voltage(snk_pdo[i-1]));
> > +   ma = min(ma, 1000 * mw / min_mv);
> > +
> > +   /* Insert the new pdo to the end */
> > +   chip->snk_pdo[i] = PDO_VAR(min_mv, mv, ma);
> > +
> > +   return i+1;
> > +}
> > +
> >   static int fusb302_probe(struct i2c_client *client,
> >  const struct i2c_device_id *id)
> >   {
> > @@ -1784,18 +1812,13 @@ static int fusb302_probe(struct i2c_client *client,
> > chip->tcpc_dev.config = &chip->tcpc_config;
> > mutex_init(&chip->lock);
> >
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", &v))
> > -   chip->tcpc_config.max_snk_mv = v / 1000;
> > -
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microamp", &v))
> > -   chip->tcpc_config.max_snk_ma = v / 1000;
> > -
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", &v))
> > -   chip->tcpc_config.max_snk_mw = v / 1000;
> > -
> > if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", &v))
> > chip->tcpc_config.operating_snk_mw = v / 1000;
> >
> > +   /* Composite sink PDO */
> > +   chip->tcp

Re: Not enough bandwidth with Magewell XI100DUSB-HDMI

2018-04-09 Thread Michael Tretter
On Tue, 20 Feb 2018 15:29:28 +0200, Mathias Nyman wrote:
> On 16.02.2018 15:28, Michael Tretter wrote:
> > On Mon, 29 Jan 2018 14:02:57 +0200, Mathias Nyman wrote:  
> >> On 19.01.2018 22:12, Philipp Zabel wrote:  
> >>> On Fri, Jan 19, 2018 at 2:10 PM, Michael Tretter
> >>>  wrote:  
>  I found the old thread and it sounds exactly like my issue. Different
>  camera, but same xHCI controller.  
> >>>
> >>> I have exactly the same issue with the xHCI controller of my laptop and
> >>> "Oculus Sensor" USB3 isochronous mostly-UVC cameras:
> >>>
> >>> 00:14.0 USB controller: Intel Corporation Wildcat Point-LP USB xHCI
> >>> Controller (rev 03) (prog-if 30 [XHCI])
> >>>   Subsystem: Lenovo Wildcat Point-LP USB xHCI Controller
> >>>   Flags: bus master, medium devsel, latency 0, IRQ 44
> >>>   Memory at f222 (64-bit, non-prefetchable) [size=64K]
> >>>   Capabilities: [70] Power Management version 2
> >>>   Capabilities: [80] MSI: Enable+ Count=1/8 Maskable- 64bit+
> >>>   Kernel driver in use: xhci_hcd
> >>>   Kernel modules: xhci_pci
> >>>
> >>> T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=5000 MxCh= 0
> >>> D:  Ver= 3.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs=  1
> >>> P:  Vendor=2833 ProdID=0211 Rev= 0.00
> >>> S:  Manufacturer=Oculus VR
> >>> S:  Product=Rift Sensor
> >>> S:  SerialNumber=WMTD3034300BCT
> >>> C:* #Ifs= 2 Cfg#= 1 Atr=80 MxPwr=800mA
> >>> A:  FirstIf#= 0 IfCount= 2 Cls=ff(vend.) Sub=03 Prot=00
> >>> I:* If#= 0 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=01 Prot=00 Driver=uvcvideo
> >>> E:  Ad=83(I) Atr=03(Int.) MxPS=  32 Ivl=128ms
> >>> I:* If#= 1 Alt= 0 #EPs= 0 Cls=ff(vend.) Sub=02 Prot=00 Driver=uvcvideo
> >>> I:  If#= 1 Alt= 1 #EPs= 1 Cls=ff(vend.) Sub=02 Prot=00 Driver=uvcvideo
> >>> E:  Ad=81(I) Atr=05(Isoc) MxPS=1024 Ivl=125us
> >>> I:  If#= 1 Alt= 2 #EPs= 1 Cls=ff(vend.) Sub=02 Prot=00 Driver=uvcvideo
> >>> E:  Ad=81(I) Atr=05(Isoc) MxPS=1024 Ivl=125us
> >>>
> >>> Any USB2 or USB3 device that I plug in while the first camera is 
> >>> streaming in
> >>> altsetting 1 or 2 causes the bandwidth error. The same happens when I try 
> >>> to
> >>> change the altsetting on an isochronous endpoint of an already plugged 
> >>> device.
> >>> While the camera is in altsetting 0, other devices can be probed and work.
> >>>  
>  For some tests, I changed the xhci_change_max_exit_latency() function
>  to ignore the requested MEL and set the MEL to 0. Now the USB devices
>  are detected correctly.  
> >>>
> >>> Exactly the same thing helps here, as well. With this hack, streaming 
> >>> from two
> >>> of those cameras at the same time works without any apparent problem:
> >>>
> >>> --8<--
> >>> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> >>> index 297536c9fd00..3cb4a60d8822 100644
> >>> --- a/drivers/usb/host/xhci.c
> >>> +++ b/drivers/usb/host/xhci.c
> >>> @@ -4025,7 +4025,7 @@ static int __maybe_unused
> >>> xhci_change_max_exit_latency(struct xhci_hcd *xhci,
> >>>   ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG);
> >>>   slot_ctx = xhci_get_slot_ctx(xhci, command->in_ctx);
> >>>   slot_ctx->dev_info2 &= cpu_to_le32(~((u32) MAX_EXIT));
> >>> -   slot_ctx->dev_info2 |= cpu_to_le32(max_exit_latency);
> >>> +   slot_ctx->dev_info2 |= cpu_to_le32(0);
> >>>   slot_ctx->dev_state = 0;
> >>>
> >>>   xhci_dbg_trace(xhci, trace_xhci_dbg_context_change,  
> >>> -->8--  
> >>>  
> >>
> >> Ok, back after a week on sickleave.
> >> I'm getting the magewell capture device and try to reproduce this myself.  
> > 
> > I don't think that the issue is specific to the magewell capture
> > device, but rather should be reproducible with any USB3 device with
> > isochronous endpoints.
> > 
> > Anyway, please tell me, if I can somehow help you to get this properly
> > fixed.  
> 
> I'm currently looking at device reset issues after suspend, but this is on the
> todo list.
> 
> I got a magewell device, (haven't unboxed it yet)
> Maybe step by step instructions to reproduce it could speed things up.

Did you have time to unbox and test the Magewell device?

Michael
--
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] usb: typec: ucsi: fix tracepoint related build error

2018-04-09 Thread Tobias Regnery
The ucsi driver defines several tracepoints, but the header file with the
tracepoint definition trace.h is only conditionally built depending on
CONFIG_FTRACE.

This leads to the following build error with CONFIG_FTRACE=n and
CONFIG_TYPEC_UCSI=m:

ERROR: "__tracepoint_ucsi_command" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
undefined!
ERROR: "__tracepoint_ucsi_register_port" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
undefined!
ERROR: "__tracepoint_ucsi_notify" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
undefined!
ERROR: "__tracepoint_ucsi_reset_ppm" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
undefined!
ERROR: "__tracepoint_ucsi_run_command" [drivers/usb/typec/ucsi/typec_ucsi.ko] 
undefined!
ERROR: "__tracepoint_ucsi_ack" [drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!
ERROR: "__tracepoint_ucsi_connector_change" 
[drivers/usb/typec/ucsi/typec_ucsi.ko] undefined!

With CONFIG_TYPEC_UCSI=y the build fails with several link errors.

Fix this by changing the Makefile to unconditionally build trace.o.
Tracepints are a runtime contruct and no other user of tracepoints depends
on CONFIG_FTRACE.

Fixes: c1b0bc2dabfa ("usb: typec: Add support for UCSI interface")
Signed-off-by: Tobias Regnery 
---
 drivers/usb/typec/ucsi/Makefile | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile
index b57891c1fd31..971befbbc2a8 100644
--- a/drivers/usb/typec/ucsi/Makefile
+++ b/drivers/usb/typec/ucsi/Makefile
@@ -3,8 +3,6 @@ CFLAGS_trace.o  := -I$(src)
 
 obj-$(CONFIG_TYPEC_UCSI)   += typec_ucsi.o
 
-typec_ucsi-y   := ucsi.o
-
-typec_ucsi-$(CONFIG_FTRACE)+= trace.o
+typec_ucsi-y   := ucsi.o trace.o
 
 obj-$(CONFIG_UCSI_ACPI)+= ucsi_acpi.o
-- 
2.16.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] usb: gadget: udc-xilinx: Add clock support

2018-04-09 Thread Felipe Balbi

Hi,

shubhrajyoti.da...@gmail.com writes:
> From: Shubhrajyoti Datta 
>
> Currently the driver depends on the  bootloader to enable the clocks.
> Add support for clocking. The patch enables the clock at  probe and
> disables them at remove.
>
> Signed-off-by: Shubhrajyoti Datta 

which platform uses this? Isn't zynq using the chipidea core? Why don't
you switch this board to the generic chipidea driver instead?

-- 
balbi


signature.asc
Description: PGP signature


RE: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink config

2018-04-09 Thread Jun Li
Hi
> -Original Message-
> From: Hans de Goede [mailto:hdego...@redhat.com]
> Sent: 2018年4月3日 23:26
> To: Jun Li ; gre...@linuxfoundation.org; robh...@kernel.org;
> mark.rutl...@arm.com; heikki.kroge...@linux.intel.com
> Cc: li...@roeck-us.net; rmf...@gmail.com; yueyao@gmail.com;
> linux-usb@vger.kernel.org; devicet...@vger.kernel.org; dl-linux-imx
> 
> Subject: Re: [PATCH v2 2/5] usb: typec: fusb302: remove max_snk_* for sink
> config
> 
> Hi,
> 
> On 23-03-18 15:58, Li Jun wrote:
> > Since max_snk_* is to be deprecated, so remove max_snk_* by adding a
> > variable PDO for sink config.
> >
> > Signed-off-by: Li Jun 
> > ---
> >   drivers/usb/typec/fusb302/fusb302.c | 51
> +++--
> >   1 file changed, 37 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/usb/typec/fusb302/fusb302.c
> > b/drivers/usb/typec/fusb302/fusb302.c
> > index 7036171..db4d9cd 100644
> > --- a/drivers/usb/typec/fusb302/fusb302.c
> > +++ b/drivers/usb/typec/fusb302/fusb302.c
> > @@ -120,6 +120,7 @@ struct fusb302_chip {
> > enum typec_cc_polarity cc_polarity;
> > enum typec_cc_status cc1;
> > enum typec_cc_status cc2;
> > +   u32 snk_pdo[PDO_MAX_OBJECTS];
> >
> >   #ifdef CONFIG_DEBUG_FS
> > struct dentry *dentry;
> > @@ -1212,11 +1213,6 @@ static const u32 snk_pdo[] = {
> >   static const struct tcpc_config fusb302_tcpc_config = {
> > .src_pdo = src_pdo,
> > .nr_src_pdo = ARRAY_SIZE(src_pdo),
> > -   .snk_pdo = snk_pdo,
> > -   .nr_snk_pdo = ARRAY_SIZE(snk_pdo),
> > -   .max_snk_mv = 5000,
> > -   .max_snk_ma = 3000,
> > -   .max_snk_mw = 15000,
> > .operating_snk_mw = 2500,
> > .type = TYPEC_PORT_DRP,
> > .data = TYPEC_PORT_DRD,
> > @@ -1756,6 +1752,38 @@ static int init_gpio(struct fusb302_chip *chip)
> > return 0;
> >   }
> >
> > +static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip)
> > +{
> > +   struct device *dev = chip->dev;
> > +   u32 mv, ma, mw, min_mv;
> > +   unsigned int i;
> > +
> > +   /* Copy the static snk pdo */
> > +   for (i = 0; i < ARRAY_SIZE(snk_pdo); i++)
> > +   chip->snk_pdo[i] = snk_pdo[i];
> 
> The static snk PDO is constant and only contains:
>   PDO_FIXED(5000, 400, PDO_FIXED_FLAGS),
> 
> So you can just do:
> 
>   chip->snk_pdo[0] = PDO_FIXED(5000, 400, PDO_FIXED_FLAGS);
> 
> Here.
> 
> > +
> > +   if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &mv) ||
> > +   device_property_read_u32(dev, "fcs,max-sink-microamp", &ma) ||
> > +   device_property_read_u32(dev, "fcs,max-sink-microwatt", &mw))
> 
> You can drop the reading of "fcs,max-sink-microwatt" here, it was only ever
> added because the tcpm code used to depend on max_mw being set, now that
> that is no longer the case, we don't need it.
> 
> So this entire function can be simplified to:
> 
> static int fusb302_composite_snk_pdo_array(struct fusb302_chip *chip) {
>   struct device *dev = chip->dev;
>   u32 max_uv, max_ua;
> 
>   chip->snk_pdo[0] = PDO_FIXED(5000, 400, PDO_FIXED_FLAGS);
> 
>   if (device_property_read_u32(dev, "fcs,max-sink-microvolt", &max_uv) ||
>   device_property_read_u32(dev, "fcs,max-sink-microamp", &max_ua))
>   return 1;
> 
>   chip->snk_pdo[1] = PDO_VAR(5000, max_uv / 1000, max_ua / 1000);
>   return 2;
> }

OK, I will change in v3.

Thanks
Jun

> 
> > @@ -1784,18 +1812,13 @@ static int fusb302_probe(struct i2c_client *client,
> > chip->tcpc_dev.config = &chip->tcpc_config;
> > mutex_init(&chip->lock);
> >
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microvolt", &v))
> > -   chip->tcpc_config.max_snk_mv = v / 1000;
> > -
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microamp", &v))
> > -   chip->tcpc_config.max_snk_ma = v / 1000;
> > -
> > -   if (!device_property_read_u32(dev, "fcs,max-sink-microwatt", &v))
> > -   chip->tcpc_config.max_snk_mw = v / 1000;
> > -
> > if (!device_property_read_u32(dev, "fcs,operating-sink-microwatt", &v))
> > chip->tcpc_config.operating_snk_mw = v / 1000;
> >
> > +   /* Composite sink PDO */
> > +   chip->tcpc_config.nr_snk_pdo = fusb302_composite_snk_pdo_array(chip);
> > +   chip->tcpc_config.snk_pdo = chip->snk_pdo;
> > +
> > /*
> >  * Devicetree platforms should get extcon via phandle (not yet
> >  * supported). On ACPI platforms, we get the name from a device prop.
> >
> 
> Regards,
> 
> Hans