Re: [PATCH v5 1/1] usb:host:xhci support option to disable the xHCI USB2 HW LPM

2017-08-16 Thread Thang Q. Nguyen
On Tue, Aug 8, 2017 at 11:27 AM, Thang Q. Nguyen  wrote:
> XHCI specification 1.1 does not require xHCI-compliant controllers
> to always enable hardware USB2 LPM. However, the current xHCI
> driver always enable it when seeing HLC=1.
> This patch supports an option for users to control disabling
> USB2 Hardware LPM via DT/ACPI attribute.
> This option is needed in case user would like to disable this
> feature. For example, their xHCI controller has its USB2 HW LPM
> broken.
>
> Signed-off-by: Tung Nguyen 
> Signed-off-by: Thang Q. Nguyen 
> Acked-by: Rob Herring 
> ---
> Changes since v4:
>  - When HW LPM is optionally disabled, explicitly disable HLE, RWE, ...
>  - Update codes to work with kernel 4.13-rc4
>  - Add Acked-By from Rob Herring 
> Changes since v3:
>  - Bypass updating LPM parameters when HW LPM is optionally disabled.
> Changes since v2:
>  - Change code to disable HW LPM as an option for user which
>is set via ACPI/DT.
> Changes since v1:
>  - Update DT/ACPI attribute and corresponding codes from HLE to LPM to
>be consistent with other attribute names.
> ---
>  Documentation/devicetree/bindings/usb/usb-xhci.txt |1 +
>  drivers/usb/host/xhci-plat.c   |3 +++
>  drivers/usb/host/xhci.c|2 +-
>  drivers/usb/host/xhci.h|1 +
>  4 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/usb/usb-xhci.txt 
> b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> index 2d80b60..ae6e484 100644
> --- a/Documentation/devicetree/bindings/usb/usb-xhci.txt
> +++ b/Documentation/devicetree/bindings/usb/usb-xhci.txt
> @@ -26,6 +26,7 @@ Required properties:
>
>  Optional properties:
>- clocks: reference to a clock
> +  - usb2-lpm-disable: indicate if we don't want to enable USB2 HW LPM
>- usb3-lpm-capable: determines if platform is USB3 LPM capable
>- quirk-broken-port-ped: set if the controller has broken port disable 
> mechanism
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index c04144b..9028fb5 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -267,6 +267,9 @@ static int xhci_plat_probe(struct platform_device *pdev)
> goto disable_clk;
> }
>
> +   if (device_property_read_bool(sysdev, "usb2-lpm-disable"))
> +   xhci->quirks |= XHCI_HW_LPM_DISABLE;
> +
> if (device_property_read_bool(sysdev, "usb3-lpm-capable"))
> xhci->quirks |= XHCI_LPM_SUPPORT;
>
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index b2ff1ff..3a8e75f 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -4087,7 +4087,7 @@ static int xhci_set_usb2_hardware_lpm(struct usb_hcd 
> *hcd,
> xhci_dbg(xhci, "%s port %d USB2 hardware LPM\n",
> enable ? "enable" : "disable", port_num + 1);
>
> -   if (enable) {
> +   if (enable && !(xhci->quirks & XHCI_HW_LPM_DISABLE)) {
> /* Host supports BESL timeout instead of HIRD */
> if (udev->usb2_hw_lpm_besl_capable) {
> /* if device doesn't have a preferred BESL value use a
> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> index e3e9352..5d89c51 100644
> --- a/drivers/usb/host/xhci.h
> +++ b/drivers/usb/host/xhci.h
> @@ -1821,6 +1821,7 @@ struct xhci_hcd {
>  #define XHCI_LIMIT_ENDPOINT_INTERVAL_7 (1 << 26)
>  #define XHCI_U2_DISABLE_WAKE   (1 << 27)
>  #define XHCI_ASMEDIA_MODIFY_FLOWCONTROL(1 << 28)
> +#define XHCI_HW_LPM_DISABLE(1 << 29)
>
> unsigned intnum_active_eps;
> unsigned intlimit_active_eps;
> --
> 1.7.1
>

Do you have any comments about this patch? Thanks.
--
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: Identifying Synopsys USB3 Controller on Baytrail Device

2017-08-16 Thread Joseph Kogut
Hi,

On Mon, Oct 31, 2016 at 12:57 AM, Felipe Balbi
 wrote:
>
> Hi,
>
> Joseph Kogut  writes:
>> Well, after comparing the kernel log from both systems, it seems that
>> the device controller simply isn't being enumerated by the kernel for
>> some reason.
>>
>> Here's the relevant section from the Android kernel:
>>
>> <6>[0.612857] PCI host bridge to bus :00
>> <6>[0.612869] pci_bus :00: root bus resource [bus 00-ff]
>> <6>[0.612877] pci_bus :00: root bus resource [io  0x-0x006f]
>> <6>[0.612885] pci_bus :00: root bus resource [io  0x0078-0x0cf7]
>> <6>[0.612893] pci_bus :00: root bus resource [io  0x0d00-0x]
>> <6>[0.612900] pci_bus :00: root bus resource [mem 
>> 0x000a-0x000b]
>> <6>[0.612908] pci_bus :00: root bus resource [mem 
>> 0x000c-0x000d]
>> <6>[0.612915] pci_bus :00: root bus resource [mem 
>> 0x000e-0x000f]
>> <6>[0.612923] pci_bus :00: root bus resource [mem 
>> 0x7d01-0x7f00]
>> <6>[0.612931] pci_bus :00: root bus resource [mem 
>> 0x8000-0x90ee]
>> <6>[0.612938] pci_bus :00: root bus resource [mem 
>> 0xfed4-0xfed40fff]
>> <7>[0.612960] pci :00:00.0: [8086:0f00] type 00 class 0x06
>> <7>[0.613276] pci :00:02.0: [8086:0f31] type 00 class 0x03
>> <7>[0.613304] pci :00:02.0: reg 10: [mem 0x9040-0x907f]
>> <7>[0.613326] pci :00:02.0: reg 18: [mem 0x8000-0x8fff pref]
>> <7>[0.613346] pci :00:02.0: reg 20: [io  0x1000-0x1007]
>> <7>[0.613672] pci :00:03.0: [8086:0f38] type 00 class 0x048000
>> <7>[0.613696] pci :00:03.0: reg 10: [mem 0x9000-0x903f]
>> <7>[0.614052] pci :00:14.0: [8086:0f35] type 00 class 0x0c0330
>> <7>[0.614087] pci :00:14.0: reg 10: [mem 0x90e0-0x90e0 64bit]
>> <7>[0.614179] pci :00:14.0: PME# supported from D3hot D3cold
>> <7>[0.614473] pci :00:16.0: [8086:0f37] type 00 class 0x0c0380
>> <6>[0.614488] EM:OEM1  table found, size=64
>> <6>[0.614493] OEM1 charging bit = 1
>> <7>[0.614514] pci :00:16.0: reg 10: [mem 0x9080-0x909f]
>> <7>[0.614530] pci :00:16.0: reg 14: [mem 0x90e2e000-0x90e2efff]
>> <7>[0.614611] pci :00:16.0: PME# supported from D0 D3hot
>> <7>[0.614916] pci :00:1a.0: [8086:0f18] type 00 class 0x108000
>> <7>[0.614957] pci :00:1a.0: reg 10: [mem 0x90d0-0x90df]
>> <7>[0.614979] pci :00:1a.0: reg 14: [mem 0x90c0-0x90cf]
>> <7>[0.615118] pci :00:1a.0: PME# supported from D0 D3hot
>> <7>[0.615416] pci :00:1f.0: [8086:0f1c] type 00 class 0x060100
>> <7>[ 0.615775] pci_bus :00: on NUMA node 0
>>
>> As you can see, our device controller is recognized and enumerated in
>> Android. I suppose this explains why it works there. :)
>>
>> Here's the relevant section from the mainline kernel:
>>
>> [0.636189] PCI host bridge to bus :00
>> [0.636196] pci_bus :00: root bus resource [io  0x0070-0x0077]
>> [0.636201] pci_bus :00: root bus resource [io  0x-0x006f window]
>> [0.636205] pci_bus :00: root bus resource [io  0x0078-0x0cf7 window]
>> [0.636209] pci_bus :00: root bus resource [io  0x0d00-0x window]
>> [0.636213] pci_bus :00: root bus resource [mem
>> 0x000a-0x000b window]
>> [0.636217] pci_bus :00: root bus resource [mem
>> 0x000c-0x000d window]
>> [0.636221] pci_bus :00: root bus resource [mem
>> 0x000e-0x000f window]
>> [0.636225] pci_bus :00: root bus resource [mem
>> 0x90c0-0x90ff window]
>> [0.636228] pci_bus :00: root bus resource [mem
>> 0x7cf1-0x7ef0 window]
>> [0.636232] pci_bus :00: root bus resource [mem
>> 0x8000-0x908e window]
>> [0.636236] pci_bus :00: root bus resource [mem
>> 0xfed4-0xfed40fff window]
>> [0.636241] pci_bus :00: root bus resource [bus 00-ff]
>> [0.636258] pci :00:00.0: [8086:0f00] type 00 class 0x06
>> [0.636608] pci :00:02.0: [8086:0f31] type 00 class 0x03
>> [0.636627] pci :00:02.0: reg 0x10: [mem 0x9000-0x903f]
>> [0.636644] pci :00:02.0: reg 0x18: [mem 0x8000-0x8fff pref]
>> [0.636659] pci :00:02.0: reg 0x20: [io  0x1000-0x1007]
>> [0.637019] pci :00:14.0: [8086:0f35] type 00 class 0x0c0330
>> [0.637045] pci :00:14.0: reg 0x10: [mem 0x9080-0x9080 64bit]
>> [0.637128] pci :00:14.0: PME# supported from D3hot D3cold
>> [0.637451] pci :00:1a.0: [8086:0f18] type 00 class 0x108000
>> [0.637477] pci :00:1a.0: reg 0x10: [mem 0x9070-0x907f]
>> [0.637491] pci :00:1a.0: reg 0x14: [mem 0x9060-0x906f]
>> [0.637596] pci :00:1a.0: PME# supported from D0 D3hot
>> [0.637915] pci :00:1f.0: [8086:0f1c] type 00 class 0x060100
>> [ 

[PATCH v4 0/5] usb: xhci: Handle USB transaction error on address command

2017-08-16 Thread Lu Baolu
Xhci driver handles USB transaction errors on transfer events,
but transaction errors are possible on address device command
completion events as well.

The xHCI specification (section 4.6.5) says: A USB Transaction
Error Completion Code for an Address Device Command may be due
to a Stall response from a device. Software should issue a Disable
Slot Command for the Device Slot then an Enable Slot Command to
recover from this error.

The related discussion threads can be found through below links.

http://marc.info/?l=linux-usb=149362010728921=2
http://marc.info/?l=linux-usb=149252752825755=2

This patch set includes some fixes in xhci_disable_slot() as well
which will be used to handle USB transaction error on address
command.

---
Change log:

v1->v2:
 - Add 4 fixes in xhci_disable_slot which will be used
   to handle USB transaction error on address command.

v2->v3:
 - Add checking virt dev for test mode in PATCH 1/5.

v3->v4:
 - Resolve xhci->mutex locking issue in 5/5.

Lu Baolu (5):
  usb: xhci: Disable slot even virt-dev is null
  usb: xhci: Fix potential memory leak in xhci_disable_slot()
  usb: xhci: Fix memory leak when xhci_disable_slot() returns error
  usb: xhci: Return error when host is dead in xhci_disable_slot()
  usb: xhci: Handle USB transaction error on address command

 drivers/usb/host/xhci-hub.c |  5 -
 drivers/usb/host/xhci.c | 54 +++--
 drivers/usb/host/xhci.h |  3 +--
 3 files changed, 28 insertions(+), 34 deletions(-)

-- 
2.7.4

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


[PATCH v4 2/5] usb: xhci: Fix potential memory leak in xhci_disable_slot()

2017-08-16 Thread Lu Baolu
xhci_disable_slot() allows the invoker to pass a command pointer
as paramenter. Otherwise, it will allocate one. This will cause
memory leak when a command structure was allocated inside of this
function while queuing command trb fails. Another problem comes up
when the invoker passed a command pointer, but xhci_disable_slot()
frees it when it detects a dead host.

This patch fixes these two problems by removing the command parameter
from xhci_disable_slot().

Fixes: f9e609b82479 ("usb: xhci: Add helper function xhci_disable_slot().")
Cc: Guoqing Zhang 
Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci-hub.c |  2 +-
 drivers/usb/host/xhci.c | 30 +-
 drivers/usb/host/xhci.h |  3 +--
 3 files changed, 11 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 6fcb98d..daaf155 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -615,7 +615,7 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci,
if (!xhci->devs[i])
continue;
 
-   retval = xhci_disable_slot(xhci, NULL, i);
+   retval = xhci_disable_slot(xhci, i);
if (retval)
xhci_err(xhci, "Failed to disable slot %d, %d. Enter 
test mode anyway\n",
 i, retval);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index e69073f..cb2461a 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3519,11 +3519,6 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
struct xhci_virt_device *virt_dev;
struct xhci_slot_ctx *slot_ctx;
int i, ret;
-   struct xhci_command *command;
-
-   command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
-   if (!command)
-   return;
 
 #ifndef CONFIG_USB_DEFAULT_PERSIST
/*
@@ -3539,10 +3534,8 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
/* If the host is halted due to driver unload, we still need to free the
 * device.
 */
-   if (ret <= 0 && ret != -ENODEV) {
-   kfree(command);
+   if (ret <= 0 && ret != -ENODEV)
return;
-   }
 
virt_dev = xhci->devs[udev->slot_id];
slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->out_ctx);
@@ -3554,22 +3547,21 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
del_timer_sync(_dev->eps[i].stop_cmd_timer);
}
 
-   xhci_disable_slot(xhci, command, udev->slot_id);
+   xhci_disable_slot(xhci, udev->slot_id);
/*
 * Event command completion handler will free any data structures
 * associated with the slot.  XXX Can free sleep?
 */
 }
 
-int xhci_disable_slot(struct xhci_hcd *xhci, struct xhci_command *command,
-   u32 slot_id)
+int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
 {
+   struct xhci_command *command;
unsigned long flags;
u32 state;
int ret = 0;
 
-   if (!command)
-   command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
+   command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
if (!command)
return -ENOMEM;
 
@@ -3588,7 +3580,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, struct 
xhci_command *command,
slot_id);
if (ret) {
spin_unlock_irqrestore(>lock, flags);
-   xhci_dbg(xhci, "FIXME: allocate a command ring segment\n");
+   kfree(command);
return ret;
}
xhci_ring_cmd_db(xhci);
@@ -3663,6 +3655,8 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device 
*udev)
return 0;
}
 
