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

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

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

Signed-off-by: Baolin Wang 
---
Changes since v1:
 - Move the suspend checking to right place to avoid checking twice.
---
 drivers/usb/dwc3/core.h   |8 
 drivers/usb/dwc3/gadget.c |   49 +
 2 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 23765a1..c5fd862 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -496,6 +497,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  * @lock: spinlock for endpoint request queue traversal
  * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
@@ -521,6 +523,8 @@ struct dwc3_ep {
struct list_headpending_list;
struct list_headstarted_list;
 
+   wait_queue_head_t   wait_end_transfer;
+
spinlock_t  lock;
void __iomem*regs;
 
@@ -537,6 +541,7 @@ struct dwc3_ep {
 #define DWC3_EP_BUSY   (1 << 4)
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
+#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
@@ -1044,6 +1049,9 @@ struct dwc3_event_depevt {
 #define DEPEVT_TRANSFER_BUS_EXPIRY 2
 
u32 parameters:16;
+
+/* For Command Complete Events */
+#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
 } __packed;
 
 /**
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3722c90..e248bd3 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -570,11 +570,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
dep->comp_desc = comp_desc;
dep->type = usb_endpoint_type(desc);
dep->flags |= DWC3_EP_ENABLED;
+   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
 
reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
reg |= DWC3_DALEPENA_EP(dep->number);
dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
 
+   init_waitqueue_head(>wait_end_transfer);
+
if (usb_endpoint_xfer_control(desc))
return 0;
 
@@ -647,7 +650,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
dep->endpoint.desc = NULL;
dep->comp_desc = NULL;
dep->type = 0;
-   dep->flags = 0;
+   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
 
return 0;
 }
@@ -1736,12 +1739,38 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 {
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long   flags;
+   int epnum;
 
spin_lock_irqsave(>lock, flags);
__dwc3_gadget_stop(dwc);
dwc->gadget_driver  = NULL;
+
+   /*
+* If the dwc3 core has been in suspend state, we will never get
+* the command complete event, thus ignore.
+*/
+   if (pm_runtime_suspended(dwc->dev)) {
+   spin_unlock_irqrestore(>lock, flags);
+   goto out;
+   }
+
+   for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+   struct dwc3_ep  *dep = dwc->eps[epnum];
+
+   if (!dep)
+   continue;
+
+   if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
+   continue;
+
+   wait_event_lock_irq(dep->wait_end_transfer,
+   !(dep->flags & 
DWC3_EP_END_TRANSFER_PENDING),
+   dwc->lock);
+   }
+
spin_unlock_irqrestore(>lock, flags);
 
+out:
free_irq(dwc->irq_gadget, dwc->ev_buf);
 
return 0;
@@ -2105,10 +2134,12 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
 {
struct dwc3_ep  *dep;
u8  epnum = event->endpoint_number;
+   u8  cmd;
 
dep = dwc->eps[epnum];
 
-   if (!(dep->flags & DWC3_EP_ENABLED))
+   if (!(dep->flags & DWC3_EP_ENABLED) &&
+   !(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
return;
 
if (epnum == 0 || epnum == 1) {
@@ -2180,6 +2211,13 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun", 

[PATCH v4 1/4] usb: dbc: early driver for xhci debug capability

2016-10-31 Thread Lu Baolu
xHCI debug capability (DbC) is an optional but standalone
functionality provided by an xHCI host controller. Software
learns this capability by walking through the extended
capability list of the host. xHCI specification describes
DbC in section 7.6.

This patch introduces the code to probe and initialize the
debug capability hardware during early boot. With hardware
initialized, the debug target (system on which this code is
running) will present a debug device through the debug port
(normally the first USB3 port). The debug device is fully
compliant with the USB framework and provides the equivalent
of a very high performance (USB3) full-duplex serial link
between the debug host and target. The DbC functionality is
independent of xHCI host. There isn't any precondition from
xHCI host side for DbC to work.

This patch also includes bulk out and bulk in interfaces.
These interfaces could be used to implement early printk
bootconsole or hook to various system debuggers.

This code is designed to be only used for kernel debugging
when machine crashes very early before the console code is
initialized. For normal operation it is not recommended.

Cc: Mathias Nyman 
Signed-off-by: Lu Baolu 
---
 arch/x86/Kconfig.debug|   14 +
 drivers/usb/Kconfig   |3 +
 drivers/usb/Makefile  |2 +-
 drivers/usb/early/Makefile|1 +
 drivers/usb/early/xhci-dbc.c  | 1050 +
 drivers/usb/early/xhci-dbc.h  |  202 
 include/linux/usb/xhci-dbgp.h |   22 +
 7 files changed, 1293 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/early/xhci-dbc.c
 create mode 100644 drivers/usb/early/xhci-dbc.h
 create mode 100644 include/linux/usb/xhci-dbgp.h

diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
index 67eec55..13e85b7 100644
--- a/arch/x86/Kconfig.debug
+++ b/arch/x86/Kconfig.debug
@@ -29,6 +29,7 @@ config EARLY_PRINTK
 config EARLY_PRINTK_DBGP
bool "Early printk via EHCI debug port"
depends on EARLY_PRINTK && PCI
+   select USB_EARLY_PRINTK
---help---
  Write kernel log output directly into the EHCI debug port.
 
@@ -48,6 +49,19 @@ config EARLY_PRINTK_EFI
  This is useful for kernel debugging when your machine crashes very
  early before the console code is initialized.
 
+config EARLY_PRINTK_XDBC
+   bool "Early printk via xHCI debug port"
+   depends on EARLY_PRINTK && PCI
+   select USB_EARLY_PRINTK
+   ---help---
+ Write kernel log output directly into the xHCI debug port.
+
+ This is useful for kernel debugging when your machine crashes very
+ early before the console code is initialized. For normal operation
+ it is not recommended because it looks ugly and doesn't cooperate
+ with klogd/syslogd or the X server. You should normally N here,
+ unless you want to debug such a crash.
+
 config X86_PTDUMP_CORE
def_bool n
 
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index fbe493d..9313fff 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -19,6 +19,9 @@ config USB_EHCI_BIG_ENDIAN_MMIO
 config USB_EHCI_BIG_ENDIAN_DESC
bool
 
+config USB_EARLY_PRINTK
+   bool
+
 menuconfig USB_SUPPORT
bool "USB support"
depends on HAS_IOMEM
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 7791af6..0c37838 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -49,7 +49,7 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
+obj-$(CONFIG_USB_EARLY_PRINTK) += early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
 obj-$(CONFIG_USB_SPEEDTOUCH)   += atm/
diff --git a/drivers/usb/early/Makefile b/drivers/usb/early/Makefile
index 24bbe51..2db5906 100644
--- a/drivers/usb/early/Makefile
+++ b/drivers/usb/early/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_EARLY_PRINTK_DBGP) += ehci-dbgp.o
+obj-$(CONFIG_EARLY_PRINTK_XDBC) += xhci-dbc.o
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
new file mode 100644
index 000..728a1a0
--- /dev/null
+++ b/drivers/usb/early/xhci-dbc.c
@@ -0,0 +1,1050 @@
+/**
+ * xhci-dbc.c - xHCI debug capability early driver
+ *
+ * Copyright (C) 2016 Intel Corporation
+ *
+ * Author: Lu Baolu 
+ *
+ * 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.
+ */
+
+#define pr_fmt(fmt)KBUILD_MODNAME ":%s: " fmt, __func__
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "../host/xhci.h"
+#include "xhci-dbc.h"
+
+static struct xdbc_state xdbc;
+static int early_console_keep;
+
+#ifdef XDBC_TRACE

[PATCH v4 2/4] x86: add support for earlyprintk via USB3 debug port

2016-10-31 Thread Lu Baolu
Add support for early printk by writing debug messages to the
USB3 debug port.   Users can use this type of early printk by
specifying kernel parameter of "earlyprintk=xdbc". This gives
users a chance of providing debug output.

The hardware for USB3 debug port requires DMA memory blocks.
This requires to delay setting up debugging hardware and
registering boot console until the memblocks are filled.

Cc: Ingo Molnar 
Cc: x...@kernel.org
Signed-off-by: Lu Baolu 
---
 Documentation/kernel-parameters.txt | 1 +
 arch/x86/kernel/early_printk.c  | 5 +
 arch/x86/kernel/setup.c | 7 +++
 3 files changed, 13 insertions(+)

diff --git a/Documentation/kernel-parameters.txt 
b/Documentation/kernel-parameters.txt
index 37babf9..99b64b3 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1178,6 +1178,7 @@ bytes respectively. Such letter suffixes can also be 
entirely omitted.
earlyprintk=ttySn[,baudrate]
earlyprintk=dbgp[debugController#]
earlyprintk=pciserial,bus:device.function[,baudrate]
+   earlyprintk=xdbc[xhciController#]
 
earlyprintk is useful when the kernel crashes before
the normal console is initialized. It is not enabled by
diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
index 8a12199..c4031b9 100644
--- a/arch/x86/kernel/early_printk.c
+++ b/arch/x86/kernel/early_printk.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -381,6 +382,10 @@ static int __init setup_early_printk(char *buf)
if (!strncmp(buf, "efi", 3))
early_console_register(_efi_console, keep);
 #endif
+#ifdef CONFIG_EARLY_PRINTK_XDBC
+   if (!strncmp(buf, "xdbc", 4))
+   early_xdbc_parse_parameter(buf + 4);
+#endif
 
buf++;
}
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 9c337b0..09d4a56 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -70,6 +70,8 @@
 #include 
 #include 
 
+#include 
+
 #include 
 
 #include 
@@ -1096,6 +1098,11 @@ void __init setup_arch(char **cmdline_p)
memblock_set_current_limit(ISA_END_ADDRESS);
memblock_x86_fill();
 
+#ifdef CONFIG_EARLY_PRINTK_XDBC
+   if (!early_xdbc_setup_hardware())
+   early_xdbc_register_console();
+#endif
+
reserve_bios_regions();
 
if (efi_enabled(EFI_MEMMAP)) {
-- 
2.1.4

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


[PATCH v4 3/4] usb: serial: usb_debug: add support for dbc debug device

2016-10-31 Thread Lu Baolu
This patch add dbc debug device support in usb_debug driver.

Signed-off-by: Lu Baolu 
Acked-by: Johan Hovold 
---
 drivers/usb/serial/usb_debug.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/usb_debug.c b/drivers/usb/serial/usb_debug.c
index ca2fa5b..92f7e5c 100644
--- a/drivers/usb/serial/usb_debug.c
+++ b/drivers/usb/serial/usb_debug.c
@@ -32,7 +32,18 @@ static const struct usb_device_id id_table[] = {
{ USB_DEVICE(0x0525, 0x127a) },
{ },
 };
-MODULE_DEVICE_TABLE(usb, id_table);
+
+static const struct usb_device_id dbc_id_table[] = {
+   { USB_DEVICE(0x1d6b, 0x0004) },
+   { },
+};
+
+static const struct usb_device_id id_table_combined[] = {
+   { USB_DEVICE(0x0525, 0x127a) },
+   { USB_DEVICE(0x1d6b, 0x0004) },
+   { },
+};
+MODULE_DEVICE_TABLE(usb, id_table_combined);
 
 /* This HW really does not support a serial break, so one will be
  * emulated when ever the break state is set to true.
@@ -71,9 +82,20 @@ static struct usb_serial_driver debug_device = {
.process_read_urb = usb_debug_process_read_urb,
 };
 
+static struct usb_serial_driver dbc_device = {
+   .driver = {
+   .owner =THIS_MODULE,
+   .name = "xhci_dbc",
+   },
+   .id_table = dbc_id_table,
+   .num_ports =1,
+   .break_ctl =usb_debug_break_ctl,
+   .process_read_urb = usb_debug_process_read_urb,
+};
+
 static struct usb_serial_driver * const serial_drivers[] = {
-   _device, NULL
+   _device, _device, NULL
 };
 
-module_usb_serial_driver(serial_drivers, id_table);
+module_usb_serial_driver(serial_drivers, id_table_combined);
 MODULE_LICENSE("GPL");
-- 
2.1.4

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


[PATCH v4 4/4] usb: doc: add document for USB3 debug port usage

2016-10-31 Thread Lu Baolu
Add Documentation/usb/usb3-debug-port.rst. This document includes
the user guide for USB3 debug port.

Cc: linux-...@vger.kernel.org
Signed-off-by: Lu Baolu 
---
 Documentation/usb/usb3-debug-port.rst | 95 +++
 1 file changed, 95 insertions(+)
 create mode 100644 Documentation/usb/usb3-debug-port.rst

diff --git a/Documentation/usb/usb3-debug-port.rst 
b/Documentation/usb/usb3-debug-port.rst
new file mode 100644
index 000..70eabe4
--- /dev/null
+++ b/Documentation/usb/usb3-debug-port.rst
@@ -0,0 +1,95 @@
+===
+USB3 debug port
+===
+
+:Author: Lu Baolu 
+:Date: October 2016
+
+GENERAL
+===
+
+This is a HOWTO for using USB3 debug port on x86 systems.
+
+Before using any kernel debugging functionalities based on USB3
+debug port, you need to check 1) whether debug port is supported
+by the xHCI host, 2) which port is used for debugging purpose
+(normally the first USB3 root port). You must have a USB 3.0
+super-speed A-to-A debugging cable to connect the debug target
+with a debug host. In this document, a debug target stands for
+the system under debugging; while, a debug host stands for a
+stand-alone system that is able to talk to the debugging target
+through the USB3 debug port.
+
+EARLY PRINTK
+
+
+On debug target system, you need to customize a debugging kernel
+with CONFIG_EARLY_PRINTK_XDBC enabled. And add below kernel boot
+parameter::
+
+   "earlyprintk=xdbc"
+
+If there are multiple xHCI controllers in the system, you can
+append a host contoller index to this kernel parameter. This
+index is started from 0.
+
+If you are going to leverage the keep option defined by the
+early printk framework to keep the boot console alive after
+early boot, you'd better add below kernel boot parameter::
+
+   "usbcore.autosuspend=-1"
+
+On debug host side, you don't need to customize the kernel, but
+you need to disable usb subsystem runtime power management by
+adding below kernel boot parameter::
+
+   "usbcore.autosuspend=-1"
+
+Before starting the debug target, you should connect the debug
+port on debug target with a root port or port of any external hub
+on the debug host. The cable used to connect these two ports
+should be a USB 3.0 super-speed A-to-A debugging cable.
+
+During early boot of debug target, DbC (the debug engine for USB3
+debug port) hardware gets initialized. Debug host should be able
+to enumerate the debug target as a debug device. Debug host will
+then bind the debug device with the usb_debug driver module and
+create the /dev/ttyUSB0 device.
+
+If device enumeration goes smoothly, you should be able to see
+below kernel messages on debug host::
+
+   # tail -f /var/log/kern.log
+   [ 1815.983374] usb 4-3: new SuperSpeed USB device number 4 using 
xhci_hcd
+   [ 1815.999595] usb 4-3: LPM exit latency is zeroed, disabling LPM.
+   [ 1815.999899] usb 4-3: New USB device found, idVendor=1d6b, 
idProduct=0004
+   [ 1815.02] usb 4-3: New USB device strings: Mfr=1, Product=2, 
SerialNumber=3
+   [ 1815.03] usb 4-3: Product: Remote GDB
+   [ 1815.04] usb 4-3: Manufacturer: Linux
+   [ 1815.05] usb 4-3: SerialNumber: 0001
+   [ 1816.000240] usb_debug 4-3:1.0: xhci_dbc converter detected
+   [ 1816.000360] usb 4-3: xhci_dbc converter now attached to ttyUSB0
+
+You can run below bash scripts on debug host to read the kernel
+log sent from debug target.
+
+.. code-block:: sh
+
+   = start of bash scripts =
+   #!/bin/bash
+
+   while true ; do
+   while [ ! -d /sys/class/tty/ttyUSB0 ] ; do
+   :
+   done
+   cat /dev/ttyUSB0 >> xdbc.log
+   done
+   = end of bash scripts ===
+
+You should be able to see the early boot message in xdbc.log.
+
+If it doesn't work, please ask it on the 
+mailing list. Below USB hosts have been verified to work::
+
+   Intel Corporation Sunrise Point-H USB 3.0 xHCI Controller
+   Intel Corporation Wildcat Point-LP USB xHCI Controller
-- 
2.1.4

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


[PATCH v4 0/4] usb: early: add support for early printk through USB3 debug port

2016-10-31 Thread Lu Baolu
xHCI debug capability (DbC) is an optional but standalone
functionality provided by an xHCI host controller. With DbC
hardware initialized, the system will present a debug device
through the USB3 debug port (normally the first USB3 port).
The debug device is fully compliant with the USB framework
and provides the equivalent of a very high performance (USB3)
full-duplex serial link between the debug host and target.
The DbC functionality is independent of xHCI host. There
isn't any precondition from xHCI host side for DbC to work.

This patch set adds support for early printk functionality
through a USB3 debug port by 1) initializing and enabling
the DbC hardware during early boot; 2) registering a boot
console to the system so that early printk messages can go
through the USB3 debug port. It also includes some lines
of changes in usb_debug driver so that it can be bound when
a USB3 debug device is enumerated.

This code is designed to be used only for kernel debugging
when machine crashes very early before the console code is
initialized. It makes the life of kernel debugging easier
when people work with a modern machine without any legacy
serial ports.

---
Change log:
v3->v4:
  - Rename the document with .dst suffix.
  - Add the list of hardware that has been succesfuly
tested on in the document.

v2->v3:
  - Removed spinlock usage.
  - Removed work queue usage.
  - Refined the user guide document.

v1->v2:
  - Refactor the duplicate code in xdbc_early_start() and
xdbc_handle_external_reset().
  - Free resources when hardware not used any more.
  - Refine the user guide document.

Lu Baolu (4):
  usb: dbc: early driver for xhci debug capability
  x86: add support for earlyprintk via USB3 debug port
  usb: serial: usb_debug: add support for dbc debug device
  usb: doc: add document for USB3 debug port usage

 Documentation/kernel-parameters.txt   |1 +
 Documentation/usb/usb3-debug-port.rst |   95 +++
 arch/x86/Kconfig.debug|   14 +
 arch/x86/kernel/early_printk.c|5 +
 arch/x86/kernel/setup.c   |7 +
 drivers/usb/Kconfig   |3 +
 drivers/usb/Makefile  |2 +-
 drivers/usb/early/Makefile|1 +
 drivers/usb/early/xhci-dbc.c  | 1050 +
 drivers/usb/early/xhci-dbc.h  |  202 +++
 drivers/usb/serial/usb_debug.c|   28 +-
 include/linux/usb/xhci-dbgp.h |   22 +
 12 files changed, 1426 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/usb/usb3-debug-port.rst
 create mode 100644 drivers/usb/early/xhci-dbc.c
 create mode 100644 drivers/usb/early/xhci-dbc.h
 create mode 100644 include/linux/usb/xhci-dbgp.h

-- 
2.1.4

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


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

2016-10-31 Thread Baolin Wang
Hi,

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

If we set the suspend checking at here, we will lose the chance to
free gadget irq when stopping gadget.

>
> spin_lock_irqsave(>lock, flags);
> __dwc3_gadget_stop(dwc);
> dwc->gadget_driver  = NULL;

Can we set the suspend checking at here? And we should not delete the
suspend checking in __dwc3_gadget_stop() function.

+  if 

Super Top USB SD card reader resets and corruption - XHCI

2016-10-31 Thread Krzysztof HaƂasa
Hi,

I came across a problem with an USB SD card reader apparently causing
USB resets and corrupting data on the card.

The reader in question is a very cheap:

14cd:1212 Super Top microSD card reader (SY-T18)
The card is an old SDHC, 32 GB, Sandisk brand.

The problems don't seem to exist now if I connect the reader to an
EHCI-equipped machine (an old Core2 duo + ICH10). I can read and write
MBs of data, however older logs suggest that this computer also had the
issue in the past (with Linux 4.6.3-300.fc24.x86_64, with both EHCI and UHCI).

I can't use it with an XHCI. Both:
Intel Corp 8 Series/C220 Series Chipset Family USB xHCI (rev 04) (prog-if 30 
[XHCI])
(SandyBridge laptop with only USB2.0 connectors) and:
Intel Corp Sunrise Point-H USB 3.0 xHCI Controller (rev 31)
(a Skylake + Z170 and USB3, though the reader is USB2) have the issue.

I have spotted the following writted to the SD card, I guess it's some
USB mass storage write command:

3d085000  55 53 42 43 ca 08 00 00  00 e0 01 00 00 00 0a 2a  |USBC...*|
3d085010  00 00 1e 83 70 00 00 f0  00 00 00 00 00 00 00 b2  |p...|
3d085020  2d 00 38 00 a9 c8 f4 ab  10 8d cc 39 e1 8f 43 45  |-.89..CE|

I think the problem doesn't manifest itself if I don't write (RO mount)
to the SD card. However, even light writes seem to trigger the issue.

The kernels are basically recent Fedora, 4.7.4-200.fc24.x86_64,
4.7.9-200.fc24.x86_64 but it seems e.g. 4.6.3-300.fc24.x86_64 was also
affected. The one which doesn't cause problems now (EHCI) is
4.7.2-201.fc24.x86_64 (though EHCI did cause problems previously).

Could it be faulty hw?
What can I do with this?

[80125.418020] usb 1-1: new high-speed USB device number 9 using xhci_hcd
[80125.583307] usb 1-1: New USB device found, idVendor=14cd, idProduct=1212
[80125.583315] usb 1-1: New USB device strings: Mfr=1, Product=3, SerialNumber=2
[80125.583320] usb 1-1: Product: Mass Storage Device
[80125.583324] usb 1-1: Manufacturer: Generic
[80125.583327] usb 1-1: SerialNumber: 121220130416
[80125.585139] usb-storage 1-1:1.0: USB Mass Storage device detected
[80125.585392] scsi host6: usb-storage 1-1:1.0
[80126.586670] scsi 6:0:0:0: Direct-Access Mass Storage Device   1.00 
PQ: 0 ANSI: 0 CCS
[80126.587547] sd 6:0:0:0: Attached scsi generic sg3 type 0
[80126.775260] sd 6:0:0:0: [sdc] 62333952 512-byte logical blocks: (31.9 
GB/29.7 GiB)
[80126.775504] sd 6:0:0:0: [sdc] Write Protect is off
[80126.775510] sd 6:0:0:0: [sdc] Mode Sense: 03 00 00 00
[80126.775686] sd 6:0:0:0: [sdc] No Caching mode page found
[80126.775696] sd 6:0:0:0: [sdc] Assuming drive cache: write through
[80126.787956]  sdc: sdc1
[80126.789309] sd 6:0:0:0: [sdc] Attached SCSI removable disk
[80396.165947] usb 1-1: reset high-speed USB device number 9 using xhci_hcd
[80408.251009] usb 1-1: USB disconnect, device number 9
[80408.256545] sd 6:0:0:0: [sdc] tag#0 FAILED Result: hostbyte=DID_NO_CONNECT 
driverbyte=DRIVER_OK
[80408.256555] sd 6:0:0:0: [sdc] tag#0 CDB: Write(10) 2a 00 00 02 82 50 00 00 
f0 00
[80408.256560] blk_update_request: I/O error, dev sdc, sector 164432
[80408.256567] Buffer I/O error on dev sdc1, logical block 19530, lost async 
page write
[80408.256578] Buffer I/O error on dev sdc1, logical block 19531, lost async 
page write
[80408.256583] Buffer I/O error on dev sdc1, logical block 19532, lost async 
page write
[80408.256587] Buffer I/O error on dev sdc1, logical block 19533, lost async 
page write
[80408.256592] Buffer I/O error on dev sdc1, logical block 19534, lost async 
page write
[80408.256596] Buffer I/O error on dev sdc1, logical block 19535, lost async 
page write
[80408.256600] Buffer I/O error on dev sdc1, logical block 19536, lost async 
page write
[80408.256604] Buffer I/O error on dev sdc1, logical block 19537, lost async 
page write
[80408.256608] Buffer I/O error on dev sdc1, logical block 19538, lost async 
page write
[80408.256611] Buffer I/O error on dev sdc1, logical block 19539, lost async 
page write
[80408.340407] VFS: Dirty inode writeback failed for block device sdc1 (err=-5).
[80408.618642] usb 1-1: new high-speed USB device number 10 using xhci_hcd
[80408.783479] usb 1-1: New USB device found, idVendor=14cd, idProduct=1212
[80408.783487] usb 1-1: New USB device strings: Mfr=1, Product=3, SerialNumber=2
[80408.783492] usb 1-1: Product: Mass Storage Device
[80408.783496] usb 1-1: Manufacturer: Generic
[80408.784034] usb-storage 1-1:1.0: USB Mass Storage device detected
[80408.784253] scsi host6: usb-storage 1-1:1.0
[80409.786335] scsi 6:0:0:0: Direct-Access Mass Storage Device   1.00 
PQ: 0 ANSI: 0 CCS
[80409.787089] sd 6:0:0:0: Attached scsi generic sg3 type 0
[80409.975129] sd 6:0:0:0: [sdc] 62333952 512-byte logical blocks: (31.9 
GB/29.7 GiB)
[80409.975380] sd 6:0:0:0: [sdc] Write Protect is off
[80409.975389] sd 6:0:0:0: [sdc] Mode Sense: 03 00 00 00
[80409.976494] sd 6:0:0:0: [sdc] No Caching mode page found
[80409.976503] sd 6:0:0:0: [sdc] Assuming drive cache: 

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

2016-10-31 Thread kbuild test robot
Hi Vardan,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.9-rc3 next-20161028]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]
[Suggest to use git(>=2.9.0) format-patch --base= (or --base=auto for 
convenience) to record what (public, well-known) commit your patch series was 
built on]
[Check https://git-scm.com/docs/git-format-patch for more information]

url:
https://github.com/0day-ci/linux/commits/John-Youn/usb-dwc2-gadget-Update-for-new-usb_endpoint_maxp/20161101-052727
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-randconfig-x014-201644 (attached as .config)
compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   drivers/usb/dwc2/gadget.c: In function 'dwc2_hsotg_ep_enable':
>> drivers/usb/dwc2/gadget.c:2979:7: error: implicit declaration of function 
>> 'usb_endpoint_maxp_mult' [-Werror=implicit-function-declaration]
 mc = usb_endpoint_maxp_mult(desc);
  ^~
   cc1: some warnings being treated as errors

vim +/usb_endpoint_maxp_mult +2979 drivers/usb/dwc2/gadget.c

  2973  if (dir_in != hs_ep->dir_in) {
  2974  dev_err(hsotg->dev, "%s: direction mismatch!\n", 
__func__);
  2975  return -EINVAL;
  2976  }
  2977  
  2978  mps = usb_endpoint_maxp(desc);
> 2979  mc = usb_endpoint_maxp_mult(desc);
  2980  
  2981  /* note, we handle this here instead of 
dwc2_hsotg_set_ep_maxpacket */
  2982  

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


.config.gz
Description: application/gzip


[PATCH] usb: storage: drop freezer.h usage

2016-10-31 Thread Greg KH
From: Greg Kroah-Hartman 

usb-storage does not use any freezer apis, so drop the inclusion of
freezer.h from the drivers/usb/storage/usb.c file.

Signed-off-by: Greg Kroah-Hartman 

diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 2cba13a532cd..615bea08ec0a 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -52,7 +52,6 @@
 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
--
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: [RFC][PATCH] usb: dwc2: Make sure we disconnect the gadget state on reset

2016-10-31 Thread John Youn
On 10/31/2016 4:19 AM, Felipe Balbi wrote:
> 
> Hi,
> 
> John Stultz  writes:
>> I had seen some odd behavior with HiKey's usb-gadget interface
>> that I finally seemed to have chased down. Basically every other
>> time I pluged in the OTG port, the gadget interface would
>> properly initialize. The other times, I'd get a big WARN_ON
>> in dwc2_hsotg_init_fifo() about the fifo_map not being clear.
>>
>> Ends up If we don't disconnect the gadget state on reset, the
>> fifo-map doesn't get cleared properly, which causes WARN_ON
>> messages and also results in the device not properly being
>> setup as a gadget every other time the OTG port is connected.
>>
>> So this patch adds a call to dwc2_hsotg_disconnect() in the
>> reset path so the state is properly cleared.
>>
>> With it, the gadget interface initializes properly on every
>> plug in.
>>
>> I don't know if this is actually the right fix, but it seems
>> to work well. Feedback would be greatly appreciated!
>>
>> Cc: Wei Xu 
>> Cc: Guodong Xu 
>> Cc: Chen Yu 
>> Cc: Amit Pundir 
>> Cc: Rob Herring 
>> Cc: Mark Rutland 
>> Cc: John Youn 
>> Cc: Douglas Anderson 
>> Cc: Greg Kroah-Hartman 
>> Cc: linux-usb@vger.kernel.org
>> Signed-off-by: John Stultz 
>> ---
>>  drivers/usb/dwc2/gadget.c | 2 ++
>>  1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
>> index 24fbebc..5505001 100644
>> --- a/drivers/usb/dwc2/gadget.c
>> +++ b/drivers/usb/dwc2/gadget.c
>> @@ -2519,6 +2519,8 @@ void dwc2_hsotg_core_init_disconnected(struct 
>> dwc2_hsotg *hsotg,
>>  
>>  /* Kill any ep0 requests as controller will be reinitialized */
>>  kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET);
>> +/* Make sure everything is disconnected */
>> +dwc2_hsotg_disconnect(hsotg);
> 
> Dunno, seems like you're actually working around a different
> bug. Looking at USB Reset handler we have:
> 
>   if (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) {
> 
>   u32 usb_status = dwc2_readl(hsotg->regs + GOTGCTL);
>   u32 connected = hsotg->connected;
> 
>   dev_dbg(hsotg->dev, "%s: USBRst\n", __func__);
>   dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
>   dwc2_readl(hsotg->regs + GNPTXSTS));
> 
>   dwc2_writel(GINTSTS_USBRST, hsotg->regs + GINTSTS);
> 
>   /* Report disconnection if it is not already done. */
>   dwc2_hsotg_disconnect(hsotg);
> 
>   if (usb_status & GOTGCTL_BSESVLD && connected)
>   dwc2_hsotg_core_init_disconnected(hsotg, true);
>   }
> 
> so, dwc2_hsotg_disconnect() is already called from Reset path. What
> you're doing here is that you could, potentially, call
> driver->disconnect() twice.
> 
> The real problem could be your implementation for ->pullup() which
> duplicates part of what ->udc_start() does:
> 
> static int dwc2_hsotg_pullup(struct usb_gadget *gadget, int is_on)
> {
>   struct dwc2_hsotg *hsotg = to_hsotg(gadget);
>   unsigned long flags = 0;
> 
>   dev_dbg(hsotg->dev, "%s: is_on: %d op_state: %d\n", __func__, is_on,
>   hsotg->op_state);
> 
>   /* Don't modify pullup state while in host mode */
>   if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) {
>   hsotg->enabled = is_on;
>   return 0;
>   }
> 
>   spin_lock_irqsave(>lock, flags);
>   if (is_on) {
>   hsotg->enabled = 1;
>   dwc2_hsotg_core_init_disconnected(hsotg, false);
>   dwc2_hsotg_core_connect(hsotg);
>   } else {
>   dwc2_hsotg_core_disconnect(hsotg);
>   dwc2_hsotg_disconnect(hsotg);
>   hsotg->enabled = 0;
>   }
> 
>   hsotg->gadget.speed = USB_SPEED_UNKNOWN;
>   spin_unlock_irqrestore(>lock, flags);
> 
>   return 0;
> }
> 
> Here's what I think dwc2_hsotg_pullup() and dwc2_hsotg_udc_start()
> should contain:
> 
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 9dc6c482b89e..dbe28947d3a9 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -3388,6 +3388,7 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
>   dwc2_writel(0, hsotg->regs + DAINTMSK);
>  
>   /* Be in disconnected state until gadget is registered */
> + /* REVISIT This should be done in probe() */
>   __orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
>  
>   /* setup fifos */
> @@ -3428,26 +3429,6 @@ static int dwc2_hsotg_udc_start(struct usb_gadget 
> *gadget,
>   unsigned long flags;
>   int ret;
>  
> - if (!hsotg) {
> - pr_err("%s: called with no device\n", __func__);
> - return -ENODEV;

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

2016-10-31 Thread John Youn
From: Vardan Mikayelyan 

Update the dwc2 driver for the new behavior of the usb_endpoint_maxp()
and also use the new usb_endpoint_maxp_mult() helper function.

This commit fixes failures in high-badwith ISOC transfer tests.

Signed-off-by: Vardan Mikayelyan 
Signed-off-by: John Youn 
---
 drivers/usb/dwc2/gadget.c | 38 --
 1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 8a7fd73..a505bbf 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1812,17 +1812,17 @@ static u32 dwc2_hsotg_ep0_mps(unsigned int mps)
  * @hsotg: The driver state.
  * @ep: The index number of the endpoint
  * @mps: The maximum packet size in bytes
+ * @mc: The multicount value
  *
  * Configure the maximum packet size for the given endpoint, updating
  * the hardware control registers to reflect this.
  */
 static void dwc2_hsotg_set_ep_maxpacket(struct dwc2_hsotg *hsotg,
-   unsigned int ep, unsigned int mps, unsigned int dir_in)
+   unsigned int ep, unsigned int mps,
+   unsigned int mc, unsigned int dir_in)
 {
struct dwc2_hsotg_ep *hs_ep;
void __iomem *regs = hsotg->regs;
-   u32 mpsval;
-   u32 mcval;
u32 reg;
 
hs_ep = index_to_ep(hsotg, ep, dir_in);
@@ -1831,31 +1831,29 @@ static void dwc2_hsotg_set_ep_maxpacket(struct 
dwc2_hsotg *hsotg,
 
if (ep == 0) {
/* EP0 is a special case */
-   mpsval = dwc2_hsotg_ep0_mps(mps);
-   if (mpsval > 3)
+   mps = dwc2_hsotg_ep0_mps(mps);
+   if (mps > 3)
goto bad_mps;
hs_ep->ep.maxpacket = mps;
hs_ep->mc = 1;
} else {
-   mpsval = mps & DXEPCTL_MPS_MASK;
-   if (mpsval > 1024)
+   if (mps > 1024)
goto bad_mps;
-   mcval = ((mps >> 11) & 0x3) + 1;
-   hs_ep->mc = mcval;
-   if (mcval > 3)
+   hs_ep->mc = mc;
+   if (mc > 3)
goto bad_mps;
-   hs_ep->ep.maxpacket = mpsval;
+   hs_ep->ep.maxpacket = mps;
}
 
if (dir_in) {
reg = dwc2_readl(regs + DIEPCTL(ep));
reg &= ~DXEPCTL_MPS_MASK;
-   reg |= mpsval;
+   reg |= mps;
dwc2_writel(reg, regs + DIEPCTL(ep));
} else {
reg = dwc2_readl(regs + DOEPCTL(ep));
reg &= ~DXEPCTL_MPS_MASK;
-   reg |= mpsval;
+   reg |= mps;
dwc2_writel(reg, regs + DOEPCTL(ep));
}
 
@@ -2390,13 +2388,15 @@ static void dwc2_hsotg_irq_enumdone(struct dwc2_hsotg 
*hsotg)
if (ep0_mps) {
int i;
/* Initialize ep0 for both in and out directions */
-   dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 1);
-   dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0);
+   dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 1);
+   dwc2_hsotg_set_ep_maxpacket(hsotg, 0, ep0_mps, 0, 0);
for (i = 1; i < hsotg->num_of_eps; i++) {
if (hsotg->eps_in[i])
-   dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 
1);
+   dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps,
+   0, 1);
if (hsotg->eps_out[i])
-   dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps, 
0);
+   dwc2_hsotg_set_ep_maxpacket(hsotg, i, ep_mps,
+   0, 0);
}
}
 
@@ -2952,6 +2952,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
u32 epctrl_reg;
u32 epctrl;
u32 mps;
+   u32 mc;
u32 mask;
unsigned int dir_in;
unsigned int i, val, size;
@@ -2975,6 +2976,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
}
 