+   xhci_free_command(xhci, command);
+
if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK)) {
spin_lock_irqsave(>lock, flags);
ret = xhci_reserve_host_control_ep_resources(xhci);
@@ -3698,18 +3692,12 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
pm_runtime_get_noresume(hcd->self.controller);
 #endif
 
-
-   xhci_free_command(xhci, command);
/* Is this a LS or FS device under a HS hub? */
/* Hub or peripherial? */
return 1;
 
 disable_slot:
-   /* Disable slot, if we can do it without mem alloc */
-   kfree(command->completion);
-   command->completion = NULL;
-   command->status = 0;
-   return xhci_disable_slot(xhci, command, udev->slot_id);
+   return xhci_disable_slot(xhci, udev->slot_id);
 }
 
 /*
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index e3e9352..6325d58 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2003,8 +2003,7 @@ int xhci_run(struct usb_hcd *hcd);
 int xhci_gen_setup(struct 

[PATCH v4 1/5] usb: xhci: Disable slot even virt-dev is null

2017-08-16 Thread Lu Baolu
xhci_disable_slot() is a helper for disabling a slot when a device
goes away or recovers from error situations. Currently, it checks
the corespoding virt-dev pointer and returns directly (w/o issuing
disable slot command) if it's null.

This is unnecessary and will cause problems in case where virt-dev
allocation fails and xhci_disable_slot() is called to roll back the
hardware state. Refer to the implementation of xhci_alloc_dev().

This patch removes lines to check virt-dev in xhci_disable_slot().

Fixes: f9e609b82479 ("usb: xhci: Add helper function xhci_disable_slot().")
Cc: Guoqing Zhang 
Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci-hub.c | 3 +++
 drivers/usb/host/xhci.c | 4 
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 00721e8..6fcb98d 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -612,6 +612,9 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci,
xhci_dbg(xhci, "Disable all slots\n");
spin_unlock_irqrestore(>lock, *flags);
for (i = 1; i <= HCS_MAX_SLOTS(xhci->hcs_params1); i++) {
+   if (!xhci->devs[i])
+   continue;
+
retval = xhci_disable_slot(xhci, NULL, i);
if (retval)
xhci_err(xhci, "Failed to disable slot %d, %d. Enter 
test mode anyway\n",
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index b2ff1ff..e69073f 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3567,11 +3567,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, struct 
xhci_command *command,
unsigned long flags;
u32 state;
int ret = 0;
-   struct xhci_virt_device *virt_dev;
 
-   virt_dev = xhci->devs[slot_id];
-   if (!virt_dev)
-   return -EINVAL;
if (!command)
command = xhci_alloc_command(xhci, false, false, GFP_KERNEL);
if (!command)
-- 
2.7.4

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


[PATCH v4 3/5] usb: xhci: Fix memory leak when xhci_disable_slot() returns error

2017-08-16 Thread Lu Baolu
If xhci_disable_slot() returns success, a disable slot command
trb was queued in the command ring. The command completion
handler will free the virtual device data structure associated
with the slot. On the other hand, when xhci_disable_slot()
returns error, the invokers should take the responsibilities to
free the slot related data structure. Otherwise, memory leakage
happens.

Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci.c | 14 --
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index cb2461a..2df601e 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3547,11 +3547,9 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
del_timer_sync(_dev->eps[i].stop_cmd_timer);
}
 
-   xhci_disable_slot(xhci, udev->slot_id);
-   /*
-* Event command completion handler will free any data structures
-* associated with the slot.  XXX Can free sleep?
-*/
+   ret = xhci_disable_slot(xhci, udev->slot_id);
+   if (ret)
+   xhci_free_virt_device(xhci, udev->slot_id);
 }
 
 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
@@ -3697,7 +3695,11 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
return 1;
 
 disable_slot:
-   return xhci_disable_slot(xhci, udev->slot_id);
+   ret = xhci_disable_slot(xhci, udev->slot_id);
+   if (ret)
+   xhci_free_virt_device(xhci, udev->slot_id);
+
+   return 0;
 }
 
 /*
-- 
2.7.4

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


[PATCH v4 5/5] usb: xhci: Handle USB transaction error on address command

2017-08-16 Thread Lu Baolu
Xhci driver handles USB transaction errors on transfer events,
but transaction errors are possible on address device command
completion events as well.

The xHCI specification (section 4.6.5) says: A USB Transaction
Error Completion Code for an Address Device Command may be due
to a Stall response from a device. Software should issue a Disable
Slot Command for the Device Slot then an Enable Slot Command to
recover from this error.

This patch handles USB transaction errors on address command
completion events. The related discussion threads can be found
through below links.

http://marc.info/?l=linux-usb=149362010728921=2
http://marc.info/?l=linux-usb=149252752825755=2

Suggested-by: Mathias Nyman 
Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index d6b728d..c8a64d2 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3822,6 +3822,13 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct 
usb_device *udev,
break;
case COMP_USB_TRANSACTION_ERROR:
dev_warn(>dev, "Device not responding to setup %s.\n", 
act);
+
+   mutex_unlock(>mutex);
+   ret = xhci_disable_slot(xhci, udev->slot_id);
+   if (!ret)
+   xhci_alloc_dev(hcd, udev);
+   mutex_lock(>mutex);
+
ret = -EPROTO;
break;
case COMP_INCOMPATIBLE_DEVICE_ERROR:
-- 
2.7.4

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


[PATCH v4 4/5] usb: xhci: Return error when host is dead in xhci_disable_slot()

2017-08-16 Thread Lu Baolu
xhci_disable_slot() is a helper for disabling a slot when a device
goes away or recovers from error situations. Currently, it returns
success when it sees a dead host. This is not the right way to go.
It should return error and let the invoker know that disable slot
command was failed due to a dead host.

Fixes: f9e609b82479 ("usb: xhci: Add helper function xhci_disable_slot().")
Cc: Guoqing Zhang 
Signed-off-by: Lu Baolu 
---
 drivers/usb/host/xhci.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 2df601e..d6b728d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3568,10 +3568,9 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
state = readl(>op_regs->status);
if (state == 0x || (xhci->xhc_state & XHCI_STATE_DYING) ||
(xhci->xhc_state & XHCI_STATE_HALTED)) {
-   xhci_free_virt_device(xhci, slot_id);
spin_unlock_irqrestore(>lock, flags);
kfree(command);
-   return ret;
+   return -ENODEV;
}
 
ret = xhci_queue_slot_control(xhci, command, TRB_DISABLE_SLOT,
-- 
2.7.4

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


Re: [PATCH 7/9] xhci: add port status tracing

2017-08-16 Thread Greg KH
On Wed, Aug 16, 2017 at 04:10:00PM +0300, Mathias Nyman wrote:
> On 16.08.2017 14:45, Felipe Balbi wrote:
> > 
> > Hi,
> > 
> > Mathias Nyman  writes:
> > > Track the port status in a human readble way each time we get a
> > > port status change event
> > > 
> > > Signed-off-by: Mathias Nyman 
> > > ---
> > >   drivers/usb/host/xhci-ring.c  |  2 ++
> > >   drivers/usb/host/xhci-trace.h | 23 +++
> > >   2 files changed, 25 insertions(+)
> > > 
> > > diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> > > index 52a6650..a944365 100644
> > > --- a/drivers/usb/host/xhci-ring.c
> > > +++ b/drivers/usb/host/xhci-ring.c
> > > @@ -1638,6 +1638,8 @@ static void handle_port_status(struct xhci_hcd 
> > > *xhci,
> > >   port_id);
> > >   portsc = readl(port_array[faked_port_index]);
> > > 
> > > + trace_xhci_handle_port_status(faked_port_index, portsc);
> > > +
> > >   if (hcd->state == HC_STATE_SUSPENDED) {
> > >   xhci_dbg(xhci, "resume root hub\n");
> > >   usb_hcd_resume_root_hub(hcd);
> > > diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
> > > index 8ce96de..f20753b 100644
> > > --- a/drivers/usb/host/xhci-trace.h
> > > +++ b/drivers/usb/host/xhci-trace.h
> > > @@ -453,6 +453,29 @@
> > >   TP_PROTO(struct xhci_ring *ring),
> > >   TP_ARGS(ring)
> > >   );
> > > +
> > > +DECLARE_EVENT_CLASS(xhci_log_portsc,
> > > + TP_PROTO(u32 portnum, u32 portsc),
> > > + TP_ARGS(portnum, portsc),
> > > + TP_STRUCT__entry(
> > > +  __field(u32, portnum)
> > > +  __field(u32, portsc)
> > > +  ),
> > > + TP_fast_assign(
> > > +__entry->portnum = portnum;
> > > +__entry->portsc = portsc;
> > > +),
> > > + TP_printk("port-%d: %s",
> > 
> > this will give you "port-0" for a USB3 and USB2 roothub. How are you
> > going to differentiate between the two in a long trace?
> > 
> > you could pass hcd to the tracer, and extract hcd->speed to print out
> > something like "usb2-port-0: %s".
> > 
> 
> Seems like an improvement that could be done, but unless there is anything 
> else
> that needs fixing in this series I'd prefer to not respin/retest it this late
> in the rc

Just send a follow-on patch please.

thanks,

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


[PATCH v2 2/2] dt-bindings: usb: keystone-usb: Update bindings pm and clocks properties

2017-08-16 Thread Franklin S Cooper Jr
Update various properties to properly indicate their requirement depending
on the SoC.

Signed-off-by: Franklin S Cooper Jr 
---
Version 2:
Clarify clock requirements in binding document

 Documentation/devicetree/bindings/usb/keystone-usb.txt | 17 +++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/keystone-usb.txt 
b/Documentation/devicetree/bindings/usb/keystone-usb.txt
index 60527d3..2d1bef1 100644
--- a/Documentation/devicetree/bindings/usb/keystone-usb.txt
+++ b/Documentation/devicetree/bindings/usb/keystone-usb.txt
@@ -12,8 +12,21 @@ Required properties:
MPU.
  - ranges: allows valid 1:1 translation between child's address space and
parent's address space.
- - clocks: Clock IDs array as required by the controller.
- - clock-names: names of clocks correseponding to IDs in the clock property.
+
+SoC-specific Required Properties:
+The following are mandatory properties for Keystone 2 66AK2HK, 66AK2L and 
66AK2E
+SoCs only:
+
+- clocks:  Clock ID for USB functional clock.
+- clock-names: Must be "usb".
+
+
+The following are mandatory properties for Keystone 2 66AK2G SoCs only:
+
+- power-domains:   Should contain a phandle to a PM domain provider node
+   and an args specifier containing the USB device id
+   value. This property is as per the binding,
+   
Documentation/devicetree/bindings/soc/ti/sci-pm-domain.txt
 
 Sub-nodes:
 The dwc3 core should be added as subnode to Keystone DWC3 glue.
-- 
2.9.4.dirty

--
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/2] ARM: dts: k2g: Add support for USB instances on 66AK2G

2017-08-16 Thread Franklin S Cooper Jr
Add support for 66AK2G usb instances. However, the driver needs to be updated
to support PM_RUNTIME. This update has been validated to work on K2L and boot
tested on K2HK and K2E.

Version 2:
Clarify clock properties requirements in binding document

Franklin S Cooper Jr (2):
  usb: dwc3: keystone: Add PM_RUNTIME Support to DWC3 Keystone USB
driver
  dt-bindings: usb: keystone-usb: Update bindings pm and clocks
properties

 .../devicetree/bindings/usb/keystone-usb.txt   | 17 +++--
 drivers/usb/dwc3/dwc3-keystone.c   | 22 ++
 2 files changed, 25 insertions(+), 14 deletions(-)

-- 
2.9.4.dirty

--
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] usb: dwc3: keystone: Add PM_RUNTIME Support to DWC3 Keystone USB driver

2017-08-16 Thread Franklin S Cooper Jr
For 66AK2Gx there is a requirement to use PM Runtime to properly manage
clocks and the power domains. Therefore, add PM runtime support. Remove
legacy clock api's calls since other users of this driver worked without
these clock apis calls.

Signed-off-by: Franklin S Cooper Jr 
---
 drivers/usb/dwc3/dwc3-keystone.c | 22 ++
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c
index 12ee23f..d2ed952 100644
--- a/drivers/usb/dwc3/dwc3-keystone.c
+++ b/drivers/usb/dwc3/dwc3-keystone.c
@@ -15,7 +15,6 @@
  * GNU General Public License for more details.
  */
 
-#include 
 #include 
 #include 
 #include 
@@ -23,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* USBSS register offsets */
 #define USBSS_REVISION 0x
@@ -41,7 +41,6 @@
 
 struct dwc3_keystone {
struct device   *dev;
-   struct clk  *clk;
void __iomem*usbss;
 };
 
@@ -106,17 +105,13 @@ static int kdwc3_probe(struct platform_device *pdev)
if (IS_ERR(kdwc->usbss))
return PTR_ERR(kdwc->usbss);
 
-   kdwc->clk = devm_clk_get(kdwc->dev, "usb");
-   if (IS_ERR(kdwc->clk)) {
-   dev_err(kdwc->dev, "unable to get usb clock\n");
-   return PTR_ERR(kdwc->clk);
-   }
+   pm_runtime_enable(kdwc->dev);
 
-   error = clk_prepare_enable(kdwc->clk);
+   error = pm_runtime_get_sync(kdwc->dev);
if (error < 0) {
-   dev_err(kdwc->dev, "unable to enable usb clock, error %d\n",
+   dev_err(kdwc->dev, "pm_runtime_get_sync failed, error %d\n",
error);
-   return error;
+   goto err_irq;
}
 
irq = platform_get_irq(pdev, 0);
@@ -147,7 +142,8 @@ static int kdwc3_probe(struct platform_device *pdev)
 err_core:
kdwc3_disable_irqs(kdwc);
 err_irq:
-   clk_disable_unprepare(kdwc->clk);
+   pm_runtime_put_sync(kdwc->dev);
+   pm_runtime_disable(kdwc->dev);
 
return error;
 }
@@ -167,7 +163,9 @@ static int kdwc3_remove(struct platform_device *pdev)
 
kdwc3_disable_irqs(kdwc);
device_for_each_child(>dev, NULL, kdwc3_remove_core);
-   clk_disable_unprepare(kdwc->clk);
+   pm_runtime_put_sync(kdwc->dev);
+   pm_runtime_disable(kdwc->dev);
+
platform_set_drvdata(pdev, NULL);
 
return 0;
-- 
2.9.4.dirty

--
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: [RFCv2 usb-next 2/3] usb: host: add a generic platform USB roothub driver

2017-08-16 Thread Martin Blumenstingl
Hi,

On Tue, Jul 25, 2017 at 8:40 AM, Chunfeng Yun  wrote:
> On Thu, 2017-07-13 at 12:59 +0200, Martin Blumenstingl wrote:
>> Many SoC platforms have separate devices for the USB PHY which are
>> registered through the generic PHY framework. These PHYs have to be
>> enabled to make the USB controller actually work. They also have to be
>> disabled again on shutdown/suspend.
>>
>> Currently (at least) the following HCI platform drivers are using custom
>> code to obtain all PHYs via devicetree for the roothub/controller and
>> disable/enable them when required:
>> - ehci-platform.c has ehci_platform_power_{on,off}
>> - xhci-mtk.c has xhci_mtk_phy_{init,exit,power_on,power_off}
>> - ohci-platform.c has ohci_platform_power_{on,off}
>>
>> These drivers are not using the generic devicetree USB device bindings
>> yet which were only introduced recently (documentation is available in
>> devicetree/bindings/usb/usb-device.txt).
>> With this new driver the usb2-phy and usb3-phy can be specified directly
>> in the child-node of the corresponding port of the roothub via
>> devicetree. This can be extended by not just parsing PHYs (some of the
>> other drivers listed above are for example also parsing a list of clocks
>> as well) when required.
>>
>> Signed-off-by: Martin Blumenstingl 
>> ---
>>  drivers/usb/host/Kconfig|   3 +
>>  drivers/usb/host/Makefile   |   2 +
>>  drivers/usb/host/platform-roothub.c | 146 
>> 
>>  drivers/usb/host/platform-roothub.h |  14 
>>  4 files changed, 165 insertions(+)
>>  create mode 100644 drivers/usb/host/platform-roothub.c
>>  create mode 100644 drivers/usb/host/platform-roothub.h
>>
>> diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
>> index fa5692dec832..b8b05c786b2a 100644
>> --- a/drivers/usb/host/Kconfig
>> +++ b/drivers/usb/host/Kconfig
>> @@ -805,6 +805,9 @@ config USB_HCD_SSB
>>
>> If unsure, say N.
>>
>> +config USB_PLATFORM_ROOTHUB
>> + bool
>> +
>>  config USB_HCD_TEST_MODE
>>   bool "HCD test mode support"
>>   ---help---
>> diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
>> index cf2691fffcc0..dc817f82d632 100644
>> --- a/drivers/usb/host/Makefile
>> +++ b/drivers/usb/host/Makefile
>> @@ -29,6 +29,8 @@ obj-$(CONFIG_USB_WHCI_HCD)  += whci/
>>
>>  obj-$(CONFIG_USB_PCI)+= pci-quirks.o
>>
>> +obj-$(CONFIG_USB_PLATFORM_ROOTHUB)   += platform-roothub.o
>> +
>>  obj-$(CONFIG_USB_EHCI_HCD)   += ehci-hcd.o
>>  obj-$(CONFIG_USB_EHCI_PCI)   += ehci-pci.o
>>  obj-$(CONFIG_USB_EHCI_HCD_PLATFORM)  += ehci-platform.o
>> diff --git a/drivers/usb/host/platform-roothub.c 
>> b/drivers/usb/host/platform-roothub.c
>> new file mode 100644
>> index ..84837e42b006
>> --- /dev/null
>> +++ b/drivers/usb/host/platform-roothub.c
>> @@ -0,0 +1,146 @@
>> +/*
>> + * platform roothub driver - a virtual PHY device which passes all phy_*
>> + * function calls to multiple (actual) PHY devices. This is comes handy when
>> + * initializing all PHYs on a root-hub (to keep them all in the same state).
>> + *
>> + * Copyright (C) 2017 Martin Blumenstingl 
>> 
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program. If not, see .
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "platform-roothub.h"
>> +
>> +#define ROOTHUB_PORTNUM  0
>> +
>> +struct platform_roothub {
>> + struct phy  *phy;
>> + struct list_headlist;
>> +};
>> +
>> +static struct platform_roothub *platform_roothub_alloc(struct device *dev)
>> +{
>> + struct platform_roothub *roothub_entry;
>> +
>> + roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
>> + if (!roothub_entry)
>> + return ERR_PTR(-ENOMEM);
>> +
>> + INIT_LIST_HEAD(_entry->list);
>> +
>> + return roothub_entry;
>> +}
>> +
>> +static int platform_roothub_add_phy(struct device *dev,
>> + struct device_node *port_np,
>> + const char *con_id, struct list_head *list)
>> +{
>> + struct platform_roothub *roothub_entry;
>> + struct phy *phy = devm_of_phy_get(dev, port_np, con_id);
>> +
>> + if (IS_ERR_OR_NULL(phy)) {
>> + if (!phy || PTR_ERR(phy) == -ENODEV)
>> + return 0;
>> + else
>> + return PTR_ERR(phy);
>> + }
>> +
>> + roothub_entry = platform_roothub_alloc(dev);
>> + if (IS_ERR(roothub_entry))
>> + return PTR_ERR(roothub_entry);
>> +
>> + roothub_entry->phy 

Re: Inconsistency in usb_add_gadget_udc_release() interface

2017-08-16 Thread Alexey Khoroshilov
On 16.08.2017 18:24, Alan Stern wrote:
> On Wed, 16 Aug 2017, Alexey Khoroshilov wrote:
> 
>> Hello,
>>
>> usb_add_gadget_udc_release() gets release() argument that allows to
>> release user resources.
>>
>> As far as I can see, the release() is called on error paths 
>> of usb_add_gadget_udc_release() as a result of
>> put_device(>dev);
>> except for the only path going via err1.
>>
>> As a result a caller of the usb_add_gadget_udc_release() have no chance
>> to know if the release() was invoked or not.
>>
>> It may lead to memory leaks (drivers/usb/gadget/udc/snps_udc_core.c)
>> or to double free (drivers/usb/gadget/udc/fsl_udc_core.c).
>>
>> Is my reading correct? If so, should we always call release() on error paths?
> 
> How about this (untested)?
> 

It looks reasonable. I would only suggest also to make contract
description more explicit, e.g.

/**
 * usb_add_gadget_udc_release - adds a new gadget to the udc class
driver list
 * @parent: the parent device to this udc. Usually the controller driver's
 * device.
 * @gadget: the gadget to be added to the list.
 * @release: a gadget release function.
 *
 * Returns zero on success, negative errno otherwise.
+* Calls the gadget release function in the latter case.
 */

--
Alexey Khoroshilov
Linux Verification Center, ISPRAS
web: http://linuxtesting.org
--
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 v3] usb: serial: add vid:pid for Cypress WICED dev board

2017-08-16 Thread Greg KH
On Wed, Aug 16, 2017 at 05:07:26PM -0400, Jeffrey Chu wrote:
> Add CYPRESS_VID vid and CYPRESS_WICED_BT_USB and CYPRESS_WICED_WL_USB
> device IDs to ftdi_sio driver
> 
> Signed-off-by: Jeffrey Chu 
> ---
>  drivers/usb/serial/ftdi_sio.c | 2 ++
>  drivers/usb/serial/ftdi_sio_ids.h | 7 +++
>  2 files changed, 9 insertions(+)
> 
> diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
> index 1cec037..49d1b2d 100644
> --- a/drivers/usb/serial/ftdi_sio.c
> +++ b/drivers/usb/serial/ftdi_sio.c
> @@ -1015,6 +1015,8 @@ static const struct usb_device_id id_table_combined[] = 
> {
>   { USB_DEVICE(WICED_VID, WICED_USB20706V2_PID) },
>   { USB_DEVICE(TI_VID, TI_CC3200_LAUNCHPAD_PID),
>   .driver_info = (kernel_ulong_t)_jtag_quirk },
> + { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_BT_USB_PID) },
> + { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_WL_USB_PID) },
>   { } /* Terminating entry */
>  };

Whitespace is still corrupted :(

You have read the in-kernel documenation about how to fix your email
client, right?  If not, please do so.

thanks,

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


[PATCH v3] usb: serial: add vid:pid for Cypress WICED dev board

2017-08-16 Thread Jeffrey Chu
Add CYPRESS_VID vid and CYPRESS_WICED_BT_USB and CYPRESS_WICED_WL_USB
device IDs to ftdi_sio driver

Signed-off-by: Jeffrey Chu 
---
 drivers/usb/serial/ftdi_sio.c | 2 ++
 drivers/usb/serial/ftdi_sio_ids.h | 7 +++
 2 files changed, 9 insertions(+)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 1cec037..49d1b2d 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1015,6 +1015,8 @@ static const struct usb_device_id id_table_combined[] = {
  { USB_DEVICE(WICED_VID, WICED_USB20706V2_PID) },
  { USB_DEVICE(TI_VID, TI_CC3200_LAUNCHPAD_PID),
  .driver_info = (kernel_ulong_t)_jtag_quirk },
+ { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_BT_USB_PID) },
+ { USB_DEVICE(CYPRESS_VID, CYPRESS_WICED_WL_USB_PID) },
  { } /* Terminating entry */
 };

diff --git a/drivers/usb/serial/ftdi_sio_ids.h
b/drivers/usb/serial/ftdi_sio_ids.h
index 4fcf1ce..d58dc1b 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -692,6 +692,13 @@
 #define WICED_USB20706V2_PID 0x6422

 /*
+ * Cypress WICED USB UART
+ */
+#define CYPRESS_VID 0x04B4
+#define CYPRESS_WICED_BT_USB_PID 0x009B
+#define CYPRESS_WICED_WL_USB_PID 0xF900
+
+/*
  * Definitions for ID TECH (www.idt-net.com) devices
  */
 #define IDTECH_VID 0x0ACD /* ID TECH Vendor ID */
-- 
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: gadget: serial: fix oops when data rx'd after close

2017-08-16 Thread Stephen Warren
From: Stephen Warren 

When the gadget serial device has no associated TTY, do not pass any
received data into the TTY layer for processing; simply drop it instead.
This prevents the TTY layer from calling back into the gadget serial
driver, which will then crash in e.g. gs_write_room() due to lack of
gadget serial device to TTY association (i.e. a NULL pointer dereference).

Signed-off-by: Stephen Warren 
---
 drivers/usb/gadget/function/u_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index 9b0805f55ad7..16bb24a047d9 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -537,7 +537,7 @@ static void gs_rx_push(unsigned long _port)
}
 