mps = usb_endpoint_maxp(desc);
+   mc = usb_endpoint_maxp_mult(desc);
 
/* note, we handle this here instead of dwc2_hsotg_set_ep_maxpacket */
 
@@ -2996,7 +2998,7 @@ static int dwc2_hsotg_ep_enable(struct usb_ep *ep,
epctrl |= DXEPCTL_USBACTEP;
 
/* update the endpoint state */
-   dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, dir_in);
+   dwc2_hsotg_set_ep_maxpacket(hsotg, hs_ep->index, mps, mc, dir_in);
 
/* default, set to non-periodic */
hs_ep->isochronous = 0;
-- 
2.10.0

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

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

2016-10-31 Thread Stefan Wahren
I inspired by this issue [1] i build up a slightly modified setup with a
Raspberry Pi B (mainline kernel 4.9rc3), a powered 7 port USB hub and 5 Prolific
PL2303 USB to serial convertors. I modified the usb_test for dwc2 [2], which
only tries to open all ttyUSB devices one after the other. 

Unfortunately the complete system stuck after opening the first ttyUSB device (
heartbeat LED stop blinking, no reaction to debug UART). The only way to
reanimate the system is to powerdown the USB hub with the USB to serial
convertors.

[1] - https://github.com/raspberrypi/linux/issues/1692
[2] - https://gist.github.com/lategoodbye/dd0d30af27b6f101b03d5923b279dbaa

pi@raspberrypi:~$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc2/1p, 480M
|__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/3p, 480M
|__ Port 1: Dev 3, If 0, Class=Vendor Specific Class, Driver=smsc95xx,
480M
|__ Port 2: Dev 11, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 15, If 0, Class=Vendor Specific Class,
Driver=pl2303, 12M
|__ Port 1: Dev 12, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 2: Dev 14, If 0, Class=Vendor Specific Class,
Driver=pl2303, 12M
|__ Port 3: Dev 16, If 0, Class=Vendor Specific Class,
Driver=pl2303, 12M
|__ Port 4: Dev 17, If 0, Class=Vendor Specific Class,
Driver=pl2303, 12M
|__ Port 2: Dev 13, If 0, Class=Vendor Specific Class,
Driver=pl2303, 12M

pi@raspberrypi:~$ ./usb_test
idle
opening [/dev/ttyUSB0] ok
[  232.658768] NMI watchdog: BUG: soft lockup - CPU#0 stuck for 146s!
[usb_test:522]
[  232.678443] Modules linked in: pwm_bcm2835 vchiq(C)
[  232.678481] CPU: 0 PID: 522 Comm: usb_test Tainted: G C
 4.9.0-rc3+ #33
[  232.678486] Hardware name: BCM2835
[  232.678498] task: cab54e40 task.stack: c688c000
[  232.678520] PC is at __do_softirq+0x68/0x2a8
[  232.678538] LR is at irq_exit+0xb8/0x120
[  232.678552] pc : []lr : []psr: 6113
sp : c688da60  ip : c688daa8  fp : c688daa4
[  232.678560] r10: c0b7f800  r9 : c688c000  r8 : 0040
[  232.678567] r7 : 000a  r6 : cb802400  r5 :   r4 : 0001
[  232.678575] r3 :   r2 : 0100  r1 : 0040  r0 : 
[  232.678585] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment none
[  232.678593] Control: 00c5387d  Table: 068a4008  DAC: 0051
[  232.678604] CPU: 0 PID: 522 Comm: usb_test Tainted: G C
 4.9.0-rc3+ #33
[  232.678609] Hardware name: BCM2835
[  232.678667] [] (unwind_backtrace) from []
(show_stack+0x20/0x24)
[  232.678695] [] (show_stack) from []
(dump_stack+0x20/0x28)
[  232.678718] [] (dump_stack) from [] (show_regs+0x1c/0x20)
[  232.678752] [] (show_regs) from []
(watchdog_timer_fn+0x140/0x19c)
[  232.678779] [] (watchdog_timer_fn) from []
(__hrtimer_run_queues.constprop.3+0xec/0x210)
[  232.678798] [] (__hrtimer_run_queues.constprop.3) from []
(hrtimer_interrupt+0xa4/0x1cc)
[  232.678827] [] (hrtimer_interrupt) from []
(bcm2835_time_interrupt+0x40/0x48)
[  232.678865] [] (bcm2835_time_interrupt) from []
(__handle_irq_event_percpu+0x68/0x1b8)
[  232.678891] [] (__handle_irq_event_percpu) from []
(handle_irq_event_percpu+0x2c/0x68)
[  232.678915] [] (handle_irq_event_percpu) from []
(handle_irq_event+0x38/0x4c)
[  232.678939] [] (handle_irq_event) from []
(handle_level_irq+0xc4/0xf8)
[  232.678960] [] (handle_level_irq) from []
(generic_handle_irq+0x28/0x38)
[  232.678983] [] (generic_handle_irq) from []
(__handle_domain_irq+0x90/0xb8)
[  232.679004] [] (__handle_domain_irq) from []
(bcm2835_handle_irq+0x30/0x48)
[  232.679022] [] (bcm2835_handle_irq) from []
(__irq_svc+0x6c/0x90)
[  232.679031] Exception stack(0xc688da10 to 0xc688da58)
[  232.679044] da00:  0040
0100 
[  232.679062] da20: 0001  cb802400 000a 0040 c688c000
c0b7f800 c688daa4
[  232.679078] da40: c688daa8 c688da60 c0121270 c01014d0 6113 f00
c687a300 c9374900 ca918b00 caff1200 c688db84
[  232.679235] db20: c688db28 c688db40 c04a1cf8 c049cb64 6013 
[  232.679272] [] (__irq_svc) from []
(_dwc2_hcd_urb_enqueue+0x414/0x560)
[  232.679302] [] (_dwc2_hcd_urb_enqueue) from []
(usb_hcd_submit_urb+0x704/0x8c4)
[  232.679327] [] (usb_hcd_submit_urb) from []
(usb_submit_urb+0x438/0x4e0)
[  232.679358] [] (usb_submit_urb) from []
(usb_serial_generic_submit_read_urb+0x50/0xc8)
[  232.679382] [] (usb_serial_generic_submit_read_urb) from
[] (usb_serial_generic_submit_read_urbs+0x28/0x70)
[  232.679407] [] (usb_serial_generic_submit_read_urbs) from
[] (usb_serial_generic_open+0x44/0x4c)
[  232.679435] [] (usb_serial_generic_open) from []
(pl2303_open+0xc0/0xe0)
[  232.679458] [] (pl2303_open) from []
(serial_port_activate+0x54/0x8c)
[  232.679486] [] (serial_port_activate) from []
(tty_port_open+0x84/0xd4)
[  232.679509] [] (tty_port_open) from []
(serial_open+0x34/0x5c)
[  232.679546] [] (serial_open) from []

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

2016-10-31 Thread John Youn
On 10/28/2016 3:09 AM, Felipe Balbi wrote:
> 
> Hi,
> 
> John Youn  writes:
>> On 10/27/2016 3:47 AM, Felipe Balbi wrote:
>>>
>>> Hi,
>>>
>>> John Youn  writes:
 Add interrupt moderation interval binding for dwc3.

 Signed-off-by: John Youn 
 ---
  Documentation/devicetree/bindings/usb/dwc3.txt | 1 +
  1 file changed, 1 insertion(+)

 diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
 b/Documentation/devicetree/bindings/usb/dwc3.txt
 index e3e6983..17de9fc 100644
 --- a/Documentation/devicetree/bindings/usb/dwc3.txt
 +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
 @@ -53,6 +53,7 @@ Optional properties:
   - snps,quirk-frame-length-adjustment: Value for GFLADJ_30MHZ field of 
 GFLADJ
register for post-silicon frame length adjustment when the
fladj_30mhz_sdbnd signal is invalid or incorrect.
 + - snps,imod_interval: the interrupt moderation interval.
>>>
>>> on top of all other comments, what's the unit here? nanoseconds? clock 
>>> cycles?
>>>
>>
>> Number of 250 ns intervals. I'll update the description to clarify.
> 
> it's probably better to add it in nanoseconds itself, then let driver
> compute register value with DIV_ROUND_UP()
> 

I'm fine with it either way, but I think "increments of 250 ns" is
slightly cleaner in that it reflects the exact settings that are
possible and documented, and also fits neatly into a u16.

I assume you'd also like the internal variable dwc3->imod_interval
changed as well?

Regards,
John


--
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 14/82] media: usb: uvc: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Laurent Pinchart
Hi Felipe,

Thank you for the patch.

On Monday 31 Oct 2016 12:48:06 Felipe Balbi wrote:
> We have introduced a helper to calculate multiplier
> value from wMaxPacketSize. Start using it.
> 
> Cc: Laurent Pinchart 
> Cc: Mauro Carvalho Chehab 
> Cc: 
> Signed-off-by: Felipe Balbi 

Acked-by: Laurent Pinchart 