/* push data to (open) tty */
-   if (req->actual) {
+   if (req->actual & tty) {
char*packet = req->buf;
unsignedsize = req->actual;
unsignedn;
-- 
2.14.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: usb 3-1: 1:1: cannot get freq at ep 0x81

2017-08-16 Thread Greg KH
On Wed, Aug 16, 2017 at 01:40:48PM -0300, Cristian wrote:
> Hello,
> 
> Launchpad.net:
> https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1711151

What are we supposed to do with a one line description and a pointer to
some random distro bug site?

Please, if you want our help, give us the needed information here in an
email, nothing we can do with other bug tracking systems at all.

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


usb 3-1: 1:1: cannot get freq at ep 0x81

2017-08-16 Thread Cristian
Hello,

Launchpad.net:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1711151

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


Re: [PATCH] udc: Memory leak on error path and use after free

2017-08-16 Thread Alan Stern
On Wed, 16 Aug 2017, Anton Vasilyev wrote:

> On 16.08.2017 18:29, Alan Stern wrote:
> > On Wed, 16 Aug 2017, Anton Vasilyev wrote:
> > 
> >> gadget_release() is responsible for cleanup dev memory.
> >> But if net2280_probe() fails after dev allocation, then
> >> gadget_release() become unregistered and dev memory leaks.
> > 
> > This isn't needed if usb_add_gadget_udc_release() is fixed, right?
> > 
> 
> No, this situation could appear before call
> usb_add_gadget_udc_release().
> 
> >> Also net2280_remove() calls usb_del_gadget_udc() which
> >> perform schedule_delayed_work() with gadget_release(), so
> >> it is possible that dev will be deallocated exactly after
> >> this call and leads to use after free.
> > 
> > Where is there a possible use after free?
> > 
> 
> net2280_remove() continue work with struct net2280 *dev after call
> usb_del_gadget_udc(>gadget), but this net2280 *dev could be
> deallocated by gadget_release()
> 
> >> The patch moves deallocation from gadget_release() to
> >> net2280_remove().
> > 
> > Alan Stern

Okay, now I understand what you were saying.  Yes, I agree, the 
existing code isn't right.

But a better solution would be to move the usb_del_gadget_udc() call
from the beginning of net2280_remove() to the end.  And make the call
conditional, depending on whether usb_add_gadget_udc_release() has
already been called successfully.

The point is that the device core does not allow drivers to deallocate 
memory containing a struct device before the ->release callback has 
been invoked.  Your patch might do that, if the release was delayed for 
some reason.

Alan Stern

--
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] udc: Memory leak on error path and use after free

2017-08-16 Thread Anton Vasilyev



On 16.08.2017 18:29, Alan Stern wrote:

On Wed, 16 Aug 2017, Anton Vasilyev wrote:


gadget_release() is responsible for cleanup dev memory.
But if net2280_probe() fails after dev allocation, then
gadget_release() become unregistered and dev memory leaks.


This isn't needed if usb_add_gadget_udc_release() is fixed, right?



No, this situation could appear before call
usb_add_gadget_udc_release().


Also net2280_remove() calls usb_del_gadget_udc() which
perform schedule_delayed_work() with gadget_release(), so
it is possible that dev will be deallocated exactly after
this call and leads to use after free.


Where is there a possible use after free?



net2280_remove() continue work with struct net2280 *dev after call
usb_del_gadget_udc(>gadget), but this net2280 *dev could be
deallocated by gadget_release()


The patch moves deallocation from gadget_release() to
net2280_remove().


Alan Stern



--
Anton Vasilyev
Linux Verification Center, ISPRAS
web: http://linuxtesting.org
e-mail: vasil...@ispras.ru
--
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: fix coding style issue

2017-08-16 Thread Greg KH
On Wed, Aug 16, 2017 at 11:01:20AM +0800, pierre Kuo wrote:
> try to fix some codeing style issue, such as "space prohibited" and "not
> initialise statics".

Only do one type of thing in a single patch please.  And no, "fix all
coding style issues" is not a single thing.

This needs to be multiple patches.

If you want to do coding style cleanups, please start out in
drivers/staging/ so you can get the process correct.

thanks,

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


Re: [PATCH] udc: Memory leak on error path and use after free

2017-08-16 Thread Alan Stern
On Wed, 16 Aug 2017, Anton Vasilyev wrote:

> gadget_release() is responsible for cleanup dev memory.
> But if net2280_probe() fails after dev allocation, then
> gadget_release() become unregistered and dev memory leaks.

This isn't needed if usb_add_gadget_udc_release() is fixed, right?

> Also net2280_remove() calls usb_del_gadget_udc() which
> perform schedule_delayed_work() with gadget_release(), so
> it is possible that dev will be deallocated exactly after
> this call and leads to use after free.

Where is there a possible use after free?

> The patch moves deallocation from gadget_release() to
> net2280_remove().

Alan Stern

--
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: Inconsistency in usb_add_gadget_udc_release() interface

2017-08-16 Thread Alan Stern
On Wed, 16 Aug 2017, Alexey Khoroshilov wrote:

> Hello,
> 
> usb_add_gadget_udc_release() gets release() argument that allows to
> release user resources.
> 
> As far as I can see, the release() is called on error paths 
> of usb_add_gadget_udc_release() as a result of
> put_device(>dev);
> except for the only path going via err1.
> 
> As a result a caller of the usb_add_gadget_udc_release() have no chance
> to know if the release() was invoked or not.
> 
> It may lead to memory leaks (drivers/usb/gadget/udc/snps_udc_core.c)
> or to double free (drivers/usb/gadget/udc/fsl_udc_core.c).
> 
> Is my reading correct? If so, should we always call release() on error paths?

How about this (untested)?

Alan Stern


Index: usb-4.x/drivers/usb/gadget/udc/core.c
===
--- usb-4.x.orig/drivers/usb/gadget/udc/core.c
+++ usb-4.x/drivers/usb/gadget/udc/core.c
@@ -1137,10 +1137,6 @@ int usb_add_gadget_udc_release(struct de
struct usb_udc  *udc;
int ret = -ENOMEM;
 
-   udc = kzalloc(sizeof(*udc), GFP_KERNEL);
-   if (!udc)
-   goto err1;
-
dev_set_name(>dev, "gadget");
INIT_WORK(>work, usb_gadget_state_work);
gadget->dev.parent = parent;
@@ -1150,7 +1146,13 @@ int usb_add_gadget_udc_release(struct de
else
gadget->dev.release = usb_udc_nop_release;
 
-   ret = device_register(>dev);
+   device_initialize(>dev);
+
+   udc = kzalloc(sizeof(*udc), GFP_KERNEL);
+   if (!udc)
+   goto err1;
+
+   ret = device_add(>dev);
if (ret)
goto err2;
 
@@ -1197,10 +1199,10 @@ err3:
device_del(>dev);
 
 err2:
-   put_device(>dev);
kfree(udc);
 
 err1:
+   put_device(>dev);
return ret;
 }
 EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release);

--
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 8/9] usb: Increase root hub reset signaling time to prevent retry

2017-08-16 Thread Alan Stern
On Wed, 16 Aug 2017, Mathias Nyman wrote:

> Save 80ms device enumeration time by increasing root hub port reset time
> 
> The 50ms reset signaling time is not enough for most root hub ports.
> Increasing the reset time to 60ms allows host controllers to finish port
> reset and removes a retry causing an extra 50ms delay.
> 
> The USB 2 specification requires "at least 50ms" for driving root
> port reset. The current msleep is exactly 50ms which may not be
> enough if there are any delays between writing the reset bit to host
> controller portsc register and phy actually driving reset.
> 
> On Haswell, Skylake and Kabylake xHC port reset took in average 52-59ms
> 
> The 80ms improvement comes from (40ms * 2 port resets) save at enumeration
> for each device connected to a root hub port.
> 
> more details about root port reset in USB2 section 7.1.7.5:.
> "Software must ensure that resets issued to the root ports drive reset
> long enough to overwhelm any concurrent resume attempts by downstream
> devices. It is required that resets from root ports have a duration of
> at least 50 ms (TDRSTR).
> 
> Cc: Alan Stern 
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/core/hub.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index e53308c..41eaf0b 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -2614,7 +2614,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
>  #define SET_CONFIG_TRIES (2 * (use_both_schemes + 1))
>  #define USE_NEW_SCHEME(i)((i) / 2 == (int)old_scheme_first)
>  
> -#define HUB_ROOT_RESET_TIME  50  /* times are in msec */
> +#define HUB_ROOT_RESET_TIME  60  /* times are in msec */
>  #define HUB_SHORT_RESET_TIME 10
>  #define HUB_BH_RESET_TIME50
>  #define HUB_LONG_RESET_TIME  200

Acked-by: Alan Stern 

--
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] udc: Memory leak on error path and use after free

2017-08-16 Thread Anton Vasilyev
gadget_release() is responsible for cleanup dev memory.
But if net2280_probe() fails after dev allocation, then
gadget_release() become unregistered and dev memory leaks.
Also net2280_remove() calls usb_del_gadget_udc() which
perform schedule_delayed_work() with gadget_release(), so
it is possible that dev will be deallocated exactly after
this call and leads to use after free.

The patch moves deallocation from gadget_release() to
net2280_remove().

Found by Linux Driver Verififcation project (linuxtesting.org).

Signed-off-by: Anton Vasilyev 
---
 drivers/usb/gadget/udc/net2280.c | 14 +++---
 1 file changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index f608c1f..62ac876 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -3546,15 +3546,6 @@ static irqreturn_t net2280_irq(int irq, void *_dev)
return IRQ_HANDLED;
 }
 
-/*-*/
-
-static void gadget_release(struct device *_dev)
-{
-   struct net2280  *dev = dev_get_drvdata(_dev);
-
-   kfree(dev);
-}
-
 /* tear down the binding between this driver and the pci device */
 
 static void net2280_remove(struct pci_dev *pdev)
@@ -3592,6 +3583,8 @@ static void net2280_remove(struct pci_dev *pdev)
device_remove_file(>dev, _attr_registers);
 
ep_info(dev, "unbind\n");
+
+   kfree(dev);
 }
 
 /* wrap this driver around the specified device, but
@@ -3769,8 +3762,7 @@ static int net2280_probe(struct pci_dev *pdev, const 
struct pci_device_id *id)
if (retval)
goto done;
 
-   retval = usb_add_gadget_udc_release(>dev, >gadget,
-   gadget_release);
+   retval = usb_add_gadget_udc(>dev, >gadget);
if (retval)
goto done;
return 0;
-- 
2.7.4

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


Re: [PATCH 7/9] xhci: add port status tracing

2017-08-16 Thread Mathias Nyman

On 16.08.2017 14:45, Felipe Balbi wrote:


Hi,

Mathias Nyman  writes:

Track the port status in a human readble way each time we get a
port status change event

Signed-off-by: Mathias Nyman 
---
  drivers/usb/host/xhci-ring.c  |  2 ++
  drivers/usb/host/xhci-trace.h | 23 +++
  2 files changed, 25 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 52a6650..a944365 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1638,6 +1638,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
port_id);
portsc = readl(port_array[faked_port_index]);

+   trace_xhci_handle_port_status(faked_port_index, portsc);
+
if (hcd->state == HC_STATE_SUSPENDED) {
xhci_dbg(xhci, "resume root hub\n");
usb_hcd_resume_root_hub(hcd);
diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
index 8ce96de..f20753b 100644
--- a/drivers/usb/host/xhci-trace.h
+++ b/drivers/usb/host/xhci-trace.h
@@ -453,6 +453,29 @@
TP_PROTO(struct xhci_ring *ring),
TP_ARGS(ring)
  );
+
+DECLARE_EVENT_CLASS(xhci_log_portsc,
+   TP_PROTO(u32 portnum, u32 portsc),
+   TP_ARGS(portnum, portsc),
+   TP_STRUCT__entry(
+__field(u32, portnum)
+__field(u32, portsc)
+),
+   TP_fast_assign(
+  __entry->portnum = portnum;
+  __entry->portsc = portsc;
+  ),
+   TP_printk("port-%d: %s",


this will give you "port-0" for a USB3 and USB2 roothub. How are you
going to differentiate between the two in a long trace?

you could pass hcd to the tracer, and extract hcd->speed to print out
something like "usb2-port-0: %s".



Seems like an improvement that could be done, but unless there is anything else
that needs fixing in this series I'd prefer to not respin/retest it this late
in the rc

-Mathias

-Mathas
--
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: Sometimes supports_usb_power_delivery reports incorrect value.

2017-08-16 Thread Heikki Krogerus
On Tue, Aug 15, 2017 at 04:26:07PM -0700, Badhri Jagan Sridharan wrote:
> Submitted couple of patches for the missing pieces in TCPM.
> Those patches along with "usb: typec: update partner power delivery
> support with opmode"
> seems to address the issue of reporting the right value for
> supports_usb_power_delivery.

Cool! Thanks Badhri!

-- 
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 7/9] xhci: add port status tracing

2017-08-16 Thread Felipe Balbi

Hi,

Mathias Nyman  writes:
> Track the port status in a human readble way each time we get a
> port status change event
>
> Signed-off-by: Mathias Nyman 
> ---
>  drivers/usb/host/xhci-ring.c  |  2 ++
>  drivers/usb/host/xhci-trace.h | 23 +++
>  2 files changed, 25 insertions(+)
>
> diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
> index 52a6650..a944365 100644
> --- a/drivers/usb/host/xhci-ring.c
> +++ b/drivers/usb/host/xhci-ring.c
> @@ -1638,6 +1638,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
>   port_id);
>   portsc = readl(port_array[faked_port_index]);
>  
> + trace_xhci_handle_port_status(faked_port_index, portsc);
> +
>   if (hcd->state == HC_STATE_SUSPENDED) {
>   xhci_dbg(xhci, "resume root hub\n");
>   usb_hcd_resume_root_hub(hcd);
> diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
> index 8ce96de..f20753b 100644
> --- a/drivers/usb/host/xhci-trace.h
> +++ b/drivers/usb/host/xhci-trace.h
> @@ -453,6 +453,29 @@
>   TP_PROTO(struct xhci_ring *ring),
>   TP_ARGS(ring)
>  );
> +
> +DECLARE_EVENT_CLASS(xhci_log_portsc,
> + TP_PROTO(u32 portnum, u32 portsc),
> + TP_ARGS(portnum, portsc),
> + TP_STRUCT__entry(
> +  __field(u32, portnum)
> +  __field(u32, portsc)
> +  ),
> + TP_fast_assign(
> +__entry->portnum = portnum;
> +__entry->portsc = portsc;
> +),
> + TP_printk("port-%d: %s",

this will give you "port-0" for a USB3 and USB2 roothub. How are you
going to differentiate between the two in a long trace?

you could pass hcd to the tracer, and extract hcd->speed to print out
something like "usb2-port-0: %s".

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


[PATCH 2/9] usb: host: xhci: plat: re-fact xhci_plat_priv for R-Car Gen3

2017-08-16 Thread Mathias Nyman
From: Yoshihiro Shimoda 

Since the firmware_name is decided by xhci-rcar.c on R-Car Gen3 now,
this patch removes 2 things:
 - Remove struct xhci_plat_priv xhci_plat_renesas_rcar_r8a7796.
 - Remoce .firmware_name from xhci_plat_renesas_rcar_gen3.

The behavior is the same as before.

Signed-off-by: Yoshihiro Shimoda 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-plat.c | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index c04144b..163bafd 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -107,14 +107,6 @@ static int xhci_plat_start(struct usb_hcd *hcd)
 };
 
 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
-   .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2,
-   .init_quirk = xhci_rcar_init_quirk,
-   .plat_start = xhci_rcar_start,
-   .resume_quirk = xhci_rcar_resume_quirk,
-};
-
-static const struct xhci_plat_priv xhci_plat_renesas_rcar_r8a7796 = {
-   .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3,
.init_quirk = xhci_rcar_init_quirk,
.plat_start = xhci_rcar_start,
.resume_quirk = xhci_rcar_resume_quirk,
@@ -145,7 +137,7 @@ static int xhci_plat_start(struct usb_hcd *hcd)
.data = _plat_renesas_rcar_gen3,
}, {
.compatible = "renesas,xhci-r8a7796",
-   .data = _plat_renesas_rcar_r8a7796,
+   .data = _plat_renesas_rcar_gen3,
}, {
.compatible = "renesas,rcar-gen2-xhci",
.data = _plat_renesas_rcar_gen2,
-- 
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 8/9] usb: Increase root hub reset signaling time to prevent retry

2017-08-16 Thread Mathias Nyman
Save 80ms device enumeration time by increasing root hub port reset time

The 50ms reset signaling time is not enough for most root hub ports.
Increasing the reset time to 60ms allows host controllers to finish port
reset and removes a retry causing an extra 50ms delay.

The USB 2 specification requires "at least 50ms" for driving root
port reset. The current msleep is exactly 50ms which may not be
enough if there are any delays between writing the reset bit to host
controller portsc register and phy actually driving reset.

On Haswell, Skylake and Kabylake xHC port reset took in average 52-59ms

The 80ms improvement comes from (40ms * 2 port resets) save at enumeration
for each device connected to a root hub port.

more details about root port reset in USB2 section 7.1.7.5:.
"Software must ensure that resets issued to the root ports drive reset
long enough to overwhelm any concurrent resume attempts by downstream
devices. It is required that resets from root ports have a duration of
at least 50 ms (TDRSTR).

Cc: Alan Stern 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/core/hub.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index e53308c..41eaf0b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -2614,7 +2614,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
 #define SET_CONFIG_TRIES   (2 * (use_both_schemes + 1))
 #define USE_NEW_SCHEME(i)  ((i) / 2 == (int)old_scheme_first)
 
-#define HUB_ROOT_RESET_TIME50  /* times are in msec */
+#define HUB_ROOT_RESET_TIME60  /* times are in msec */
 #define HUB_SHORT_RESET_TIME   10
 #define HUB_BH_RESET_TIME  50
 #define HUB_LONG_RESET_TIME200
-- 
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 3/9] usb: host: xhci: rcar: Add support for R-Car H3 ES2.0

2017-08-16 Thread Mathias Nyman
From: Yoshihiro Shimoda 

This patch adds support for R-Car H3 ES2.0. Since this SoC revision
(or later) should use the V3 firmware, the driver needs to check
the revision via soc_device_match().

Signed-off-by: Yoshihiro Shimoda 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-rcar.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 8f78d04..198bc18 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -20,7 +20,8 @@
 #include "xhci-rcar.h"
 
 /*
-* - The V3 firmware is for r8a7796 (with good performance).
+* - The V3 firmware is for r8a7796 (with good performance) and r8a7795 es2.0
+*   or later.
 * - The V2 firmware can be used on both r8a7795 (es1.x) and r8a7796.
 * - The V2 firmware is possible to use on R-Car Gen2. However, the V2 causes
 *   performance degradation. So, this driver continues to use the V1 if R-Car
@@ -78,6 +79,10 @@
.data = (void *)RCAR_XHCI_FIRMWARE_V2,
},
{
+   .soc_id = "r8a7795",
+   .data = (void *)RCAR_XHCI_FIRMWARE_V3,
+   },
+   {
.soc_id = "r8a7796",
.data = (void *)RCAR_XHCI_FIRMWARE_V3,
},
-- 
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 6/9] xhci: rename temp and temp1 variables

2017-08-16 Thread Mathias Nyman
temp and temp1 variables are used for port status (portsc) and
command register. Give them more descriptive names

No functional changes

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-ring.c | 20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index cc368ad..52a6650 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1572,7 +1572,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
 {
struct usb_hcd *hcd;
u32 port_id;
-   u32 temp, temp1;
+   u32 portsc, cmd_reg;
int max_ports;
int slot_id;
unsigned int faked_port_index;
@@ -1636,26 +1636,26 @@ static void handle_port_status(struct xhci_hcd *xhci,
/* Find the faked port hub number */
faked_port_index = find_faked_portnum_from_hw_portnum(hcd, xhci,
port_id);
+   portsc = readl(port_array[faked_port_index]);
 
-   temp = readl(port_array[faked_port_index]);
if (hcd->state == HC_STATE_SUSPENDED) {
xhci_dbg(xhci, "resume root hub\n");
usb_hcd_resume_root_hub(hcd);
}
 
-   if (hcd->speed >= HCD_USB3 && (temp & PORT_PLS_MASK) == XDEV_INACTIVE)
+   if (hcd->speed >= HCD_USB3 && (portsc & PORT_PLS_MASK) == XDEV_INACTIVE)
bus_state->port_remote_wakeup &= ~(1 << faked_port_index);
 