> ---
>  drivers/media/usb/uvc/uvc_video.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/usb/uvc/uvc_video.c
> b/drivers/media/usb/uvc/uvc_video.c index b5589d5f5da4..11e0e5f4e1c2 100644
> --- a/drivers/media/usb/uvc/uvc_video.c
> +++ b/drivers/media/usb/uvc/uvc_video.c
> @@ -1467,6 +1467,7 @@ static unsigned int uvc_endpoint_max_bpi(struct
> usb_device *dev, struct usb_host_endpoint *ep)
>  {
>   u16 psize;
> + u16 mult;
> 
>   switch (dev->speed) {
>   case USB_SPEED_SUPER:
> @@ -1474,7 +1475,8 @@ static unsigned int uvc_endpoint_max_bpi(struct
> usb_device *dev, return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
>   case USB_SPEED_HIGH:
>   psize = usb_endpoint_maxp(>desc);
> - return (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
> + mult = usb_endpoint_maxp_mult(>desc);
> + return (psize & 0x07ff) * mult;
>   case USB_SPEED_WIRELESS:
>   psize = usb_endpoint_maxp(>desc);
>   return psize;

-- 
Regards,

Laurent Pinchart

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


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

2016-10-31 Thread John Youn
On 10/28/2016 3:39 AM, Mark Rutland wrote:
> On Fri, Oct 28, 2016 at 01:30:07PM +0300, Felipe Balbi wrote:
>> Mark Rutland  writes:
>>> On Thu, Oct 27, 2016 at 02:08:25PM -0700, John Youn wrote:
 On 10/26/2016 3:57 AM, Mark Rutland wrote:
> On Tue, Oct 25, 2016 at 12:42:46PM -0700, John Youn wrote:
>> Add interrupt moderation interval binding for dwc3.
>>>
>> + - snps,imod_interval: the interrupt moderation interval.
> 
 This series implements the feature and enables it as a workaround for
 a particular version of the controller.
>>>
>>> ... as a workaround for *what*? Is there a bug in that IP version, or an
>>
>> you didn't receive the entire series, I guess. Here's last patch in the
>> series:
> 
> No, I did not. Thanks for forwarding this.
> 
>>  This is a workaround for STAR 9000961433 which affects only version
>>  3.00a of the DWC_usb3 core. This prevents the controller interrupt from
>>  being masked while handling events. Enabling interrupt moderation allows
>>  us to work around this issue because once the GEVNTCOUNT.count is
>>  written the IRQ is immediately deasserted and won't be asserted again
>>  until GEVNTCOUNT.EHB is cleared.
>>
>>  Signed-off-by: John Youn 
>>  ---
>>   drivers/usb/dwc3/core.c | 12 
>>   1 file changed, 12 insertions(+)
>>
>>  diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>>  index 6733838..7fa0832 100644
>>  --- a/drivers/usb/dwc3/core.c
>>  +++ b/drivers/usb/dwc3/core.c
>>  @@ -1050,6 +1050,18 @@ static void dwc3_check_params(struct dwc3 *dwc)
>>   dwc->imod_interval = 0;
>>   }
>>
>>  +   /*
>>  +* Workaround for STAR 9000961433 which affects only version
>>  +* 3.00a of the DWC_usb3 core. This prevents the controller
>>  +* interrupt from being masked while handling events. IMOD
>>  +* allows us to work around this issue. Enable it for the
>>  +* affected version.
>>  +*/
>>  +   if (!dwc->imod_interval &&
>>  +   (dwc->revision == DWC3_REVISION_300A)) {
>>  +   dwc->imod_interval = 1;
>>  +   }
>>  +
>>   /* Check the maximum_speed parameter */
>>   switch (dwc->maximum_speed) {
>>   case USB_SPEED_LOW:
>>
>>> integration issue? Does the problem vary per-board?
>>>
>>> Generally, if there's a problem that needs to be worked around, we
>>> describe the problem in the DT (perhaps implicitly in the compatible
>>> string), and then the kernel chooses the workaround.
>>
>> Regardless of the silicon erratum, interrupt moderation is a *feature*
>> of the IP, common to all instances since revision v3.00a (IIRC). John is
>> just using interrupt moderation in the context of implementing this
>> workaround. But the actual feature is valid also without the erratum.
> 
> Sure, I understand this.
> 
>> Another thing to remember is that different applications (i.e. boards)
>> might want to moderate the interrupt for different periods. That's,
>> again, not related to the erratum at all.
> 
> ... again, the question is *why*?
> 
> If this varies per use-case, then it would be better to handle this
> dynamically -- people can run wildly different use-cases on the same
> hardware.

It could make sense either per use-case or per platform.

If we add a dynamic setting, would that be through sysfs?

> 
> I'm not sure that it makes sense for this to be in the DT, though I may
> have misunderstood.

I'm ok omitting the DT binding until it is needed by someone. Since we
currently only need it for the workaround, which is detected
automatically.

Felipe, are you ok with this?

Regards,
John
--
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 00/82] usb: patch bomb

2016-10-31 Thread Bin Liu
Hi Felipe,

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

It seems you missed my comments in the RFC set, basically the set breaks
MUSB and other controllers.

Regards,
-Bin.

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


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

2016-10-31 Thread John Youn
On 10/31/2016 3:51 AM, Felipe Balbi wrote:
> By extracting smaller functions from
> dwc3_ep0_handle_feature(), it becomes far easier to
> understand what's going on. Cleanup only, no
> functional changes.
> 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/dwc3/ep0.c | 256 
> +++--
>  1 file changed, 163 insertions(+), 93 deletions(-)
> 
> diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
> index c562613ccd1a..5e642d65a3b2 100644
> --- a/drivers/usb/dwc3/ep0.c
> +++ b/drivers/usb/dwc3/ep0.c
> @@ -371,126 +371,196 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,
>   return __dwc3_gadget_ep0_queue(dep, >ep0_usb_req);
>  }
>  
> -static int dwc3_ep0_handle_feature(struct dwc3 *dwc,
> +static int dwc3_ep0_handle_u1(struct dwc3 *dwc, enum usb_device_state state,
> + int set)
> +{
> + u32 reg;
> +
> + if (state != USB_STATE_CONFIGURED)
> + return -EINVAL;
> + if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
> + (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS))
> + return -EINVAL;
> +
> + reg = dwc3_readl(dwc->regs, DWC3_DCTL);
> + if (set)
> + reg |= DWC3_DCTL_INITU1ENA;
> + else
> + reg &= ~DWC3_DCTL_INITU1ENA;
> + dwc3_writel(dwc->regs, DWC3_DCTL, reg);
> +
> + return 0;
> +}
> +
> +static int dwc3_ep0_handle_u2(struct dwc3 *dwc, enum usb_device_state state,
> + int set)
> +{
> + u32 reg;
> +
> +
> + if (state != USB_STATE_CONFIGURED)
> + return -EINVAL;
> + if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
> + (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS))
> + return -EINVAL;
> +
> + reg = dwc3_readl(dwc->regs, DWC3_DCTL);
> + if (set)
> + reg |= DWC3_DCTL_INITU2ENA;
> + else
> + reg &= ~DWC3_DCTL_INITU2ENA;
> + dwc3_writel(dwc->regs, DWC3_DCTL, reg);
> +
> + return 0;
> +}
> +
> +static int dwc3_ep0_handle_test(struct dwc3 *dwc, enum usb_device_state 
> state,
> + u32 wIndex, int set)
> +{
> + if ((wIndex & 0xff) != 0)
> + return -EINVAL;
> + if (!set)
> + return -EINVAL;
> +
> + switch (wIndex >> 8) {
> + case TEST_J:
> + case TEST_K:
> + case TEST_SE0_NAK:
> + case TEST_PACKET:
> + case TEST_FORCE_EN:
> + dwc->test_mode_nr = wIndex >> 8;
> + dwc->test_mode = true;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +static int dwc3_ep0_handle_device(struct dwc3 *dwc,
>   struct usb_ctrlrequest *ctrl, int set)
>  {
> - struct dwc3_ep  *dep;
> - u32 recip;
> + enum usb_device_state   state;
>   u32 wValue;
>   u32 wIndex;
> - u32 reg;
> - int ret;
> - enum usb_device_state   state;
> + int ret = 0;
>  
>   wValue = le16_to_cpu(ctrl->wValue);
>   wIndex = le16_to_cpu(ctrl->wIndex);
> - recip = ctrl->bRequestType & USB_RECIP_MASK;
>   state = dwc->gadget.state;
>  
> - switch (recip) {
> - case USB_RECIP_DEVICE:
> + switch (wValue) {
> + case USB_DEVICE_REMOTE_WAKEUP:
> + break;
> + /*
> +  * 9.4.1 says only only for SS, in AddressState only for
> +  * default control pipe
> +  */
> + case USB_DEVICE_U1_ENABLE:
> + ret = dwc3_ep0_handle_u1(dwc, state, set);
> + break;
> + case USB_DEVICE_U2_ENABLE:
> + ret = dwc3_ep0_handle_u2(dwc, state, set);
> + break;
> + case USB_DEVICE_LTM_ENABLE:
> + ret = -EINVAL;
> + break;
> + case USB_DEVICE_TEST_MODE:
> + ret = dwc3_ep0_handle_test(dwc, state, wIndex, set);

Need a break here.

Found with coverity.

Regards,
John



> + default:
> + ret = -EINVAL;
> + }
>  
> - switch (wValue) {
> - case USB_DEVICE_REMOTE_WAKEUP:
> - break;
> - /*
> -  * 9.4.1 says only only for SS, in AddressState only for
> -  * default control pipe
> -  */
> - case USB_DEVICE_U1_ENABLE:
> - if (state != USB_STATE_CONFIGURED)
> - return -EINVAL;
> - if ((dwc->speed != DWC3_DSTS_SUPERSPEED) &&
> - (dwc->speed != DWC3_DSTS_SUPERSPEED_PLUS))
> - return -EINVAL;
> + return ret;
> +}
>  
> - reg = dwc3_readl(dwc->regs, DWC3_DCTL);
> - if (set)
> - reg |= DWC3_DCTL_INITU1ENA;
> - else
> - reg &= ~DWC3_DCTL_INITU1ENA;
> - dwc3_writel(dwc->regs, 

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

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

Similar to patch 51.

Lost the initialization of 'res' and then used uninitialized
here.

Regards,
John

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


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

2016-10-31 Thread David Miller
From: Ville SyrjÀlÀ 
Date: Fri, 28 Oct 2016 19:33:32 +0300

> On Fri, Oct 28, 2016 at 01:16:13PM +0300, Felipe Balbi wrote:
>> Yeah, I'm guessing we're gonna need some help from networking folks. The
>> only thing we did since v4.7 was actually respect req->no_interrupt flag
>> coming from u_ether itself. No idea why that causes so much trouble for
>> u_ether.
>> 
>> BTW, Instead of reverting so many patches, you can just remove
>> throttling:
>> 
>> diff --git a/drivers/usb/gadget/function/u_ether.c 
>> b/drivers/usb/gadget/function/u_ether.c
>> index f4a640216913..119a2e5848e8 100644
>> --- a/drivers/usb/gadget/function/u_ether.c
>> +++ b/drivers/usb/gadget/function/u_ether.c
>> @@ -589,14 +589,6 @@ static netdev_tx_t eth_start_xmit(struct sk_buff *skb,
>>  
>> req->length = length;
>>  
>> -   /* throttle high/super speed IRQ rate back slightly */
>> -   if (gadget_is_dualspeed(dev->gadget))
>> -   req->no_interrupt = (((dev->gadget->speed == USB_SPEED_HIGH 
>> ||
>> -  dev->gadget->speed == 
>> USB_SPEED_SUPER)) &&
>> -   !list_empty(>tx_reqs))
>> -   ? ((atomic_read(>tx_qlen) % dev->qmult) != 0)
>> -   : 0;
>> -
>> retval = usb_ep_queue(in, req, GFP_ATOMIC);
>> switch (retval) {
>> default:
> 
> Ah cool. That indeed fixes the problem for me.
> 
>> 
>> I'm adding netdev and couple other folks to the loop.
>> 
>> Just to summarize, USB peripheral controller now actually throttles
>> interrupt when requested to do so and that causes lags for USB
>> networking gadgets.
>> 
>> Without throttle we, potentially, call netif_wake_queue() more
>> frequently than with throttling. I'm wondering if something changed in
>> NET layer within the past few years but the USB networking gadgets ended
>> up being forgotten.
>> 
>> Anyway, if anybody has any hints, I'd be glad to hear about them.

This throttling mechanism seems to have the same problem we've seen in
the past with some ethernet drivers trying to do TX mitigation in
software.

If I understand correctly, the interrupt bit for TX completions is set
only periodically.

However, the networking stack has a hard requirement that all SKBs
which are transmitted must have their completion signalled in a finite
amount of time.  This is because, until the SKB is freed by the
driver, it holds onto socket, netfilter, and other subsystem
resources.

So, for example, if your scheme is that only every 8th TX packet will
generate an interrupt you run into problems if you suddenly have 7
pending TX packets and no more traffic is generated for a long time.

Those 7 packets will sit in the TX queue indefinitely, and this is the
situation which drivers must avoid.

Therefore, for devices with per-TX-queue-entry interrupt bit schemes,
it's not easy to take advantage of this facility.  The safest thing to
do is to interrupt for every queue entry.

For the time being, this revert is the way to go and it should be
submitted formally, with proper commit message and signoffs, via
whatever tree this gadget driver's changes should be submitted via.

It might be possible to elide TX queue entry interrupts using the
skb->xmit_more state.  Basically, if the TX queue is not full and
skb->xmit_more is set, you can skip the interrupt indication bit
in the descriptor.

Thanks.

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


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

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

'ret' is returned uninitialized in the error handling path.

Found in coverity.

Regards,
John


> + int irq;
>  
> - irq = platform_get_irq_byname(dwc3_pdev, "peripheral");
> - if (irq == -EPROBE_DEFER)
> - return irq;
> -
> - if (irq <= 0) {
> - irq = platform_get_irq_byname(dwc3_pdev, "dwc_usb3");
> - if (irq == -EPROBE_DEFER)
> - return irq;
> -
> - if (irq <= 0) {
> - irq = platform_get_irq(dwc3_pdev, 0);
> - if (irq <= 0) {
> - if (irq != -EPROBE_DEFER) {
> - dev_err(dwc->dev,
> - "missing peripheral IRQ\n");
> - }
> - if (!irq)
> - irq = -EINVAL;
> - return irq;
> - }
> - }
> - }
> + irq = dwc3_gadget_get_irq(dwc);
> + if (irq < 0)
> + goto err0;
>  
>   dwc->irq_gadget = irq;
>  
> 

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


[no subject]

2016-10-31 Thread Debra_Farmer/SSB/HIDOE

I am Mrs. Gu Kailai and i intend to make a DONATION. Contact my personal E-mail 
Via: mrsgukai...@post.cz for more details:
--
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 v1] usb: dwc3: gadget: wait for End Transfer to complete

2016-10-31 Thread Felipe Balbi

Hi,

Baolin Wang  writes:
> Instead of just delaying for 100us, we should
> actually wait for End Transfer Command Complete
> interrupt before moving on. Note that this should
> only be done if we're dealing with one of the core
> revisions that actually require the interrupt before
> moving on.
>
> [ felipe.ba...@linux.intel.com: minor improvements ]
>
> Signed-off-by: Baolin Wang 

I made one extra modification to prevent us from checking for
pm_runtime_suspended() twice:

commit 8f48e8d6d3dfe75b5582c8a7b1ee5739a393748c
Author: Baolin Wang 
Date:   Mon Oct 31 19:38:36 2016 +0800

usb: dwc3: gadget: wait for End Transfer to complete

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

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

Signed-off-by: Baolin Wang 
Signed-off-by: Felipe Balbi 

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

Re: [PATCH 22/82] usb: gadget: udc: gr: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi

Hi,

Sergei Shtylyov  writes:
> On 10/31/2016 1:48 PM, Felipe Balbi wrote:
>
>> We have introduced a helper to calculate multiplier
>> value from wMaxPacketSize. Start using it.
>>
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/gadget/udc/gr_udc.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/usb/gadget/udc/gr_udc.c 
>> b/drivers/usb/gadget/udc/gr_udc.c
>> index 39b7136d31d9..3786b5dbfd01 100644
>> --- a/drivers/usb/gadget/udc/gr_udc.c
>> +++ b/drivers/usb/gadget/udc/gr_udc.c
>> @@ -1539,7 +1539,7 @@ static int gr_ep_enable(struct usb_ep *_ep,
>>   * additional transactions.
>>   */
>>  max = 0x7ff & usb_endpoint_maxp(desc);
>> -nt = 0x3 & (usb_endpoint_maxp(desc) >> 11);
>> +nt = usb_endpoint_maxp_mult(desc);
>
> Don't you need '- 1' here?

Good catch, here's v2:

8<--
From d20794e89a0f290edc9c522c5e75177a30d45d41 Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Wed, 28 Sep 2016 13:36:58 +0300
Subject: [PATCH v2] usb: gadget: udc: gr: make use of new
 usb_endpoint_maxp_mult()

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

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

diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
index 39b7136d31d9..b16f8af34050 100644
--- a/drivers/usb/gadget/udc/gr_udc.c
+++ b/drivers/usb/gadget/udc/gr_udc.c
@@ -1539,7 +1539,7 @@ static int gr_ep_enable(struct usb_ep *_ep,
 * additional transactions.
 */
max = 0x7ff & usb_endpoint_maxp(desc);
-   nt = 0x3 & (usb_endpoint_maxp(desc) >> 11);
+   nt = usb_endpoint_maxp_mult(desc) - 1;
buffer_size = GR_BUFFER_SIZE(epctrl);
if (nt && (mode == 0 || mode == 2)) {
dev_err(dev->dev,
-- 
2.10.1



-- 
balbi


signature.asc
Description: PGP signature


Re: musb RPM sleep-while-atomic in 4.9-rc1

2016-10-31 Thread Johan Hovold
On Fri, Oct 28, 2016 at 11:13:19AM -0700, Tony Lindgren wrote:
> * Johan Hovold  [161028 02:45]:
> > On Thu, Oct 27, 2016 at 12:15:52PM -0700, Tony Lindgren wrote:
> > > * Johan Hovold  [161027 11:46]:
> > > > But then this looks like it could trigger an ABBA deadlock as musb->lock
> > > > is held while queue_on_resume() takes musb->list_lock, and
> > > > musb_run_pending() would take the same locks in the reverse order.
> > > 
> > > It seems we can avoid that by locking only list_add_tail() and list_del():
> > > 
> > > list_for_each_entry_safe(w, _w, >resume_work, node) {
> > >   spin_lock_irqsave(>list_lock, flags);
> > >   list_del(>node);
> > >   spin_unlock_irqrestore(>list_lock, flags);
> > >   if (w->callback)
> > >   w->callback(musb, w->data);
> > >   devm_kfree(musb->controller, w);
> > > }
> > 
> > I think you still need to hold the lock while traversing the list (even
> > if you temporarily release it during the callback).
> 
> Hmm yeah we need iterate through the list again to avoid missing new
> elements being added. I've updated the patch to use a the common
> while (!list_empty(>resume_work)) loop. Does that solve the
> concern you had or did you also had some other concern there?

Yeah, while that minimises the race window it is still possible that the
timer callback checks pm_runtime_active() after the queue has been
processed but before the rpm status is updated. 

How about using a work struct and synchronous get for the deferred case?

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


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

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

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

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

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 23765a1..c5fd862 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -496,6 +497,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  * @lock: spinlock for endpoint request queue traversal
  * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
@@ -521,6 +523,8 @@ struct dwc3_ep {
struct list_headpending_list;
struct list_headstarted_list;
 
+   wait_queue_head_t   wait_end_transfer;
+
spinlock_t  lock;
void __iomem*regs;
 
@@ -537,6 +541,7 @@ struct dwc3_ep {
 #define DWC3_EP_BUSY   (1 << 4)
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
+#define DWC3_EP_END_TRANSFER_PENDING   (1 << 7)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
@@ -1044,6 +1049,9 @@ struct dwc3_event_depevt {
 #define DEPEVT_TRANSFER_BUS_EXPIRY 2
 
u32 parameters:16;
+
+/* For Command Complete Events */
+#define DEPEVT_PARAMETER_CMD(n)(((n) & (0xf << 8)) >> 8)
 } __packed;
 
 /**
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3722c90..018611d 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -570,11 +570,14 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
dep->comp_desc = comp_desc;
dep->type = usb_endpoint_type(desc);
dep->flags |= DWC3_EP_ENABLED;
+   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
 
reg = dwc3_readl(dwc->regs, DWC3_DALEPENA);
reg |= DWC3_DALEPENA_EP(dep->number);
dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
 
+   init_waitqueue_head(>wait_end_transfer);
+
if (usb_endpoint_xfer_control(desc))
return 0;
 
@@ -647,7 +650,7 @@ static int __dwc3_gadget_ep_disable(struct dwc3_ep *dep)
dep->endpoint.desc = NULL;
dep->comp_desc = NULL;
dep->type = 0;
-   dep->flags = 0;
+   dep->flags &= DWC3_EP_END_TRANSFER_PENDING;
 
return 0;
 }
@@ -1736,10 +1739,34 @@ static int dwc3_gadget_stop(struct usb_gadget *g)
 {
struct dwc3 *dwc = gadget_to_dwc(g);
unsigned long   flags;
+   int epnum;
 
spin_lock_irqsave(>lock, flags);
__dwc3_gadget_stop(dwc);
dwc->gadget_driver  = NULL;
+
+   for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+   struct dwc3_ep  *dep = dwc->eps[epnum];
+
+   /*
+* If the dwc3 core has been in suspend state, we will never get
+* the command complete event, thus ignore.
+*/
+   if (pm_runtime_suspended(dwc->dev))
+   break;
+
+   if (!dep)
+   continue;
+
+   if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
+   continue;
+
+
+   wait_event_lock_irq(dep->wait_end_transfer,
+   !(dep->flags & 
DWC3_EP_END_TRANSFER_PENDING),
+   dwc->lock);
+   }
+
spin_unlock_irqrestore(>lock, flags);
 
free_irq(dwc->irq_gadget, dwc->ev_buf);
@@ -2105,10 +2132,12 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
 {
struct dwc3_ep  *dep;
u8  epnum = event->endpoint_number;
+   u8  cmd;
 
dep = dwc->eps[epnum];
 
-   if (!(dep->flags & DWC3_EP_ENABLED))
+   if (!(dep->flags & DWC3_EP_ENABLED) &&
+   !(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
return;
 
if (epnum == 0 || epnum == 1) {
@@ -2180,6 +2209,13 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
dwc3_trace(trace_dwc3_gadget, "%s FIFO Overrun", dep->name);
break;
case DWC3_DEPEVT_EPCMDCMPLT:
+   cmd = DEPEVT_PARAMETER_CMD(event->parameters);

Re: [PATCH 75/82] usb: dwc3: gadget: wait for End Transfer to complete

2016-10-31 Thread Baolin Wang
Hi Feilpe,

On 31 October 2016 at 18:55, Felipe Balbi  wrote:
>
> Hi Baolin,
>
> Felipe Balbi  writes:
>> From: Baolin Wang 
>>
>> Instead of just delaying for 100us, we should
>> actually wait for End Transfer Command Complete
>> interrupt before moving on. Note that this should
>> only be done if we're dealing with one of the core
>> revisions that actually require the interrupt before
>> moving on.
>>
>> [ felipe.ba...@linux.intel.com: minor improvements ]
>>
>> NYET-Signed-off-by: Baolin Wang 
>> Signed-off-by: Felipe Balbi 
>
> I guess I should drop this patch from the queue since you wanted to send
> your own version, right?

Yes, I think so. Since I just pasted the sample code in previous email
and I did not see in your patchset, I will send out the new patch.

>
> Let me know ;-)
>
> --
> balbi



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


[balbi-usb:testing/next 49/82] drivers/usb/dwc3/dwc3-st.c:328:2: error: implicit declaration of function 'pinctrl_pm_select_sleep_state'

2016-10-31 Thread kbuild test robot
tree:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git 
testing/next
head:   391ea04dea216a223b8dea3a0a832ff83884db1b
commit: 6a58c79df975feebfc5bd338b9fb0c9bc61081e5 [49/82] usb: dwc3: Kconfig: 
allow all glues to build if COMPILE_TEST
config: powerpc-allyesconfig (attached as .config)
compiler: powerpc64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git checkout 6a58c79df975feebfc5bd338b9fb0c9bc61081e5
# save the attached .config to linux build tree
make.cross ARCH=powerpc 

All errors (new ones prefixed by >>):

   drivers/usb/dwc3/dwc3-st.c: In function 'st_dwc3_suspend':
>> drivers/usb/dwc3/dwc3-st.c:328:2: error: implicit declaration of function 
>> 'pinctrl_pm_select_sleep_state' [-Werror=implicit-function-declaration]
 pinctrl_pm_select_sleep_state(dev);
 ^
   drivers/usb/dwc3/dwc3-st.c: In function 'st_dwc3_resume':
>> drivers/usb/dwc3/dwc3-st.c:338:2: error: implicit declaration of function 
>> 'pinctrl_pm_select_default_state' [-Werror=implicit-function-declaration]
 pinctrl_pm_select_default_state(dev);
 ^~~
   cc1: some warnings being treated as errors

vim +/pinctrl_pm_select_sleep_state +328 drivers/usb/dwc3/dwc3-st.c

f83fca07 Peter Griffin 2014-09-05  322  {
f83fca07 Peter Griffin 2014-09-05  323  struct st_dwc3 *dwc3_data = 
dev_get_drvdata(dev);
f83fca07 Peter Griffin 2014-09-05  324  
f83fca07 Peter Griffin 2014-09-05  325  
reset_control_assert(dwc3_data->rstc_pwrdn);
f83fca07 Peter Griffin 2014-09-05  326  
reset_control_assert(dwc3_data->rstc_rst);
f83fca07 Peter Griffin 2014-09-05  327  
f83fca07 Peter Griffin 2014-09-05 @328  
pinctrl_pm_select_sleep_state(dev);
f83fca07 Peter Griffin 2014-09-05  329  
f83fca07 Peter Griffin 2014-09-05  330  return 0;
f83fca07 Peter Griffin 2014-09-05  331  }
f83fca07 Peter Griffin 2014-09-05  332  
f83fca07 Peter Griffin 2014-09-05  333  static int st_dwc3_resume(struct device 
*dev)
f83fca07 Peter Griffin 2014-09-05  334  {
f83fca07 Peter Griffin 2014-09-05  335  struct st_dwc3 *dwc3_data = 
dev_get_drvdata(dev);
f83fca07 Peter Griffin 2014-09-05  336  int ret;
f83fca07 Peter Griffin 2014-09-05  337  
f83fca07 Peter Griffin 2014-09-05 @338  
pinctrl_pm_select_default_state(dev);
f83fca07 Peter Griffin 2014-09-05  339  
f83fca07 Peter Griffin 2014-09-05  340  
reset_control_deassert(dwc3_data->rstc_pwrdn);
f83fca07 Peter Griffin 2014-09-05  341  
reset_control_deassert(dwc3_data->rstc_rst);

:: The code at line 328 was first introduced by commit
:: f83fca0707c66e36f14efef7f68702cb12de70b7 usb: dwc3: add ST dwc3 glue 
layer to manage dwc3 HC

:: TO: Peter Griffin 
:: CC: Felipe Balbi 

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


.config.gz
Description: application/gzip


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

2016-10-31 Thread Baolin Wang
On 29 October 2016 at 01:03, Mark Brown  wrote:
> On Fri, Oct 28, 2016 at 08:51:41PM +0800, Baolin Wang wrote:
>> On 28 October 2016 at 06:00, NeilBrown  wrote:
>
>> > 1/ I think we agreed that it doesn't make sense for there to be
>> >  two chargers registered in a system.
>
>> Yes, until now...
>
>> >  However usb_charger_register() still allows that, and assigns
>> >  and arbitrary name to each based on discovery order.
>> >  This *cannot* make sense.
>
>> Fine, I can change that to allow only one charger to register.
>
> Yeah, it's a reasonable change.  I'm not sure the prior discussion was
> 100% conclusive on the issue (I remember there being some debate about
> leaving things there to avoid any need for future refactoring to touch
> the interface).

I think we should leave these things to avoid refactoring in future.

>
>> > 2/ Why do you have usb_charger_set_current()??
>> >   No code ever calls it.
>> >   This updates the min and max current which are defined in a
>> >   standard.  It never makes sense to change the min and max
>> >   for a particular cable type.
>
>> Mark, do we have some scenarios which want to change the current
>> limitation? If not, okay, I agree with you to remove this function.
>
> I'm not aware of any, we can always add it back if the need arises.

OK.

>
>> >  Related:  I don't like charger_type_show().  I don't think
>> >  the usb-charger should export that information to user-space because
>> >  extcon already does that, and duplication is confusing and pointless.
>
>> I think we should combine all charger related information into one
>> place for user. Moreover if we don't get charger type from extcon, we
>> should also need one place to export the charger type.
>
> I had also thought there was some software negotation as well as the
> physical charger in cases where the device is plugged into an active
> host?  I could be wrong.
>
>> > 5/ There is no convincing example usage of this framework.
>> >   wm8931x_power.c just scratches the surface.
>> >   If it is so good, it should be easy to convert a lot of other
>> >   drivers over to it.  If you did that it would be much easier
>> >   to see how it works and what the strengths/weaknesses were.
>
>> Jun have send out one patchset[1] based on my patchset, and he tested
>> mypatchset. Thanks for your comments.
>> [1]http://www.spinics.net/lists/linux-usb/msg139809.html
>
> I think it's a good idea to pick up Jun's patches into your patch set,
> that way Jun doesn't need to rebase and it might help with review of
> your patches too.

Yes, I think so. I will ask for Jun's help.


-- 
Baolin.wang
Best Regards
--
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: [RFC][PATCH] usb: dwc2: Make sure we disconnect the gadget state on reset

2016-10-31 Thread Felipe Balbi

Hi,

John Stultz  writes:
> I had seen some odd behavior with HiKey's usb-gadget interface
> that I finally seemed to have chased down. Basically every other
> time I pluged in the OTG port, the gadget interface would
> properly initialize. The other times, I'd get a big WARN_ON
> in dwc2_hsotg_init_fifo() about the fifo_map not being clear.
>
> Ends up If we don't disconnect the gadget state on reset, the
> fifo-map doesn't get cleared properly, which causes WARN_ON
> messages and also results in the device not properly being
> setup as a gadget every other time the OTG port is connected.
>
> So this patch adds a call to dwc2_hsotg_disconnect() in the
> reset path so the state is properly cleared.
>
> With it, the gadget interface initializes properly on every
> plug in.
>
> I don't know if this is actually the right fix, but it seems
> to work well. Feedback would be greatly appreciated!
>
> Cc: Wei Xu 
> Cc: Guodong Xu 
> Cc: Chen Yu 
> Cc: Amit Pundir 
> Cc: Rob Herring 
> Cc: Mark Rutland 
> Cc: John Youn 
> Cc: Douglas Anderson 
> Cc: Greg Kroah-Hartman 
> Cc: linux-usb@vger.kernel.org
> Signed-off-by: John Stultz 
> ---
>  drivers/usb/dwc2/gadget.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 24fbebc..5505001 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -2519,6 +2519,8 @@ void dwc2_hsotg_core_init_disconnected(struct 
> dwc2_hsotg *hsotg,
>  
>   /* Kill any ep0 requests as controller will be reinitialized */
>   kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET);
> + /* Make sure everything is disconnected */
> + dwc2_hsotg_disconnect(hsotg);

Dunno, seems like you're actually working around a different
bug. Looking at USB Reset handler we have:

if (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) {

u32 usb_status = dwc2_readl(hsotg->regs + GOTGCTL);
u32 connected = hsotg->connected;

dev_dbg(hsotg->dev, "%s: USBRst\n", __func__);
dev_dbg(hsotg->dev, "GNPTXSTS=%08x\n",
dwc2_readl(hsotg->regs + GNPTXSTS));

dwc2_writel(GINTSTS_USBRST, hsotg->regs + GINTSTS);

/* Report disconnection if it is not already done. */
dwc2_hsotg_disconnect(hsotg);

if (usb_status & GOTGCTL_BSESVLD && connected)
dwc2_hsotg_core_init_disconnected(hsotg, true);
}

so, dwc2_hsotg_disconnect() is already called from Reset path. What
you're doing here is that you could, potentially, call
driver->disconnect() twice.

The real problem could be your implementation for ->pullup() which
duplicates part of what ->udc_start() does:

static int dwc2_hsotg_pullup(struct usb_gadget *gadget, int is_on)
{
struct dwc2_hsotg *hsotg = to_hsotg(gadget);
unsigned long flags = 0;

dev_dbg(hsotg->dev, "%s: is_on: %d op_state: %d\n", __func__, is_on,
hsotg->op_state);

/* Don't modify pullup state while in host mode */
if (hsotg->op_state != OTG_STATE_B_PERIPHERAL) {
hsotg->enabled = is_on;
return 0;
}

spin_lock_irqsave(>lock, flags);
if (is_on) {
hsotg->enabled = 1;
dwc2_hsotg_core_init_disconnected(hsotg, false);
dwc2_hsotg_core_connect(hsotg);
} else {
dwc2_hsotg_core_disconnect(hsotg);
dwc2_hsotg_disconnect(hsotg);
hsotg->enabled = 0;
}

hsotg->gadget.speed = USB_SPEED_UNKNOWN;
spin_unlock_irqrestore(>lock, flags);

return 0;
}

Here's what I think dwc2_hsotg_pullup() and dwc2_hsotg_udc_start()
should contain:


diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 9dc6c482b89e..dbe28947d3a9 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3388,6 +3388,7 @@ static void dwc2_hsotg_init(struct dwc2_hsotg *hsotg)
dwc2_writel(0, hsotg->regs + DAINTMSK);
 
/* Be in disconnected state until gadget is registered */
+   /* REVISIT This should be done in probe() */
__orr32(hsotg->regs + DCTL, DCTL_SFTDISCON);
 
/* setup fifos */
@@ -3428,26 +3429,6 @@ static int dwc2_hsotg_udc_start(struct usb_gadget 
*gadget,
unsigned long flags;
int ret;
 
-   if (!hsotg) {
-   pr_err("%s: called with no device\n", __func__);
-   return -ENODEV;
-   }
-
-   if (!driver) {
-   dev_err(hsotg->dev, "%s: no driver\n", __func__);
-   return -EINVAL;
-   }
-
-   if 

Re: [PATCH v2 0/3] usb: trivial cleanups with list_first_entry_or_null()

2016-10-31 Thread Masahiro Yamada
Hi Felipe,

>>
>> If this series looks good, can you pick it up please?
>
> it's in my testing/next branch. Has been there for a while ;-)


Good.  Thanks for taking care of it!



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


Re: [PATCH v2 0/3] usb: trivial cleanups with list_first_entry_or_null()

2016-10-31 Thread Felipe Balbi

Hi,

Masahiro Yamada  writes:
> Hello Felipe,
>
> If this series looks good, can you pick it up please?

it's in my testing/next branch. Has been there for a while ;-)

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH 22/82] usb: gadget: udc: gr: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Sergei Shtylyov

On 10/31/2016 1:48 PM, Felipe Balbi wrote:


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

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

diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
index 39b7136d31d9..3786b5dbfd01 100644
--- a/drivers/usb/gadget/udc/gr_udc.c
+++ b/drivers/usb/gadget/udc/gr_udc.c
@@ -1539,7 +1539,7 @@ static int gr_ep_enable(struct usb_ep *_ep,
 * additional transactions.
 */
max = 0x7ff & usb_endpoint_maxp(desc);
-   nt = 0x3 & (usb_endpoint_maxp(desc) >> 11);
+   nt = usb_endpoint_maxp_mult(desc);


   Don't you need '- 1' here?

MBR, Sergei

--
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 75/82] usb: dwc3: gadget: wait for End Transfer to complete

2016-10-31 Thread Felipe Balbi

Hi Baolin,

Felipe Balbi  writes:
> From: Baolin Wang 
>
> Instead of just delaying for 100us, we should
> actually wait for End Transfer Command Complete
> interrupt before moving on. Note that this should
> only be done if we're dealing with one of the core
> revisions that actually require the interrupt before
> moving on.
>
> [ felipe.ba...@linux.intel.com: minor improvements ]
>
> NYET-Signed-off-by: Baolin Wang 
> Signed-off-by: Felipe Balbi 

I guess I should drop this patch from the queue since you wanted to send
your own version, right?

Let me know ;-)

-- 
balbi


signature.asc
Description: PGP signature


[PATCH 65/82] usb: dwc3: gadget: don't clear RUN/STOP when it's invalid to do so

2016-10-31 Thread Felipe Balbi
From: Baolin Wang 

When we change the USB function with configfs dynamically, we possibly
met this situation: one core is doing the control transfer, another core
is trying to unregister the USB gadget from userspace, we must wait for
completing this control tranfer, or it will hang the controller to set
the DEVCTRLHLT flag.

[ felipe.ba...@linux.intel.com: several fixes to the patch
- call complete() before starting following SETUP transfer
- add a macro for ep0_in_setup's timeout
- change commit subject slightly
- break lines at 72 characters (git adds an 8-character tab)
- avoid changes to dwc3_gadget_run_stop() ]

Signed-off-by: Baolin Wang 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h   |  3 +++
 drivers/usb/dwc3/ep0.c|  2 ++
 drivers/usb/dwc3/gadget.c | 17 +
 3 files changed, 22 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index e878366ead00..5fc437021ac7 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -37,6 +37,7 @@
 #define DWC3_MSG_MAX   500
 
 /* Global constants */
+#define DWC3_PULL_UP_TIMEOUT   500 /* ms */
 #define DWC3_ZLP_BUF_SIZE  1024/* size of a superspeed bulk */
 #define DWC3_EP0_BOUNCE_SIZE   512
 #define DWC3_ENDPOINTS_NUM 32
@@ -751,6 +752,7 @@ struct dwc3_scratchpad_array {
  * @ep0_usb_req: dummy req used while handling STD USB requests
  * @ep0_bounce_addr: dma address of ep0_bounce
  * @scratch_addr: dma address of scratchbuf
+ * @ep0_in_setup: one control transfer is completed and enter setup phase
  * @lock: for synchronizing
  * @dev: pointer to our struct device
  * @xhci: pointer to our xHCI child
@@ -848,6 +850,7 @@ struct dwc3 {
dma_addr_t  ep0_bounce_addr;
dma_addr_t  scratch_addr;
struct dwc3_request ep0_usb_req;
+   struct completion   ep0_in_setup;
 
/* device lock */
spinlock_t  lock;
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 5e642d65a3b2..417cfd3f04ab 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -284,6 +284,8 @@ void dwc3_ep0_out_start(struct dwc3 *dwc)
 {
int ret;
 
+   complete(>ep0_in_setup);
+
ret = dwc3_ep0_start_trans(dwc, 0, dwc->ctrl_req_addr, 8,
DWC3_TRBCTL_CONTROL_SETUP, false);
WARN_ON(ret < 0);
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index ef9508e8609e..3b53a5714df4 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1550,6 +1550,21 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int 
is_on)
 
is_on = !!is_on;
 
+   /*
+* Per databook, when we want to stop the gadget, if a control transfer
+* is still in process, complete it and get the core into setup phase.
+*/
+   if (!is_on && dwc->ep0state != EP0_SETUP_PHASE) {
+   reinit_completion(>ep0_in_setup);
+
+   ret = wait_for_completion_timeout(>ep0_in_setup,
+   msecs_to_jiffies(DWC3_PULL_UP_TIMEOUT));
+   if (ret == 0) {
+   dev_err(dwc->dev, "timed out waiting for SETUP 
phase\n");
+   return -ETIMEDOUT;
+   }
+   }
+
spin_lock_irqsave(>lock, flags);
ret = dwc3_gadget_run_stop(dwc, is_on, false);
spin_unlock_irqrestore(>lock, flags);
@@ -2943,6 +2958,8 @@ int dwc3_gadget_init(struct dwc3 *dwc)
goto err4;
}
 
+   init_completion(>ep0_in_setup);
+
dwc->gadget.ops = _gadget_ops;
dwc->gadget.speed   = USB_SPEED_UNKNOWN;
dwc->gadget.sg_supported= true;
-- 
2.10.1

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


[PATCH 73/82] usb: gadget: u_ether: link socket buffers to the device for received packets

2016-10-31 Thread Felipe Balbi
From: Torsten Polle 

Socket buffers should be linked to the (network) device that allocated
the buffers. __netdev_alloc_skb performs this task.

Signed-off-by: Torsten Polle 
Signed-off-by: Jim Baxter 
Signed-off-by: Harish Jenny K N 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/u_ether.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index fe1811650dbc..5aeb6d903075 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -224,7 +224,7 @@ rx_submit(struct eth_dev *dev, struct usb_request *req, 
gfp_t gfp_flags)
if (dev->port_usb->is_fixed)
size = max_t(size_t, size, dev->port_usb->fixed_out_len);
 
-   skb = alloc_skb(size + NET_IP_ALIGN, gfp_flags);
+   skb = __netdev_alloc_skb(dev->net, size + NET_IP_ALIGN, gfp_flags);
if (skb == NULL) {
DBG(dev, "no rx skb\n");
goto enomem;
-- 
2.10.1

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


[PATCH 78/82] usb: dwc3: gadget: always try to prepare on started_list first

2016-10-31 Thread Felipe Balbi
In cases where we're given an SG-list which is
longer than the amount of currently available TRBs,
we will be left with the same request on
started_list and we should prioritize that request
over possible new requests on pending_list. That's
a way to guarantee requests complete in order.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 84b449b17160..bca4150e3cf5 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1023,6 +1023,24 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep)
if (!dwc3_calc_trbs_left(dep))
return;
 
+   /*
+* We can get in a situation where there's a request in the started list
+* but there weren't enough TRBs to fully kick it in the first time
+* around, so it has been waiting for more TRBs to be freed up.
+*
+* In that case, we should check if we have a request with pending_sgs
+* in the started list and prepare TRBs for that request first,
+* otherwise we will prepare TRBs completely out of order and that will
+* break things.
+*/
+   list_for_each_entry(req, >started_list, list) {
+   if (req->num_pending_sgs > 0)
+   dwc3_prepare_one_trb_sg(dep, req);
+
+   if (!dwc3_calc_trbs_left(dep))
+   return;
+   }
+
list_for_each_entry_safe(req, n, >pending_list, list) {
if (req->num_pending_sgs > 0)
dwc3_prepare_one_trb_sg(dep, req);
-- 
2.10.1

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


[PATCH 44/82] usb: gadget: udc: fsl: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Cc: Li Yang 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/udc/fsl_udc_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c 
b/drivers/usb/gadget/udc/fsl_udc_core.c
index 4459644b9b55..71094e479a96 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -586,7 +586,6 @@ static int fsl_ep_enable(struct usb_ep *_ep,
case USB_ENDPOINT_XFER_ISOC:
/* Calculate transactions needed for high bandwidth iso */
mult = usb_endpoint_maxp_mult(desc);
-   max = max & 0x7ff;  /* bit 0~10 */
/* 3 transactions at most */
if (mult > 3)
goto en_done;
-- 
2.10.1

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


[PATCH 74/82] usb: gadget: NCM: differentiate consumed packets from dropped packets

2016-10-31 Thread Felipe Balbi
From: Torsten Polle 

dev_kfree_skb_any() is used to free packets that are dropped by the
network stack. Therefore the function should not be used for packets
that have been successfully processed by the network stack. Instead
dev_consume_skb_any() has to be used for such consumed packets.

This separation helps to identify dropped packets.

Signed-off-by: Torsten Polle 
Signed-off-by: Harish Jenny K N 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/f_ncm.c   | 8 
 drivers/usb/gadget/function/u_ether.c | 3 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/function/f_ncm.c 
b/drivers/usb/gadget/function/f_ncm.c
index b6771ad2485a..e8008fa35e1e 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -998,7 +998,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm)
/* Merge the skbs */
swap(skb2, ncm->skb_tx_data);
if (ncm->skb_tx_data) {
-   dev_kfree_skb_any(ncm->skb_tx_data);
+   dev_consume_skb_any(ncm->skb_tx_data);
ncm->skb_tx_data = NULL;
}
 
@@ -1009,7 +1009,7 @@ static struct sk_buff *package_for_tx(struct f_ncm *ncm)
/* Copy NTB across. */
ntb_iter = (void *) skb_put(skb2, ncm->skb_tx_ndp->len);
memcpy(ntb_iter, ncm->skb_tx_ndp->data, ncm->skb_tx_ndp->len);
-   dev_kfree_skb_any(ncm->skb_tx_ndp);
+   dev_consume_skb_any(ncm->skb_tx_ndp);
ncm->skb_tx_ndp = NULL;
 
/* Insert zero'd datagram. */
@@ -1136,7 +1136,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
memset(ntb_data, 0, dgram_pad);
ntb_data = (void *) skb_put(ncm->skb_tx_data, skb->len);
memcpy(ntb_data, skb->data, skb->len);
-   dev_kfree_skb_any(skb);
+   dev_consume_skb_any(skb);
skb = NULL;
 
} else if (ncm->skb_tx_data && ncm->timer_force_tx) {
@@ -1332,7 +1332,7 @@ static int ncm_unwrap_ntb(struct gether *port,
} while (ndp_len > 2 * (opts->dgram_item_len * 2));
} while (ndp_index);
 
-   dev_kfree_skb_any(skb);
+   dev_consume_skb_any(skb);
 
VDBG(port->func.config->cdev,
 "Parsed NTB with %d frames\n", dgram_counter);
diff --git a/drivers/usb/gadget/function/u_ether.c 
b/drivers/usb/gadget/function/u_ether.c
index 5aeb6d903075..f4a640216913 100644
--- a/drivers/usb/gadget/function/u_ether.c
+++ b/drivers/usb/gadget/function/u_ether.c
@@ -455,16 +455,17 @@ static void tx_complete(struct usb_ep *ep, struct 
usb_request *req)
/* FALLTHROUGH */
case -ECONNRESET:   /* unlink */
case -ESHUTDOWN:/* disconnect etc */
+   dev_kfree_skb_any(skb);
break;
case 0:
dev->net->stats.tx_bytes += skb->len;
+   dev_consume_skb_any(skb);
}
dev->net->stats.tx_packets++;
 
spin_lock(>req_lock);
list_add(>list, >tx_reqs);
spin_unlock(>req_lock);
-   dev_kfree_skb_any(skb);
 
atomic_dec(>tx_qlen);
if (netif_carrier_ok(dev->net))
-- 
2.10.1

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


[PATCH 82/82] usb: dwc3: pci: call _DSM for suspend/resume

2016-10-31 Thread Felipe Balbi
Intel's BXT devices need to execute a _DSM method
during {runtime_,}{suspend,resume} in order to get a
chunk of dwc3 to power gate and save some extra
power.

Let's do that now.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/Kconfig|  2 +-
 drivers/usb/dwc3/dwc3-pci.c | 73 +
 2 files changed, 62 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index a45b4f1ba689..c5aa235863e8 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -70,7 +70,7 @@ config USB_DWC3_EXYNOS
 
 config USB_DWC3_PCI
tristate "PCIe-based Platforms"
-   depends on PCI
+   depends on PCI && ACPI
default USB_DWC3
help
  If you're using the DesignWare Core IP with a PCIe, please say
diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 0f54b8166e54..8c39ec6522fd 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -39,14 +39,25 @@
 #define PCI_DEVICE_ID_INTEL_APL0x5aaa
 #define PCI_DEVICE_ID_INTEL_KBP0xa2b0
 
+#define PCI_INTEL_BXT_DSM_UUID "732b85d5-b7a7-4a1b-9ba0-4bbd00ffd511"
+#define PCI_INTEL_BXT_FUNC_PMU_PWR 4
+#define PCI_INTEL_BXT_STATE_D0 0
+#define PCI_INTEL_BXT_STATE_D3 3
+
 /**
  * struct dwc3_pci - Driver private structure
  * @dwc3: child dwc3 platform_device
  * @pci: our link to PCI bus
+ * @uuid: _DSM UUID
+ * @has_dsm_for_pm: true for devices which need to run _DSM on runtime PM
  */
 struct dwc3_pci {
struct platform_device *dwc3;
struct pci_dev *pci;
+
+   u8 uuid[16];
+
+   unsigned int has_dsm_for_pm:1;
 };
 
 static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
@@ -102,6 +113,12 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
if (ret < 0)
return ret;
 
+   if (pdev->device == PCI_DEVICE_ID_INTEL_BXT ||
+   pdev->device == PCI_DEVICE_ID_INTEL_BXT_M) {
+   acpi_str_to_uuid(PCI_INTEL_BXT_DSM_UUID, dwc->uuid);
+   dwc->has_dsm_for_pm = true;
+   }
+
if (pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
struct gpio_desc *gpio;
 
@@ -149,6 +166,30 @@ static int dwc3_pci_quirks(struct dwc3_pci *dwc)
return 0;
 }
 
+static int dwc3_pci_dsm(struct dwc3_pci *dwc, int param)
+{
+   union acpi_object *obj;
+   union acpi_object tmp;
+   union acpi_object argv4 = ACPI_INIT_DSM_ARGV4(1, );
+
+   if (!dwc->has_dsm_for_pm)
+   return 0;
+
+   tmp.type = ACPI_TYPE_INTEGER;
+   tmp.integer.value = param;
+
+   obj = acpi_evaluate_dsm(ACPI_HANDLE(>pci->dev), dwc->uuid,
+   1, PCI_INTEL_BXT_FUNC_PMU_PWR, );
+   if (!obj) {
+   dev_err(>pci->dev, "failed to evaluate _DSM\n");
+   return -EIO;
+   }
+
+   ACPI_FREE(obj);
+
+   return 0;
+}
+
 static int dwc3_pci_probe(struct pci_dev *pci,
const struct pci_device_id *id)
 {
@@ -255,8 +296,10 @@ MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
 #ifdef CONFIG_PM
 static int dwc3_pci_runtime_suspend(struct device *dev)
 {
+   struct dwc3_pci *dwc = dev_get_drvdata(dev);
+
if (device_run_wake(dev))
-   return 0;
+   return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
 
return -EBUSY;
 }
@@ -265,28 +308,34 @@ static int dwc3_pci_runtime_resume(struct device *dev)
 {
struct dwc3_pci *dwc = dev_get_drvdata(dev);
struct platform_device  *dwc3 = dwc->dwc3;
+   int ret;
+
+   ret = dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
+   if (ret)
+   return ret;
 
return pm_runtime_get(>dev);
 }
 #endif /* CONFIG_PM */
 
 #ifdef CONFIG_PM_SLEEP
-static int dwc3_pci_pm_dummy(struct device *dev)
+static int dwc3_pci_suspend(struct device *dev)
 {
-   /*
-* There's nothing to do here. No, seriously. Everything is either taken
-* care either by PCI subsystem or dwc3/core.c, so we have nothing
-* missing here.
-*
-* So you'd think we didn't need this at all, but PCI subsystem will
-* bail out if we don't have a valid callback :-s
-*/
-   return 0;
+   struct dwc3_pci *dwc = dev_get_drvdata(dev);
+
+   return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D3);
+}
+
+static int dwc3_pci_resume(struct device *dev)
+{
+   struct dwc3_pci *dwc = dev_get_drvdata(dev);
+
+   return dwc3_pci_dsm(dwc, PCI_INTEL_BXT_STATE_D0);
 }
 #endif /* CONFIG_PM_SLEEP */
 
 static struct dev_pm_ops dwc3_pci_dev_pm_ops = {
-   SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_pm_dummy, dwc3_pci_pm_dummy)
+   SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume)

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

2016-10-31 Thread Felipe Balbi
By extracting smaller functions from
dwc3_ep0_handle_feature(), it becomes far easier to
understand what's going on. Cleanup only, no
functional changes.

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

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

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

2016-10-31 Thread Felipe Balbi
Cleanup only, no functional changes.

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

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

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


[PATCH 67/82] usb: Convert pr_warning to pr_warn

2016-10-31 Thread Felipe Balbi
From: Joe Perches 

Use the more common logging mechanism.

Miscellanea:

o Realign multiline statements
o Coalesce format

Acked-by: Robert Jarzmik 
Acked-by: Nicolas Ferre 
Signed-off-by: Joe Perches 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/rndis.c |  9 -
 drivers/usb/gadget/function/u_serial.c  |  4 ++--
 drivers/usb/gadget/udc/at91_udc.h   |  2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c |  4 ++--
 drivers/usb/gadget/udc/fsl_usb2_udc.h   |  2 +-
 drivers/usb/gadget/udc/m66592-udc.c |  4 ++--
 drivers/usb/gadget/udc/omap_udc.h   |  2 +-
 drivers/usb/gadget/udc/pxa25x_udc.h |  2 +-
 drivers/usb/host/isp1362-hcd.c  | 27 ++-
 drivers/usb/isp1760/isp1760-if.c|  2 +-
 10 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/drivers/usb/gadget/function/rndis.c 
b/drivers/usb/gadget/function/rndis.c
index ab6ac1b74ac0..766c328c15c0 100644
--- a/drivers/usb/gadget/function/rndis.c
+++ b/drivers/usb/gadget/function/rndis.c
@@ -474,8 +474,7 @@ static int gen_ndis_query_resp(struct rndis_params *params, 
u32 OID, u8 *buf,
break;
 
default:
-   pr_warning("%s: query unknown OID 0x%08X\n",
-__func__, OID);
+   pr_warn("%s: query unknown OID 0x%08X\n", __func__, OID);
}
if (retval < 0)
length = 0;
@@ -546,8 +545,8 @@ static int gen_ndis_set_resp(struct rndis_params *params, 
u32 OID,
break;
 
default:
-   pr_warning("%s: set unknown OID 0x%08X, size %d\n",
-__func__, OID, buf_len);
+   pr_warn("%s: set unknown OID 0x%08X, size %d\n",
+   __func__, OID, buf_len);
}
 
return retval;
@@ -854,7 +853,7 @@ int rndis_msg_parser(struct rndis_params *params, u8 *buf)
 * In one case those messages seemed to relate to the host
 * suspending itself.
 */
-   pr_warning("%s: unknown RNDIS message 0x%08X len %d\n",
+   pr_warn("%s: unknown RNDIS message 0x%08X len %d\n",
__func__, MsgType, MsgLength);
print_hex_dump_bytes(__func__, DUMP_PREFIX_OFFSET,
 buf, MsgLength);
diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index e0cd1e4c8892..62ec842874aa 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -622,8 +622,8 @@ static void gs_write_complete(struct usb_ep *ep, struct 
usb_request *req)
switch (req->status) {
default:
/* presumably a transient fault */
-   pr_warning("%s: unexpected %s status %d\n",
-   __func__, ep->name, req->status);
+   pr_warn("%s: unexpected %s status %d\n",
+   __func__, ep->name, req->status);
/* FALL THROUGH */
case 0:
/* normal completion */
diff --git a/drivers/usb/gadget/udc/at91_udc.h 
b/drivers/usb/gadget/udc/at91_udc.h
index 0a433e6b346b..9bbe72764f31 100644
--- a/drivers/usb/gadget/udc/at91_udc.h
+++ b/drivers/usb/gadget/udc/at91_udc.h
@@ -175,7 +175,7 @@ struct at91_request {
 #endif
 
 #define ERR(stuff...)  pr_err("udc: " stuff)
-#define WARNING(stuff...)  pr_warning("udc: " stuff)
+#define WARNING(stuff...)  pr_warn("udc: " stuff)
 #define INFO(stuff...) pr_info("udc: " stuff)
 #define DBG(stuff...)  pr_debug("udc: " stuff)
 
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 125680db9379..f3212db9bc37 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1464,8 +1464,8 @@ static void usba_control_irq(struct usba_udc *udc, struct 
usba_ep *ep)
pkt_len = USBA_BFEXT(BYTE_COUNT, usba_ep_readl(ep, STA));
DBG(DBG_HW, "Packet length: %u\n", pkt_len);
if (pkt_len != sizeof(crq)) {
-   pr_warning("udc: Invalid packet length %u "
-   "(expected %zu)\n", pkt_len, sizeof(crq));
+   pr_warn("udc: Invalid packet length %u (expected 
%zu)\n",
+   pkt_len, sizeof(crq));
set_protocol_stall(udc, ep);
return;
}
diff --git a/drivers/usb/gadget/udc/fsl_usb2_udc.h 
b/drivers/usb/gadget/udc/fsl_usb2_udc.h
index 84715625b2b3..e92b8408b6f6 100644
--- a/drivers/usb/gadget/udc/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/udc/fsl_usb2_udc.h
@@ -554,7 +554,7 @@ static void dump_msg(const char *label, const u8 * buf, 
unsigned int length)
 #endif
 
 #define ERR(stuff...)  pr_err("udc: " 

[PATCH 64/82] usb: dwc3: gadget: purge dwc3_stop_active_transfers()

2016-10-31 Thread Felipe Balbi
That function is unnecessarily called from
dwc3_gadget_reset_interrupt(). Gadget drivers (and
thus, functions) are required to dequeue all pending
requests when they get notified about a USB Bus
Reset.

Trying to make sure there are no pending requests
only serves the purpose of working around possibly
bad gadgets.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index d74319b6e1be..ef9508e8609e 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2302,24 +2302,6 @@ static void dwc3_stop_active_transfer(struct dwc3 *dwc, 
u32 epnum, bool force)
udelay(100);
 }
 
-static void dwc3_stop_active_transfers(struct dwc3 *dwc)
-{
-   u32 epnum;
-
-   for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
-   struct dwc3_ep *dep;
-
-   dep = dwc->eps[epnum];
-   if (!dep)
-   continue;
-
-   if (!(dep->flags & DWC3_EP_ENABLED))
-   continue;
-
-   dwc3_remove_requests(dwc, dep);
-   }
-}
-
 static void dwc3_clear_stall_all_ep(struct dwc3 *dwc)
 {
u32 epnum;
@@ -2405,8 +2387,6 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc)
reg &= ~DWC3_DCTL_TSTCTRL_MASK;
dwc3_writel(dwc->regs, DWC3_DCTL, reg);
dwc->test_mode = false;
-
-   dwc3_stop_active_transfers(dwc);
dwc3_clear_stall_all_ep(dwc);
 
/* Reset device address to zero */
-- 
2.10.1

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


[PATCH 43/82] usb: ip: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Cc: Valentina Manea 
Cc: Shuah Khan 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/usbip/vudc_dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/usbip/vudc_dev.c b/drivers/usb/usbip/vudc_dev.c
index 7091848df6c8..2fdcdeb13a86 100644
--- a/drivers/usb/usbip/vudc_dev.c
+++ b/drivers/usb/usbip/vudc_dev.c
@@ -259,7 +259,7 @@ static int vep_enable(struct usb_ep *_ep,
 
spin_lock_irqsave(>lock, flags);
 
-   maxp = usb_endpoint_maxp(desc) & 0x7ff;
+   maxp = usb_endpoint_maxp(desc);
_ep->maxpacket = maxp;
ep->desc = desc;
ep->type = usb_endpoint_type(desc);
-- 
2.10.1

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


[PATCH 80/82] usb: dwc3: gadget: always kick if num_pending_sgs > 0

2016-10-31 Thread Felipe Balbi
When we get a half-way processed request, we should
make sure to try to prepare further TRBs for it or
for any possibly queued up request held in our
pending_list. This will make sure our controller is
kept busy for as long as possible.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index bf8a85e80fb9..d1b9777b7ef2 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2125,8 +2125,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 
req->request.actual = length - req->remaining;
 
-   if (ret && chain && (req->request.actual < length)
-   && req->num_pending_sgs)
+   if ((req->request.actual < length) && req->num_pending_sgs)
return __dwc3_gadget_kick_transfer(dep, 0);
 
dwc3_gadget_giveback(dep, req, status);
-- 
2.10.1

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


[PATCH 72/82] usb: gadget: NCM: link socket buffers to the device for tx packets

2016-10-31 Thread Felipe Balbi
From: Torsten Polle 

Socket buffers should be linked to the (network) device that allocated
the buffers.

Signed-off-by: Torsten Polle 
Signed-off-by: Harish Jenny K N 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/f_ncm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/function/f_ncm.c 
b/drivers/usb/gadget/function/f_ncm.c
index 639603722709..b6771ad2485a 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -1078,6 +1078,7 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
if (!ncm->skb_tx_data)
goto err;
 
+   ncm->skb_tx_data->dev = ncm->netdev;
ntb_data = (void *) skb_put(ncm->skb_tx_data, ncb_len);
memset(ntb_data, 0, ncb_len);
/* dwSignature */
@@ -1096,6 +1097,8 @@ static struct sk_buff *ncm_wrap_ntb(struct gether *port,
GFP_ATOMIC);
if (!ncm->skb_tx_ndp)
goto err;
+
+   ncm->skb_tx_ndp->dev = ncm->netdev;
ntb_ndp = (void *) skb_put(ncm->skb_tx_ndp,
opts->ndp_size);
memset(ntb_ndp, 0, ncb_len);
-- 
2.10.1

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


[PATCH 50/82] usb: dwc3: trace: add a proper tracepoint for reg accessors

2016-10-31 Thread Felipe Balbi
We want to reduce the usage of dwc3_trace() in favor
of proper tracepoints which can be enabled/disabled
by the user. Let's start with our register
accessors.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/io.h|  6 ++
 drivers/usb/dwc3/trace.h | 35 ++-
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/io.h b/drivers/usb/dwc3/io.h
index a06f9a8fecc7..c69b06696824 100644
--- a/drivers/usb/dwc3/io.h
+++ b/drivers/usb/dwc3/io.h
@@ -40,8 +40,7 @@ static inline u32 dwc3_readl(void __iomem *base, u32 offset)
 * documentation, so we revert it back to the proper addresses, the
 * same way they are described on SNPS documentation
 */
-   dwc3_trace(trace_dwc3_readl, "addr %p value %08x",
-   base - DWC3_GLOBALS_REGS_START + offset, value);
+   trace_dwc3_readl(base - DWC3_GLOBALS_REGS_START, offset, value);
 
return value;
 }
@@ -60,8 +59,7 @@ static inline void dwc3_writel(void __iomem *base, u32 
offset, u32 value)
 * documentation, so we revert it back to the proper addresses, the
 * same way they are described on SNPS documentation
 */
-   dwc3_trace(trace_dwc3_writel, "addr %p value %08x",
-   base - DWC3_GLOBALS_REGS_START + offset, value);
+   trace_dwc3_writel(base - DWC3_GLOBALS_REGS_START, offset, value);
 }
 
 #endif /* __DRIVERS_USB_DWC3_IO_H */
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index 88ddd01c42af..b2153f231cf0 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -37,29 +37,46 @@ DECLARE_EVENT_CLASS(dwc3_log_msg,
TP_printk("%s", __get_str(msg))
 );
 
-DEFINE_EVENT(dwc3_log_msg, dwc3_readl,
+DEFINE_EVENT(dwc3_log_msg, dwc3_gadget,
TP_PROTO(struct va_format *vaf),
TP_ARGS(vaf)
 );
 
-DEFINE_EVENT(dwc3_log_msg, dwc3_writel,
+DEFINE_EVENT(dwc3_log_msg, dwc3_core,
TP_PROTO(struct va_format *vaf),
TP_ARGS(vaf)
 );
 
-DEFINE_EVENT(dwc3_log_msg, dwc3_gadget,
+DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
TP_PROTO(struct va_format *vaf),
TP_ARGS(vaf)
 );
 
-DEFINE_EVENT(dwc3_log_msg, dwc3_core,
-   TP_PROTO(struct va_format *vaf),
-   TP_ARGS(vaf)
+DECLARE_EVENT_CLASS(dwc3_log_io,
+   TP_PROTO(void *base, u32 offset, u32 value),
+   TP_ARGS(base, offset, value),
+   TP_STRUCT__entry(
+   __field(void *, base)
+   __field(u32, offset)
+   __field(u32, value)
+   ),
+   TP_fast_assign(
+   __entry->base = base;
+   __entry->offset = offset;
+   __entry->value = value;
+   ),
+   TP_printk("addr %p value %08x", __entry->base + __entry->offset,
+   __entry->value)
 );
 
-DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
-   TP_PROTO(struct va_format *vaf),
-   TP_ARGS(vaf)
+DEFINE_EVENT(dwc3_log_io, dwc3_readl,
+   TP_PROTO(void *base, u32 offset, u32 value),
+   TP_ARGS(base, offset, value)
+);
+
+DEFINE_EVENT(dwc3_log_io, dwc3_writel,
+   TP_PROTO(void *base, u32 offset, u32 value),
+   TP_ARGS(base, offset, value)
 );
 
 DECLARE_EVENT_CLASS(dwc3_log_event,
-- 
2.10.1

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


[PATCH 56/82] usb: dwc3: gadget: only interrupt on short if short_not_ok is set

2016-10-31 Thread Felipe Balbi
We don't need to know about short packets unless
gadget driver told us it's not ok to see them on the
bus. In the normal situation we can continue
processing the list of requests if we get a Short
packet.

Also, note that we're making sure ISP is only set
for OUT endpoints, where that setting is valid.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index bb80f91ed309..a19c1e432226 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -875,12 +875,16 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
}
 
/* always enable Continue on Short Packet */
-   if (usb_endpoint_dir_out(dep->endpoint.desc))
+   if (usb_endpoint_dir_out(dep->endpoint.desc)) {
trb->ctrl |= DWC3_TRB_CTRL_CSP;
 
+   if (req->request.short_not_ok)
+   trb->ctrl |= DWC3_TRB_CTRL_ISP_IMI;
+   }
+
if ((!req->request.no_interrupt && !chain) ||
(dwc3_calc_trbs_left(dep) == 0))
-   trb->ctrl |= DWC3_TRB_CTRL_IOC | DWC3_TRB_CTRL_ISP_IMI;
+   trb->ctrl |= DWC3_TRB_CTRL_IOC;
 
if (chain)
trb->ctrl |= DWC3_TRB_CTRL_CHN;
-- 
2.10.1

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


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

2016-10-31 Thread Felipe Balbi
Cleanup only, no functional changes.

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

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

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


[PATCH 69/82] usb: dwc3: cleanup with list_first_entry_or_null()

2016-10-31 Thread Felipe Balbi
From: Masahiro Yamada 

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

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

diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h
index e4a1d974a5ae..3129bcf74d7d 100644
--- a/drivers/usb/dwc3/gadget.h
+++ b/drivers/usb/dwc3/gadget.h
@@ -62,10 +62,7 @@ struct dwc3;
 
 static inline struct dwc3_request *next_request(struct list_head *list)
 {
-   if (list_empty(list))
-   return NULL;
-
-   return list_first_entry(list, struct dwc3_request, list);
+   return list_first_entry_or_null(list, struct dwc3_request, list);
 }
 
 static inline void dwc3_gadget_move_started_request(struct dwc3_request *req)
-- 
2.10.1

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


[PATCH 81/82] usb: dwc3: pci: add a private driver structure

2016-10-31 Thread Felipe Balbi
We'll be tracking a little more information for PCI
drivers, it's about time we add a private structure
for that.

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

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 6df0f5dad9a4..0f54b8166e54 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -39,6 +39,16 @@
 #define PCI_DEVICE_ID_INTEL_APL0x5aaa
 #define PCI_DEVICE_ID_INTEL_KBP0xa2b0
 
+/**
+ * struct dwc3_pci - Driver private structure
+ * @dwc3: child dwc3 platform_device
+ * @pci: our link to PCI bus
+ */
+struct dwc3_pci {
+   struct platform_device *dwc3;
+   struct pci_dev *pci;
+};
+
 static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
 static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
 
@@ -48,8 +58,11 @@ static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] 
= {
{ },
 };
 
-static int dwc3_pci_quirks(struct pci_dev *pdev, struct platform_device *dwc3)
+static int dwc3_pci_quirks(struct dwc3_pci *dwc)
 {
+   struct platform_device  *dwc3 = dwc->dwc3;
+   struct pci_dev  *pdev = dwc->pci;
+
if (pdev->vendor == PCI_VENDOR_ID_AMD &&
pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
struct property_entry properties[] = {
@@ -139,8 +152,8 @@ static int dwc3_pci_quirks(struct pci_dev *pdev, struct 
platform_device *dwc3)
 static int dwc3_pci_probe(struct pci_dev *pci,
const struct pci_device_id *id)
 {
+   struct dwc3_pci *dwc;
struct resource res[2];
-   struct platform_device  *dwc3;
int ret;
struct device   *dev = >dev;
 
@@ -152,11 +165,13 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 
pci_set_master(pci);
 
-   dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
-   if (!dwc3) {
-   dev_err(dev, "couldn't allocate dwc3 device\n");
+   dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
+   if (!dwc)
+   return -ENOMEM;
+
+   dwc->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO);
+   if (!dwc->dwc3)
return -ENOMEM;
-   }
 
memset(res, 0x00, sizeof(struct resource) * ARRAY_SIZE(res));
 
@@ -169,20 +184,21 @@ static int dwc3_pci_probe(struct pci_dev *pci,
res[1].name = "dwc_usb3";
res[1].flags= IORESOURCE_IRQ;
 
-   ret = platform_device_add_resources(dwc3, res, ARRAY_SIZE(res));
+   ret = platform_device_add_resources(dwc->dwc3, res, ARRAY_SIZE(res));
if (ret) {
dev_err(dev, "couldn't add resources to dwc3 device\n");
return ret;
}
 
-   dwc3->dev.parent = dev;
-   ACPI_COMPANION_SET(>dev, ACPI_COMPANION(dev));
+   dwc->pci = pci;
+   dwc->dwc3->dev.parent = dev;
+   ACPI_COMPANION_SET(>dwc3->dev, ACPI_COMPANION(dev));
 
-   ret = dwc3_pci_quirks(pci, dwc3);
+   ret = dwc3_pci_quirks(dwc);
if (ret)
goto err;
 
-   ret = platform_device_add(dwc3);
+   ret = platform_device_add(dwc->dwc3);
if (ret) {
dev_err(dev, "failed to register dwc3 device\n");
goto err;
@@ -190,21 +206,23 @@ static int dwc3_pci_probe(struct pci_dev *pci,
 
device_init_wakeup(dev, true);
device_set_run_wake(dev, true);
-   pci_set_drvdata(pci, dwc3);
+   pci_set_drvdata(pci, dwc);
pm_runtime_put(dev);
 
return 0;
 err:
-   platform_device_put(dwc3);
+   platform_device_put(dwc->dwc3);
return ret;
 }
 
 static void dwc3_pci_remove(struct pci_dev *pci)
 {
+   struct dwc3_pci *dwc = pci_get_drvdata(pci);
+
device_init_wakeup(>dev, false);
pm_runtime_get(>dev);
acpi_dev_remove_driver_gpios(ACPI_COMPANION(>dev));
-   platform_device_unregister(pci_get_drvdata(pci));
+   platform_device_unregister(dwc->dwc3);
 }
 
 static const struct pci_device_id dwc3_pci_id_table[] = {
@@ -245,7 +263,8 @@ static int dwc3_pci_runtime_suspend(struct device *dev)
 
 static int dwc3_pci_runtime_resume(struct device *dev)
 {
-   struct platform_device *dwc3 = dev_get_drvdata(dev);
+   struct dwc3_pci *dwc = dev_get_drvdata(dev);
+   struct platform_device  *dwc3 = dwc->dwc3;
 
return pm_runtime_get(>dev);
 }
-- 
2.10.1

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


[PATCH 71/82] usb: gadget: f_fs: use complete() instead complete_all()

2016-10-31 Thread Felipe Balbi
From: Daniel Wagner 

There is only one waiter for the completion, therefore there
is no need to use complete_all(). Let's make that clear by
using complete() instead of complete_all().

The usage pattern of the completion is:

waiter context  waker context
  reinit_completion()
  usb_esp_queue()
  wait_for_completion_interruptible()

ffs_ep0_complete()
  complete()

Acked-by: Michal Nazarewicz 
Signed-off-by: Daniel Wagner 
Cc: Felipe Balbi 
Cc: Michal Nazarewicz 
Cc: Greg Kroah-Hartman 
Cc: linux-usb@vger.kernel.org
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/function/f_fs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c 
b/drivers/usb/gadget/function/f_fs.c
index e40d47d47d82..dff72a873297 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -266,7 +266,7 @@ static void ffs_ep0_complete(struct usb_ep *ep, struct 
usb_request *req)
 {
struct ffs_data *ffs = req->context;
 
-   complete_all(>ep0req_completion);
+   complete(>ep0req_completion);
 }
 
 static int __ffs_ep0_queue_wait(struct ffs_data *ffs, char *data, size_t len)
-- 
2.10.1

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


[PATCH 62/82] usb: dwc3: core: remove unnecessary alignment

2016-10-31 Thread Felipe Balbi
Kernel will give us page aligned memory anyway.

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

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index e65f30afb89a..1f33abf21e0f 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -948,8 +948,6 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
}
 }
 
-#define DWC3_ALIGN_MASK(16 - 1)
-
 static int dwc3_probe(struct platform_device *pdev)
 {
struct device   *dev = >dev;
@@ -962,13 +960,11 @@ static int dwc3_probe(struct platform_device *pdev)
int ret;
 
void __iomem*regs;
-   void*mem;
 
-   mem = devm_kzalloc(dev, sizeof(*dwc) + DWC3_ALIGN_MASK, GFP_KERNEL);
-   if (!mem)
+   dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
+   if (!dwc)
return -ENOMEM;
 
-   dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
dwc->dev = dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-- 
2.10.1

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


[PATCH 61/82] usb: dwc3: core: introduce dwc3_core_setup_global_control()

2016-10-31 Thread Felipe Balbi
This little helper will be used to setup anything
related to GCTL register. There are no functional
changes, this is a cleanup only patch.

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

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 3e9515073e05..e65f30afb89a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -615,49 +615,10 @@ static bool dwc3_core_is_valid(struct dwc3 *dwc)
return true;
 }
 
-/**
- * dwc3_core_init - Low-level initialization of DWC3 Core
- * @dwc: Pointer to our controller context structure
- *
- * Returns 0 on success otherwise negative errno.
- */
-static int dwc3_core_init(struct dwc3 *dwc)
+static void dwc3_core_setup_global_control(struct dwc3 *dwc)
 {
-   u32 hwparams4 = dwc->hwparams.hwparams4;
-   u32 reg;
-   int ret;
-
-   if (!dwc3_core_is_valid(dwc)) {
-   dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
-   ret = -ENODEV;
-   goto err0;
-   }
-
-   /*
-* Write Linux Version Code to our GUID register so it's easy to figure
-* out which kernel version a bug was found.
-*/
-   dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
-
-   /* Handle USB2.0-only core configuration */
-   if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
-   DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
-   if (dwc->maximum_speed == USB_SPEED_SUPER)
-   dwc->maximum_speed = USB_SPEED_HIGH;
-   }
-
-   /* issue device SoftReset too */
-   ret = dwc3_soft_reset(dwc);
-   if (ret)
-   goto err0;
-
-   ret = dwc3_core_soft_reset(dwc);
-   if (ret)
-   goto err0;
-
-   ret = dwc3_phy_setup(dwc);
-   if (ret)
-   goto err0;
+   u32 hwparams4 = dwc->hwparams.hwparams4;
+   u32 reg;
 
reg = dwc3_readl(dwc->regs, DWC3_GCTL);
reg &= ~DWC3_GCTL_SCALEDOWN_MASK;
@@ -726,7 +687,52 @@ static int dwc3_core_init(struct dwc3 *dwc)
reg |= DWC3_GCTL_U2RSTECN;
 
dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
+
+/**
+ * dwc3_core_init - Low-level initialization of DWC3 Core
+ * @dwc: Pointer to our controller context structure
+ *
+ * Returns 0 on success otherwise negative errno.
+ */
+static int dwc3_core_init(struct dwc3 *dwc)
+{
+   u32 reg;
+   int ret;
+
+   if (!dwc3_core_is_valid(dwc)) {
+   dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
+   ret = -ENODEV;
+   goto err0;
+   }
+
+   /*
+* Write Linux Version Code to our GUID register so it's easy to figure
+* out which kernel version a bug was found.
+*/
+   dwc3_writel(dwc->regs, DWC3_GUID, LINUX_VERSION_CODE);
+
+   /* Handle USB2.0-only core configuration */
+   if (DWC3_GHWPARAMS3_SSPHY_IFC(dwc->hwparams.hwparams3) ==
+   DWC3_GHWPARAMS3_SSPHY_IFC_DIS) {
+   if (dwc->maximum_speed == USB_SPEED_SUPER)
+   dwc->maximum_speed = USB_SPEED_HIGH;
+   }
+
+   /* issue device SoftReset too */
+   ret = dwc3_soft_reset(dwc);
+   if (ret)
+   goto err0;
+
+   ret = dwc3_core_soft_reset(dwc);
+   if (ret)
+   goto err0;
+
+   ret = dwc3_phy_setup(dwc);
+   if (ret)
+   goto err0;
 
+   dwc3_core_setup_global_control(dwc);
dwc3_core_num_eps(dwc);
 
ret = dwc3_setup_scratch_buffers(dwc);
-- 
2.10.1

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


[PATCH 45/82] usb: gadget: udc: mv: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/udc/mv_udc_core.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/mv_udc_core.c 
b/drivers/usb/gadget/udc/mv_udc_core.c
index 542b70a83ee6..d82a91bddbd9 100644
--- a/drivers/usb/gadget/udc/mv_udc_core.c
+++ b/drivers/usb/gadget/udc/mv_udc_core.c
@@ -495,7 +495,6 @@ static int mv_ep_enable(struct usb_ep *_ep,
case USB_ENDPOINT_XFER_ISOC:
/* Calculate transactions needed for high bandwidth iso */
mult = usb_endpoint_maxp_mult(desc);
-   max = max & 0x7ff;  /* bit 0~10 */
/* 3 transactions at most */
if (mult > 3)
goto en_done;
-- 
2.10.1

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


[PATCH 75/82] usb: dwc3: gadget: wait for End Transfer to complete

2016-10-31 Thread Felipe Balbi
From: Baolin Wang 

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

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

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

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 5fc437021ac7..0cb3b78d28b7 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -26,6 +26,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -505,6 +506,7 @@ struct dwc3_event_buffer {
  * @endpoint: usb endpoint
  * @pending_list: list of pending requests for this endpoint
  * @started_list: list of started requests on this endpoint
+ * @wait_end_transfer: wait_queue_head_t for waiting on End Transfer complete
  * @lock: spinlock for endpoint request queue traversal
  * @regs: pointer to first endpoint register
  * @trb_pool: array of transaction buffers
@@ -530,6 +532,8 @@ struct dwc3_ep {
struct list_headpending_list;
struct list_headstarted_list;
 
+   wait_queue_head_t   wait_end_transfer;
+
spinlock_t  lock;
void __iomem*regs;
 
@@ -546,6 +550,7 @@ struct dwc3_ep {
 #define DWC3_EP_BUSY   (1 << 4)
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
+#define DWC3_EP_END_TRANSFER_PENDING (1 << 7)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
@@ -1050,6 +1055,9 @@ struct dwc3_event_depevt {
 #define DEPEVT_TRANSFER_BUS_EXPIRY 2
 
u32 parameters:16;
+
+/* For Command Complete Events */
+#define DEPEVT_PARAMETER_CMD(n) (((n) & (0xf << 8)) >> 8)
 } __packed;
 
 /**
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3b53a5714df4..bc985f8571c6 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -598,6 +598,8 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
reg |= DWC3_DALEPENA_EP(dep->number);
dwc3_writel(dwc->regs, DWC3_DALEPENA, reg);
 
+   init_waitqueue_head(>wait_end_transfer);
+
if (usb_endpoint_xfer_control(desc))
return 0;
 
@@ -772,6 +774,10 @@ static int dwc3_gadget_ep_disable(struct usb_ep *ep)
dep->name))
return 0;
 
+   if (dep->flags & DWC3_EP_END_TRANSFER_PENDING)
+   wait_event(dep->wait_end_transfer,
+   !(dep->flags & DWC3_EP_END_TRANSFER_PENDING));
+
spin_lock_irqsave(>lock, flags);
ret = __dwc3_gadget_ep_disable(dep);
spin_unlock_irqrestore(>lock, flags);
@@ -1782,13 +1788,30 @@ static int dwc3_gadget_start(struct usb_gadget *g,
 }
 
 static void __dwc3_gadget_stop(struct dwc3 *dwc)
+__releases(>lock) __acquires(>lock)
 {
+   int epnum;
+
if (pm_runtime_suspended(dwc->dev))
return;
 
dwc3_gadget_disable_irq(dwc);
__dwc3_gadget_ep_disable(dwc->eps[0]);
__dwc3_gadget_ep_disable(dwc->eps[1]);
+
+   for (epnum = 2; epnum < DWC3_ENDPOINTS_NUM; epnum++) {
+   struct dwc3_ep  *dep = dwc->eps[epnum];
+
+   if (!(dep->flags & DWC3_EP_ENABLED))
+   continue;
+
+   if (!(dep->flags & DWC3_EP_END_TRANSFER_PENDING))
+   continue;
+
+   wait_event_lock_irq(dep->wait_end_transfer,
+   !(dep->flags & DWC3_EP_END_TRANSFER_PENDING),
+   dwc->lock);
+   }
 }
 
 static int dwc3_gadget_stop(struct usb_gadget *g)
@@ -2171,6 +2194,7 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
 {
struct dwc3_ep  *dep;
u8  epnum = event->endpoint_number;
+   u8  cmd;
 
dep = dwc->eps[epnum];
 
@@ -2215,8 +2239,15 @@ static void dwc3_endpoint_interrupt(struct dwc3 *dwc,
return;
}
break;
-   case DWC3_DEPEVT_RXTXFIFOEVT:
case DWC3_DEPEVT_EPCMDCMPLT:
+   cmd = DEPEVT_PARAMETER_CMD(event->parameters);
+
+   if (cmd == DWC3_DEPCMD_ENDTRANSFER) {
+   dep->flags &= ~DWC3_EP_END_TRANSFER_PENDING;
+   wake_up_all(>wait_end_transfer);
+   }
+   break;
+   case DWC3_DEPEVT_RXTXFIFOEVT:
break;
}
 }
@@ -2269,7 +2300,8 @@ static void dwc3_stop_active_transfer(struct 

[PATCH 47/82] usb: dwc3: gadget: offset Start Transfer latency for bulk EPs

2016-10-31 Thread Felipe Balbi
We can offset the latency of a full Start Transfer
command - where we _must_ poll for its completion -
to usb_ep_enable() time. This means that once
requests start showing up from the gadget driver, we
can rely on No Response Update Transfer command -
where we don't need to poll for completion.

This patch, starts implementing this method for Bulk
endpoints, even though, technically, we could extend
it to all other endpoints in future commits.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 4d191c8acb59..c692aafa7397 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -617,6 +617,35 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
trb_link->ctrl |= DWC3_TRB_CTRL_HWO;
}
 
+   /*
+* Issue StartTransfer here with no-op TRB so we can always rely on No
+* Response Update Transfer command.
+*/
+   if (usb_endpoint_xfer_bulk(desc)) {
+   struct dwc3_gadget_ep_cmd_params params;
+   struct dwc3_trb *trb;
+   dma_addr_t trb_dma;
+   u32 cmd;
+
+   memset(, 0, sizeof(params));
+   trb = >trb_pool[0];
+   trb_dma = dwc3_trb_dma_offset(dep, trb);
+
+   params.param0 = upper_32_bits(trb_dma);
+   params.param1 = lower_32_bits(trb_dma);
+
+   cmd = DWC3_DEPCMD_STARTTRANSFER;
+
+   ret = dwc3_send_gadget_ep_cmd(dep, cmd, );
+   if (ret < 0)
+   return ret;
+
+   dep->flags |= DWC3_EP_BUSY;
+
+   dep->resource_index = dwc3_gadget_ep_get_transfer_index(dep);
+   WARN_ON_ONCE(!dep->resource_index);
+   }
+
return 0;
 }
 
-- 
2.10.1

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


[PATCH 79/82] usb: dwc3: gadget: stop touching HWO TRBs

2016-10-31 Thread Felipe Balbi
Say we have three requests prepared to the HW (reqA,
reqB, and reqC). All of them are composed of
SG-lists with several entries and they all requests
interrupt only on last TRBs of the SG-list.

When we get interrupt for reqA, it could be that
reqB is already half-way transferred and some of its
TRBs will have HWO already cleared.

It's okay to free up TRBs without HWO bit set, but
we need to guarantee we don't giveback a request
that's half-way transferred as that will confuse
gadget drivers.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index bca4150e3cf5..bf8a85e80fb9 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2106,6 +2106,9 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
for_each_sg(sg, s, pending, i) {
trb = >trb_pool[dep->trb_dequeue];
 
+   if (trb->ctrl & DWC3_TRB_CTRL_HWO)
+   break;
+
req->sg = sg_next(s);
req->num_pending_sgs--;
 
-- 
2.10.1

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


[PATCH 57/82] usb: dwc3: gadget: never ever kill the machine

2016-10-31 Thread Felipe Balbi
We should never kill the machine just because some
USB endpoint type is wrong. WARN about it and move
on.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index a19c1e432226..d74319b6e1be 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -871,7 +871,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
 * This is only possible with faulty memory because we
 * checked it already :)
 */
-   BUG();
+   dev_WARN(dwc->dev, "Unknown endpoint type %d\n",
+   usb_endpoint_type(dep->endpoint.desc));
}
 
/* always enable Continue on Short Packet */
-- 
2.10.1

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


[PATCH 76/82] usb: dwc3: gadget: cope with XferNotReady before usb_ep_queue()

2016-10-31 Thread Felipe Balbi
If XferNotReady comes before usb_ep_queue() we will
set our PENDING request flag and wait for a
request. However, originally, we were assuming
usb_ep_queue() would always happen before our first
XferNotReady and that causes a corner case where we
could try to issue ENDTRANSFER command before
STARTTRANSFER.

Let's fix that by tracking endpoints which have been
started.

Reported-by: Janusz Dziedzic 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h   |  1 +
 drivers/usb/dwc3/gadget.c | 40 +---
 2 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 0cb3b78d28b7..180239fb021a 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -551,6 +551,7 @@ struct dwc3_ep {
 #define DWC3_EP_PENDING_REQUEST(1 << 5)
 #define DWC3_EP_MISSED_ISOC(1 << 6)
 #define DWC3_EP_END_TRANSFER_PENDING (1 << 7)
+#define DWC3_EP_TRANSFER_STARTED (1 << 8)
 
/* This last one is specific to EP0 */
 #define DWC3_EP0_DIR_IN(1 << 31)
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index bc985f8571c6..310535e9b731 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -340,6 +340,20 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned 
cmd,
 
trace_dwc3_gadget_ep_cmd(dep, cmd, params, cmd_status);
 
+   if (ret == 0) {
+   switch (DWC3_DEPCMD_CMD(cmd)) {
+   case DWC3_DEPCMD_STARTTRANSFER:
+   dep->flags |= DWC3_EP_TRANSFER_STARTED;
+   break;
+   case DWC3_DEPCMD_ENDTRANSFER:
+   dep->flags &= ~DWC3_EP_TRANSFER_STARTED;
+   break;
+   default:
+   /* nothing */
+   break;
+   }
+   }
+
if (unlikely(susphy)) {
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
reg |= DWC3_GUSB2PHYCFG_SUSPHY;
@@ -1069,6 +1083,14 @@ static int __dwc3_gadget_kick_transfer(struct dwc3_ep 
*dep, u16 cmd_param)
return 0;
 }
 
+static int __dwc3_gadget_get_frame(struct dwc3 *dwc)
+{
+   u32 reg;
+
+   reg = dwc3_readl(dwc->regs, DWC3_DSTS);
+   return DWC3_DSTS_SOFFN(reg);
+}
+
 static void __dwc3_gadget_start_isoc(struct dwc3 *dwc,
struct dwc3_ep *dep, u32 cur_uf)
 {
@@ -1146,10 +1168,16 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
 * errors which will force us issue EndTransfer command.
 */
if (usb_endpoint_xfer_isoc(dep->endpoint.desc)) {
-   if ((dep->flags & DWC3_EP_PENDING_REQUEST) &&
-   list_empty(>started_list)) {
-   dwc3_stop_active_transfer(dwc, dep->number, true);
-   dep->flags = DWC3_EP_ENABLED;
+   if ((dep->flags & DWC3_EP_PENDING_REQUEST)) {
+   if (dep->flags & DWC3_EP_TRANSFER_STARTED) {
+   dwc3_stop_active_transfer(dwc, dep->number, 
true);
+   dep->flags = DWC3_EP_ENABLED;
+   } else {
+   u32 cur_uf;
+
+   cur_uf = __dwc3_gadget_get_frame(dwc);
+   __dwc3_gadget_start_isoc(dwc, dep, cur_uf);
+   }
}
return 0;
}
@@ -1395,10 +1423,8 @@ static const struct usb_ep_ops dwc3_gadget_ep_ops = {
 static int dwc3_gadget_get_frame(struct usb_gadget *g)
 {
struct dwc3 *dwc = gadget_to_dwc(g);
-   u32 reg;
 
-   reg = dwc3_readl(dwc->regs, DWC3_DSTS);
-   return DWC3_DSTS_SOFFN(reg);
+   return __dwc3_gadget_get_frame(dwc);
 }
 
 static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
-- 
2.10.1

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


[PATCH 77/82] usb: dwc3: gadget: tracking per-TRB remaining bytes

2016-10-31 Thread Felipe Balbi
This will give us a simpler way of figuring out how
many bytes were left in each TRB. It's useful for
cases where we queue only part of an SG-list due to
amount of available TRBs at the time of kicking the
transfer.

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

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 180239fb021a..b585a3020f28 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -715,6 +715,7 @@ struct dwc3_hwparams {
  * @dep: struct dwc3_ep owning this request
  * @sg: pointer to first incomplete sg
  * @num_pending_sgs: counter to pending sgs
+ * @remaining: amount of data remaining
  * @epnum: endpoint number to which this request refers
  * @trb: pointer to struct dwc3_trb
  * @trb_dma: DMA address of @trb
@@ -729,6 +730,7 @@ struct dwc3_request {
struct scatterlist  *sg;
 
unsignednum_pending_sgs;
+   unsignedremaining;
u8  epnum;
struct dwc3_trb *trb;
dma_addr_t  trb_dma;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 310535e9b731..84b449b17160 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -178,6 +178,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct 
dwc3_request *req,
req->started = false;
list_del(>list);
req->trb = NULL;
+   req->remaining = 0;
 
if (req->request.status == -EINPROGRESS)
req->request.status = status;
@@ -2016,7 +2017,7 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
return 1;
 
count = trb->size & DWC3_TRB_SIZE_MASK;
-   req->request.actual += count;
+   req->remaining += count;
 
if (dep->direction) {
if (count) {
@@ -2070,11 +2071,10 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
struct dwc3_request *req, *n;
struct dwc3_trb *trb;
boolioc = false;
-   int ret;
+   int ret = 0;
 
list_for_each_entry_safe(req, n, >started_list, list) {
unsigned length;
-   unsigned actual;
int chain;
 
length = req->request.length;
@@ -2102,17 +2102,10 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
event, status, chain);
}
 
-   /*
-* We assume here we will always receive the entire data block
-* which we should receive. Meaning, if we program RX to
-* receive 4K but we receive only 2K, we assume that's all we
-* should receive and we simply bounce the request back to the
-* gadget driver for further processing.
-*/
-   actual = length - req->request.actual;
-   req->request.actual = actual;
+   req->request.actual = length - req->remaining;
 
-   if (ret && chain && (actual < length) && req->num_pending_sgs)
+   if (ret && chain && (req->request.actual < length)
+   && req->num_pending_sgs)
return __dwc3_gadget_kick_transfer(dep, 0);
 
dwc3_gadget_giveback(dep, req, status);
-- 
2.10.1

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


[PATCH 63/82] usb: dwc3: core: add dwc3_get_properties()

2016-10-31 Thread Felipe Balbi
This helper will be responsible for reading and
parsing our properties. No functional changes in
this patch, cleanup only.

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

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 1f33abf21e0f..5e61ef6a378d 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -948,52 +948,13 @@ static void dwc3_core_exit_mode(struct dwc3 *dwc)
}
 }
 
-static int dwc3_probe(struct platform_device *pdev)
+static void dwc3_get_properties(struct dwc3 *dwc)
 {
-   struct device   *dev = >dev;
-   struct resource *res;
-   struct dwc3 *dwc;
+   struct device   *dev = dwc->dev;
u8  lpm_nyet_threshold;
u8  tx_de_emphasis;
u8  hird_threshold;
 
-   int ret;
-
-   void __iomem*regs;
-
-   dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
-   if (!dwc)
-   return -ENOMEM;
-
-   dwc->dev = dev;
-
-   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   if (!res) {
-   dev_err(dev, "missing memory resource\n");
-   return -ENODEV;
-   }
-
-   dwc->xhci_resources[0].start = res->start;
-   dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
-   DWC3_XHCI_REGS_END;
-   dwc->xhci_resources[0].flags = res->flags;
-   dwc->xhci_resources[0].name = res->name;
-
-   res->start += DWC3_GLOBALS_REGS_START;
-
-   /*
-* Request memory region but exclude xHCI regs,
-* since it will be requested by the xhci-plat driver.
-*/
-   regs = devm_ioremap_resource(dev, res);
-   if (IS_ERR(regs)) {
-   ret = PTR_ERR(regs);
-   goto err0;
-   }
-
-   dwc->regs   = regs;
-   dwc->regs_size  = resource_size(res);
-
/* default to highest possible threshold */
lpm_nyet_threshold = 0xff;
 
@@ -1065,6 +1026,53 @@ static int dwc3_probe(struct platform_device *pdev)
dwc->hird_threshold = hird_threshold
| (dwc->is_utmi_l1_suspend << 4);
 
+}
+
+static int dwc3_probe(struct platform_device *pdev)
+{
+   struct device   *dev = >dev;
+   struct resource *res;
+   struct dwc3 *dwc;
+
+   int ret;
+
+   void __iomem*regs;
+
+   dwc = devm_kzalloc(dev, sizeof(*dwc), GFP_KERNEL);
+   if (!dwc)
+   return -ENOMEM;
+
+   dwc->dev = dev;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res) {
+   dev_err(dev, "missing memory resource\n");
+   return -ENODEV;
+   }
+
+   dwc->xhci_resources[0].start = res->start;
+   dwc->xhci_resources[0].end = dwc->xhci_resources[0].start +
+   DWC3_XHCI_REGS_END;
+   dwc->xhci_resources[0].flags = res->flags;
+   dwc->xhci_resources[0].name = res->name;
+
+   res->start += DWC3_GLOBALS_REGS_START;
+
+   /*
+* Request memory region but exclude xHCI regs,
+* since it will be requested by the xhci-plat driver.
+*/
+   regs = devm_ioremap_resource(dev, res);
+   if (IS_ERR(regs)) {
+   ret = PTR_ERR(regs);
+   goto err0;
+   }
+
+   dwc->regs   = regs;
+   dwc->regs_size  = resource_size(res);
+
+   dwc3_get_properties(dwc);
+
platform_set_drvdata(pdev, dwc);
dwc3_cache_hwparams(dwc);
 
-- 
2.10.1

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


[PATCH 46/82] usb: dwc3: trace: pretty print high-bandwidth transfers too

2016-10-31 Thread Felipe Balbi
In case of periodic transfers, let's pretty print
the size field as a multiplier followed by length,
such as :

3x 1024

instead of:

33555456

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/trace.h | 25 +++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index a4ef5e7bf6b8..88ddd01c42af 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -239,6 +239,7 @@ DECLARE_EVENT_CLASS(dwc3_log_trb,
__field(u32, bph)
__field(u32, size)
__field(u32, ctrl)
+   __field(u32, type)
),
TP_fast_assign(
snprintf(__get_str(name), DWC3_MSG_MAX, "%s", dep->name);
@@ -249,11 +250,31 @@ DECLARE_EVENT_CLASS(dwc3_log_trb,
__entry->bph = trb->bph;
__entry->size = trb->size;
__entry->ctrl = trb->ctrl;
+   __entry->type = usb_endpoint_type(dep->endpoint.desc);
),
-   TP_printk("%s: %d/%d trb %p buf %08x%08x size %d ctrl %08x 
(%c%c%c%c:%c%c:%s)",
+   TP_printk("%s: %d/%d trb %p buf %08x%08x size %s%d ctrl %08x 
(%c%c%c%c:%c%c:%s)",
__get_str(name), __entry->queued, __entry->allocated,
__entry->trb, __entry->bph, __entry->bpl,
-   __entry->size, __entry->ctrl,
+   ({char *s;
+   int pcm = ((__entry->size >> 24) & 3) + 1;
+   switch (__entry->type) {
+   case USB_ENDPOINT_XFER_INT:
+   case USB_ENDPOINT_XFER_ISOC:
+   switch (pcm) {
+   case 1:
+   s = "1x ";
+   break;
+   case 2:
+   s = "2x ";
+   break;
+   case 3:
+   s = "3x ";
+   break;
+   }
+   default:
+   s = "";
+   } s; }),
+   DWC3_TRB_SIZE_LENGTH(__entry->size), __entry->ctrl,
__entry->ctrl & DWC3_TRB_CTRL_HWO ? 'H' : 'h',
__entry->ctrl & DWC3_TRB_CTRL_LST ? 'L' : 'l',
__entry->ctrl & DWC3_TRB_CTRL_CHN ? 'C' : 'c',
-- 
2.10.1

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


[PATCH 54/82] usb: dwc3: gadget: remove unused 'first_trb_index'

2016-10-31 Thread Felipe Balbi
Recent changes have turned this field obsolete. Remove it.

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

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 18e4c09ae286..bdd37871fc6c 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -705,7 +705,6 @@ struct dwc3_hwparams {
  * @dep: struct dwc3_ep owning this request
  * @sg: pointer to first incomplete sg
  * @num_pending_sgs: counter to pending sgs
- * @first_trb_index: index to first trb used by this request
  * @epnum: endpoint number to which this request refers
  * @trb: pointer to struct dwc3_trb
  * @trb_dma: DMA address of @trb
@@ -720,7 +719,6 @@ struct dwc3_request {
struct scatterlist  *sg;
 
unsignednum_pending_sgs;
-   u8  first_trb_index;
u8  epnum;
struct dwc3_trb *trb;
dma_addr_t  trb_dma;
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c0011174a1f1..425200b99f53 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -832,7 +832,6 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
dwc3_gadget_move_started_request(req);
req->trb = trb;
req->trb_dma = dwc3_trb_dma_offset(dep, trb);
-   req->first_trb_index = dep->trb_enqueue;
dep->queued_requests++;
}
 
-- 
2.10.1

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


[PATCH 60/82] usb: dwc3: core: introduce dwc3_core_is_valid()

2016-10-31 Thread Felipe Balbi
This little helper will be used to make sure we're
dealing with a valid Synopsys DWC3 or DWC3.1 core.

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

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index fe1ecae73086..3e9515073e05 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -594,19 +594,12 @@ static void dwc3_core_exit(struct dwc3 *dwc)
phy_power_off(dwc->usb3_generic_phy);
 }
 
-/**
- * dwc3_core_init - Low-level initialization of DWC3 Core
- * @dwc: Pointer to our controller context structure
- *
- * Returns 0 on success otherwise negative errno.
- */
-static int dwc3_core_init(struct dwc3 *dwc)
+static bool dwc3_core_is_valid(struct dwc3 *dwc)
 {
-   u32 hwparams4 = dwc->hwparams.hwparams4;
-   u32 reg;
-   int ret;
+   u32 reg;
 
reg = dwc3_readl(dwc->regs, DWC3_GSNPSID);
+
/* This should read as U3 followed by revision number */
if ((reg & DWC3_GSNPSID_MASK) == 0x5533) {
/* Detected DWC_usb3 IP */
@@ -616,6 +609,25 @@ static int dwc3_core_init(struct dwc3 *dwc)
dwc->revision = dwc3_readl(dwc->regs, DWC3_VER_NUMBER);
dwc->revision |= DWC3_REVISION_IS_DWC31;
} else {
+   return false;
+   }
+
+   return true;
+}
+
+/**
+ * dwc3_core_init - Low-level initialization of DWC3 Core
+ * @dwc: Pointer to our controller context structure
+ *
+ * Returns 0 on success otherwise negative errno.
+ */
+static int dwc3_core_init(struct dwc3 *dwc)
+{
+   u32 hwparams4 = dwc->hwparams.hwparams4;
+   u32 reg;
+   int ret;
+
+   if (!dwc3_core_is_valid(dwc)) {
dev_err(dwc->dev, "this is not a DesignWare USB3 DRD Core\n");
ret = -ENODEV;
goto err0;
-- 
2.10.1

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


[PATCH 59/82] usb: dwc3: Add support for device L1 exit

2016-10-31 Thread Felipe Balbi
From: John Youn 

For the usb31 IP and from version 2.90a of the usb3 IP, the core
supports HW exit from L1 in HS. Enable it, otherwise the controller may
never exit from LPM to do a transfer.

Signed-off-by: John Youn 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.c | 10 ++
 drivers/usb/dwc3/core.h |  4 
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 3dc535a703f1..fe1ecae73086 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -766,6 +766,16 @@ static int dwc3_core_init(struct dwc3 *dwc)
dwc3_writel(dwc->regs, DWC3_GUCTL2, reg);
}
 
+   /*
+* Enable hardware control of sending remote wakeup in HS when
+* the device is in the L1 state.
+*/
+   if (dwc->revision >= DWC3_REVISION_290A) {
+   reg = dwc3_readl(dwc->regs, DWC3_GUCTL1);
+   reg |= DWC3_GUCTL1_DEV_L1_EXIT_BY_HW;
+   dwc3_writel(dwc->regs, DWC3_GUCTL1, reg);
+   }
+
return 0;
 
 err4:
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 29fd7aa5fc72..e878366ead00 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -198,6 +198,9 @@
 #define DWC3_GCTL_GBLHIBERNATIONEN (1 << 1)
 #define DWC3_GCTL_DSBLCLKGTNG  (1 << 0)
 
+/* Global User Control 1 Register */
+#define DWC3_GUCTL1_DEV_L1_EXIT_BY_HW  (1 << 24)
+
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST(1 << 31)
 #define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30)
@@ -908,6 +911,7 @@ struct dwc3 {
 #define DWC3_REVISION_260A 0x5533260a
 #define DWC3_REVISION_270A 0x5533270a
 #define DWC3_REVISION_280A 0x5533280a
+#define DWC3_REVISION_290A 0x5533290a
 #define DWC3_REVISION_300A 0x5533300a
 #define DWC3_REVISION_310A 0x5533310a
 
-- 
2.10.1

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


[PATCH 58/82] usb: dwc3: remove unused struct member dwc3->mem

2016-10-31 Thread Felipe Balbi
From: Lu Baolu 

Member @mem in struct dwc3 is not used in any places. Clean up it.

Signed-off-by: Lu Baolu 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.c | 1 -
 drivers/usb/dwc3/core.h | 3 ---
 2 files changed, 4 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 7287a763cd0c..3dc535a703f1 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -941,7 +941,6 @@ static int dwc3_probe(struct platform_device *pdev)
return -ENOMEM;
 
dwc = PTR_ALIGN(mem, DWC3_ALIGN_MASK + 1);
-   dwc->mem = mem;
dwc->dev = dev;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index bdd37871fc6c..29fd7aa5fc72 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -784,7 +784,6 @@ struct dwc3_scratchpad_array {
  * @ep0state: state of endpoint zero
  * @link_state: link state
  * @speed: device speed (super, high, full, low)
- * @mem: points to start of memory which is used for this struct.
  * @hwparams: copy of hwparams registers
  * @root: debugfs root folder pointer
  * @regset: debugfs pointer to regdump file
@@ -934,8 +933,6 @@ struct dwc3 {
u8  num_out_eps;
u8  num_in_eps;
 
-   void*mem;
-
struct dwc3_hwparamshwparams;
struct dentry   *root;
struct debugfs_regset32 *regset;
-- 
2.10.1

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


[PATCH 70/82] usb: renesas_usbhs: cleanup with list_first_entry_or_null()

2016-10-31 Thread Felipe Balbi
From: Masahiro Yamada 

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

Acked-by: Yoshihiro Shimoda 
Signed-off-by: Masahiro Yamada 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/renesas_usbhs/fifo.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/fifo.c b/drivers/usb/renesas_usbhs/fifo.c
index 857e78337324..d1af831f43eb 100644
--- a/drivers/usb/renesas_usbhs/fifo.c
+++ b/drivers/usb/renesas_usbhs/fifo.c
@@ -100,10 +100,7 @@ static void __usbhsf_pkt_del(struct usbhs_pkt *pkt)
 
 static struct usbhs_pkt *__usbhsf_pkt_get(struct usbhs_pipe *pipe)
 {
-   if (list_empty(>list))
-   return NULL;
-
-   return list_first_entry(>list, struct usbhs_pkt, node);
+   return list_first_entry_or_null(>list, struct usbhs_pkt, node);
 }
 
 static void usbhsf_fifo_clear(struct usbhs_pipe *pipe,
-- 
2.10.1

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


[PATCH 55/82] usb: dwc3: gadget: CSP is only valid for OUT endpoints

2016-10-31 Thread Felipe Balbi
CSP bit is only valid for OUT endpoints. Synopsys
databook is unclear if HW ignores CSP for IN
endpoints (chances are, it does) but to avoid
problems, let's make sure to set CSP only when valid
to do so.

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

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 425200b99f53..bb80f91ed309 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -875,7 +875,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
}
 
/* always enable Continue on Short Packet */
-   trb->ctrl |= DWC3_TRB_CTRL_CSP;
+   if (usb_endpoint_dir_out(dep->endpoint.desc))
+   trb->ctrl |= DWC3_TRB_CTRL_CSP;
 
if ((!req->request.no_interrupt && !chain) ||
(dwc3_calc_trbs_left(dep) == 0))
-- 
2.10.1

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


[PATCH 49/82] usb: dwc3: Kconfig: allow all glues to build if COMPILE_TEST

2016-10-31 Thread Felipe Balbi
We shouldn't have any glue layer which doesn't
compile everywhere. In order to make sure this is
always the case, make sure COMPILE_TEST is properly
added at dependency list of a config entry.

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

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index b97cde76914d..a45b4f1ba689 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -62,7 +62,7 @@ config USB_DWC3_OMAP
 
 config USB_DWC3_EXYNOS
tristate "Samsung Exynos Platform"
-   depends on ARCH_EXYNOS && OF || COMPILE_TEST
+   depends on (ARCH_EXYNOS || COMPILE_TEST) && OF
default USB_DWC3
help
  Recent Exynos5 SoCs ship with one DesignWare Core USB3 IP inside,
@@ -98,7 +98,7 @@ config USB_DWC3_OF_SIMPLE
 
 config USB_DWC3_ST
tristate "STMicroelectronics Platforms"
-   depends on ARCH_STI && OF
+   depends on (ARCH_STI || COMPILE_TEST) && OF
default USB_DWC3
help
  STMicroelectronics SoCs with one DesignWare Core USB3 IP
-- 
2.10.1

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


[PATCH 68/82] usb: dwc2: cleanup with list_first_entry_or_null()

2016-10-31 Thread Felipe Balbi
From: Masahiro Yamada 

The combo of list_empty() check and return list_first_entry()
can be replaced with list_first_entry_or_null().

Signed-off-by: Masahiro Yamada 
Acked-by: John Youn 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc2/gadget.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 24fbebc9b409..9dc6c482b89e 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -1099,10 +1099,8 @@ static int dwc2_hsotg_ep_sethalt(struct usb_ep *ep, int 
value, bool now);
  */
 static struct dwc2_hsotg_req *get_ep_head(struct dwc2_hsotg_ep *hs_ep)
 {
-   if (list_empty(_ep->queue))
-   return NULL;
-
-   return list_first_entry(_ep->queue, struct dwc2_hsotg_req, queue);
+   return list_first_entry_or_null(_ep->queue, struct dwc2_hsotg_req,
+   queue);
 }
 
 /**
-- 
2.10.1

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


[PATCH 66/82] usb: gadget: composite: use kasprintf() instead of open coding it

2016-10-31 Thread Felipe Balbi
From: Juergen Gross 

Let's not reimplement generic kernel helpers,
instead call kasprintf().

[ felipe.ba...@linux.intel.com: better commit log ]

Signed-off-by: Juergen Gross 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/composite.c | 14 ++
 1 file changed, 2 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 919d7d1b611c..41ab61f9b6e0 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -2387,18 +2387,8 @@ EXPORT_SYMBOL_GPL(usb_composite_setup_continue);
 
 static char *composite_default_mfr(struct usb_gadget *gadget)
 {
-   char *mfr;
-   int len;
-
-   len = snprintf(NULL, 0, "%s %s with %s", init_utsname()->sysname,
-   init_utsname()->release, gadget->name);
-   len++;
-   mfr = kmalloc(len, GFP_KERNEL);
-   if (!mfr)
-   return NULL;
-   snprintf(mfr, len, "%s %s with %s", init_utsname()->sysname,
-   init_utsname()->release, gadget->name);
-   return mfr;
+   return kasprintf(GFP_KERNEL, "%s %s with %s", init_utsname()->sysname,
+init_utsname()->release, gadget->name);
 }
 
 void usb_composite_overwrite_options(struct usb_composite_dev *cdev,
-- 
2.10.1

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


[PATCH 48/82] usb: dwc3: don't compile dwc3_trace() unless CONFIG_FTRACE=y

2016-10-31 Thread Felipe Balbi
We don't need dwc3_trace() unless we're building a
kernel with CONFIG_FTRACE. This patch reduces
dwc3.ko text size a bit while also removing overhead
of dwc3_trace() calls.

   textdata bss dec hex filename
  50796 581   0   51377c8b1 drivers/usb/dwc3/dwc3.o
  43961 581   0   44542adfe drivers/usb/dwc3/dwc3.o.patched

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/Makefile | 6 +-
 drivers/usb/dwc3/debug.h  | 6 ++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 22420e17d68b..84de1e4151c4 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -3,7 +3,11 @@ CFLAGS_trace.o := -I$(src)
 
 obj-$(CONFIG_USB_DWC3) += dwc3.o
 
-dwc3-y := core.o debug.o trace.o
+dwc3-y := core.o
+
+ifneq ($(CONFIG_FTRACE),)
+   dwc3-y  += debug.o trace.o
+endif
 
 ifneq ($(filter y,$(CONFIG_USB_DWC3_HOST) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
dwc3-y  += host.o
diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index b287fc6ab29e..d93780e84f07 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -344,7 +344,13 @@ static inline const char 
*dwc3_gadget_generic_cmd_status_string(int status)
}
 }
 
+
+#if IS_ENABLED(CONFIG_FTRACE)
 void dwc3_trace(void (*trace)(struct va_format *), const char *fmt, ...);
+#else
+static inline void dwc3_trace(void (*trace)(struct va_format *), const char 
*fmt, ...)
+{  }
+#endif
 
 #ifdef CONFIG_DEBUG_FS
 extern void dwc3_debugfs_init(struct dwc3 *);
-- 
2.10.1

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


[PATCH 36/82] usb: gadget: udc: atmel: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index c57012b1ddf4..125680db9379 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -529,7 +529,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
 
DBG(DBG_GADGET, "%s: ep_enable: desc=%p\n", ep->ep.name, desc);
 
-   maxpacket = usb_endpoint_maxp(desc) & 0x7ff;
+   maxpacket = usb_endpoint_maxp(desc);
 
if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
|| ep->index == 0
-- 
2.10.1

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


[PATCH 42/82] usb: misc: usbtest: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 8edfbc8bf345..3525626bf086 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -2001,7 +2001,7 @@ test_queue(struct usbtest_dev *dev, struct 
usbtest_param_32 *param,
"iso period %d %sframes, wMaxPacket %d, transactions: 
%d\n",
1 << (desc->bInterval - 1),
(udev->speed == USB_SPEED_HIGH) ? "micro" : "",
-   usb_endpoint_maxp(desc) & 0x7ff,
+   usb_endpoint_maxp(desc),
usb_endpoint_maxp_mult(desc));
 
dev_info(>intf->dev,
-- 
2.10.1

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


[PATCH 34/82] usb: host: ehci: remove unnecessary max_packet() macro

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove this macro
from the driver.

Cc: Alan Stern 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/ehci-q.c | 22 +-
 drivers/usb/host/ehci-sched.c |  1 -
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index a45a5dc7ed9f..8f3f055c05fa 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -550,9 +550,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
 
 /*-*/
 
-// ... and packet size, for any kind of endpoint descriptor
-#define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
-
 /*
  * reverse of qh_urb_transaction:  free a list of TDs.
  * used for cleanup after errors, before HC sees an URB's TDs.
@@ -649,7 +646,7 @@ qh_urb_transaction (
token |= (1 /* "in" */ << 8);
/* else it's already initted to "out" pid (0 << 8) */
 
-   maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, !is_input));
+   maxpacket = usb_maxpacket(urb->dev, urb->pipe, !is_input);
 
/*
 * buffer gets wrapped in one or more qtds;
@@ -788,14 +785,14 @@ qh_make (
is_input = usb_pipein (urb->pipe);
type = usb_pipetype (urb->pipe);
ep = usb_pipe_endpoint (urb->dev, urb->pipe);
-   maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
+   maxp = usb_endpoint_maxp (>desc);
mult = usb_endpoint_maxp_mult (>desc);
 
/* 1024 byte maxpacket is a hardware ceiling.  High bandwidth
 * acts like up to 3KB, but is built from smaller packets.
 */
-   if (max_packet(maxp) > 1024) {
-   ehci_dbg(ehci, "bogus qh maxpacket %d\n", max_packet(maxp));
+   if (maxp > 1024) {
+   ehci_dbg(ehci, "bogus qh maxpacket %d\n", maxp);
goto done;
}
 
@@ -811,8 +808,7 @@ qh_make (
unsignedtmp;
 
qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
-   is_input, 0,
-   mult * max_packet(maxp)));
+   is_input, 0, mult * maxp));
qh->ps.phase = NO_FRAME;
 
if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -856,7 +852,7 @@ qh_make (
think_time = tt ? tt->think_time : 0;
qh->ps.tt_usecs = NS_TO_US(think_time +
usb_calc_bus_time (urb->dev->speed,
-   is_input, 0, max_packet (maxp)));
+   is_input, 0, maxp));
if (urb->interval > ehci->periodic_size)
urb->interval = ehci->periodic_size;
qh->ps.period = urb->interval;
@@ -927,10 +923,10 @@ qh_make (
 * to help them do so.  So now people expect to use
 * such nonconformant devices with Linux too; sigh.
 */
-   info1 |= max_packet(maxp) << 16;
+   info1 |= maxp << 16;
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else {/* PIPE_INTERRUPT */
-   info1 |= max_packet (maxp) << 16;
+   info1 |= maxp << 16;
info2 |= mult << 30;
}
break;
@@ -1223,7 +1219,7 @@ static int submit_single_step_set_feature(
 
token |= (1 /* "in" */ << 8);  /*This is IN stage*/
 
-   maxpacket = max_packet(usb_maxpacket(urb->dev, urb->pipe, 0));
+   maxpacket = usb_maxpacket(urb->dev, urb->pipe, 0);
 
qtd_fill(ehci, qtd, buf, len, token, maxpacket);
 
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 6a9fa2c3a24e..980a6b3b2da2 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1068,7 +1068,6 @@ iso_stream_init(
 
stream->highspeed = 1;
 
-   maxp = max_packet(maxp);
buf1 |= maxp;
maxp *= multi;
 
-- 
2.10.1

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


[PATCH 20/82] usb: gadget: udc: fsl: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/gadget/udc/fsl_udc_core.c 
b/drivers/usb/gadget/udc/fsl_udc_core.c
index aab5221d6c2e..4459644b9b55 100644
--- a/drivers/usb/gadget/udc/fsl_udc_core.c
+++ b/drivers/usb/gadget/udc/fsl_udc_core.c
@@ -585,7 +585,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,
break;
case USB_ENDPOINT_XFER_ISOC:
/* Calculate transactions needed for high bandwidth iso */
-   mult = (unsigned char)(1 + ((max >> 11) & 0x03));
+   mult = usb_endpoint_maxp_mult(desc);
max = max & 0x7ff;  /* bit 0~10 */
/* 3 transactions at most */
if (mult > 3)
-- 
2.10.1

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


[PATCH 35/82] usb: gadget: composite: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 0426d3c1fff9..919d7d1b611c 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -197,7 +197,7 @@ int config_ep_by_speed(struct usb_gadget *g,
 
 ep_found:
/* commit results */
-   _ep->maxpacket = usb_endpoint_maxp(chosen_desc) & 0x7ff;
+   _ep->maxpacket = usb_endpoint_maxp(chosen_desc);
_ep->desc = chosen_desc;
_ep->comp_desc = NULL;
_ep->maxburst = 0;
-- 
2.10.1

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


[PATCH 23/82] usb: gadget: udc: mv_udc: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/gadget/udc/mv_udc_core.c 
b/drivers/usb/gadget/udc/mv_udc_core.c
index ce73b3552269..542b70a83ee6 100644
--- a/drivers/usb/gadget/udc/mv_udc_core.c
+++ b/drivers/usb/gadget/udc/mv_udc_core.c
@@ -494,7 +494,7 @@ static int mv_ep_enable(struct usb_ep *_ep,
break;
case USB_ENDPOINT_XFER_ISOC:
/* Calculate transactions needed for high bandwidth iso */
-   mult = (unsigned char)(1 + ((max >> 11) & 0x03));
+   mult = usb_endpoint_maxp_mult(desc);
max = max & 0x7ff;  /* bit 0~10 */
/* 3 transactions at most */
if (mult > 3)
-- 
2.10.1

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


[PATCH 14/82] media: usb: uvc: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Laurent Pinchart 
Cc: Mauro Carvalho Chehab 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/media/usb/uvc/uvc_video.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/usb/uvc/uvc_video.c 
b/drivers/media/usb/uvc/uvc_video.c
index b5589d5f5da4..11e0e5f4e1c2 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1467,6 +1467,7 @@ static unsigned int uvc_endpoint_max_bpi(struct 
usb_device *dev,
 struct usb_host_endpoint *ep)
 {
u16 psize;
+   u16 mult;
 
switch (dev->speed) {
case USB_SPEED_SUPER:
@@ -1474,7 +1475,8 @@ static unsigned int uvc_endpoint_max_bpi(struct 
usb_device *dev,
return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
case USB_SPEED_HIGH:
psize = usb_endpoint_maxp(>desc);
-   return (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
+   mult = usb_endpoint_maxp_mult(>desc);
+   return (psize & 0x07ff) * mult;
case USB_SPEED_WIRELESS:
psize = usb_endpoint_maxp(>desc);
return psize;
-- 
2.10.1

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


[PATCH 25/82] usb: host: xhci: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Mathias Nyman 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/xhci-mem.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 6afe32381209..679672da58ed 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1370,7 +1370,7 @@ static u32 xhci_get_endpoint_max_burst(struct usb_device 
*udev,
if (udev->speed == USB_SPEED_HIGH &&
(usb_endpoint_xfer_isoc(>desc) ||
 usb_endpoint_xfer_int(>desc)))
-   return (usb_endpoint_maxp(>desc) & 0x1800) >> 11;
+   return usb_endpoint_maxp_mult(>desc) - 1;
 
return 0;
 }
@@ -1416,9 +1416,9 @@ static u32 xhci_get_max_esit_payload(struct usb_device 
*udev,
return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
 
max_packet = GET_MAX_PACKET(usb_endpoint_maxp(>desc));
-   max_burst = (usb_endpoint_maxp(>desc) & 0x1800) >> 11;
+   max_burst = usb_endpoint_maxp_mult(>desc);
/* A 0 in max burst means 1 transfer per ESIT */
-   return max_packet * (max_burst + 1);
+   return max_packet * max_burst;
 }
 
 /* Set up an endpoint with one ring segment.  Do not allocate stream rings.
-- 
2.10.1

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


[PATCH 40/82] usb: gadget: udc: net2280: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/udc/net2280.c b/drivers/usb/gadget/udc/net2280.c
index 61c938c36d88..85504419ab31 100644
--- a/drivers/usb/gadget/udc/net2280.c
+++ b/drivers/usb/gadget/udc/net2280.c
@@ -224,14 +224,14 @@ net2280_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
}
 
/* sanity check ep-e/ep-f since their fifos are small */
-   max = usb_endpoint_maxp(desc) & 0x1fff;
+   max = usb_endpoint_maxp(desc);
if (ep->num > 4 && max > 64 && (dev->quirks & PLX_LEGACY)) {
ret = -ERANGE;
goto print_err;
}
 
spin_lock_irqsave(>lock, flags);
-   _ep->maxpacket = max & 0x7ff;
+   _ep->maxpacket = max;
ep->desc = desc;
 
/* ep_reset() has already been called */
@@ -1839,7 +1839,7 @@ static ssize_t queues_show(struct device *_dev, struct 
device_attribute *attr,
ep->ep.name, t & USB_ENDPOINT_NUMBER_MASK,
(t & USB_DIR_IN) ? "in" : "out",
type_string(d->bmAttributes),
-   usb_endpoint_maxp(d) & 0x1fff,
+   usb_endpoint_maxp(d),
ep->dma ? "dma" : "pio", ep->fifo_size
);
} else /* ep0 should only have one transfer queued */
-- 
2.10.1

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


[PATCH 24/82] usb: host: ehci: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Alan Stern 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/ehci-q.c | 10 ++
 drivers/usb/host/ehci-sched.c |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index eca3710d8fc4..a45a5dc7ed9f 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -550,8 +550,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
 
 /*-*/
 
-// high bandwidth multiplier, as encoded in highspeed endpoint descriptors
-#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
 // ... and packet size, for any kind of endpoint descriptor
 #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
 
@@ -770,9 +768,11 @@ qh_make (
gfp_t   flags
 ) {
struct ehci_qh  *qh = ehci_qh_alloc (ehci, flags);
+   struct usb_host_endpoint *ep;
u32 info1 = 0, info2 = 0;
int is_input, type;
int maxp = 0;
+   int mult;
struct usb_tt   *tt = urb->dev->tt;
struct ehci_qh_hw   *hw;
 
@@ -787,7 +787,9 @@ qh_make (
 
is_input = usb_pipein (urb->pipe);
type = usb_pipetype (urb->pipe);
+   ep = usb_pipe_endpoint (urb->dev, urb->pipe);
maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
+   mult = usb_endpoint_maxp_mult (>desc);
 
/* 1024 byte maxpacket is a hardware ceiling.  High bandwidth
 * acts like up to 3KB, but is built from smaller packets.
@@ -810,7 +812,7 @@ qh_make (
 
qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
is_input, 0,
-   hb_mult(maxp) * max_packet(maxp)));
+   mult * max_packet(maxp)));
qh->ps.phase = NO_FRAME;
 
if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -929,7 +931,7 @@ qh_make (
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else {/* PIPE_INTERRUPT */
info1 |= max_packet (maxp) << 16;
-   info2 |= hb_mult (maxp) << 30;
+   info2 |= mult << 30;
}
break;
default:
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 1dfe54f14737..6a9fa2c3a24e 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1064,7 +1064,7 @@ iso_stream_init(
 
/* knows about ITD vs SITD */
if (dev->speed == USB_SPEED_HIGH) {
-   unsigned multi = hb_mult(maxp);
+   unsigned multi = usb_endpoint_maxp_mult(>ep->desc);
 
stream->highspeed = 1;
 
-- 
2.10.1

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


[PATCH 28/82] usb: ch9: make usb_endpoint_maxp() return only packet size

2016-10-31 Thread Felipe Balbi
Now that we have a helper to gather periodic
endpoints' multiplier bits from wMaxPacketSize and
every driver is using it, we can safely make sure
that usb_endpoint_maxp() returns only bits 10:0 of
wMaxPacketSize which is where the actual packet size
lies.

Signed-off-by: Felipe Balbi 
---
 include/uapi/linux/usb/ch9.h | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/usb/ch9.h b/include/uapi/linux/usb/ch9.h
index 7628dff5fac3..2c5d7c4a69e3 100644
--- a/include/uapi/linux/usb/ch9.h
+++ b/include/uapi/linux/usb/ch9.h
@@ -423,6 +423,7 @@ struct usb_endpoint_descriptor {
 #define USB_ENDPOINT_XFER_INT  3
 #define USB_ENDPOINT_MAX_ADJUSTABLE0x80
 
+#define USB_ENDPOINT_MAXP_MASK 0x07ff
 #define USB_EP_MAXP_MULT_SHIFT 11
 #define USB_EP_MAXP_MULT_MASK  (3 << USB_EP_MAXP_MULT_SHIFT)
 #define USB_EP_MAXP_MULT(m) \
@@ -628,11 +629,11 @@ static inline int usb_endpoint_is_isoc_out(
  * usb_endpoint_maxp - get endpoint's max packet size
  * @epd: endpoint to be checked
  *
- * Returns @epd's max packet
+ * Returns @epd's max packet bits [10:0]
  */
 static inline int usb_endpoint_maxp(const struct usb_endpoint_descriptor *epd)
 {
-   return __le16_to_cpu(epd->wMaxPacketSize);
+   return __le16_to_cpu(epd->wMaxPacketSize) & USB_ENDPOINT_MAXP_MASK;
 }
 
 /**
-- 
2.10.1

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


[PATCH 41/82] usb: gadget: udc: s3c2410: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/udc/s3c2410_udc.c 
b/drivers/usb/gadget/udc/s3c2410_udc.c
index eb3571ee59e3..4643a01262b4 100644
--- a/drivers/usb/gadget/udc/s3c2410_udc.c
+++ b/drivers/usb/gadget/udc/s3c2410_udc.c
@@ -1047,10 +1047,10 @@ static int s3c2410_udc_ep_enable(struct usb_ep *_ep,
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
return -ESHUTDOWN;
 
-   max = usb_endpoint_maxp(desc) & 0x1fff;
+   max = usb_endpoint_maxp(desc);
 
local_irq_save(flags);
-   _ep->maxpacket = max & 0x7ff;
+   _ep->maxpacket = max;
ep->ep.desc = desc;
ep->halted = 0;
ep->bEndpointAddress = desc->bEndpointAddress;
-- 
2.10.1

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


[PATCH 19/82] usb: gadget: udc: dummy: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/gadget/udc/dummy_hcd.c 
b/drivers/usb/gadget/udc/dummy_hcd.c
index 77d07904f932..14004cf88d4d 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -1483,8 +1483,7 @@ static int periodic_bytes(struct dummy *dum, struct 
dummy_ep *ep)
int tmp;
 
/* high bandwidth mode */
-   tmp = usb_endpoint_maxp(ep->desc);
-   tmp = (tmp >> 11) & 0x03;
+   tmp = usb_endpoint_maxp_mult(ep->desc);
tmp *= 8 /* applies to entire frame */;
limit += limit * tmp;
}
-- 
2.10.1

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


[PATCH 16/82] usb: core: devices: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Greg Kroah-Hartman 
Cc: 
Acked-by: Greg Kroah-Hartman 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/core/devices.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index ef04b50e6bbb..00d1b26a81d3 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -182,14 +182,8 @@ static char *usb_dump_endpoint_descriptor(int speed, char 
*start, char *end,
 
dir = usb_endpoint_dir_in(desc) ? 'I' : 'O';
 
-   if (speed == USB_SPEED_HIGH) {
-   switch (usb_endpoint_maxp(desc) & (0x03 << 11)) {
-   case 1 << 11:
-   bandwidth = 2; break;
-   case 2 << 11:
-   bandwidth = 3; break;
-   }
-   }
+   if (speed == USB_SPEED_HIGH)
+   bandwidth = usb_endpoint_maxp_mult(desc);
 
/* this isn't checking for illegal values */
switch (usb_endpoint_type(desc)) {
-- 
2.10.1

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


[PATCH 33/82] usb: core: endpoint: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Cc: Greg Kroah-Hartman 
Acked-by: Greg Kroah-Hartman 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/core/endpoint.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index 101983b7e8d2..d8f37fbee848 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -50,8 +50,7 @@ static ssize_t wMaxPacketSize_show(struct device *dev,
   struct device_attribute *attr, char *buf)
 {
struct ep_device *ep = to_ep_device(dev);
-   return sprintf(buf, "%04x\n",
-   usb_endpoint_maxp(ep->desc) & 0x07ff);
+   return sprintf(buf, "%04x\n", usb_endpoint_maxp(ep->desc));
 }
 static DEVICE_ATTR_RO(wMaxPacketSize);
 
-- 
2.10.1

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


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

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 661f43fe0f9e..2b95ca887ca4 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1254,7 +1254,7 @@ static int ep_enable(struct usb_ep *ep,
hwep->type = usb_endpoint_type(desc);
 
hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
-   hwep->ep.mult = QH_ISO_MULT(usb_endpoint_maxp(desc));
+   hwep->ep.mult = usb_endpoint_maxp_mult(desc);
 
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
cap |= QH_IOS;
-- 
2.10.1

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


[PATCH 38/82] usb: gadget: udc: dummy: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/udc/dummy_hcd.c 
b/drivers/usb/gadget/udc/dummy_hcd.c
index 14004cf88d4d..02b14e91ae6c 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -503,7 +503,7 @@ static int dummy_enable(struct usb_ep *_ep,
 * maximum packet size.
 * For SS devices the wMaxPacketSize is limited by 1024.
 */
-   max = usb_endpoint_maxp(desc) & 0x7ff;
+   max = usb_endpoint_maxp(desc);
 
/* drivers must not request bad settings, since lower levels
 * (hardware or its drivers) may not check.  some endpoints
-- 
2.10.1

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


[PATCH 13/82] media: usbtv: core: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Mauro Carvalho Chehab 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/media/usb/usbtv/usbtv-core.c | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/usbtv/usbtv-core.c 
b/drivers/media/usb/usbtv/usbtv-core.c
index dc76fd41e00f..ceb953be0770 100644
--- a/drivers/media/usb/usbtv/usbtv-core.c
+++ b/drivers/media/usb/usbtv/usbtv-core.c
@@ -71,6 +71,7 @@ static int usbtv_probe(struct usb_interface *intf,
int size;
struct device *dev = >dev;
struct usbtv *usbtv;
+   struct usb_host_endpoint *ep;
 
/* Checks that the device is what we think it is. */
if (intf->num_altsetting != 2)
@@ -78,10 +79,12 @@ static int usbtv_probe(struct usb_interface *intf,
if (intf->altsetting[1].desc.bNumEndpoints != 4)
return -ENODEV;
 
+   ep = >altsetting[1].endpoint[0];
+
/* Packet size is split into 11 bits of base size and count of
 * extra multiplies of it.*/
-   size = usb_endpoint_maxp(>altsetting[1].endpoint[0].desc);
-   size = (size & 0x07ff) * (((size & 0x1800) >> 11) + 1);
+   size = usb_endpoint_maxp(>desc);
+   size = (size & 0x07ff) * usb_endpoint_maxp_mult(>desc);
 
/* Device structure */
usbtv = kzalloc(sizeof(struct usbtv), GFP_KERNEL);
-- 
2.10.1

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


[PATCH 26/82] usb: misc: usbtest: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 5c8210dc6fd9..8edfbc8bf345 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -1915,7 +1915,7 @@ static struct urb *iso_alloc_urb(
if (bytes < 0 || !desc)
return NULL;
maxp = 0x7ff & usb_endpoint_maxp(desc);
-   maxp *= 1 + (0x3 & (usb_endpoint_maxp(desc) >> 11));
+   maxp *= usb_endpoint_maxp_mult(desc);
packets = DIV_ROUND_UP(bytes, maxp);
 
urb = usb_alloc_urb(packets, GFP_KERNEL);
@@ -2002,7 +2002,7 @@ test_queue(struct usbtest_dev *dev, struct 
usbtest_param_32 *param,
1 << (desc->bInterval - 1),
(udev->speed == USB_SPEED_HIGH) ? "micro" : "",
usb_endpoint_maxp(desc) & 0x7ff,
-   1 + (0x3 & (usb_endpoint_maxp(desc) >> 11)));
+   usb_endpoint_maxp_mult(desc));
 
dev_info(>intf->dev,
"total %lu msec (%lu packets)\n",
-- 
2.10.1

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


[PATCH 12/82] usb: dwc3: trace: print out ep0state also from XferComplete

2016-10-31 Thread Felipe Balbi
With this extra piece of information, it will be
easier to find mismatches between driver and HW.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debug.h  | 11 ---
 drivers/usb/dwc3/ep0.c|  4 
 drivers/usb/dwc3/gadget.c |  2 +-
 drivers/usb/dwc3/trace.h  | 12 +++-
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index 61b6f0f207cf..b287fc6ab29e 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -200,10 +200,11 @@ dwc3_gadget_event_string(const struct dwc3_event_devt 
*event)
  * @event: then event code
  */
 static inline const char *
-dwc3_ep_event_string(const struct dwc3_event_depevt *event)
+dwc3_ep_event_string(const struct dwc3_event_depevt *event, u32 ep0state)
 {
u8 epnum = event->endpoint_number;
static char str[256];
+   size_t len;
int status;
int ret;
 
@@ -215,6 +216,10 @@ dwc3_ep_event_string(const struct dwc3_event_depevt *event)
switch (event->endpoint_event) {
case DWC3_DEPEVT_XFERCOMPLETE:
strcat(str, "Transfer Complete");
+   len = strlen(str);
+
+   if (epnum <= 1)
+   sprintf(str + len, " [%s]", 
dwc3_ep0_state_string(ep0state));
break;
case DWC3_DEPEVT_XFERINPROGRESS:
strcat(str, "Transfer In-Progress");
@@ -299,14 +304,14 @@ static inline const char 
*dwc3_gadget_event_type_string(u8 event)
}
 }
 
-static inline const char *dwc3_decode_event(u32 event)
+static inline const char *dwc3_decode_event(u32 event, u32 ep0state)
 {
const union dwc3_event evt = (union dwc3_event) event;
 
if (evt.type.is_devspec)
return dwc3_gadget_event_string();
else
-   return dwc3_ep_event_string();
+   return dwc3_ep_event_string(, ep0state);
 }
 
 static inline const char *dwc3_ep_cmd_status_string(int status)
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 1be54712147e..c562613ccd1a 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -1078,10 +1078,6 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,
 void dwc3_ep0_interrupt(struct dwc3 *dwc,
const struct dwc3_event_depevt *event)
 {
-   dwc3_trace(trace_dwc3_ep0, "%s: state '%s'",
-   dwc3_ep_event_string(event),
-   dwc3_ep0_state_string(dwc->ep0state));
-
switch (event->endpoint_event) {
case DWC3_DEPEVT_XFERCOMPLETE:
dwc3_ep0_xfer_complete(dwc, event);
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index fb5d65a58ef8..4d191c8acb59 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2728,7 +2728,7 @@ static void dwc3_gadget_interrupt(struct dwc3 *dwc,
 static void dwc3_process_event_entry(struct dwc3 *dwc,
const union dwc3_event *event)
 {
-   trace_dwc3_event(event->raw);
+   trace_dwc3_event(event->raw, dwc);
 
/* Endpoint IRQ, handle it and return early */
if (event->type.is_devspec == 0) {
diff --git a/drivers/usb/dwc3/trace.h b/drivers/usb/dwc3/trace.h
index d24cefd191b5..a4ef5e7bf6b8 100644
--- a/drivers/usb/dwc3/trace.h
+++ b/drivers/usb/dwc3/trace.h
@@ -63,21 +63,23 @@ DEFINE_EVENT(dwc3_log_msg, dwc3_ep0,
 );
 
 DECLARE_EVENT_CLASS(dwc3_log_event,
-   TP_PROTO(u32 event),
-   TP_ARGS(event),
+   TP_PROTO(u32 event, struct dwc3 *dwc),
+   TP_ARGS(event, dwc),
TP_STRUCT__entry(
__field(u32, event)
+   __field(u32, ep0state)
),
TP_fast_assign(
__entry->event = event;
+   __entry->ep0state = dwc->ep0state;
),
TP_printk("event (%08x): %s", __entry->event,
-   dwc3_decode_event(__entry->event))
+   dwc3_decode_event(__entry->event, __entry->ep0state))
 );
 
 DEFINE_EVENT(dwc3_log_event, dwc3_event,
-   TP_PROTO(u32 event),
-   TP_ARGS(event)
+   TP_PROTO(u32 event, struct dwc3 *dwc),
+   TP_ARGS(event, dwc)
 );
 
 DECLARE_EVENT_CLASS(dwc3_log_ctrl,
-- 
2.10.1

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


[PATCH 11/82] usb: dwc3: debug: move dwc3_ep0_state_string() to debug.h

2016-10-31 Thread Felipe Balbi
We will be using dwc3_ep0_state_string() from within
our tracepoints, so we need to move that helper to
debug.h in order for it to be accessible.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/debug.h | 16 
 drivers/usb/dwc3/ep0.c   | 16 
 2 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h
index fe8abee31551..61b6f0f207cf 100644
--- a/drivers/usb/dwc3/debug.h
+++ b/drivers/usb/dwc3/debug.h
@@ -124,6 +124,22 @@ dwc3_gadget_link_string(enum dwc3_link_state link_state)
}
 }
 
+static inline const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
+{
+   switch (state) {
+   case EP0_UNCONNECTED:
+   return "Unconnected";
+   case EP0_SETUP_PHASE:
+   return "Setup Phase";
+   case EP0_DATA_PHASE:
+   return "Data Phase";
+   case EP0_STATUS_PHASE:
+   return "Status Phase";
+   default:
+   return "UNKNOWN";
+   }
+}
+
 /**
  * dwc3_gadget_event_string - returns event name
  * @event: the event code
diff --git a/drivers/usb/dwc3/ep0.c b/drivers/usb/dwc3/ep0.c
index 2d2f582068cb..1be54712147e 100644
--- a/drivers/usb/dwc3/ep0.c
+++ b/drivers/usb/dwc3/ep0.c
@@ -39,22 +39,6 @@ static void __dwc3_ep0_do_control_status(struct dwc3 *dwc, 
struct dwc3_ep *dep);
 static void __dwc3_ep0_do_control_data(struct dwc3 *dwc,
struct dwc3_ep *dep, struct dwc3_request *req);
 
-static const char *dwc3_ep0_state_string(enum dwc3_ep0_state state)
-{
-   switch (state) {
-   case EP0_UNCONNECTED:
-   return "Unconnected";
-   case EP0_SETUP_PHASE:
-   return "Setup Phase";
-   case EP0_DATA_PHASE:
-   return "Data Phase";
-   case EP0_STATUS_PHASE:
-   return "Status Phase";
-   default:
-   return "UNKNOWN";
-   }
-}
-
 static int dwc3_ep0_start_trans(struct dwc3 *dwc, u8 epnum, dma_addr_t buf_dma,
u32 len, u32 type, bool chain)
 {
-- 
2.10.1

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


[PATCH 37/82] usb: gadget: udc: bdc: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

Cc: Ashwini Pahuja 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/gadget/udc/bdc/bdc_ep.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c 
b/drivers/usb/gadget/udc/bdc/bdc_ep.c
index ccaa74ab6c0e..ff1ef24d1777 100644
--- a/drivers/usb/gadget/udc/bdc/bdc_ep.c
+++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c
@@ -446,7 +446,7 @@ static int setup_bd_list_xfr(struct bdc *bdc, struct 
bdc_req *req, int num_bds)
bd_xfr->start_bdi = bd_list->eqp_bdi;
bd = bdi_to_bd(ep, bd_list->eqp_bdi);
req_len = req->usb_req.length;
-   maxp = usb_endpoint_maxp(ep->desc) & 0x7ff;
+   maxp = usb_endpoint_maxp(ep->desc);
tfs = roundup(req->usb_req.length, maxp);
tfs = tfs/maxp;
dev_vdbg(bdc->dev, "%s ep:%s num_bds:%d tfs:%d r_len:%d bd:%p\n",
-- 
2.10.1

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


[PATCH 31/82] usb: chipidea: udc: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
index 2b95ca887ca4..37311a5ce159 100644
--- a/drivers/usb/chipidea/udc.c
+++ b/drivers/usb/chipidea/udc.c
@@ -1253,7 +1253,7 @@ static int ep_enable(struct usb_ep *ep,
hwep->num  = usb_endpoint_num(desc);
hwep->type = usb_endpoint_type(desc);
 
-   hwep->ep.maxpacket = usb_endpoint_maxp(desc) & 0x07ff;
+   hwep->ep.maxpacket = usb_endpoint_maxp(desc);
hwep->ep.mult = usb_endpoint_maxp_mult(desc);
 
if (hwep->type == USB_ENDPOINT_XFER_CONTROL)
-- 
2.10.1

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


[PATCH 21/82] usb: gadget: udc: fusb300: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/gadget/udc/fusb300_udc.c 
b/drivers/usb/gadget/udc/fusb300_udc.c
index 948845c90e47..42ff308578df 100644
--- a/drivers/usb/gadget/udc/fusb300_udc.c
+++ b/drivers/usb/gadget/udc/fusb300_udc.c
@@ -218,7 +218,7 @@ static int config_ep(struct fusb300_ep *ep,
   (info.type == USB_ENDPOINT_XFER_ISOC)) {
info.interval = desc->bInterval;
if (info.type == USB_ENDPOINT_XFER_ISOC)
-   info.bw_num = ((desc->wMaxPacketSize & 0x1800) >> 11);
+   info.bw_num = usb_endpoint_maxp_mult(desc);
}
 
ep_fifo_setting(fusb300, info);
-- 
2.10.1

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


[PATCH 17/82] usb: gadget: udc: atmel: make use of new usb_endpoint_maxp_mult()

2016-10-31 Thread Felipe Balbi
We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

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

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 45bc997d0711..c57012b1ddf4 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -573,7 +573,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
 * Bits 11:12 specify number of _additional_
 * transactions per microframe.
 */
-   nr_trans = ((usb_endpoint_maxp(desc) >> 11) & 3) + 1;
+   nr_trans = usb_endpoint_maxp_mult(desc);
if (nr_trans > 3)
return -EINVAL;
 
-- 
2.10.1

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


[PATCH 39/82] usb: gadget: udc: net2272: remove unnecessary & operation

2016-10-31 Thread Felipe Balbi
Now that usb_endpoint_maxp() only returns the lowest
11 bits from wMaxPacketSize, we can remove the &
operation from this driver.

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

diff --git a/drivers/usb/gadget/udc/net2272.c b/drivers/usb/gadget/udc/net2272.c
index 7c6113432093..078c91d546e0 100644
--- a/drivers/usb/gadget/udc/net2272.c
+++ b/drivers/usb/gadget/udc/net2272.c
@@ -202,10 +202,10 @@ net2272_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
return -ESHUTDOWN;
 
-   max = usb_endpoint_maxp(desc) & 0x1fff;
+   max = usb_endpoint_maxp(desc);
 
spin_lock_irqsave(>lock, flags);
-   _ep->maxpacket = max & 0x7fff;
+   _ep->maxpacket = max;
ep->desc = desc;
 
/* net2272_ep_reset() has already been called */
-- 
2.10.1

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


  1   2   >