-   if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_RESUME) {
+   if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_RESUME) {
xhci_dbg(xhci, "port resume event for port %d\n", port_id);
 
-   temp1 = readl(>op_regs->command);
-   if (!(temp1 & CMD_RUN)) {
+   cmd_reg = readl(>op_regs->command);
+   if (!(cmd_reg & CMD_RUN)) {
xhci_warn(xhci, "xHC is not running.\n");
goto cleanup;
}
 
-   if (DEV_SUPERSPEED_ANY(temp)) {
+   if (DEV_SUPERSPEED_ANY(portsc)) {
xhci_dbg(xhci, "remote wake SS port %d\n", port_id);
/* Set a flag to say the port signaled remote wakeup,
 * so we can tell the difference between the end of
@@ -1683,8 +1683,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
}
}
 
-   if ((temp & PORT_PLC) && (temp & PORT_PLS_MASK) == XDEV_U0 &&
-   DEV_SUPERSPEED_ANY(temp)) {
+   if ((portsc & PORT_PLC) && (portsc & PORT_PLS_MASK) == XDEV_U0 &&
+   DEV_SUPERSPEED_ANY(portsc)) {
xhci_dbg(xhci, "resume SS port %d finished\n", port_id);
/* We've just brought the device into U0 through either the
 * Resume state after a device remote wakeup, or through the
@@ -1714,7 +1714,7 @@ static void handle_port_status(struct xhci_hcd *xhci,
 * RExit to a disconnect state).  If so, let the the driver know it's
 * out of the RExit state.
 */
-   if (!DEV_SUPERSPEED_ANY(temp) &&
+   if (!DEV_SUPERSPEED_ANY(portsc) &&
test_and_clear_bit(faked_port_index,
_state->rexit_ports)) {
complete(_state->rexit_done[faked_port_index]);
-- 
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 7/9] xhci: add port status tracing

2017-08-16 Thread Mathias Nyman
Track the port status in a human readble way each time we get a
port status change event

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-ring.c  |  2 ++
 drivers/usb/host/xhci-trace.h | 23 +++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 52a6650..a944365 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1638,6 +1638,8 @@ static void handle_port_status(struct xhci_hcd *xhci,
port_id);
portsc = readl(port_array[faked_port_index]);
 
+   trace_xhci_handle_port_status(faked_port_index, portsc);
+
if (hcd->state == HC_STATE_SUSPENDED) {
xhci_dbg(xhci, "resume root hub\n");
usb_hcd_resume_root_hub(hcd);
diff --git a/drivers/usb/host/xhci-trace.h b/drivers/usb/host/xhci-trace.h
index 8ce96de..f20753b 100644
--- a/drivers/usb/host/xhci-trace.h
+++ b/drivers/usb/host/xhci-trace.h
@@ -453,6 +453,29 @@
TP_PROTO(struct xhci_ring *ring),
TP_ARGS(ring)
 );
+
+DECLARE_EVENT_CLASS(xhci_log_portsc,
+   TP_PROTO(u32 portnum, u32 portsc),
+   TP_ARGS(portnum, portsc),
+   TP_STRUCT__entry(
+__field(u32, portnum)
+__field(u32, portsc)
+),
+   TP_fast_assign(
+  __entry->portnum = portnum;
+  __entry->portsc = portsc;
+  ),
+   TP_printk("port-%d: %s",
+ __entry->portnum,
+ xhci_decode_portsc(__entry->portsc)
+ )
+);
+
+DEFINE_EVENT(xhci_log_portsc, xhci_handle_port_status,
+TP_PROTO(u32 portnum, u32 portsc),
+TP_ARGS(portnum, portsc)
+);
+
 #endif /* __XHCI_TRACE_H */
 
 /* this part must be outside header guard */
-- 
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 4/9] xhci: add definitions for all port link states

2017-08-16 Thread Mathias Nyman
Add definitions for all port link states defined in xhci
specification for PORTSC register.

Will be needed for human readable port status tracing

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci.h | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index e3e9352..18fe51c 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -311,12 +311,19 @@ struct xhci_op_regs {
  */
 #define PORT_PLS_MASK  (0xf << 5)
 #define XDEV_U0(0x0 << 5)
+#define XDEV_U1(0x1 << 5)
 #define XDEV_U2(0x2 << 5)
 #define XDEV_U3(0x3 << 5)
+#define XDEV_DISABLED  (0x4 << 5)
+#define XDEV_RXDETECT  (0x5 << 5)
 #define XDEV_INACTIVE  (0x6 << 5)
 #define XDEV_POLLING   (0x7 << 5)
-#define XDEV_COMP_MODE  (0xa << 5)
+#define XDEV_RECOVERY  (0x8 << 5)
+#define XDEV_HOT_RESET (0x9 << 5)
+#define XDEV_COMP_MODE (0xa << 5)
+#define XDEV_TEST_MODE (0xb << 5)
 #define XDEV_RESUME(0xf << 5)
+
 /* true: port has power (see HCC_PPC) */
 #define PORT_POWER (1 << 9)
 /* bits 10:13 indicate device speed:
-- 
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 5/9] xhci: Add port status decoder for tracing purposes

2017-08-16 Thread Mathias Nyman
Add PORTSC Port status and control register decoder to
show human readable tracing of portsc register

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci.h | 81 +
 1 file changed, 81 insertions(+)

diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 18fe51c..2abaa4d 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -2399,6 +2399,87 @@ static inline const char *xhci_decode_slot_context(u32 
info, u32 info2,
return str;
 }
 
+
+static inline const char *xhci_portsc_link_state_string(u32 portsc)
+{
+   switch (portsc & PORT_PLS_MASK) {
+   case XDEV_U0:
+   return "U0";
+   case XDEV_U1:
+   return "U1";
+   case XDEV_U2:
+   return "U2";
+   case XDEV_U3:
+   return "U3";
+   case XDEV_DISABLED:
+   return "Disabled";
+   case XDEV_RXDETECT:
+   return "RxDetect";
+   case XDEV_INACTIVE:
+   return "Inactive";
+   case XDEV_POLLING:
+   return "Polling";
+   case XDEV_RECOVERY:
+   return "Recovery";
+   case XDEV_HOT_RESET:
+   return "Hot Reset";
+   case XDEV_COMP_MODE:
+   return "Compliance mode";
+   case XDEV_TEST_MODE:
+   return "Test mode";
+   case XDEV_RESUME:
+   return "Resume";
+   default:
+   break;
+   }
+   return "Unknown";
+}
+
+static inline const char *xhci_decode_portsc(u32 portsc)
+{
+   static char str[256];
+   int ret;
+
+   ret = sprintf(str, "%s %s %s Link:%s ",
+ portsc & PORT_POWER   ? "Powered" : "Powered-off",
+ portsc & PORT_CONNECT ? "Connected" : "Not-connected",
+ portsc & PORT_PE  ? "Enabled" : "Disabled",
+ xhci_portsc_link_state_string(portsc));
+
+   if (portsc & PORT_OC)
+   ret += sprintf(str + ret, "OverCurrent ");
+   if (portsc & PORT_RESET)
+   ret += sprintf(str + ret, "In-Reset ");
+
+   ret += sprintf(str + ret, "Change: ");
+   if (portsc & PORT_CSC)
+   ret += sprintf(str + ret, "CSC ");
+   if (portsc & PORT_PEC)
+   ret += sprintf(str + ret, "PEC ");
+   if (portsc & PORT_WRC)
+   ret += sprintf(str + ret, "WRC ");
+   if (portsc & PORT_OCC)
+   ret += sprintf(str + ret, "OCC ");
+   if (portsc & PORT_RC)
+   ret += sprintf(str + ret, "PRC ");
+   if (portsc & PORT_PLC)
+   ret += sprintf(str + ret, "PLC ");
+   if (portsc & PORT_CEC)
+   ret += sprintf(str + ret, "CEC ");
+   if (portsc & PORT_CAS)
+   ret += sprintf(str + ret, "CAS ");
+
+   ret += sprintf(str + ret, "Wake: ");
+   if (portsc & PORT_WKCONN_E)
+   ret += sprintf(str + ret, "WCE ");
+   if (portsc & PORT_WKDISC_E)
+   ret += sprintf(str + ret, "WDE ");
+   if (portsc & PORT_WKOC_E)
+   ret += sprintf(str + ret, "WOE ");
+
+   return str;
+}
+
 static inline const char *xhci_ep_state_string(u8 state)
 {
switch (state) {
-- 
1.9.1

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


[PATCH 1/9] usb: host: xhci: rcar: Add firmware_name selection by soc_device_match()

2017-08-16 Thread Mathias Nyman
From: Yoshihiro Shimoda 

This patch adds firmware_name selection by soc_device_match() to
use other firmware name in the future. (For now, using the firmware
is the same as before.)

Signed-off-by: Yoshihiro Shimoda 
Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-rcar.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 0727822..8f78d04 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "xhci.h"
 #include "xhci-plat.h"
@@ -67,6 +68,22 @@
 #define RCAR_USB3_RX_POL_VAL   BIT(21)
 #define RCAR_USB3_TX_POL_VAL   BIT(4)
 
+/* For soc_device_attribute */
+#define RCAR_XHCI_FIRMWARE_V2   BIT(0) /* FIRMWARE V2 */
+#define RCAR_XHCI_FIRMWARE_V3   BIT(1) /* FIRMWARE V3 */
+
+static const struct soc_device_attribute rcar_quirks_match[]  = {
+   {
+   .soc_id = "r8a7795", .revision = "ES1.*",
+   .data = (void *)RCAR_XHCI_FIRMWARE_V2,
+   },
+   {
+   .soc_id = "r8a7796",
+   .data = (void *)RCAR_XHCI_FIRMWARE_V3,
+   },
+   { /* sentinel */ },
+};
+
 static void xhci_rcar_start_gen2(struct usb_hcd *hcd)
 {
/* LCLK Select */
@@ -122,9 +139,23 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
int retval, index, j, time;
int timeout = 1;
u32 data, val, temp;
+   u32 quirks = 0;
+   const struct soc_device_attribute *attr;
+   const char *firmware_name;
+
+   attr = soc_device_match(rcar_quirks_match);
+   if (attr)
+   quirks = (uintptr_t)attr->data;
+
+   if (quirks & RCAR_XHCI_FIRMWARE_V2)
+   firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2;
+   else if (quirks & RCAR_XHCI_FIRMWARE_V3)
+   firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3;
+   else
+   firmware_name = priv->firmware_name;
 
/* request R-Car USB3.0 firmware */
-   retval = request_firmware(, priv->firmware_name, dev);
+   retval = request_firmware(, firmware_name, dev);
if (retval)
return retval;
 
-- 
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 9/9] xhci: rework bus_resume and check ports are suspended before resuming them.

2017-08-16 Thread Mathias Nyman
bus_resume() tried to resume the same ports the bus_suspend()
suspeded. This caused PLC timeouts in case a suspended device disconnected
and was not in a resumable state at bus_resume().

Add a check to make sure the link state is either U3 or resuming
before actually resuming the link.

At the same time do some other changes such as make sure we remove
wake on connect/disconnect/overcurrent also for the resuming ports,
and avoid extra portsc port register writes.

This improves resume time with 10ms in those PLC timeout cases where
devices disconnect at suspend/resume cycle.

Signed-off-by: Mathias Nyman 
---
 drivers/usb/host/xhci-hub.c | 94 -
 1 file changed, 51 insertions(+), 43 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 00721e8..4bc6f42 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -1521,15 +1521,14 @@ static bool xhci_port_missing_cas_quirk(int port_index,
 int xhci_bus_resume(struct usb_hcd *hcd)
 {
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
-   int max_ports, port_index;
-   __le32 __iomem **port_array;
struct xhci_bus_state *bus_state;
-   u32 temp;
+   __le32 __iomem **port_array;
unsigned long flags;
-   unsigned long port_was_suspended = 0;
-   bool need_usb2_u3_exit = false;
+   int max_ports, port_index;
int slot_id;
int sret;
+   u32 next_state;
+   u32 temp, portsc;
 
max_ports = xhci_get_ports(hcd, _array);
bus_state = >bus_state[hcd_index(hcd)];
@@ -1548,68 +1547,77 @@ int xhci_bus_resume(struct usb_hcd *hcd)
temp &= ~CMD_EIE;
writel(temp, >op_regs->command);
 
+   /* bus specific resume for ports we suspended at bus_suspend */
+   if (hcd->speed >= HCD_USB3)
+   next_state = XDEV_U0;
+   else
+   next_state = XDEV_RESUME;
+
port_index = max_ports;
while (port_index--) {
-   /* Check whether need resume ports. If needed
-  resume port and disable remote wakeup */
-   u32 temp;
-
-   temp = readl(port_array[port_index]);
+   portsc = readl(port_array[port_index]);
 
/* warm reset CAS limited ports stuck in polling/compliance */
if ((xhci->quirks & XHCI_MISSING_CAS) &&
(hcd->speed >= HCD_USB3) &&
xhci_port_missing_cas_quirk(port_index, port_array)) {
xhci_dbg(xhci, "reset stuck port %d\n", port_index);
+   clear_bit(port_index, _state->bus_suspended);
continue;
}
-   if (DEV_SUPERSPEED_ANY(temp))
-   temp &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
-   else
-   temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
-   if (test_bit(port_index, _state->bus_suspended) &&
-   (temp & PORT_PLS_MASK)) {
-   set_bit(port_index, _was_suspended);
-   if (!DEV_SUPERSPEED_ANY(temp)) {
-   xhci_set_link_state(xhci, port_array,
-   port_index, XDEV_RESUME);
-   need_usb2_u3_exit = true;
+   /* resume if we suspended the link, and it is still suspended */
+   if (test_bit(port_index, _state->bus_suspended))
+   switch (portsc & PORT_PLS_MASK) {
+   case XDEV_U3:
+   portsc = xhci_port_state_to_neutral(portsc);
+   portsc &= ~PORT_PLS_MASK;
+   portsc |= PORT_LINK_STROBE | next_state;
+   break;
+   case XDEV_RESUME:
+   /* resume already initiated */
+   break;
+   default:
+   /* not in a resumeable state, ignore it */
+   clear_bit(port_index,
+ _state->bus_suspended);
+   break;
}
-   } else
-   writel(temp, port_array[port_index]);
-   }
-
-   if (need_usb2_u3_exit) {
-   spin_unlock_irqrestore(>lock, flags);
-   msleep(USB_RESUME_TIMEOUT);
-   spin_lock_irqsave(>lock, flags);
+   /* disable wake for all ports, write new link state if needed */
+   portsc &= ~(PORT_RWC_BITS | PORT_CEC | PORT_WAKE_BITS);
+   writel(portsc, port_array[port_index]);
}
 
-   port_index = max_ports;
-   while (port_index--) {
-   if (!(port_was_suspended & BIT(port_index)))
-   continue;
-   /* 

[PATCH 0/9] xhci features for usb-next

2017-08-16 Thread Mathias Nyman
Hi Greg

Patch 8/9 is a usb core change that increases reset signaling time for
root hub ports for all hosts. Just wanted to point this out to you and Alan.
It should end up saving port reset time in most cases.

The rest adds xhci port tracing, tunes xhci bus resume and
sorts out firmware revisions for rcar hosts

-Mathias

Mathias Nyman (6):
  xhci: add definitions for all port link states
  xhci: Add port status decoder for tracing purposes
  xhci: rename temp and temp1 variables
  xhci: add port status tracing
  usb: Increase root hub reset signaling time to prevent retry
  xhci: rework bus_resume and check ports are suspended before resuming
them.

Yoshihiro Shimoda (3):
  usb: host: xhci: rcar: Add firmware_name selection by
soc_device_match()
  usb: host: xhci: plat: re-fact xhci_plat_priv for R-Car Gen3
  usb: host: xhci: rcar: Add support for R-Car H3 ES2.0

 drivers/usb/core/hub.c|  2 +-
 drivers/usb/host/xhci-hub.c   | 94 +++
 drivers/usb/host/xhci-plat.c  | 10 +
 drivers/usb/host/xhci-rcar.c  | 40 +-
 drivers/usb/host/xhci-ring.c  | 22 +-
 drivers/usb/host/xhci-trace.h | 23 +++
 drivers/usb/host/xhci.h   | 90 -
 7 files changed, 215 insertions(+), 66 deletions(-)

-- 
1.9.1

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


Re: [PATCH v6 3/8] usb: chipidea: Add support for Tegra20/30/114/124

2017-08-16 Thread Dmitry Osipenko
Peter, you've applied the v3 of this patch to your local tree and so it is
already in linux-next. Don't you mind to pick up a newer version of the patch?

-- 
Dmitry
--
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 v6 7/8] ARM: tegra: Enable UDC on Jetson TK1

2017-08-16 Thread Dmitry Osipenko
From: Thierry Reding 

Override the compatible string of the first USB controller to enable
device mode.

Signed-off-by: Thierry Reding 
Tested-by: Nicolas Chauvet 
Acked-by: Stephen Warren 
---
 arch/arm/boot/dts/tegra124-jetson-tk1.dts | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/tegra124-jetson-tk1.dts 
b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
index 7bacb2954f58..61873d642a45 100644
--- a/arch/arm/boot/dts/tegra124-jetson-tk1.dts
+++ b/arch/arm/boot/dts/tegra124-jetson-tk1.dts
@@ -1722,7 +1722,7 @@
 
lanes {
usb2-0 {
-   nvidia,function = "xusb";
+   nvidia,function = "snps";
status = "okay";
};
 
@@ -1829,6 +1829,16 @@
};
};
 
+   usb@7d00 {
+   compatible = "nvidia,tegra124-udc";
+   status = "okay";
+   dr_mode = "peripheral";
+   };
+
+   usb-phy@7d00 {
+   status = "okay";
+   };
+
/* mini-PCIe USB */
usb@7d004000 {
status = "okay";
-- 
2.13.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 v6 1/8] usb: gadget: f_ncm/u_ether: Move 'SKB reserve' quirk setup to u_ether

2017-08-16 Thread Dmitry Osipenko
That quirk is required to make USB Ethernet gadget working on HW that
can't cope with unaligned DMA. For some reason only f_ncm sets up that
quirk, let's setup it directly in u_ether so other network models would
have that quirk applied as well. All network models have been tested with
ChipIdea UDC driver on NVIDIA Tegra20 SoC that require DMA to be aligned.

Signed-off-by: Dmitry Osipenko 
---
 drivers/usb/gadget/function/f_ncm.c   | 2 --
 drivers/usb/gadget/function/u_ether.c | 2 +-
 drivers/usb/gadget/function/u_ether.h | 1 -
 3 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ncm.c 
b/drivers/usb/gadget/function/f_ncm.c
index 24e34cfcb4bd..45b334ceaf2e 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -925,8 +925,6 @@ static int ncm_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
 */
ncm->port.is_zlp_ok =
gadget_is_zlp_supported(cdev->gadget);
-   ncm->port.no_skb_reserve =
-   gadget_avoids_skb_reserve(cdev->gadget);
ncm->port.cdc_filter = DEFAULT_FILTER;
DBG(cdev, "activate ncm\n");
net = gether_connect(>port);
diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index a8b40d07e927..bdbc3fdc7c4f 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -1073,7 +1073,7 @@ struct net_device *gether_connect(struct gether *link)
 
if (result == 0) {
dev->zlp = link->is_zlp_ok;
-   dev->no_skb_reserve = link->no_skb_reserve;
+   dev->no_skb_reserve = gadget_avoids_skb_reserve(dev->gadget);
DBG(dev, "qlen %d\n", qlen(dev->gadget, dev->qmult));
 
dev->header_len = link->header_len;
diff --git a/drivers/usb/gadget/function/u_ether.h 
b/drivers/usb/gadget/function/u_ether.h
index 81d94a7ae4b4..c77145bd6b5b 100644
--- a/drivers/usb/gadget/function/u_ether.h
+++ b/drivers/usb/gadget/function/u_ether.h
@@ -64,7 +64,6 @@ struct gether {
struct usb_ep   *out_ep;
 
boolis_zlp_ok;
-   boolno_skb_reserve;
 
u16 cdc_filter;
 
-- 
2.13.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 v6 3/8] usb: chipidea: Add support for Tegra20/30/114/124

2017-08-16 Thread Dmitry Osipenko
From: Thierry Reding 

All of these Tegra SoC generations have a ChipIdea UDC IP block that can
be used for device mode communication with a host. Implement rudimentary
support that doesn't allow switching between host and device modes.

Tested-by: Michał Mirosław 
Signed-off-by: Thierry Reding 
[dig...@gmail.com: rebased patches and added DMA alignment quirk for Tegra20]
Signed-off-by: Dmitry Osipenko 
Acked-by: Peter Chen 
---
 drivers/usb/chipidea/Makefile|   1 +
 drivers/usb/chipidea/ci_hdrc_tegra.c | 155 +++
 2 files changed, 156 insertions(+)
 create mode 100644 drivers/usb/chipidea/ci_hdrc_tegra.c

diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 39fca5715ed3..ddcbddf8361a 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -15,3 +15,4 @@ obj-$(CONFIG_USB_CHIPIDEA)+= ci_hdrc_zevio.o
 obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o
 
 obj-$(CONFIG_USB_CHIPIDEA_OF)  += usbmisc_imx.o ci_hdrc_imx.o
+obj-$(CONFIG_USB_CHIPIDEA_OF)  += ci_hdrc_tegra.o
diff --git a/drivers/usb/chipidea/ci_hdrc_tegra.c 
b/drivers/usb/chipidea/ci_hdrc_tegra.c
new file mode 100644
index ..bfcee2702d50
--- /dev/null
+++ b/drivers/usb/chipidea/ci_hdrc_tegra.c
@@ -0,0 +1,155 @@
+/*
+ * Copyright (c) 2016, NVIDIA Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "ci.h"
+
+struct tegra_udc {
+   struct ci_hdrc_platform_data data;
+   struct platform_device *dev;
+
+   struct usb_phy *phy;
+   struct clk *clk;
+};
+
+struct tegra_udc_soc_info {
+   unsigned long flags;
+};
+
+static const struct tegra_udc_soc_info tegra20_udc_soc_info = {
+   .flags = CI_HDRC_REQUIRES_ALIGNED_DMA,
+};
+
+static const struct tegra_udc_soc_info tegra30_udc_soc_info = {
+   .flags = 0,
+};
+
+static const struct tegra_udc_soc_info tegra114_udc_soc_info = {
+   .flags = 0,
+};
+
+static const struct tegra_udc_soc_info tegra124_udc_soc_info = {
+   .flags = 0,
+};
+
+static const struct of_device_id tegra_udc_of_match[] = {
+   {
+   .compatible = "nvidia,tegra20-udc",
+   .data = _udc_soc_info,
+   }, {
+   .compatible = "nvidia,tegra30-udc",
+   .data = _udc_soc_info,
+   }, {
+   .compatible = "nvidia,tegra114-udc",
+   .data = _udc_soc_info,
+   }, {
+   .compatible = "nvidia,tegra124-udc",
+   .data = _udc_soc_info,
+   }, {
+   /* sentinel */
+   }
+};
+MODULE_DEVICE_TABLE(of, tegra_udc_of_match);
+
+static int tegra_udc_probe(struct platform_device *pdev)
+{
+   const struct tegra_udc_soc_info *soc;
+   struct tegra_udc *udc;
+   int err;
+
+   udc = devm_kzalloc(>dev, sizeof(*udc), GFP_KERNEL);
+   if (!udc)
+   return -ENOMEM;
+
+   soc = of_device_get_match_data(>dev);
+   if (!soc) {
+   dev_err(>dev, "failed to match OF data\n");
+   return -EINVAL;
+   }
+
+   udc->phy = devm_usb_get_phy_by_phandle(>dev, "nvidia,phy", 0);
+   if (IS_ERR(udc->phy)) {
+   err = PTR_ERR(udc->phy);
+   dev_err(>dev, "failed to get PHY: %d\n", err);
+   return err;
+   }
+
+   udc->clk = devm_clk_get(>dev, NULL);
+   if (IS_ERR(udc->clk)) {
+   err = PTR_ERR(udc->clk);
+   dev_err(>dev, "failed to get clock: %d\n", err);
+   return err;
+   }
+
+   err = clk_prepare_enable(udc->clk);
+   if (err < 0) {
+   dev_err(>dev, "failed to enable clock: %d\n", err);
+   return err;
+   }
+
+   /*
+* Tegra's USB PHY driver doesn't implement optional phy_init()
+* hook, so we have to power on UDC controller before ChipIdea
+* driver initialization kicks in.
+*/
+   usb_phy_set_suspend(udc->phy, 0);
+
+   /* setup and register ChipIdea HDRC device */
+   udc->data.name = "tegra-udc";
+   udc->data.flags = soc->flags;
+   udc->data.usb_phy = udc->phy;
+   udc->data.capoffset = DEF_CAPOFFSET;
+
+   udc->dev = ci_hdrc_add_device(>dev, pdev->resource,
+ pdev->num_resources, >data);
+   if (IS_ERR(udc->dev)) {
+   err = PTR_ERR(udc->dev);
+   dev_err(>dev, "failed to add HDRC device: %d\n", err);
+   goto fail_power_off;
+   }
+
+   platform_set_drvdata(pdev, udc);
+
+   return 0;
+
+fail_power_off:
+   usb_phy_set_suspend(udc->phy, 1);
+   clk_disable_unprepare(udc->clk);
+   return err;
+}
+

[PATCH v6 5/8] ARM: tegra: Enable UDC on Beaver

2017-08-16 Thread Dmitry Osipenko
From: Thierry Reding 

Override the compatible string of the first USB controller to enable
device mode.

Signed-off-by: Thierry Reding 
Acked-by: Stephen Warren 
---
 arch/arm/boot/dts/tegra30-beaver.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/tegra30-beaver.dts 
b/arch/arm/boot/dts/tegra30-beaver.dts
index 4f41b18d9547..3e104ddeb220 100644
--- a/arch/arm/boot/dts/tegra30-beaver.dts
+++ b/arch/arm/boot/dts/tegra30-beaver.dts
@@ -1927,6 +1927,16 @@
non-removable;
};
 
+   usb@7d00 {
+   compatible = "nvidia,tegra30-udc";
+   status = "okay";
+   dr_mode = "peripheral";
+   };
+
+   usb-phy@7d00 {
+   status = "okay";
+   };
+
usb@7d004000 {
status = "okay";
};
-- 
2.13.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 v6 8/8] ARM: tegra: Enable UDC on AC100

2017-08-16 Thread Dmitry Osipenko
Override the compatible string of the first USB controller to enable
device mode.

Signed-off-by: Dmitry Osipenko 
Tested-by: Marc Dietrich 
Acked-by: Stephen Warren 
---
 arch/arm/boot/dts/tegra20-paz00.dts | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/arch/arm/boot/dts/tegra20-paz00.dts 
b/arch/arm/boot/dts/tegra20-paz00.dts
index b4bfa5586c23..bfa9421fcf94 100644
--- a/arch/arm/boot/dts/tegra20-paz00.dts
+++ b/arch/arm/boot/dts/tegra20-paz00.dts
@@ -452,7 +452,9 @@
};
 
usb@c500 {
+   compatible = "nvidia,tegra20-udc";
status = "okay";
+   dr_mode = "peripheral";
};
 
usb-phy@c500 {
-- 
2.13.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 v6 4/8] ARM: defconfig: tegra: Enable ChipIdea UDC driver

2017-08-16 Thread Dmitry Osipenko
Since NVIDIA Tegra is supported now by the ChipIdea USB driver, let's
enable this driver in tegra_defconfig.

Signed-off-by: Dmitry Osipenko 
---
 arch/arm/configs/tegra_defconfig | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/arm/configs/tegra_defconfig b/arch/arm/configs/tegra_defconfig
index fe1275aa067e..9c9c644ed9d7 100644
--- a/arch/arm/configs/tegra_defconfig
+++ b/arch/arm/configs/tegra_defconfig
@@ -121,7 +121,6 @@ CONFIG_TOUCHSCREEN_WM97XX=y
 CONFIG_TOUCHSCREEN_STMPE=y
 CONFIG_INPUT_MISC=y
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_OF_PLATFORM=y
@@ -220,6 +219,9 @@ CONFIG_USB_EHCI_TEGRA=y
 CONFIG_USB_ACM=y
 CONFIG_USB_WDM=y
 CONFIG_USB_STORAGE=y
+CONFIG_USB_CHIPIDEA=m
+CONFIG_USB_CHIPIDEA_UDC=y
+CONFIG_USB_GADGET=m
 CONFIG_MMC=y
 CONFIG_MMC_BLOCK_MINORS=16
 CONFIG_MMC_SDHCI=y
@@ -249,8 +251,6 @@ CONFIG_RTC_DRV_TEGRA=y
 CONFIG_DMADEVICES=y
 CONFIG_TEGRA20_APB_DMA=y
 CONFIG_STAGING=y
-CONFIG_SENSORS_ISL29018=y
-CONFIG_SENSORS_ISL29028=y
 CONFIG_MFD_NVEC=y
 CONFIG_KEYBOARD_NVEC=y
 CONFIG_SERIO_NVEC_PS2=y
@@ -265,6 +265,8 @@ CONFIG_ARCH_TEGRA_124_SOC=y
 CONFIG_MEMORY=y
 CONFIG_IIO=y
 CONFIG_MPU3050_I2C=y
+CONFIG_SENSORS_ISL29018=y
+CONFIG_SENSORS_ISL29028=y
 CONFIG_AK8975=y
 CONFIG_PWM=y
 CONFIG_PWM_TEGRA=y
@@ -290,13 +292,11 @@ CONFIG_NLS_CODEPAGE_437=y
 CONFIG_NLS_ISO8859_1=y
 CONFIG_PRINTK_TIME=y
 CONFIG_DEBUG_INFO=y
-CONFIG_DEBUG_FS=y
 CONFIG_MAGIC_SYSRQ=y
 CONFIG_DEBUG_SLAB=y
 CONFIG_DEBUG_VM=y
 CONFIG_DETECT_HUNG_TASK=y
 CONFIG_SCHEDSTATS=y
-CONFIG_TIMER_STATS=y
 # CONFIG_DEBUG_PREEMPT is not set
 CONFIG_DEBUG_MUTEXES=y
 CONFIG_DEBUG_SG=y
-- 
2.13.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 v6 6/8] ARM: tegra: Enable UDC on Dalmore

2017-08-16 Thread Dmitry Osipenko
From: Thierry Reding 

Override the compatible string of the first USB controller to enable
device mode.

Signed-off-by: Thierry Reding 
---
 arch/arm/boot/dts/tegra114-dalmore.dts | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/tegra114-dalmore.dts 
b/arch/arm/boot/dts/tegra114-dalmore.dts
index 1444fbd543e7..5af4dd321952 100644
--- a/arch/arm/boot/dts/tegra114-dalmore.dts
+++ b/arch/arm/boot/dts/tegra114-dalmore.dts
@@ -1122,6 +1122,16 @@
non-removable;
};
 
+   usb@7d00 {
+   compatible = "nvidia,tegra114-udc";
+   status = "okay";
+   dr_mode = "peripheral";
+   };
+
+   usb-phy@7d00 {
+   status = "okay";
+   };
+
usb@7d008000 {
status = "okay";
};
-- 
2.13.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 v6 2/8] usb: chipidea: udc: Support SKB alignment quirk

2017-08-16 Thread Dmitry Osipenko
NVIDIA Tegra20 UDC can't cope with unaligned DMA and require a USB gadget
quirk that avoids SKB buffer alignment to be set in order to make Ethernet
Gadget working. Later Tegra generations do not require that quirk. Let's
add a new platform data flag that allows to enable USB gadget quirk for
platforms that require it.

Signed-off-by: Dmitry Osipenko 
Acked-by: Peter Chen 
---
 drivers/usb/chipidea/udc.c   | 3 +++
 include/linux/usb/chipidea.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 6502c13331e8..fe8a90543ea3 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1896,6 +1896,9 @@ static int udc_start(struct ci_hdrc *ci)
ci->gadget.name = ci->platdata->name;
ci->gadget.otg_caps = otg_caps;
 
+   if (ci->platdata->flags & CI_HDRC_REQUIRES_ALIGNED_DMA)
+   ci->gadget.quirk_avoids_skb_reserve = 1;
+
if (ci->is_otg && (otg_caps->hnp_support || otg_caps->srp_support ||
otg_caps->adp_support))
ci->gadget.is_otg = 1;
diff --git a/include/linux/usb/chipidea.h b/include/linux/usb/chipidea.h
index c5fdfcf99828..d725cff7268d 100644
--- a/include/linux/usb/chipidea.h
+++ b/include/linux/usb/chipidea.h
@@ -58,6 +58,7 @@ struct ci_hdrc_platform_data {
 #define CI_HDRC_OVERRIDE_TX_BURST  BIT(10)
 #define CI_HDRC_OVERRIDE_RX_BURST  BIT(11)
 #define CI_HDRC_OVERRIDE_PHY_CONTROL   BIT(12) /* Glue layer manages phy */
+#define CI_HDRC_REQUIRES_ALIGNED_DMA   BIT(13)
enum usb_dr_modedr_mode;
 #define CI_HDRC_CONTROLLER_RESET_EVENT 0
 #define CI_HDRC_CONTROLLER_STOPPED_EVENT   1
-- 
2.13.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 v6 0/8] Support UDC on Tegra 20/30/114/124

2017-08-16 Thread Dmitry Osipenko
Some time ago Thierry Reding sent out patches that enabled UDC on NVIDIA
Tegra, unfortunately they haven't got enough traction to get into the
kernel. I've rebased those patches and added a fix for the Ethernet USB
Gadget on Tegra20, Marc Dietrich tested UDC driver on AC100 (Tegra20),
Nicolas Chauvet on TK1 (Tegra124) and Michał Mirosław on TF300T (Tegra30).
Like an original patchset, this series adds support for the peripheral
mode only.

Changelog:

V6:
1) Moved 'SKB reserve' quirk setup from f_ncm to u_uther as per Felipe's
   suggestion.

V5:
1) Moved of_device_get_match_data() above clock enabling to not leave clock
   enabled in case of error. The SoC data matching function shouldn't ever
   fail, but let's assume that it could for consistency.

V4:
1) Used of_device_get_match_data() instead of of_match_node() to cleanup
   code a tad.

V3:
1) Specified platform flags directly in the SoC info as per Michał's
   suggestion.

V2:
1) Added comments to each of patched USB Ethernet gadget models.

2) Added explanatory comment about why usb_phy_set_suspend() invocation
   is necessary in tegra_udc_probe().

3) Dropped TrimSlice from patchset because it turned out that it uses USB1
   controller for USB-to-SATA.

4) Moved tegra_defconfig patch before DT patches as per Stephen's suggestion.

5) Changed dr_mode to "peripheral" in DT patches since we don't support role
   mode switching for now.

Dmitry Osipenko (4):
  usb: gadget: f_ncm/u_ether: Move 'SKB reserve' quirk setup to u_ether
  usb: chipidea: udc: Support SKB alignment quirk
  ARM: defconfig: tegra: Enable ChipIdea UDC driver
  ARM: tegra: Enable UDC on AC100

Thierry Reding (4):
  usb: chipidea: Add support for Tegra20/30/114/124
  ARM: tegra: Enable UDC on Beaver
  ARM: tegra: Enable UDC on Dalmore
  ARM: tegra: Enable UDC on Jetson TK1

 arch/arm/boot/dts/tegra114-dalmore.dts|  10 ++
 arch/arm/boot/dts/tegra124-jetson-tk1.dts |  12 ++-
 arch/arm/boot/dts/tegra20-paz00.dts   |   2 +
 arch/arm/boot/dts/tegra30-beaver.dts  |  10 ++
 arch/arm/configs/tegra_defconfig  |  10 +-
 drivers/usb/chipidea/Makefile |   1 +
 drivers/usb/chipidea/ci_hdrc_tegra.c  | 155 ++
 drivers/usb/chipidea/udc.c|   3 +
 drivers/usb/gadget/function/f_ncm.c   |   2 -
 drivers/usb/gadget/function/u_ether.c |   2 +-
 drivers/usb/gadget/function/u_ether.h |   1 -
 include/linux/usb/chipidea.h  |   1 +
 12 files changed, 199 insertions(+), 10 deletions(-)
 create mode 100644 drivers/usb/chipidea/ci_hdrc_tegra.c

-- 
2.13.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: uvc-gadget for UVC testing doesn't seem to work with vivid

2017-08-16 Thread Felipe Balbi

Hi,

Rail Shafigulin  writes:
>> Rail Shafigulin  writes:
>>> Let me apologize for emailing directly to the list as I'm not one of
>>> the developers and just starting out with USB and UVC. After searching
>>
>> the list is open to anybody and we welcome newcomers :-)
>>
>>> online for about a week I just couldn't find answers and I hope the
>>> original authors of the uvc-gadget tool are on the list and can help
>>> out.
>>>
>>> Needed to test a UVC in a custom built kernel (Xilinx petalinux), .
>>> Followed these directions,
>>> https://github.com/torvalds/linux/blob/ef954844c7ace62f773f4f23e28d2d915adc419f/Documentation/usb/gadget-testing.txt#L717-L730.
>>>
>>> Patches didn't work. Had to look around for correct ones. Found them
>>> here, 
>>> http://markmail.org/message/hb7evzvigbuxptz5#query:+page:1+mid:s73fdeffjgb2v2yw+state:results.
>>>
>>> Combined and applied the patches into a repo here,
>>> https://github.com/cyboflash/uvc-gadget.git.
>>>
>>> When I ran a test command, given in the instructions above,
>>> uvc-gadget -u /dev/video -v /dev/video
>>>
>>> got the following error:
>>> V4L2_CORE: (jpeg decoder) error while decoding frame
>>>
>>> and a black screen.
>>>
>>> One thing to note is that I was not using luvcview, but guvcview.
>>>
>>> It looks like the error is coming from here,
>>> https://sourceforge.net/p/guvcview/git-master/ci/master/tree/gview_v4l2core/jpeg_decoder.c#l1503
>>>
>>> My thoughts
>>> 1. I don't think the error is coming from v4l2. I tested it on another
>>> machine and it worked. But I'm not an expert so I can't say for sure.
>>> 2. I don't think the error is coming from UVC. I think since I see a
>>> black screen, it is working. Again, I'm not an expert, so I can't say
>>> for sure.
>>> 3. I think the error is due to uvc-gadget test application. It could
>>> be that the applied patches are outdated, but I just didn't find
>>> anything else online. But, I'm not an expert so definitely can't say
>>> for sure.
>>>
>>> I would greatly appreciate any help with this as I'm just starting out
>>> with UVC and USB.
>>
>> Which kernel are you using? Which UDC driver are you using?
>
> Balbi,
>
> The board is configured as a USB Camera Gadget. Here is the output of uname -a
> Linux Xilinx-ZCU102-2016_3 4.6.0 #33 SMP Thu Aug 10 11:47:57 PDT 2017
> aarch64 GNU/Linux

okay, then you need to ask for support from whoever gave you this
kernel. 4.6 is a really old release which this forum doesn't support.

> When you say UDC (USB Device Controller) driver, what exactly do you mean?

which driver is g_webcam binding to? What do you have under
/sys/class/udc ?

[...]

> Here is what I do on my board:
>
> modprobe g_webcam
> modprobe vivid

[...] I'm assuming it's this "vivid" driver which isn't in the upstream
kernel and, again, we can't support :-s

If this is part of an SDK, you've probably already paid for support from
the vendor, I suggest you use their support channel.

Best of luck

-- 
balbi


signature.asc
Description: PGP signature


Re: Inconsistency in usb_add_gadget_udc_release() interface

2017-08-16 Thread Felipe Balbi

Hi,

Alexey Khoroshilov  writes:
> Hello,
>
> usb_add_gadget_udc_release() gets release() argument that allows to
> release user resources.
>
> As far as I can see, the release() is called on error paths 
> of usb_add_gadget_udc_release() as a result of
> put_device(>dev);
> except for the only path going via err1.
>
> As a result a caller of the usb_add_gadget_udc_release() have no chance
> to know if the release() was invoked or not.
>
> It may lead to memory leaks (drivers/usb/gadget/udc/snps_udc_core.c)
> or to double free (drivers/usb/gadget/udc/fsl_udc_core.c).
>
> Is my reading correct? If so, should we always call release() on error paths?

unfortunately, it's not :-)

Note that we don't register gadget->dev until later in the code, so
there's nothing to be ->released() that early.

-- 
balbi


signature.asc
Description: PGP signature


[PATCH v2 1/4] usb: mtu3: add generic compatible string

2017-08-16 Thread Chunfeng Yun
The mtu3 driver is a generic driver for MediaTek usb3 DRD IP, add
a generic compatible to avoid confusion when support new SoCs but
use a compatible with specific SoC's name "mt8173".

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/mtu3/mtu3_plat.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/mtu3/mtu3_plat.c b/drivers/usb/mtu3/mtu3_plat.c
index 0d3ebb3..088e3e6 100644
--- a/drivers/usb/mtu3/mtu3_plat.c
+++ b/drivers/usb/mtu3/mtu3_plat.c
@@ -500,6 +500,7 @@ static int __maybe_unused mtu3_resume(struct device *dev)
 
 static const struct of_device_id mtu3_of_match[] = {
{.compatible = "mediatek,mt8173-mtu3",},
+   {.compatible = "mediatek,mtu3",},
{},
 };
 
-- 
1.7.9.5

--
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/4] dt-bindings: mt8173-xhci: add generic compatible and rename file

2017-08-16 Thread Chunfeng Yun
The mt8173-xhci.txt actually holds the bindings for all mediatek
SoCs with xHCI controller, so add a generic compatible and change
the name to mediatek,mtk-xhci.txt to reflect that.

Signed-off-by: Chunfeng Yun 
---
 .../usb/{mt8173-xhci.txt => mediatek,mtk-xhci.txt} |   14 +++---
 .../devicetree/bindings/usb/mediatek,mtu3.txt  |2 +-
 2 files changed, 12 insertions(+), 4 deletions(-)
 rename Documentation/devicetree/bindings/usb/{mt8173-xhci.txt => 
mediatek,mtk-xhci.txt} (85%)

diff --git a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
similarity index 85%
rename from Documentation/devicetree/bindings/usb/mt8173-xhci.txt
rename to Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
index 0acfc8a..ff21135 100644
--- a/Documentation/devicetree/bindings/usb/mt8173-xhci.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
@@ -11,7 +11,11 @@ into two parts.
 
 
 Required properties:
- - compatible : should contain "mediatek,mt8173-xhci"
+ - compatible : should be "mediatek,soc-model-xhci", "mediatek,mtk-xhci",
+   soc-model is the name of SoC, such as mt8173, mt2712 etc, when using
+   "mediatek,mtk-xhci" compatible string, you need SoC specific ones in
+   addition, one of:
+   - "mediatek,mt8173-xhci"
  - reg : specifies physical base address and size of the registers
  - reg-names: should be "mac" for xHCI MAC and "ippc" for IP port control
  - interrupts : interrupt used by the controller
@@ -68,10 +72,14 @@ usb30: usb@1127 {
 
 In the case, xhci is added as subnode to mtu3. An example and the DT binding
 details of mtu3 can be found in:
-Documentation/devicetree/bindings/usb/mt8173-mtu3.txt
+Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
 
 Required properties:
- - compatible : should contain "mediatek,mt8173-xhci"
+ - compatible : should be "mediatek,soc-model-xhci", "mediatek,mtk-xhci",
+   soc-model is the name of SoC, such as mt8173, mt2712 etc, when using
+   "mediatek,mtk-xhci" compatible string, you need SoC specific ones in
+   addition, one of:
+   - "mediatek,mt8173-xhci"
  - reg : specifies physical base address and size of the registers
  - reg-names: should be "mac" for xHCI MAC
  - interrupts : interrupt used by the host controller
diff --git a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 545251e..722a029 100644
--- a/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -48,7 +48,7 @@ Optional properties:
 Sub-nodes:
 The xhci should be added as subnode to mtu3 as shown in the following example
 if host mode is enabled. The DT binding details of xhci can be found in:
-Documentation/devicetree/bindings/usb/mt8173-xhci.txt
+Documentation/devicetree/bindings/usb/mediatek,mtk-xhci.txt
 
 Example:
 ssusb: usb@11271000 {
-- 
1.7.9.5

--
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/4] dt-bindings: mt8173-mtu3: add generic compatible and rename file

2017-08-16 Thread Chunfeng Yun
The mt8173-mtu3.txt actually holds the bindings for all mediatek
SoCs with usb3 DRD IP, so add a generic compatible and change the
name to mediatek,mtu3.txt.

Signed-off-by: Chunfeng Yun 
---
 .../usb/{mt8173-mtu3.txt => mediatek,mtu3.txt} |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)
 rename Documentation/devicetree/bindings/usb/{mt8173-mtu3.txt => 
mediatek,mtu3.txt} (92%)

diff --git a/Documentation/devicetree/bindings/usb/mt8173-mtu3.txt 
b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
similarity index 92%
rename from Documentation/devicetree/bindings/usb/mt8173-mtu3.txt
rename to Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
index 1d7c3bc..545251e 100644
--- a/Documentation/devicetree/bindings/usb/mt8173-mtu3.txt
+++ b/Documentation/devicetree/bindings/usb/mediatek,mtu3.txt
@@ -1,7 +1,11 @@
 The device node for Mediatek USB3.0 DRD controller
 
 Required properties:
- - compatible : should be "mediatek,mt8173-mtu3"
+ - compatible : should be "mediatek,soc-model-mtu3", "mediatek,mtu3",
+   soc-model is the name of SoC, such as mt8173, mt2712 etc,
+   when using "mediatek,mtu3" compatible string, you need SoC specific
+   ones in addition, one of:
+   - "mediatek,mt8173-mtu3"
  - reg : specifies physical base address and size of the registers
  - reg-names: should be "mac" for device IP and "ippc" for IP port control
  - interrupts : interrupt used by the device IP
-- 
1.7.9.5

--
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/4] usb: xhci-mtk: add generic compatible string

2017-08-16 Thread Chunfeng Yun
The xhci-mtk driver is a generic driver for MediaTek xHCI IP, add
a generic compatible to avoid confusion when support new SoCs but
use a compatible with specific SoC's name "mt8173".

Signed-off-by: Chunfeng Yun 
---
 drivers/usb/host/xhci-mtk.c |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 67d5dc7..8fb6065 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -795,6 +795,7 @@ static int __maybe_unused xhci_mtk_resume(struct device 
*dev)
 #ifdef CONFIG_OF
 static const struct of_device_id mtk_xhci_of_match[] = {
{ .compatible = "mediatek,mt8173-xhci"},
+   { .compatible = "mediatek,mtk-xhci"},
{ },
 };
 MODULE_DEVICE_TABLE(of, mtk_xhci_of_match);
-- 
1.7.9.5

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