[PATCH v7 2/2] usbip: vhci extension: dynamic extension

2016-11-21 Thread Nobuo Iwata
Modification for dynamic device registration and unregistration.

1. kernel config

Followings are added.

USBIP_VHCI_HC_PORTS: Number of ports per USB/IP virtual host 
controller. The default is 8 - same as current VHCI_NPORTS.
USBIP_VHCI_MAX_HCS: Muximum number of USB/IP virtual host controllers. 
The default is 1.
USBIP_VHCI_INIT_HCS: Initial number of USB/IP virtual host controllers. 
The default is 1.
Static number of devices: USBIP_VHCI_NR_HCS is removed with this patch.

2. view from sysfs

Sysfs structure is changed as following.

BEFORE this patchset:
/sys/devices/platform
+-- vhci
+-- status
+-- attach
+-- detach
+-- usbip_debug

AFTER: example for CONFIG_USBIP_INIT_HCS=2 CONFIG_USBIP_MAX_HCS=4
At the beginning
/sys/devices/platform
+-- vhci
|   +-- nports
|   +-- status
|   +-- status.1
|   +-- status.2
|   +-- status.3
|   +-- attach
|   +-- detach
|   +-- usbip_debug
+-- vhci.1

The status files are shown to the maximum number of devices. Port 
status in status.2 and status.3 represents as free but corresponding 
devices are not yes registered.
When all ports in status and status.1 are used, userspace tool requests 
'attach' to a port in status.2 then vhci.2 will be registred. The limit 
is defined with USBIP_VHCI_MAX_NCS.

By preparing muximum number of status files, there's no need to 
introduce additional operations for userspace tool.

When number of free ports becomes more than USBIP_VHCI_HC_PORTS * 
VHCI_FREE_HCS(2), a free controller other than the first one will be 
unregistered. It will be invoked by 'detach' operation and other error 
situations which ports are released.

Signed-off-by: Nobuo Iwata 
---
 drivers/usb/usbip/Kconfig  |  17 ++-
 drivers/usb/usbip/vhci.h   |  36 -
 drivers/usb/usbip/vhci_hcd.c   | 250 -
 drivers/usb/usbip/vhci_rx.c|  10 +-
 drivers/usb/usbip/vhci_sysfs.c |  49 ---
 drivers/usb/usbip/vhci_tx.c|   6 +-
 6 files changed, 293 insertions(+), 75 deletions(-)

diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig
index eeefa29..42d8979 100644
--- a/drivers/usb/usbip/Kconfig
+++ b/drivers/usb/usbip/Kconfig
@@ -35,8 +35,8 @@ config USBIP_VHCI_HC_PORTS
  host controller driver, this defines number of ports per
  USB/IP virtual host controller.
 
-config USBIP_VHCI_NR_HCS
-   int "Number of USB/IP virtual host controllers"
+config USBIP_VHCI_MAX_HCS
+   int "Maximum number of USB/IP virtual host controllers"
range 1 128
default 1
depends on USBIP_VHCI_HCD
@@ -44,7 +44,18 @@ config USBIP_VHCI_NR_HCS
  To increase number of ports available for USB/IP virtual
  host controller driver, this defines number of USB/IP
  virtual host controllers as if adding physical host
- controllers.
+ controllers. This defines the maximum number.
+
+config USBIP_VHCI_INIT_HCS
+   int "Initial number of USB/IP virtual host controllers"
+   range 1 USBIP_VHCI_MAX_HCS
+   default 1
+   depends on USBIP_VHCI_MAX_HCS
+   ---help---
+ To increase number of ports available for USB/IP virtual
+ host controller driver, this defines number of USB/IP
+ virtual host controllers as if adding physical host
+ controllers. This defines the number at initializing.
 
 config USBIP_HOST
tristate "Host driver"
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index 88b71c4..ba893a7 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -51,6 +51,9 @@ struct vhci_device {
 
/* vhci_tx thread sleeps for this queue */
wait_queue_head_t waitq_tx;
+
+   /* denotes port is in-use */
+   atomic_t using_port;
 };
 
 /* urb->hcpriv, use container_of() */
@@ -79,12 +82,21 @@ struct vhci_unlink {
 #define VHCI_HC_PORTS 8
 #endif
 
-#ifdef CONFIG_USBIP_VHCI_NR_HCS
-#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
+#ifdef CONFIG_USBIP_VHCI_MAX_HCS
+#define VHCI_MAX_HCS CONFIG_USBIP_VHCI_MAX_HCS
+#else
+#define VHCI_MAX_HCS 1
+#endif
+
+#ifdef CONFIG_USBIP_VHCI_INIT_HCS
+#define VHCI_INIT_HCS CONFIG_USBIP_VHCI_INIT_HCS
 #else
-#define VHCI_NR_HCS 1
+#define VHCI_INIT_HCS 1
 #endif
 
+/* VHCI_FREE_HCS * VHCI_HC_PORTS: ports to keep free at unregister */
+#define VHCI_FREE_HCS 2
+
 #define MAX_STATUS_NAME 16
 
 /* for usb_bus.hcpriv */
@@ -98,6 +110,8 @@ struct vhci_hcd {
 
atomic_t seqnum;
 
+   unsigned int using_ports;
+
/*
 * NOTE:
 * wIndex shows the port number and begins from 1.
@@ -106,12 +120,18 @@ struct vhci_hcd {
struct vhci_device vdev[VHCI_HC_PORTS];
 };
 
+extern int vhci_max_controllers;
+extern int vhci_init_controllers;
 extern int vhci_num_controllers;
 extern struct platform_device **vhci_pdevs;
 extern struct 

[PATCH v7 1/2] usbip: vhci extension: modifications to userspace

2016-11-21 Thread Nobuo Iwata
Modification to the userspace tools including usbip/libsrc and 
usbip/src.

Changed corresponding to new vhci_sysfs.c.

nports in sysfs is used to get total number of ports. 

Old get_nports() ignores the last status line because 
udev_device_get_sysattr_value() drops last new line. New version uses 
nports attribute so it's doesn't have this problem.

status[.N] in sysfs are used.

parse_status() which reads all status lines is broken into open, close, 
read-line and parse-line. Parse-line is reused to find free port and 
get imported device.

In daemon, status was loaded into memory by 
usbip_vhci_refresh_device_list() at receiving every request. The loaded 
status is used to find free port. It is changed to read status directly 
to find free port.

Wording inconsistencies are fixed according to the rule below.

rhport, HC_PORTS: ports within a controller (or root hub).
port, nports: ports across the controllers.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 398 +++
 tools/usb/usbip/libsrc/vhci_driver.h |  45 +--
 tools/usb/usbip/src/usbip_attach.c   |   8 +-
 tools/usb/usbip/src/usbip_port.c |  13 +-
 tools/usb/usbip/src/usbipd_app.c |  48 ++--
 5 files changed, 253 insertions(+), 259 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index 3fe92ff..720a0e9 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -15,11 +15,24 @@
 #undef  PROGNAME
 #define PROGNAME "libusbip"
 
-struct usbip_vhci_driver *vhci_driver;
-struct udev *udev_context;
+static struct udev_device *vhci_hc_device;
+static struct udev *udev_context;
+static int vhci_nports;
 
-static struct usbip_imported_device *
-imported_device_init(struct usbip_imported_device *idev, char *busid)
+struct usbip_vhci_device {
+   int port;
+   uint32_t status;
+
+   uint32_t devid;
+
+   uint8_t busnum;
+   uint8_t devnum;
+
+   /* usbip_class_device list */
+   struct usbip_usb_device udev;
+};
+
+static int imported_device_init(struct usbip_vhci_device *vdev, char *busid)
 {
struct udev_device *sudev;
 
@@ -27,132 +40,131 @@ imported_device_init(struct usbip_imported_device *idev, 
char *busid)
   "usb", busid);
if (!sudev) {
dbg("udev_device_new_from_subsystem_sysname failed: %s", busid);
-   goto err;
+   return -1;
}
-   read_usb_device(sudev, >udev);
+   read_usb_device(sudev, >udev);
udev_device_unref(sudev);
 
-   return idev;
-
-err:
-   return NULL;
+   return 0;
 }
 
+struct status_context {
+   int controller;
+   const char *c;
+};
 
+#define OPEN_MODE_FIRST  0
+#define OPEN_MODE_REOPEN 1
 
-static int parse_status(const char *value)
-{
-   int ret = 0;
-   char *c;
+static int open_hc_device(int mode);
 
+#define MAX_STATUS_NAME 16
 
-   for (int i = 0; i < vhci_driver->nports; i++)
-   memset(_driver->idev[i], 0, sizeof(vhci_driver->idev[i]));
+static int open_status(struct status_context *ctx, int mode)
+{
+   char name[MAX_STATUS_NAME+1];
 
+   if (mode == OPEN_MODE_FIRST)
+   ctx->controller = 0;
+   else
+   (ctx->controller)++;
 
-   /* skip a header line */
-   c = strchr(value, '\n');
-   if (!c)
+   if (open_hc_device(OPEN_MODE_REOPEN))
return -1;
-   c++;
-
-   while (*c != '\0') {
-   int port, status, speed, devid;
-   unsigned long socket;
-   char lbusid[SYSFS_BUS_ID_SIZE];
-
-   ret = sscanf(c, "%d %d %d %x %lx %31s\n",
-   , , ,
-   , , lbusid);
-
-   if (ret < 5) {
-   dbg("sscanf failed: %d", ret);
-   BUG();
-   }
 
-   dbg("port %d status %d speed %d devid %x",
-   port, status, speed, devid);
-   dbg("socket %lx lbusid %s", socket, lbusid);
+   if (ctx->controller == 0)
+   strcpy(name, "status");
+   else
+   snprintf(name, MAX_STATUS_NAME + 1,
+   "status.%d", ctx->controller);
+   ctx->c = udev_device_get_sysattr_value(vhci_hc_device, name);
+   if (ctx->c == NULL)
+   return -1;
 
+   return 0;
+}
 
-   /* if a device is connected, look at it */
-   {
-   struct usbip_imported_device *idev = 
_driver->idev[port];
+static void close_status(struct status_context *ctx)
+{
+   ctx->c = NULL;
+}
 
-   idev->port  = port;
-   idev->status= status;
+static int next_status_line(struct status_context *ctx)
+{
+   const char *c = ctx->c;
 
- 

[PATCH v7 0/2] usbip: vhci number of ports extension

2016-11-21 Thread Nobuo Iwata
This series of patches extends number of ports limitaion in application 
(vhci) side.

Driver portion of static extension has been merged at 4.9-rc1. 1/2 
modifies userspace tools. It's effective not only for static extension 
but also for dynamic. 2/2 modifies driver for dynamic extenstion.

1. Background

Assuming a system shown below that services distributerd devices in 
home or office via USB/IP, if the devices are set at every doors and 
windows, number devices may be up to tens.

Home/SOHO/Enterprise Intranet/Internet
 +--+   +--+ USB/IP+-+
+|device|--+|Linux |---|Service  |
|+--+  |+--+---|on Linux |
+--+   +--++-+
ex)
Device  Service
 sensors ... environment analysis
 cameras ... monitoring, recording
 ID/biometric readers .. authentication

If USB/IP is used for ubiqitous devices or IoT devices, many devices 
might be handled. 

2. About this patch set

In current USB/IP, available number of ports (ie. number of supported 
devices) is VHCI_NPORTS(8) in drivers/usb/usbip/vhci.h. The value of 
the macro can be altered to USB_MAXCHILDREN(31). This limit is came 
from hub status bit array. See also the comment at USB_MAXCHILDREN 
include/uapi/linux/usb/ch11.h.

There are two way to increase number of available ports. The first way 
is to put hub emulator under vhci. This can add ports up to 255 - the 
limit of USB 2.0 host controller. The second way is to add host 
controller. It's as same as machines have several host controllers: 
most desktop or note PCs have more than one host controller.

Current USB/IP supports only one controller defined as 'the_controller' 
in drivers/usb/usbip/vhci_hcd.c. This patch takes the second way 
described above and adds virtual controllers. In this patch, the number 
is specified by kernel configuration. 

3. Dynamic extension

According to kernel configuration, vhci devices (platform device) will 
be added and removed when they are not used. When the vhci driver is 
loaded, USBIP_VHCI_INIT_HCS (default is 1) drivers are registered. They 
will be further registered upto USBIP_VHCI_MAX_HCS (default is 1). They 
are unregistered when number of free devices becomes more than 
VHCI_FREE_HCS(2) except the first device.

4. Wording

Wording inconsistencies in function and variable names are corrected 
according to the rule below. They were not strict because only one host 
controller was handled.

rhport, HC_PORTS: ports within a controller (or root hub).
port, nports: ports across the controllers.

5. Dependencies

This series depends on 'usbip: exporting devices' patch set because 
this includes changes to application side daemon which introduced the 
patch set.

---
Version information

v7)
# Recreated based on linux-next 20161117.
# Removed a reference to merged path was '1/3 usbip: vhci extension: 
modifications to vhci driver' from change log of current 2/2.

v6)
# Recreated based on linux-next 20160928.
# Was '1/3 usbip: vhci extension: modifications to vhci driver' is 
excluded because it has been merged at 4.9-rc1.

v5)
# Fixed dynamically allocated sysfs attribute checking error when 
CONFIG_DEBUG_LOCK_ALLOC is set.
# Recreated based on linux-next 20160810.

v4)
# Changed the method to set number of controllers from a module 
parameter to kernel config.
# Excluded event thread patch merged to 4.7-rc1.
# Added dynamic extension.

v3)
# Fixed conflicts against linux-next 20160209.
# Changed sysfs object and attribute name for old tools compatibility.
# Changed nports status format not to include num_controllers value.
# Fixed checkpatch errors and warnings.

v2)
# Added static to some functions and variables not called from other 
files. 

*** BLURB HERE ***

Nobuo Iwata (2):
  usbip: vhci extension: modifications to userspace
  usbip: vhci extension: dynamic extension

 drivers/usb/usbip/Kconfig|  17 +-
 drivers/usb/usbip/vhci.h |  36 ++-
 drivers/usb/usbip/vhci_hcd.c | 250 ++---
 drivers/usb/usbip/vhci_rx.c  |  10 +-
 drivers/usb/usbip/vhci_sysfs.c   |  49 ++--
 drivers/usb/usbip/vhci_tx.c  |   6 +-
 tools/usb/usbip/libsrc/vhci_driver.c | 398 +++
 tools/usb/usbip/libsrc/vhci_driver.h |  45 +--
 tools/usb/usbip/src/usbip_attach.c   |   8 +-
 tools/usb/usbip/src/usbip_port.c |  13 +-
 tools/usb/usbip/src/usbipd_app.c |  48 ++--
 11 files changed, 546 insertions(+), 334 deletions(-)

-- 
2.1.0

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


[PATCH v13 07/10] usbip: exporting devices: new application-side daemon

2016-11-21 Thread Nobuo Iwata
This patch is the new application(vhci)-side daemon specific code.

The daemons are consisting three files.
usbip.c : common code.
usbip_dev.c: device(stub)-side specific code.
usbip_app.c: application(vhci)-side specific code - this patch.

Here, device-side daemon is EXISTING-1 and application-side daemon is 
NEW-1 in figure below.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c |  19 +++
 tools/usb/usbip/libsrc/vhci_driver.h |   1 +
 tools/usb/usbip/src/Makefile.am  |   7 +-
 tools/usb/usbip/src/usbipd.c |  12 +-
 tools/usb/usbip/src/usbipd_app.c | 242 +++
 5 files changed, 279 insertions(+), 2 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index d2221c5..3fe92ff 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -314,6 +314,25 @@ int usbip_vhci_get_free_port(void)
return -1;
 }
 
+struct usbip_imported_device *usbip_vhci_find_device(char *host, char *busid)
+{
+   int ret;
+   char rhost[NI_MAXHOST] = "unknown host";
+   char rserv[NI_MAXSERV] = "unknown port";
+   char rbusid[SYSFS_BUS_ID_SIZE];
+
+   for (int i = 0; i < vhci_driver->nports; i++) {
+   ret = read_record(vhci_driver->idev[i].port, rhost, NI_MAXHOST,
+   rserv, NI_MAXSERV, rbusid);
+   if (!ret &&
+   !strncmp(host, rhost, NI_MAXHOST) &&
+   !strncmp(busid, rbusid, SYSFS_BUS_ID_SIZE)) {
+   return vhci_driver->idev + i;
+   }
+   }
+   return NULL;
+}
+
 int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed) {
char buff[200]; /* what size should be ? */
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
b/tools/usb/usbip/libsrc/vhci_driver.h
index f955ada..acb427d 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -46,6 +46,7 @@ int  usbip_vhci_refresh_device_list(void);
 
 
 int usbip_vhci_get_free_port(void);
+struct usbip_imported_device *usbip_vhci_find_device(char *host, char *busid);
 int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed);
 
diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 1aa5156..8fdebce 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -2,11 +2,16 @@ AM_CPPFLAGS = -I$(top_srcdir)/libsrc 
-DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
 AM_CFLAGS   = @EXTRA_CFLAGS@
 LDADD   = $(top_builddir)/libsrc/libusbip.la
 
-sbin_PROGRAMS := usbip usbipd
+sbin_PROGRAMS := usbip usbipd usbipa
 
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
 usbip_connect.c usbip_disconnect.c
+usbip_CFLAGS := $(AM_CFLAGS)
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c
+usbipd_CFLAGS := $(AM_CFLAGS)
+
+usbipa_SOURCES := usbip_network.h usbipd.c usbipd_app.c usbip_network.c
+usbipa_CFLAGS := $(AM_CFLAGS) -DUSBIP_DAEMON_APP
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index bc4775f..8fe89d9 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -64,11 +64,13 @@ static const char usbipd_help_string[] =
"   -6, --ipv6\n"
"   Bind to IPv6. Default is both.\n"
"\n"
+#ifndef USBIP_DAEMON_APP
"   -e, --device\n"
"   Run in device mode.\n"
"   Rather than drive an attached device, create\n"
"   a virtual UDC to bind gadgets to.\n"
"\n"
+#endif
"   -D, --daemon\n"
"   Run as a daemon 

[PATCH v13 10/10] usbip: exporting devices: modifications to protocol text

2016-11-21 Thread Nobuo Iwata
This patch adds export and un-export request/response to 
Documentation/usb/usbip_protocol.txt.

The definition of the structs has been defined in original code of 
tools/usb/usbip/usbip_network.h but not described in the document.

Adding the request and response, words 'server' and 'client' are 
ambiguous in several place. To avoid confusion, 'device-side' and 
'application-side' are written together with 'server' and 'client'.

'export' was used in the counter side of 'import' request. This patch 
organizes usage of 'import' and 'export'.

Signed-off-by: Nobuo Iwata 
---
 Documentation/usb/usbip_protocol.txt | 204 ---
 1 file changed, 181 insertions(+), 23 deletions(-)

diff --git a/Documentation/usb/usbip_protocol.txt 
b/Documentation/usb/usbip_protocol.txt
index 16b6fe2..d4be5b6 100644
--- a/Documentation/usb/usbip_protocol.txt
+++ b/Documentation/usb/usbip_protocol.txt
@@ -1,20 +1,26 @@
 PRELIMINARY DRAFT, MAY CONTAIN MISTAKES!
 28 Jun 2011
+MODIFIED FOR CONNECT AND DISCONNECT OPERARION.
+07 March 2016
 
-The USB/IP protocol follows a server/client architecture. The server exports 
the
-USB devices and the clients imports them. The device driver for the exported
-USB device runs on the client machine.
+The USB/IP protocol follows a server/client architecture between two computers
+one has USB devices and the other runs application using the devices. There are
+two ways for initiation.
 
-The client may ask for the list of the exported USB devices. To get the list 
the
-client opens a TCP/IP connection towards the server, and sends an 
OP_REQ_DEVLIST
-packet on top of the TCP/IP connection (so the actual OP_REQ_DEVLIST may be 
sent
-in one or more pieces at the low level transport layer). The server sends back
-the OP_REP_DEVLIST packet which lists the exported USB devices. Finally the
-TCP/IP connection is closed.
+The first way is to import devices from application-side. In this way, the
+server runs in device-side and the client runs in application-side. In device
+side user makes devices importable with 'bind' operation.
 
+The client may ask for the list of the importable USB devices. To get the list
+the client opens a TCP/IP connection towards the server, and sends an
+OP_REQ_DEVLIST packet on top of the TCP/IP connection (so the actual
+OP_REQ_DEVLIST may be sent in one or more pieces at the low level transport
+layer). The server sends back the OP_REP_DEVLIST packet which lists the
+importable USB devices. Finally the TCP/IP connection is closed.
+
+   application-sidedevice-side
  virtual host controller usb host
-  "client"   "server"
-  (imports USB devices) (exports USB devices)
+  "client" (lists importable devices)"server"
   | |
   |  OP_REQ_DEVLIST |
   | --> |
@@ -23,18 +29,13 @@ TCP/IP connection is closed.
   | <-- |
   | |
 
-Once the client knows the list of exported USB devices it may decide to use one
-of them. First the client opens a TCP/IP connection towards the server and
-sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the
-import was successful the TCP/IP connection remains open and will be used
-to transfer the URB traffic between the client and the server. The client may
-send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and
-USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the
-server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively.
+Once the client knows the list of importable USB devices it may decide to use
+one of them. First the client opens a TCP/IP connection towards the server and
+sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT.
 
+   application-sidedevice-side
  virtual host controller usb host
-  "client"   "server"
-  (imports USB devices) (exports USB devices)
+  "client"   (imports a USB device)  "server"
   | |
   |  OP_REQ_IMPORT  |
   | --> |
@@ -42,6 +43,32 @@ server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK 
respectively.
   |  OP_REP_IMPORT  |
   | <-- |
   | |
+
+The second way is to export devices from device-side. In this way, the server
+runs 

[PATCH v13 09/10] usbip: exporting devices: chage to documenattion

2016-11-21 Thread Nobuo Iwata
This patch adds function and usage of new connect operation, disconnect 
operation and application(vhci)-side daemon to README and manuals.

At this point, the wording, 'server' and 'client' are ambiguous in 
several place.

For existing attach command, the daemon runs device side machine and 
attach command is executed in application side machine. Then 'server' 
is used for device side and 'client' is for application side.

For the new connect command, the daemon runs applications side machine 
and connect command is executed in device side machine. Now, 'server' 
and 'client' run in different machine than before.

To avoid confusion, to represent things to be done in device side node 
by both command and daemon, words 'device-side' is used instead of 
'server'. To represent things to be done is application side node by 
both command and daemon, 'applicationr-side' are used instead of 
'client'.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/Makefile.am  |   2 +-
 tools/usb/usbip/README   |  70 --
 tools/usb/usbip/doc/usbip.8  | 136 ---
 tools/usb/usbip/doc/usbipa.8 |  78 
 tools/usb/usbip/doc/usbipd.8 |  38 +-
 5 files changed, 263 insertions(+), 61 deletions(-)

diff --git a/tools/usb/usbip/Makefile.am b/tools/usb/usbip/Makefile.am
index 66f8bf0..f371ed9 100644
--- a/tools/usb/usbip/Makefile.am
+++ b/tools/usb/usbip/Makefile.am
@@ -3,4 +3,4 @@ includedir = @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
 usbip_common.h vhci_driver.h usbip_host_driver.h)
 
-dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)
+dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbipa.8)
diff --git a/tools/usb/usbip/README b/tools/usb/usbip/README
index 831f49f..74f4afb 100644
--- a/tools/usb/usbip/README
+++ b/tools/usb/usbip/README
@@ -1,7 +1,8 @@
 #
 # README for usbip-utils
 #
-# Copyright (C) 2011 matt mooney 
+# Copyright (C) 2015 Nobuo Iwata
+#   2011 matt mooney 
 #   2005-2008 Takahiro Hirofuchi
 
 
@@ -36,41 +37,70 @@
 
 
 [Usage]
-server:# (Physically attach your USB device.)
+Device-side: a machine has USB device(s).
+Application-side: a machine runs an application software uses remote USB 
device.
 
-server:# insmod usbip-core.ko
-server:# insmod usbip-host.ko
+1) Connect from application-side to device-side.
 
-server:# usbipd -D
+dev:# (Physically attach your USB device.)
+
+dev:# insmod usbip-core.ko
+dev:# insmod usbip-host.ko
+
+dev:# usbipd -D
- Start usbip daemon.
 
-server:# usbip list -l
-   - List driver assignments for USB devices.
+dev:# usbip list -l
+   - List driver assignments for USB devices and their busid.
 
-server:# usbip bind --busid 1-2
-   - Bind usbip-host.ko to the device with busid 1-2.
-   - The USB device 1-2 is now exportable to other hosts!
-   - Use `usbip unbind --busid 1-2' to stop exporting the device.
+dev:# usbip bind --busid 
+   - Bind usbip-host.ko to the device with .
+   - The USB device with  is now exportable to other hosts!
+   - Use `usbip unbind --busid ` to stop exporting the device.
 
-client:# insmod usbip-core.ko
-client:# insmod vhci-hcd.ko
+app:# insmod usbip-core.ko
+app:# insmod vhci-hcd.ko
 
-client:# usbip list --remote 
+app:# usbip list --remote 
- List exported USB devices on the .
 
-client:# usbip attach --remote  --busid 1-2
+app:# usbip attach --remote  --busid 
- Connect the remote USB device.
 
-client:# usbip port
+app:# usbip port
- Show virtual port status.
 
-client:# usbip detach --port 
+app:# usbip detach --port 
- Detach the USB device.
 
+2) Connect from device-side to application-side.
+
+app:# insmod usbip-core.ko
+app:# insmod 

[PATCH v13 08/10] usbip: exporting devices: change to usbip_list.c

2016-11-21 Thread Nobuo Iwata
Correction to wording inconsistency around import and export in 
usbip_list.c regarding output title, help and function names.

'exported' was used for devices bound in remote and to be attached with 
'import' request. This patch set uses pre-defined 'export' request to 
connect device.

To avoid mixed usage of 'export', 'importable' is used for devices to 
be attached with 'import' request.

The word 'imported' has already been used in output of port operation. 
It is consistent to this patch.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/usbip_list.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/tools/usb/usbip/src/usbip_list.c b/tools/usb/usbip/src/usbip_list.c
index f1b38e8..cf69f31 100644
--- a/tools/usb/usbip/src/usbip_list.c
+++ b/tools/usb/usbip/src/usbip_list.c
@@ -44,7 +44,7 @@
 static const char usbip_list_usage_string[] =
"usbip list [-p|--parsable] \n"
"-p, --parsable Parsable list format\n"
-   "-r, --remote=List the exportable USB devices on \n"
+   "-r, --remote=List the importable USB devices on \n"
"-l, --localList the local USB devices\n";
 
 void usbip_list_usage(void)
@@ -52,7 +52,7 @@ void usbip_list_usage(void)
printf("usage: %s", usbip_list_usage_string);
 }
 
-static int get_exported_devices(char *host, int sockfd)
+static int get_importable_devices(char *host, int sockfd)
 {
char product_name[100];
char class_name[100];
@@ -82,14 +82,14 @@ static int get_exported_devices(char *host, int sockfd)
return -1;
}
PACK_OP_DEVLIST_REPLY(0, );
-   dbg("exportable devices: %d\n", reply.ndev);
+   dbg("importable devices: %d\n", reply.ndev);
 
if (reply.ndev == 0) {
-   info("no exportable devices found on %s", host);
+   info("no importable devices found on %s", host);
return 0;
}
 
-   printf("Exportable USB devices\n");
+   printf("Importable USB devices\n");
printf("==\n");
printf(" - %s\n", host);
 
@@ -134,7 +134,7 @@ static int get_exported_devices(char *host, int sockfd)
return 0;
 }
 
-static int list_exported_devices(char *host)
+static int list_importable_devices(char *host)
 {
int rc;
int sockfd;
@@ -147,9 +147,10 @@ static int list_exported_devices(char *host)
}
dbg("connected to %s:%s", host, usbip_port_string);
 
-   rc = get_exported_devices(host, sockfd);
+   rc = get_importable_devices(host, sockfd);
if (rc < 0) {
err("failed to get device list from %s", host);
+   close(sockfd);
return -1;
}
 
@@ -351,7 +352,7 @@ int usbip_list(int argc, char *argv[])
parsable = true;
break;
case 'r':
-   ret = list_exported_devices(optarg);
+   ret = list_importable_devices(optarg);
goto out;
case 'l':
ret = list_devices(parsable);
-- 
2.1.0

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


[PATCH v13 06/10] usbip: exporting devices: modifications to attach and detach

2016-11-21 Thread Nobuo Iwata
Refactoring to attach and detach operation to reuse common portion to 
application(vhci)-side daemon.

The new application(vhci)-side daemon executes same procedures as 
attach and detach. Most of common code to access vhci has been 
implemented in VHCI userspace wrapper(libsrc/vhci_driver.c) but left in 
attach and detach. With this patch, an accessor of vhci driver and 
tracking of vhci connections in attach and detach are moved to the VHCI 
userspace wrapper.

Here, attach, detach and application(vhci)-side daemon is EXISTING-5, 
EXISTING-6 and NEW-1 respectively in diagram below. 

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 99 
 tools/usb/usbip/libsrc/vhci_driver.h |  6 +-
 tools/usb/usbip/src/usbip_attach.c   | 50 ++
 tools/usb/usbip/src/usbip_detach.c   | 13 ++--
 4 files changed, 100 insertions(+), 68 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index ad92047..d2221c5 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2005-2007 Takahiro Hirofuchi
  */
 
 #include "usbip_common.h"
@@ -7,6 +8,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "sysfs_utils.h"
 
 #undef  PROGNAME
@@ -215,6 +218,25 @@ static int read_record(int rhport, char *host, unsigned 
long host_len,
return 0;
 }
 
+#define OPEN_HC_MODE_FIRST 0
+#define OPEN_HC_MODE_REOPEN1
+
+static int open_hc_device(int mode)
+{
+   if (mode == OPEN_HC_MODE_REOPEN)
+   udev_device_unref(vhci_driver->hc_device);
+
+   vhci_driver->hc_device =
+   udev_device_new_from_subsystem_sysname(udev_context,
+  USBIP_VHCI_BUS_TYPE,
+  USBIP_VHCI_DRV_NAME);
+   if (!vhci_driver->hc_device) {
+   err("udev_device_new_from_subsystem_sysname failed");
+   return -1;
+   }
+   return 0;
+}
+
 /* -- */
 
 int usbip_vhci_driver_open(void)
@@ -227,28 +249,21 @@ int usbip_vhci_driver_open(void)
 
vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
 
-   /* will be freed in usbip_driver_close() */
-   vhci_driver->hc_device =
-   udev_device_new_from_subsystem_sysname(udev_context,
-  USBIP_VHCI_BUS_TYPE,
-  USBIP_VHCI_DRV_NAME);
-   if (!vhci_driver->hc_device) {
-   err("udev_device_new_from_subsystem_sysname failed");
-   goto err;
-   }
+   if (open_hc_device(OPEN_HC_MODE_FIRST))
+   goto err_free_driver;
 
vhci_driver->nports = get_nports();
 
dbg("available ports: %d", vhci_driver->nports);
 
if (refresh_imported_device_list())
-   goto err;
+   goto err_unref_device;
 
return 0;
 
-err:
+err_unref_device:
udev_device_unref(vhci_driver->hc_device);
-
+err_free_driver:
if (vhci_driver)
free(vhci_driver);
 
@@ -277,7 +292,8 @@ void usbip_vhci_driver_close(void)
 
 int usbip_vhci_refresh_device_list(void)
 {
-
+   if (open_hc_device(OPEN_HC_MODE_REOPEN))
+   goto err;
if (refresh_imported_device_list())
goto err;
 
@@ -409,3 +425,58 @@ int usbip_vhci_imported_device_dump(struct 
usbip_imported_device *idev)
 
return 0;
 }
+
+#define MAX_BUFF 100
+int usbip_vhci_create_record(char *host, char *port, char *busid, int rhport)
+{
+   int fd;
+   char path[PATH_MAX+1];
+   char buff[MAX_BUFF+1];
+   int ret;
+
+   ret = 

[PATCH v13 03/10] usbip: exporting devices: new connect operation

2016-11-21 Thread Nobuo Iwata
Implementation of new connect operation. This is linked as a part of 
usbip commnad. With this patch, usbip command has following operations.

 bind
 unbind
 list (local/remote)
 attach
 detach
 port
 connect ... this patch

In device side node, this binds a device internally, sends an export 
request and receives export response. The definition of the request and 
response are defined in original code: tools/usb/usbip/usbip_network.h 
but was not used. They are corresponding to NEW-3 in following diagram. 

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/Makefile.am |   3 +-
 tools/usb/usbip/src/usbip.c |   9 +-
 tools/usb/usbip/src/usbip.h |   5 +-
 tools/usb/usbip/src/usbip_connect.c | 228 
 4 files changed, 242 insertions(+), 3 deletions(-)

diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index e81a4eb..0947476 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -6,6 +6,7 @@ sbin_PROGRAMS := usbip usbipd
 
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
-usbip_bind.c usbip_unbind.c usbip_port.c
+usbip_bind.c usbip_unbind.c usbip_port.c \
+usbip_connect.c
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c
index d7599d9..584d7d5 100644
--- a/tools/usb/usbip/src/usbip.c
+++ b/tools/usb/usbip/src/usbip.c
@@ -2,7 +2,8 @@
  * command structure borrowed from udev
  * (git://git.kernel.org/pub/scm/linux/hotplug/udev.git)
  *
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -76,6 +77,12 @@ static const struct command cmds[] = {
.usage = usbip_detach_usage
},
{
+   .name  = "connect",
+   .fn= usbip_connect,
+   .help  = "Connect a USB device to a remote computer",
+   .usage = usbip_connect_usage
+   },
+   {
.name  = "list",
.fn= usbip_list,
.help  = "List exportable or local USB devices",
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index c296910..f365353 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -30,12 +31,14 @@ int usbip_list(int argc, char *argv[]);
 int usbip_bind(int argc, char *argv[]);
 int usbip_unbind(int argc, char *argv[]);
 int usbip_port_show(int argc, char *argv[]);
+int usbip_connect(int argc, char *argv[]);
 
 void usbip_attach_usage(void);
 void usbip_detach_usage(void);
 void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
+void usbip_connect_usage(void);
 
 int usbip_bind_device(char *busid);
 int usbip_unbind_device(char *busid);
diff --git a/tools/usb/usbip/src/usbip_connect.c 
b/tools/usb/usbip/src/usbip_connect.c
new file mode 100644
index 000..bbecc7e
--- /dev/null
+++ b/tools/usb/usbip/src/usbip_connect.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
+ *   2005-2007 Takahiro Hirofuchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 

[PATCH v13 04/10] usbip: exporting devices: new disconnect operation

2016-11-21 Thread Nobuo Iwata
Implementation of new disconnect operation. This is linked as a part of 
usbip commnad. With this patch, usbip command has following operations.

 bind
 unbind
 list (local/remote)
 attach
 detach
 port
 connect ... previous patch
 disconnect ... this patch

In device side node, this sends an un-export request, receives an 
un-export response and unbind corresponding device internally. The 
definition of the request and response are defined in original code: 
tools/usb/usbip/usbip_network.h but was not used. It's corresponding to 
NEW-4 in following diagram.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/Makefile.am|   2 +-
 tools/usb/usbip/src/usbip.c|   6 +
 tools/usb/usbip/src/usbip.h|   2 +
 tools/usb/usbip/src/usbip_disconnect.c | 215 +
 4 files changed, 224 insertions(+), 1 deletion(-)

diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 0947476..42760c3 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -7,6 +7,6 @@ sbin_PROGRAMS := usbip usbipd
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
-usbip_connect.c
+usbip_connect.c usbip_disconnect.c
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c
index 584d7d5..f0e9e06 100644
--- a/tools/usb/usbip/src/usbip.c
+++ b/tools/usb/usbip/src/usbip.c
@@ -83,6 +83,12 @@ static const struct command cmds[] = {
.usage = usbip_connect_usage
},
{
+   .name  = "disconnect",
+   .fn= usbip_disconnect,
+   .help  = "Disconnect a USB device from a remote computer",
+   .usage = usbip_disconnect_usage
+   },
+   {
.name  = "list",
.fn= usbip_list,
.help  = "List exportable or local USB devices",
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index f365353..a8cbd16 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -32,6 +32,7 @@ int usbip_bind(int argc, char *argv[]);
 int usbip_unbind(int argc, char *argv[]);
 int usbip_port_show(int argc, char *argv[]);
 int usbip_connect(int argc, char *argv[]);
+int usbip_disconnect(int argc, char *argv[]);
 
 void usbip_attach_usage(void);
 void usbip_detach_usage(void);
@@ -39,6 +40,7 @@ void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
 void usbip_connect_usage(void);
+void usbip_disconnect_usage(void);
 
 int usbip_bind_device(char *busid);
 int usbip_unbind_device(char *busid);
diff --git a/tools/usb/usbip/src/usbip_disconnect.c 
b/tools/usb/usbip/src/usbip_disconnect.c
new file mode 100644
index 000..8155384
--- /dev/null
+++ b/tools/usb/usbip/src/usbip_disconnect.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
+ *   2005-2007 Takahiro Hirofuchi
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+

[PATCH v13 05/10] usbip: exporting devices: modifications to daemon

2016-11-21 Thread Nobuo Iwata
Refactoring to the daemon to reuse common portion for new application 
side daemon. It's divided into two portions.

usbipd.c : common code for both device and application side daemon.
usbipd_dev.c : device-side specific code extracted from usbipd.c.

In following diagram, usbipd EXISTING-1 is the device-side daemon and 
NEW-1 is the application side daemon.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =

usbip_net_set_nodelay() was in the middle of device side daemon 
procedure. There's no effect by the defferring. It is moved to right 
after accept() to affect it both device and application side. In the 
client operation, it's already in right after connect().

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/Makefile.am  |   2 +-
 tools/usb/usbip/src/usbipd.c | 246 --
 tools/usb/usbip/src/usbipd.h |  39 +
 tools/usb/usbip/src/usbipd_dev.c | 252 +++
 4 files changed, 319 insertions(+), 220 deletions(-)

diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 42760c3..1aa5156 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -9,4 +9,4 @@ usbip_SOURCES := usbip.h utils.h usbip.c utils.c 
usbip_network.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
 usbip_connect.c usbip_disconnect.c
 
-usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
+usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 009afb4..bc4775f 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  * Copyright (C) 2015-2016 Samsung Electronics
  *   Igor Kotrasinski 
@@ -43,25 +44,19 @@
 #include 
 #include 
 
-#include "usbip_host_driver.h"
-#include "usbip_host_common.h"
-#include "usbip_device_driver.h"
 #include "usbip_common.h"
 #include "usbip_network.h"
+#include "usbipd.h"
 #include "list.h"
 
-#undef  PROGNAME
-#define PROGNAME "usbipd"
 #define MAXSOCKFD 20
 
 #define MAIN_LOOP_TIMEOUT 10
 
-#define DEFAULT_PID_FILE "/var/run/" PROGNAME ".pid"
-
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
-   "usage: usbipd [options]\n"
+   "usage: %s [options]\n"
"\n"
"   -4, --ipv4\n"
"   Bind to IPv4. Default is both.\n"
@@ -82,7 +77,7 @@ static const char usbipd_help_string[] =
"\n"
"   -PFILE, --pid FILE\n"
"   Write process id to FILE.\n"
-   "   If no FILE specified, use " DEFAULT_PID_FILE "\n"
+   "   If no FILE specified, use %s.\n"
"\n"
"   -tPORT, --tcp-port PORT\n"
"   Listen on TCP/IP port PORT.\n"
@@ -93,198 +88,9 @@ static const char usbipd_help_string[] =
"   -v, --version\n"
"   Show version.\n";
 
-static struct usbip_host_driver *driver;
-
 static void usbipd_help(void)
 {
-   printf("%s\n", usbipd_help_string);
-}
-
-static int recv_request_import(int sockfd)
-{
-   struct op_import_request req;
-   struct usbip_exported_device *edev;
-   struct usbip_usb_device pdu_udev;
-   struct list_head *i;
-   int found = 0;
-   int error = 0;
-   int rc;
-
-   memset(, 0, sizeof(req));
-
-   rc = usbip_net_recv(sockfd, , sizeof(req));
-   if (rc < 0) {
-   dbg("usbip_net_recv failed: import request");
-   return -1;
-   }
-   PACK_OP_IMPORT_REQUEST(0, );
-
-   list_for_each(i, >edev_list) {
-   edev = list_entry(i, struct usbip_exported_device, node);
-   if (!strncmp(req.busid, 

[PATCH v13 01/10] usbip: exporting devices: modifications to network header

2016-11-21 Thread Nobuo Iwata
Modification to export and un-export response in 
tools/usb/usbip/src/usbip_network.h. It just changes return code type 
from int to uint32_t as same as other responses.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/usbip_network.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/usb/usbip/src/usbip_network.h 
b/tools/usb/usbip/src/usbip_network.h
index c1e875c..e1ca86a 100644
--- a/tools/usb/usbip/src/usbip_network.h
+++ b/tools/usb/usbip/src/usbip_network.h
@@ -93,7 +93,7 @@ struct op_export_request {
 } __attribute__((packed));
 
 struct op_export_reply {
-   int returncode;
+   uint32_t returncode;
 } __attribute__((packed));
 
 
@@ -115,7 +115,7 @@ struct op_unexport_request {
 } __attribute__((packed));
 
 struct op_unexport_reply {
-   int returncode;
+   uint32_t returncode;
 } __attribute__((packed));
 
 #define PACK_OP_UNEXPORT_REQUEST(pack, request)  do {\
-- 
2.1.0

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


[PATCH v13 00/10] usbip: exporting devices

2016-11-21 Thread Nobuo Iwata
Dear all,

This series of patches adds exporting device operation to USB/IP.

NOTE:
This patch set modifies only userspace codes in tools/usb/usbip.

1. Goal

1-1) To give flexibility to direction of connection
Using USB/IP in internet, there can be two cases.
a) an application is inside firewall and devices are outside.
b) devices are inside firewall and an application is inside.
In case-a, import works because the connection is from inside.
In case-b, import doesn't works because the connection is from outside. 
Connection from device side is needed. This patch set adds the 
direction of connection establishment.

NOTE:
Directions of URBs requests and responses are not changed. Only 
direction of connection establishment initiated with usbip command is 
added to exsiting one.

1-2) To improve usability of operations
When two Linux machines are in a small distance, it's OK to bind (makes 
importable) at device side machine and attach (import) at application 
side.
If application is as cloud service or in blade server, it's not 
practical to attach from application side. It's useful to connect 
(export) from device side. This patch set adds the new operation to 
connect from device side.

2. What's 'exporting' device

Exporting devices is not new. The request and response PDU have already 
been defined in tools/usbip/usbip/src/usbip_network.h.
#/* Export a USB device to a remote host. */
#define OP_EXPORT   0x06
#define OP_REQ_EXPORT   (OP_REQUEST | OP_EXPORT)
#define OP_REP_EXPORT   (OP_REPLY   | OP_EXPORT)
# struct op_export_request
# struct op_export_reply
#/* un-Export a USB device from a remote host. */
#define OP_UNEXPORT 0x07
#define OP_REQ_UNEXPORT (OP_REQUEST | OP_UNEXPORT)
#define OP_REP_UNEXPORT (OP_REPLY   | OP_UNEXPORT)
# struct op_unexport_request
# struct op_unexport_reply 

But they have not been used yet. This series adds new operations: 
'connect' and 'disconnect' using these PDUs.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

 Bind and unbind are done in connect and disconnect internally.

3. The use cases

EXISTING)

In existing way, computers in small distance, having same user account, 
can be easily managed by a same user. Bind in local machine and attach 
in remote machine by the user. The devices can be exporsed 
automatically in the local machine, for example, at strat up. They can 
be attached from remote.

When there are distributes linux nodes with USB devices in internet, 
they are exposed by bind operation at start up, server behind firewall 
can list and attach the devices.  
   Internet  
 Exposed   +--+++++
 +--+  |Linux |+   |Router, ||Service |
+|device|--|Controller||---|proxy,  ||on  |
|+--+  +--+|   |firewall||Linux   |
+--++--+   ++++
   <--- attach(import)
  USB/IP + WS proxy   WS proxy + USB/IP

NEW)

Assuming that a server computer which runs application and VHCI is in a 
server room and device side machines are small distributed nodes 
outside of the server room, the operator of the server compter is 
different form the distributed nodes. The server computer may be in 
unattended operation. In the new way, after the daemon has been 
started, device can be connected with connect command in the 
distributed nodes. If the distributed nodes doesn't have user 
interface, the connect command can be executed from start up procedure.

In another senario to connect devices to a Linux based cloud service 
using WebSocket proxy, it's needed to establish connection from a 
device inside of firewall to a service outside. Exporting is suitable 
for the senario.

   Home/SOHO/Intranet   Internet  
   +--+ ++   ++
 +--+  |Linux |+

[PATCH v13 02/10] usbip: exporting devices: modifications to host side libraries

2016-11-21 Thread Nobuo Iwata
usbip_get_device() method in usbip_host_driver_ops was not used. It is 
modified as a function to find an exported device for new operations 
'connect' and 'disconnect'.

bind and unbind function are exported to reuse by new connect and 
disconnect operation.

Here, connect and disconnect is NEW-3 and NEW-4 respactively in diagram 
below.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

 Bind and unbind are done in connect and disconnect internally.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/usbip_host_common.c | 6 ++
 tools/usb/usbip/libsrc/usbip_host_common.h | 8 
 tools/usb/usbip/src/usbip.h| 3 +++
 tools/usb/usbip/src/usbip_bind.c   | 4 ++--
 tools/usb/usbip/src/usbip_unbind.c | 4 ++--
 5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c 
b/tools/usb/usbip/libsrc/usbip_host_common.c
index 9d41522..6a98d6c 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -256,17 +256,15 @@ int usbip_export_device(struct usbip_exported_device 
*edev, int sockfd)
 }
 
 struct usbip_exported_device *usbip_generic_get_device(
-   struct usbip_host_driver *hdriver, int num)
+   struct usbip_host_driver *hdriver, char *busid)
 {
struct list_head *i;
struct usbip_exported_device *edev;
-   int cnt = 0;
 
list_for_each(i, >edev_list) {
edev = list_entry(i, struct usbip_exported_device, node);
-   if (num == cnt)
+   if (!strncmp(busid, edev->udev.busid, SYSFS_BUS_ID_SIZE))
return edev;
-   cnt++;
}
 
return NULL;
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.h 
b/tools/usb/usbip/libsrc/usbip_host_common.h
index a64b803..f9a9def 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.h
+++ b/tools/usb/usbip/libsrc/usbip_host_common.h
@@ -38,7 +38,7 @@ struct usbip_host_driver_ops {
void (*close)(struct usbip_host_driver *hdriver);
int (*refresh_device_list)(struct usbip_host_driver *hdriver);
struct usbip_exported_device * (*get_device)(
-   struct usbip_host_driver *hdriver, int num);
+   struct usbip_host_driver *hdriver, char *busid);
 
int (*read_device)(struct udev_device *sdev,
   struct usbip_usb_device *dev);
@@ -86,11 +86,11 @@ static inline int usbip_refresh_device_list(struct 
usbip_host_driver *hdriver)
 }
 
 static inline struct usbip_exported_device *
-usbip_get_device(struct usbip_host_driver *hdriver, int num)
+usbip_get_device(struct usbip_host_driver *hdriver, char *busid)
 {
if (!hdriver->ops.get_device)
return NULL;
-   return hdriver->ops.get_device(hdriver, num);
+   return hdriver->ops.get_device(hdriver, busid);
 }
 
 /* Helper functions for implementing driver backend */
@@ -99,6 +99,6 @@ void usbip_generic_driver_close(struct usbip_host_driver 
*hdriver);
 int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
 int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
 struct usbip_exported_device *usbip_generic_get_device(
-   struct usbip_host_driver *hdriver, int num);
+   struct usbip_host_driver *hdriver, char *busid);
 
 #endif /* __USBIP_HOST_COMMON_H */
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index 84fe66a..c296910 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -37,4 +37,7 @@ void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
 
+int usbip_bind_device(char *busid);
+int usbip_unbind_device(char *busid);
+
 #endif /* __USBIP_H */
diff --git a/tools/usb/usbip/src/usbip_bind.c b/tools/usb/usbip/src/usbip_bind.c
index fa46141..2401745 100644
--- a/tools/usb/usbip/src/usbip_bind.c
+++ 

Re: [RFC][PATCH 3/3] usb: dwc2: Make sure we disconnect the gadget state

2016-11-21 Thread John Stultz
On Mon, Nov 21, 2016 at 7:23 PM, John Youn  wrote:
> On 11/15/2016 1:47 PM, John Stultz wrote:
>> 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.
>
> The fifo_map could end up not being clear when disconnect is never
> sent to the UDC framework. That unsets the configuration and the
> endpoints get disabled, which clears the FIFO map.
>
> Looks like the problem happens when going from A-device to B-device.
>
> If you come up as an A-Device, the gadget wouldn't have been
> configured so it shouldn't warn going A->B.
>
> If you go B->A, you will get a session end detected, which triggers
> the udc disconnect. Then A->B should not warn here either.

Yea. From the udc perspective, it seems like we see:

usb_ep_enable()
gadget works fine...

unplug gadget cable, it switches into host mode.

re-plug gadget cable, and as it switches into gadget mode:

[   74.241737] JDB: udc-core usb_ep_disable!
[   74.245812] JDB: udc-core usb_ep_disable!
[   74.302390] dwc2 f72c.usb: new device is high-speed
[   74.474131] dwc2 f72c.usb: new device is high-speed
[   74.550185] dwc2 f72c.usb: new device is high-speed
[   74.621953] dwc2 f72c.usb: new address 74
[   74.651824] configfs-gadget gadget: high-speed config #1: b
[   74.657467] JDB: udc-core usb_ep_enable!
[   74.661422] JDB: udc-core usb_ep_enable!

This is why I suspect that the overly simplistic phy driver is part of
the problem here.  However, in trying to extend it to be more
functional (I've got extcon wired up and see events when I plug in and
out), I'm still having trouble, as its not clear how the generic phy
(not usb phy) driver is supposed to interact with the UDC/dwc2 driver.

Part of the issue I've seen is that while the hikey generic phy driver
tries to mimic some of the usb-phy drivers, creating an otg device and
registering it:

priv->dev = >dev;
priv->phy.dev = priv->dev;
priv->phy.label = "hi6220_usb_phy";
priv->phy.otg = otg;
priv->phy.type = USB_PHY_TYPE_USB2;
otg->set_host = hi6220_otg_set_host;
otg->set_peripheral = hi6220_otg_set_peripheral;
otg->usb_phy = >phy;

platform_set_drvdata(pdev, priv);

phy_set_drvdata(phy, priv);

usb_add_phy_dev(>phy);

The trouble is the dwc2 driver doesn't seem to call
set_host/peripheral() because it never sets the uphy pointer in
dwc2_lowlevel_hw_init(), as the hikey generic phy driver is found
before that point.

So I'm not really sure how to get the generic phy -> usb_gadget
connection established so I can call
usb_gadget_vbus_connect/disconnect at the right time..

Suggestions?

> Can you determine why this doesn't happen on your system? It sounds
> like there might be some race condition that we need to identify. If
> you can provide logs with DEBUG enabled that would be helpful too.

I'll try to capture some more data. I've got my own debug printouts
littering the logs, so I'll try to pull those out of the way.

thanks
-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 v10 2/8] power: add power sequence library

2016-11-21 Thread Peter Chen
On Tue, Nov 22, 2016 at 03:23:12AM +0100, Rafael J. Wysocki wrote:
> > @@ -0,0 +1,237 @@
> > +/*
> > + * core.c  power sequence core file
> > + *
> > + * Copyright (C) 2016 Freescale Semiconductor, Inc.
> > + * Author: Peter Chen 
> > + *
> > + * This program is free software: you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2  of
> > + * the License as published by the Free Software Foundation.
> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program.  If not, see .
> 
> The last paragraph is not necessary AFAICS.

I just copy it from:

https://www.gnu.org/licenses/gpl-howto.en.html

If you are concerns about it, I can delete it.

> > +
> > +static struct pwrseq *pwrseq_find_available_instance(struct device_node 
> > *np)
> > +{
> > +   struct pwrseq *pwrseq;
> > +
> > +   list_for_each_entry(pwrseq, _list, node) {
> > +   if (pwrseq->used)
> > +   continue;
> > +
> > +   /* compare compatible string for pwrseq node */
> > +   if (of_match_node(pwrseq->pwrseq_of_match_table, np)) {
> > +   pwrseq->used = true;
> > +   return pwrseq;
> > +   }
> > +
> > +   /* return generic pwrseq instance */
> > +   if (!strcmp(pwrseq->pwrseq_of_match_table->compatible,
> > +   "generic")) {
> > +   pr_debug("using generic pwrseq instance for %s\n",
> > +   np->full_name);
> > +   pwrseq->used = true;
> > +   return pwrseq;
> > +   }
> > +   }
> > +   pr_warn("Can't find any pwrseq instances for %s\n", np->full_name);
> 
> pr_debug() ?

If there is no pwrseq instance for that node, the power sequence on routine will
return fail, so I think an warning message is useful for user.

> 
> > +
> > +   return NULL;
> > +}
> > +
> > +/**
> > + * of_pwrseq_on: do power sequence on for device node
> 
> of_pwrseq_on - Carry out power sequence on for device node
> 
> Argument description should follow this line.
> 
> > + *
> > + * This API is used to power on single device, if the host
> > + * controller only needs to handle one child device (this device
> > + * node points to), use this API. If multiply devices are needed
> > + * to handle on bus, use of_pwrseq_on_list.
> 
> That's unclear.
> 
> What about "Carry out a single device power on.  If multiple devices
> need to be handled, use of_pwrseq_on_list() instead."
> 
> > + *
> > + * @np: the device node would like to power on
> > + *
> > + * On successful, it returns pwrseq instance, otherwise an error value.
> 
> "Return a pointer to the power sequence instance on success, or an
> error code otherwise."
> 

Ok, will change.

> > + */
> > +struct pwrseq *of_pwrseq_on(struct device_node *np)
> > +{
> > +   struct pwrseq *pwrseq;
> > +   int ret;
> > +
> > +   pwrseq = pwrseq_find_available_instance(np);
> 
> What does guarantee the integrity of ths list at this point?

Once the use selects the specific pwrseq library, the library will
create an empty one instance during the initialization, and it
will be called at postcore_initcall, the device driver has not
probed yet.

> 
> > +   if (!pwrseq)
> > +   return ERR_PTR(-ENONET);
> 
> ENOENT I suppose?
> 

Good catch, thanks.

> > +/**
> > + * of_pwrseq_off: do power sequence off for this pwrseq instance
> > + *
> > + * This API is used to power off single device, it is the opposite
> > + * operation for of_pwrseq_on.
> > + *
> > + * @pwrseq: the pwrseq instance which related device would like to be off
> > + */
> > +void of_pwrseq_off(struct pwrseq *pwrseq)
> > +{
> > +   pwrseq_off(pwrseq);
> > +   pwrseq_put(pwrseq);
> > +}
> > +EXPORT_SYMBOL_GPL(of_pwrseq_off);
> 
> What happens if two code paths attempt to turn the same power sequence
> off in parallel?  Can it ever happen?  If not, then why not?
> 

I don't think the same pwrseq instance off will be called at the same
time, the of_pwrseq_off is supposed to be only called at error path
during power-on and at device power-off routine, and only the power-on is
successful, the device can be created, if the device is not created,
its power-off routine is not supposed to be called.

> > +
> > +/**
> > + * of_pwrseq_on_list: do power sequence on for list
> > + *
> > + * This API is used to power on multiple devices at single bus.
> > + * If there are several devices on bus (eg, USB bus), uses this
> > + * this API. Otherwise, use 

Re: [PATCH v2 2/4] usb: dwc2: Add binding for AHB burst

2016-11-21 Thread John Youn
On 11/21/2016 1:10 PM, Christian Lamparter wrote:
> Hello John,
> 
> On Monday, November 21, 2016 12:16:31 PM CET John Youn wrote:
>> On 11/18/2016 12:18 PM, Christian Lamparter wrote:
>>> On Friday, November 18, 2016 8:16:08 AM CET Rob Herring wrote:
 On Thu, Nov 17, 2016 at 04:35:10PM +0100, Stefan Wahren wrote:
> Hi John,
>
> Am 17.11.2016 um 00:47 schrieb John Youn:
>> Add the "snps,ahb-burst" binding and read it in.
>>
>> This property controls which burst type to perform on the AHB bus as a
>> master in internal DMA mode. This overrides the legacy param value,
>> which we need to keep around for now since several platforms use it.
>>
>> Some platforms may see better or worse performance based on this
>> value. The HAPS platform is one example where all INCRx have worse
>> performance than INCR.
>>
>> Other platforms (such as the Canyonlands board) report that the default
>> value causes system hangs.
>>
>> Signed-off-by: John Youn 
>> Cc: Christian Lamparter 
>> ---
>>  Documentation/devicetree/bindings/usb/dwc2.txt |  2 +
>>  drivers/usb/dwc2/core.h|  9 +
>>  drivers/usb/dwc2/params.c  | 56 
>> ++
>>  3 files changed, 67 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
>> b/Documentation/devicetree/bindings/usb/dwc2.txt
>> index 6c7c2bce..9e7b4b4 100644
>> --- a/Documentation/devicetree/bindings/usb/dwc2.txt
>> +++ b/Documentation/devicetree/bindings/usb/dwc2.txt
>
> according to Documentation/devicetree/bindings/submitting-patches.txt
> this change should be a separate patch.
>
>> @@ -26,6 +26,8 @@ Optional properties:
>>  Refer to phy/phy-bindings.txt for generic phy consumer properties
>>  - dr_mode: shall be one of "host", "peripheral" and "otg"
>>Refer to usb/generic.txt
>> +- snps,ahb-burst: specifies the ahb burst length. Valid arguments are:
>> +  "SINGLE", "INCR", "INCR4", "INCR8", "INCR16". Defaults to "INCR4".
>
> This doesn't apply in case of the bcm2835. I would prefer this option is
> ignored in that case with a dev_warn("snps,ahb-burst is not supported on
> this platform").

 Also, perhaps you should allow that the compatible string can define the 
 default.

>>> I hoped you would say that :).
>>>
>>> I've attached a patch (on top of John Youn changes) that does
>>> just that for the amcc,dwc-otg. I put the GAHBCFG_HBSTLEN_INCR
>>> value into the .data, if that's a problem, I can certainly 
>>> respin the patch and put it in a dedicated struct.
>>>
>>> Regards
>>>
>>> Christian
>>> ---
>>> From 4c31a029dde714828810b1c3e61a5b1412ac939a Mon Sep 17 00:00:00 2001
>>> From: Christian Lamparter 
>>> Date: Fri, 18 Nov 2016 21:03:19 +0100
>>> Subject: [PATCH] usb: dwc2: add a default ahb-burst setting for amcc,dwc-otg
>>>
>>> This patch adds a of_device_id table which can be used by
>>> existing devices to supply a ahb-burst value for the platform
>>> without having to add a "snps,ahb-burst" entry to the dts.
>>>
>>> Note: Adding new devices to this table is discouraged.
>>>   please consider adding the "snps,ahb-burst" property
>>>   with the correct configuration to your device tree
>>>   file instead.
>>>
>>> Signed-off-by: Christian Lamparter 
>>> ---
>>>  drivers/usb/dwc2/params.c | 22 ++
>>>  1 file changed, 22 insertions(+)
>>>
>>> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
>>> index e0fc9aa..51be266 100644
>>> --- a/drivers/usb/dwc2/params.c
>>> +++ b/drivers/usb/dwc2/params.c
>>> @@ -1097,6 +1097,22 @@ static const char *const ahb_bursts[] = {
>>> [GAHBCFG_HBSTLEN_INCR16]= "INCR16",
>>>  };
>>>  
>>> +/*
>>> + * This table provides AHB burst configuration for existing
>>> + * device tree bindings that work poorly with the default setting.
>>> + *
>>> + * Note: Adding new devices to this table is discouraged.
>>> + *  please consider adding the "snps,ahb-burst" property
>>> + *  with the correct configuration to your device tree
>>> + *  file instead.
>>> + */
>>> +static const struct of_device_id dwc2_compat_ahb_bursts[] = {
>>> +   {
>>> +   .compatible = "amcc,dwc-otg",
>>> +   .data = (void *) GAHBCFG_HBSTLEN_INCR16,
>>> +   },
>>> +};
>>> +
>>>  static int dwc2_get_property_ahb_burst(struct dwc2_hsotg *hsotg)
>>>  {
>>> struct device_node *node = hsotg->dev->of_node;
>>> @@ -1107,6 +1123,12 @@ static int dwc2_get_property_ahb_burst(struct 
>>> dwc2_hsotg *hsotg)
>>> ret = device_property_read_string(hsotg->dev,
>>>   "snps,ahb-burst", );
>>> if (ret < 0) {
>>> +   const struct of_device_id *match;
>>> +
>>> +   match = 

Re: [RFC][PATCH 3/3] usb: dwc2: Make sure we disconnect the gadget state

2016-11-21 Thread John Youn
On 11/15/2016 1:47 PM, John Stultz wrote:
> 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.

Hi,

The fifo_map could end up not being clear when disconnect is never
sent to the UDC framework. That unsets the configuration and the
endpoints get disabled, which clears the FIFO map.

Looks like the problem happens when going from A-device to B-device.

If you come up as an A-Device, the gadget wouldn't have been
configured so it shouldn't warn going A->B.

If you go B->A, you will get a session end detected, which triggers
the udc disconnect. Then A->B should not warn here either.

Can you determine why this doesn't happen on your system? It sounds
like there might be some race condition that we need to identify. If
you can provide logs with DEBUG enabled that would be helpful too.

Regards,
John


> 
> Ends up if we don't disconnect the gadget state, 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.
> 
> Cc: Wei Xu 
> Cc: Guodong Xu 
> Cc: Amit Pundir 
> Cc: Rob Herring 
> Cc: John Youn 
> Cc: Douglas Anderson 
> Cc: Chen Yu 
> Cc: Felipe Balbi 
> Cc: Greg Kroah-Hartman 
> Cc: linux-usb@vger.kernel.org
> Signed-off-by: John Stultz 
> ---
>  drivers/usb/dwc2/hcd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index 8c980fd..d2557b7 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -3228,6 +3228,7 @@ static void dwc2_conn_id_status_change(struct 
> work_struct *work)
>   dwc2_core_init(hsotg, false);
>   dwc2_enable_global_interrupts(hsotg);
>   spin_lock_irqsave(>lock, flags);
> + dwc2_hsotg_disconnect(hsotg);
>   dwc2_hsotg_core_init_disconnected(hsotg, false);
>   spin_unlock_irqrestore(>lock, flags);
>   dwc2_hsotg_core_connect(hsotg);
> 

--
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 v10 2/8] power: add power sequence library

2016-11-21 Thread Rafael J. Wysocki
On Mon, Nov 14, 2016 at 2:35 AM, Peter Chen  wrote:
> We have an well-known problem that the device needs to do some power
> sequence before it can be recognized by related host, the typical
> example like hard-wired mmc devices and usb devices.
>
> This power sequence is hard to be described at device tree and handled by
> related host driver, so we have created a common power sequence
> library to cover this requirement. The core code has supplied
> some common helpers for host driver, and individual power sequence
> libraries handle kinds of power sequence for devices. The pwrseq
> librares always need to allocate extra instance for compatible
> string match.
>
> pwrseq_generic is intended for general purpose of power sequence, which
> handles gpios and clocks currently, and can cover other controls in
> future. The host driver just needs to call of_pwrseq_on/of_pwrseq_off
> if only one power sequence is needed, else call of_pwrseq_on_list
> /of_pwrseq_off_list instead (eg, USB hub driver).
>
> For new power sequence library, it can add its compatible string
> to pwrseq_of_match_table, then the pwrseq core will match it with
> DT's, and choose this library at runtime.
>
> Signed-off-by: Peter Chen 
> Tested-by: Maciej S. Szmigiero 
> Tested-by Joshua Clayton 
> Reviewed-by: Matthias Kaehlcke 
> Tested-by: Matthias Kaehlcke 
> ---
>  MAINTAINERS   |   9 ++
>  drivers/power/Kconfig |   1 +
>  drivers/power/Makefile|   1 +
>  drivers/power/pwrseq/Kconfig  |  21 +++
>  drivers/power/pwrseq/Makefile |   2 +
>  drivers/power/pwrseq/core.c   | 237 
> ++
>  drivers/power/pwrseq/pwrseq_generic.c | 183 ++
>  include/linux/power/pwrseq.h  |  60 +
>  8 files changed, 514 insertions(+)
>  create mode 100644 drivers/power/pwrseq/Kconfig
>  create mode 100644 drivers/power/pwrseq/Makefile
>  create mode 100644 drivers/power/pwrseq/core.c
>  create mode 100644 drivers/power/pwrseq/pwrseq_generic.c
>  create mode 100644 include/linux/power/pwrseq.h
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3d838cf..066b1e4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -9621,6 +9621,15 @@ F:   include/linux/pm_*
>  F: include/linux/powercap.h
>  F: drivers/powercap/
>
> +POWER SEQUENCE LIBRARY
> +M: Peter Chen 
> +T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
> +L: linux...@vger.kernel.org
> +S: Maintained
> +F: Documentation/devicetree/bindings/power/pwrseq/
> +F: drivers/power/pwrseq/
> +F: include/linux/power/pwrseq.h/
> +
>  POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
>  M: Sebastian Reichel 
>  L: linux...@vger.kernel.org
> diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
> index 63454b5..c1bb046 100644
> --- a/drivers/power/Kconfig
> +++ b/drivers/power/Kconfig
> @@ -1,3 +1,4 @@
>  source "drivers/power/avs/Kconfig"
>  source "drivers/power/reset/Kconfig"
>  source "drivers/power/supply/Kconfig"
> +source "drivers/power/pwrseq/Kconfig"
> diff --git a/drivers/power/Makefile b/drivers/power/Makefile
> index ff35c71..7db8035 100644
> --- a/drivers/power/Makefile
> +++ b/drivers/power/Makefile
> @@ -1,3 +1,4 @@
>  obj-$(CONFIG_POWER_AVS)+= avs/
>  obj-$(CONFIG_POWER_RESET)  += reset/
>  obj-$(CONFIG_POWER_SUPPLY) += supply/
> +obj-$(CONFIG_POWER_SEQUENCE)   += pwrseq/
> diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig
> new file mode 100644
> index 000..88f5597
> --- /dev/null
> +++ b/drivers/power/pwrseq/Kconfig
> @@ -0,0 +1,21 @@
> +#
> +# Power Sequence library
> +#
> +
> +menuconfig POWER_SEQUENCE
> +   bool "Power sequence control"
> +   depends on OF
> +   help
> +  It is used for drivers which needs to do power sequence
> +  (eg, turn on clock, toggle reset gpio) before the related
> +  devices can be found by hardware, eg, USB bus.
> +
> +if POWER_SEQUENCE
> +
> +config PWRSEQ_GENERIC
> +   bool "Generic power sequence control"
> +   default y
> +   help
> +  This is the generic power sequence control library, and is
> +  supposed to support common power sequence usage.
> +endif
> diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile
> new file mode 100644
> index 000..ad82389
> --- /dev/null
> +++ b/drivers/power/pwrseq/Makefile
> @@ -0,0 +1,2 @@
> +obj-$(CONFIG_POWER_SEQUENCE) += core.o
> +obj-$(CONFIG_PWRSEQ_GENERIC) += pwrseq_generic.o
> diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c
> new file mode 100644
> index 000..e3c1fbb
> --- /dev/null
> +++ b/drivers/power/pwrseq/core.c
> @@ -0,0 +1,237 @@
> +/*
> + * core.c  power sequence core file
> 

Re: [PATCH v10 2/8] power: add power sequence library

2016-11-21 Thread Peter Chen
On Mon, Nov 14, 2016 at 09:35:53AM +0800, Peter Chen wrote:
> We have an well-known problem that the device needs to do some power
> sequence before it can be recognized by related host, the typical
> example like hard-wired mmc devices and usb devices.
> 
> This power sequence is hard to be described at device tree and handled by
> related host driver, so we have created a common power sequence
> library to cover this requirement. The core code has supplied
> some common helpers for host driver, and individual power sequence
> libraries handle kinds of power sequence for devices. The pwrseq
> librares always need to allocate extra instance for compatible
> string match.
> 
> pwrseq_generic is intended for general purpose of power sequence, which
> handles gpios and clocks currently, and can cover other controls in
> future. The host driver just needs to call of_pwrseq_on/of_pwrseq_off
> if only one power sequence is needed, else call of_pwrseq_on_list
> /of_pwrseq_off_list instead (eg, USB hub driver).
> 
> For new power sequence library, it can add its compatible string
> to pwrseq_of_match_table, then the pwrseq core will match it with
> DT's, and choose this library at runtime.
> 

Rafael, would you get any chances to review this version, it makes
some changes according to your comments, I hope this patch set could
be in v4.10-rc1, thanks.

Peter
> Signed-off-by: Peter Chen 
> Tested-by: Maciej S. Szmigiero 
> Tested-by Joshua Clayton 
> Reviewed-by: Matthias Kaehlcke 
> Tested-by: Matthias Kaehlcke 
> ---
>  MAINTAINERS   |   9 ++
>  drivers/power/Kconfig |   1 +
>  drivers/power/Makefile|   1 +
>  drivers/power/pwrseq/Kconfig  |  21 +++
>  drivers/power/pwrseq/Makefile |   2 +
>  drivers/power/pwrseq/core.c   | 237 
> ++
>  drivers/power/pwrseq/pwrseq_generic.c | 183 ++
>  include/linux/power/pwrseq.h  |  60 +
>  8 files changed, 514 insertions(+)
>  create mode 100644 drivers/power/pwrseq/Kconfig
>  create mode 100644 drivers/power/pwrseq/Makefile
>  create mode 100644 drivers/power/pwrseq/core.c
>  create mode 100644 drivers/power/pwrseq/pwrseq_generic.c
>  create mode 100644 include/linux/power/pwrseq.h
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 3d838cf..066b1e4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -9621,6 +9621,15 @@ F: include/linux/pm_*
>  F:   include/linux/powercap.h
>  F:   drivers/powercap/
>  
> +POWER SEQUENCE LIBRARY
> +M:   Peter Chen 
> +T:   git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
> +L:   linux...@vger.kernel.org
> +S:   Maintained
> +F:   Documentation/devicetree/bindings/power/pwrseq/
> +F:   drivers/power/pwrseq/
> +F:   include/linux/power/pwrseq.h/
> +
>  POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
>  M:   Sebastian Reichel 
>  L:   linux...@vger.kernel.org
> diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
> index 63454b5..c1bb046 100644
> --- a/drivers/power/Kconfig
> +++ b/drivers/power/Kconfig
> @@ -1,3 +1,4 @@
>  source "drivers/power/avs/Kconfig"
>  source "drivers/power/reset/Kconfig"
>  source "drivers/power/supply/Kconfig"
> +source "drivers/power/pwrseq/Kconfig"
> diff --git a/drivers/power/Makefile b/drivers/power/Makefile
> index ff35c71..7db8035 100644
> --- a/drivers/power/Makefile
> +++ b/drivers/power/Makefile
> @@ -1,3 +1,4 @@
>  obj-$(CONFIG_POWER_AVS)  += avs/
>  obj-$(CONFIG_POWER_RESET)+= reset/
>  obj-$(CONFIG_POWER_SUPPLY)   += supply/
> +obj-$(CONFIG_POWER_SEQUENCE) += pwrseq/
> diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig
> new file mode 100644
> index 000..88f5597
> --- /dev/null
> +++ b/drivers/power/pwrseq/Kconfig
> @@ -0,0 +1,21 @@
> +#
> +# Power Sequence library
> +#
> +
> +menuconfig POWER_SEQUENCE
> + bool "Power sequence control"
> + depends on OF
> + help
> +It is used for drivers which needs to do power sequence
> +(eg, turn on clock, toggle reset gpio) before the related
> +devices can be found by hardware, eg, USB bus.
> +
> +if POWER_SEQUENCE
> +
> +config PWRSEQ_GENERIC
> + bool "Generic power sequence control"
> + default y
> + help
> +This is the generic power sequence control library, and is
> +supposed to support common power sequence usage.
> +endif
> diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile
> new file mode 100644
> index 000..ad82389
> --- /dev/null
> +++ b/drivers/power/pwrseq/Makefile
> @@ -0,0 +1,2 @@
> +obj-$(CONFIG_POWER_SEQUENCE) += core.o
> +obj-$(CONFIG_PWRSEQ_GENERIC) += pwrseq_generic.o
> diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c
> new file mode 100644
> index 000..e3c1fbb
> --- 

Re: [PATCH 0/5] usb: dwc2: fix parameter handling

2016-11-21 Thread John Youn
On 11/20/2016 1:26 PM, Stefan Wahren wrote:
> This patch series fixes several parameter handling issues
> found on bcm2835 in gadget mode. It's based on Felipe's USB next.
> 
> Stefan Wahren (5):
>   usb: dwc2: Do not set host parameter in peripheral mode
>   usb: dwc2: fix dwc2_get_device_property for u8 and u16
>   usb: dwc2: fix default value for DMA support
>   usb: dwc2: gadget: fix default value for gadget-dma-desc
>   usb: dwc2: fix kernel-doc for dwc2_set_param
> 
>  drivers/usb/dwc2/params.c |   32 ++--
>  1 file changed, 10 insertions(+), 22 deletions(-)
> 

For this series:

Acked-by: John Youn 


Felipe,

This is too late for 4.10-rc1 right?

Can you queue for 4.10 fixes. I can remind you after 4.10-rc1 if it's
too early for that.

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: crash by cdc_acm driver in kernels 4.8-rc1/5

2016-11-21 Thread poma
On 21.11.2016 21:23, Wim Osterholt wrote:
> On Mon, Nov 21, 2016 at 04:58:25PM +0100, Wim Osterholt wrote:
>>
>> I didn't find traces of kernel-4.9-rc5 being ran on any of my laptops, so I
>> can't have seen a crash on rc5. It seems rc5 and rc6 is safe now.
> 
> Neither 4.8.10, nor 4.8.9 show the bug.
> It must be a bug ouside cdc_acm that they have fixed. (a late propagation of
> the IRQ-penalty-bug-fix maybe?)
> 
> I'm rebuilding 4.8.8 now.
> 
> Groeten, Wim.
> 


After all the patching and testing I concluded the same, 
breakage came and is gone outside drivers/usb/class/
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/diff/?id=v4.9-rc5=v4.9-rc4

--
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 v18 0/4] Introduce usb charger framework to deal with the usb gadget power negotation

2016-11-21 Thread NeilBrown
On Tue, Nov 22 2016, Mark Brown wrote:

> [ Unknown signature status ]
> On Thu, Nov 17, 2016 at 05:46:13PM +1100, NeilBrown wrote:
>> On Thu, Nov 17 2016, Mark Brown wrote:
>
>> > To me that's pretty much what's being done here, the code just happens
>> > to sit in USB instead but fundamentally it's just a blob of helper code,
>> > you could replace the notifier with a callback if that's the big concern
>> > here.
>
>> It is a lot more than "just a blob of helper code".  It duplicates
>> existing infrastructure instead of fixing and using the
>> infrastructure but I've said all this before.  Repeatedly.
>
> My read on that is that the question of what we want to be responsible
> for aggregating the information about what power the system is allowed
> to draw from a given USB port hasn't been resolved yet and that apart
> from that you're fairly close.  It seems to me like that's really what
> the difference between your two positions is.  Fixing the existing
> notifiers implies that things have to be aggregated in the power supply
> drivers but Baolin is proposing doing that in the USB code instead.  It
> does seem at least worth considering if that's a good idea since the
> current situation doesn't look terribly thought through.

I agree that the question of where the responsibility for information
aggregation lies is open for discussion. If fact all details on how
things should work are always open for discussion.
I don't agree that this is the main different between our positions,
though I can see how you might get that impression.

I don't agree that "Fixing the existing notifiers implies that things
have to be aggregated in the power supply drivers".  That would be the
simplest way to fix them, but not the only way.  You could fix them so
that the usb driver sends notifications instead of the phy, and you
could fix them so that the information contained in the notification
being a power range instead the current ad-hoc inconsistent set of
information.

You could even fix them so they look *exactly* like the notifiers that
Baolin is proposing.  This is my key point.  It is not the end result
that I particularly object to (though I do object to some details).  It
is the process of getting to the end result that I don't like.  If the
current system doesn't work and something different is needed, then the
correct thing to do is to transform the existing system into something
new that works better.  This should be a clear series of steps.  Each
one makes a small, well defined, change.  Maybe it adds a new feature.
Maybe it refactors code without changing functionality.  Maybe it fixes a
bug.  Maybe it moves the responsibility for an action from *here* to
*there*.  Each step is clearly explained and convincingly justified.
This doesn't have to be a long justification.  Sometimes a single
sentence or a short paragraph is plenty.  Sometimes the change is so
obviously an improvement that no explanation is necessary.

Changing one step at a time make it easier to ensure that no
functionality is lost and that each change is actually needed.

If the patch series fixed the existing code and transformed it into
something better and more powerful, then it would be a lot easier to
have sensible discussions about individual patches, about which there
might be disagreement.

>
> There are a whole bunch of things that need to be sorted out whatever
> the decision is like the extcon related cleanups you mentioned in your
> mail the other day (steps 1 and 2), it seems like those could be moved
> forwards independently.

Agreed.

>
> By the way it occurred to me recently that we have a use case for
> multiple USB ports that could supply power - USB C.  Things with more
> than one port like things in a laptop form factor are going to want to
> be able to use all of them interchangably for power support (likely only
> one at a time, at least initially, but still more than one port).

Thanks!  It is so much easier to discusses these sorts of things where
there is a concrete reference point.

I wonder if each port would have its own current regulator, or if there
would be a single central one.  Maybe there would be a switch that
allowed power to flow in only from one port.
Would each "charger" need to get notifications from "its" port, or would
there be a single "charger" which got notifications from the
power-switch, which in-turn got notifications from each port?
Or would the battery-charger driver want to register with every port,
receive notifications, and be able to turn each one on or off?
Without concrete details of actual hardware, we can only guess.

But I think here my key point got lost too, in part because it was hard
to refer to an actual instance.
My point was that in the present patch set, the "usb charger" is given
a name which is dependant on discovery order, and only supports
lookup-by-name.  This cannot work.
If each USB-C port registers a usb_charger, they would be
"usb-charger.0", "usb-charger.1", 

Flood of hub_ext_port_status failed (err = -71) messages

2016-11-21 Thread Simon Arlott
I have a 5-port USB 2.0 hub attached to a USB 3.0 host by a long length
of Cat 5e cable (via a pair of cheap USB<->Cat5e adapters from eBay)
that only works at full speed and doesn't stay connected all the time.

This wouldn't be a problem except that the kernel can get stuck in a
loop with the "URB transfer length is wrong, xHC issue?" error.

The message "hub_ext_port_status failed (err = -71)" in particular can
occur 70+ times for every instance of this error. There's no guarantee
that it will ever disconnect the device and stop doing this, it has
previously suddenly started generating 30MB/minute of log messages for
30 minutes until I unplugged the device.

Would it be ok to rate limit both of these messages to reduce the impact
of poor connections?

2016-06-17T09:56:09.219+01:00  kernel: xhci_hcd :00:14.0: URB 
transfer length is wrong, xHC issue? req. len = 4, act. len = 4294967292
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = 0)
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.219+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.220+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.223+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: hub_ext_port_status 
failed (err = -71)

2016-06-17T09:56:09.224+01:00  kernel: usb 1-13: USB disconnect, device 
number 46
2016-06-17T09:56:09.224+01:00  kernel: hub 1-13:1.0: activate --> -19
2016-06-17T09:56:09.499+01:00  kernel: usb 1-13: new full-speed USB 
device number 47 using xhci_hcd
2016-06-17T09:56:09.795+01:00  kernel: usb 1-13: new full-speed USB 
device number 48 using xhci_hcd
2016-06-17T09:56:09.920+01:00  kernel: usb 1-13: device descriptor 
read/all, error -71

Re: [PATCH v2 2/4] usb: dwc2: Add binding for AHB burst

2016-11-21 Thread Christian Lamparter
Hello John,

On Monday, November 21, 2016 12:16:31 PM CET John Youn wrote:
> On 11/18/2016 12:18 PM, Christian Lamparter wrote:
> > On Friday, November 18, 2016 8:16:08 AM CET Rob Herring wrote:
> >> On Thu, Nov 17, 2016 at 04:35:10PM +0100, Stefan Wahren wrote:
> >>> Hi John,
> >>>
> >>> Am 17.11.2016 um 00:47 schrieb John Youn:
>  Add the "snps,ahb-burst" binding and read it in.
> 
>  This property controls which burst type to perform on the AHB bus as a
>  master in internal DMA mode. This overrides the legacy param value,
>  which we need to keep around for now since several platforms use it.
> 
>  Some platforms may see better or worse performance based on this
>  value. The HAPS platform is one example where all INCRx have worse
>  performance than INCR.
> 
>  Other platforms (such as the Canyonlands board) report that the default
>  value causes system hangs.
> 
>  Signed-off-by: John Youn 
>  Cc: Christian Lamparter 
>  ---
>   Documentation/devicetree/bindings/usb/dwc2.txt |  2 +
>   drivers/usb/dwc2/core.h|  9 +
>   drivers/usb/dwc2/params.c  | 56 
>  ++
>   3 files changed, 67 insertions(+)
> 
>  diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
>  b/Documentation/devicetree/bindings/usb/dwc2.txt
>  index 6c7c2bce..9e7b4b4 100644
>  --- a/Documentation/devicetree/bindings/usb/dwc2.txt
>  +++ b/Documentation/devicetree/bindings/usb/dwc2.txt
> >>>
> >>> according to Documentation/devicetree/bindings/submitting-patches.txt
> >>> this change should be a separate patch.
> >>>
>  @@ -26,6 +26,8 @@ Optional properties:
>   Refer to phy/phy-bindings.txt for generic phy consumer properties
>   - dr_mode: shall be one of "host", "peripheral" and "otg"
> Refer to usb/generic.txt
>  +- snps,ahb-burst: specifies the ahb burst length. Valid arguments are:
>  +  "SINGLE", "INCR", "INCR4", "INCR8", "INCR16". Defaults to "INCR4".
> >>>
> >>> This doesn't apply in case of the bcm2835. I would prefer this option is
> >>> ignored in that case with a dev_warn("snps,ahb-burst is not supported on
> >>> this platform").
> >>
> >> Also, perhaps you should allow that the compatible string can define the 
> >> default.
> >>
> > I hoped you would say that :).
> > 
> > I've attached a patch (on top of John Youn changes) that does
> > just that for the amcc,dwc-otg. I put the GAHBCFG_HBSTLEN_INCR
> > value into the .data, if that's a problem, I can certainly 
> > respin the patch and put it in a dedicated struct.
> > 
> > Regards
> > 
> > Christian
> > ---
> > From 4c31a029dde714828810b1c3e61a5b1412ac939a Mon Sep 17 00:00:00 2001
> > From: Christian Lamparter 
> > Date: Fri, 18 Nov 2016 21:03:19 +0100
> > Subject: [PATCH] usb: dwc2: add a default ahb-burst setting for amcc,dwc-otg
> > 
> > This patch adds a of_device_id table which can be used by
> > existing devices to supply a ahb-burst value for the platform
> > without having to add a "snps,ahb-burst" entry to the dts.
> > 
> > Note: Adding new devices to this table is discouraged.
> >   please consider adding the "snps,ahb-burst" property
> >   with the correct configuration to your device tree
> >   file instead.
> > 
> > Signed-off-by: Christian Lamparter 
> > ---
> >  drivers/usb/dwc2/params.c | 22 ++
> >  1 file changed, 22 insertions(+)
> > 
> > diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
> > index e0fc9aa..51be266 100644
> > --- a/drivers/usb/dwc2/params.c
> > +++ b/drivers/usb/dwc2/params.c
> > @@ -1097,6 +1097,22 @@ static const char *const ahb_bursts[] = {
> > [GAHBCFG_HBSTLEN_INCR16]= "INCR16",
> >  };
> >  
> > +/*
> > + * This table provides AHB burst configuration for existing
> > + * device tree bindings that work poorly with the default setting.
> > + *
> > + * Note: Adding new devices to this table is discouraged.
> > + *  please consider adding the "snps,ahb-burst" property
> > + *  with the correct configuration to your device tree
> > + *  file instead.
> > + */
> > +static const struct of_device_id dwc2_compat_ahb_bursts[] = {
> > +   {
> > +   .compatible = "amcc,dwc-otg",
> > +   .data = (void *) GAHBCFG_HBSTLEN_INCR16,
> > +   },
> > +};
> > +
> >  static int dwc2_get_property_ahb_burst(struct dwc2_hsotg *hsotg)
> >  {
> > struct device_node *node = hsotg->dev->of_node;
> > @@ -1107,6 +1123,12 @@ static int dwc2_get_property_ahb_burst(struct 
> > dwc2_hsotg *hsotg)
> > ret = device_property_read_string(hsotg->dev,
> >   "snps,ahb-burst", );
> > if (ret < 0) {
> > +   const struct of_device_id *match;
> > +
> > +   match = of_match_node(dwc2_compat_ahb_bursts, node);
> > +   if (match)
> > +

Re: crash by cdc_acm driver in kernels 4.8-rc1/5

2016-11-21 Thread Wim Osterholt
On Mon, Nov 21, 2016 at 04:58:25PM +0100, Wim Osterholt wrote:
> 
> I didn't find traces of kernel-4.9-rc5 being ran on any of my laptops, so I
> can't have seen a crash on rc5. It seems rc5 and rc6 is safe now.

Neither 4.8.10, nor 4.8.9 show the bug.
It must be a bug ouside cdc_acm that they have fixed. (a late propagation of
the IRQ-penalty-bug-fix maybe?)

I'm rebuilding 4.8.8 now.

Groeten, Wim.

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


Re: [PATCH v2 2/4] usb: dwc2: Add binding for AHB burst

2016-11-21 Thread John Youn
On 11/18/2016 12:18 PM, Christian Lamparter wrote:
> On Friday, November 18, 2016 8:16:08 AM CET Rob Herring wrote:
>> On Thu, Nov 17, 2016 at 04:35:10PM +0100, Stefan Wahren wrote:
>>> Hi John,
>>>
>>> Am 17.11.2016 um 00:47 schrieb John Youn:
 Add the "snps,ahb-burst" binding and read it in.

 This property controls which burst type to perform on the AHB bus as a
 master in internal DMA mode. This overrides the legacy param value,
 which we need to keep around for now since several platforms use it.

 Some platforms may see better or worse performance based on this
 value. The HAPS platform is one example where all INCRx have worse
 performance than INCR.

 Other platforms (such as the Canyonlands board) report that the default
 value causes system hangs.

 Signed-off-by: John Youn 
 Cc: Christian Lamparter 
 ---
  Documentation/devicetree/bindings/usb/dwc2.txt |  2 +
  drivers/usb/dwc2/core.h|  9 +
  drivers/usb/dwc2/params.c  | 56 
 ++
  3 files changed, 67 insertions(+)

 diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
 b/Documentation/devicetree/bindings/usb/dwc2.txt
 index 6c7c2bce..9e7b4b4 100644
 --- a/Documentation/devicetree/bindings/usb/dwc2.txt
 +++ b/Documentation/devicetree/bindings/usb/dwc2.txt
>>>
>>> according to Documentation/devicetree/bindings/submitting-patches.txt
>>> this change should be a separate patch.
>>>
 @@ -26,6 +26,8 @@ Optional properties:
  Refer to phy/phy-bindings.txt for generic phy consumer properties
  - dr_mode: shall be one of "host", "peripheral" and "otg"
Refer to usb/generic.txt
 +- snps,ahb-burst: specifies the ahb burst length. Valid arguments are:
 +  "SINGLE", "INCR", "INCR4", "INCR8", "INCR16". Defaults to "INCR4".
>>>
>>> This doesn't apply in case of the bcm2835. I would prefer this option is
>>> ignored in that case with a dev_warn("snps,ahb-burst is not supported on
>>> this platform").
>>
>> Also, perhaps you should allow that the compatible string can define the 
>> default.
>>
> I hoped you would say that :).
> 
> I've attached a patch (on top of John Youn changes) that does
> just that for the amcc,dwc-otg. I put the GAHBCFG_HBSTLEN_INCR
> value into the .data, if that's a problem, I can certainly 
> respin the patch and put it in a dedicated struct.
> 
> Regards
> 
> Christian
> ---
> From 4c31a029dde714828810b1c3e61a5b1412ac939a Mon Sep 17 00:00:00 2001
> From: Christian Lamparter 
> Date: Fri, 18 Nov 2016 21:03:19 +0100
> Subject: [PATCH] usb: dwc2: add a default ahb-burst setting for amcc,dwc-otg
> 
> This patch adds a of_device_id table which can be used by
> existing devices to supply a ahb-burst value for the platform
> without having to add a "snps,ahb-burst" entry to the dts.
> 
> Note: Adding new devices to this table is discouraged.
>   please consider adding the "snps,ahb-burst" property
>   with the correct configuration to your device tree
>   file instead.
> 
> Signed-off-by: Christian Lamparter 
> ---
>  drivers/usb/dwc2/params.c | 22 ++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/params.c b/drivers/usb/dwc2/params.c
> index e0fc9aa..51be266 100644
> --- a/drivers/usb/dwc2/params.c
> +++ b/drivers/usb/dwc2/params.c
> @@ -1097,6 +1097,22 @@ static const char *const ahb_bursts[] = {
>   [GAHBCFG_HBSTLEN_INCR16]= "INCR16",
>  };
>  
> +/*
> + * This table provides AHB burst configuration for existing
> + * device tree bindings that work poorly with the default setting.
> + *
> + * Note: Adding new devices to this table is discouraged.
> + *please consider adding the "snps,ahb-burst" property
> + *with the correct configuration to your device tree
> + *file instead.
> + */
> +static const struct of_device_id dwc2_compat_ahb_bursts[] = {
> + {
> + .compatible = "amcc,dwc-otg",
> + .data = (void *) GAHBCFG_HBSTLEN_INCR16,
> + },
> +};
> +
>  static int dwc2_get_property_ahb_burst(struct dwc2_hsotg *hsotg)
>  {
>   struct device_node *node = hsotg->dev->of_node;
> @@ -1107,6 +1123,12 @@ static int dwc2_get_property_ahb_burst(struct 
> dwc2_hsotg *hsotg)
>   ret = device_property_read_string(hsotg->dev,
> "snps,ahb-burst", );
>   if (ret < 0) {
> + const struct of_device_id *match;
> +
> + match = of_match_node(dwc2_compat_ahb_bursts, node);
> + if (match)
> + ret = (int)match->data;
> +
>   return ret;
>   } else if (of_device_is_compatible(node, "brcm,bcm2835-usb")) {
>   dev_warn(hsotg->dev,
> 

Hi Christian,

I'd prefer if you use the binding which requires no extra code in
dwc2.


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

2016-11-21 Thread Mark Brown
On Thu, Nov 17, 2016 at 05:46:13PM +1100, NeilBrown wrote:
> On Thu, Nov 17 2016, Mark Brown wrote:

> > To me that's pretty much what's being done here, the code just happens
> > to sit in USB instead but fundamentally it's just a blob of helper code,
> > you could replace the notifier with a callback if that's the big concern
> > here.

> It is a lot more than "just a blob of helper code".  It duplicates
> existing infrastructure instead of fixing and using the
> infrastructure but I've said all this before.  Repeatedly.

My read on that is that the question of what we want to be responsible
for aggregating the information about what power the system is allowed
to draw from a given USB port hasn't been resolved yet and that apart
from that you're fairly close.  It seems to me like that's really what
the difference between your two positions is.  Fixing the existing
notifiers implies that things have to be aggregated in the power supply
drivers but Baolin is proposing doing that in the USB code instead.  It
does seem at least worth considering if that's a good idea since the
current situation doesn't look terribly thought through.

There are a whole bunch of things that need to be sorted out whatever
the decision is like the extcon related cleanups you mentioned in your
mail the other day (steps 1 and 2), it seems like those could be moved
forwards independently.

By the way it occurred to me recently that we have a use case for
multiple USB ports that could supply power - USB C.  Things with more
than one port like things in a laptop form factor are going to want to
be able to use all of them interchangably for power support (likely only
one at a time, at least initially, but still more than one port).


signature.asc
Description: PGP signature


Re: [PATCH v2 3/3] usb: ohci-da8xx: rename driver to ohci-da8xx

2016-11-21 Thread Axel Haslam
Hi Greg,

On Thu, Nov 3, 2016 at 5:03 PM, Axel Haslam  wrote:
> The davinci ohci driver name (currently "ohci") is too generic.
> To be consistent with other usb dirvers, append the "-da8xx" postfix
> to the name.
>

if there are no objections, would it be possible to pick up this patch?
the corresponding phy patch was merged and the platform changes
are ack'ed, and will we taken by the davinci maintainer once this patch
gets in.

i can resend stand-alone if its preferred.

Regards
Axel

> Signed-off-by: Axel Haslam 
> ---
>  drivers/usb/host/ohci-da8xx.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
> index 30c4878..429d58b 100644
> --- a/drivers/usb/host/ohci-da8xx.c
> +++ b/drivers/usb/host/ohci-da8xx.c
> @@ -27,7 +27,7 @@
>  #include "ohci.h"
>
>  #define DRIVER_DESC "DA8XX"
> -#define DRV_NAME "ohci"
> +#define DRV_NAME "ohci-da8xx"
>
>  static struct hc_driver __read_mostly ohci_da8xx_hc_driver;
>
> --
> 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


Re: [PATCH v6] USB hub_probe: rework ugly goto-into-compound-statement

2016-11-21 Thread Greg Kroah-Hartman
On Sat, Nov 19, 2016 at 09:55:45AM +0300, Eugene Korenevsky wrote:
> Rework smelling code (goto inside compound statement). Perhaps this is
> legacy. Anyway such code is not appropriate for Linux kernel.
> 
> Signed-off-by: Eugene Korenevsky 
> ---
> Changes in v6: more pedantic conversion from `int` to `bool`; fix comment
> Changes in v5: make `bool` a return type of `hub_check_descriptor_sanity()`
> Changes in v4: fix typo
> Changes in v3: extract the code to static function
> Changes in v2: fix spaces instead of tab, add missing 'Signed-off-by'
> 
>  drivers/usb/core/hub.c | 38 +-
>  1 file changed, 21 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
> index cbb1467..dbebfe4 100644
> --- a/drivers/usb/core/hub.c
> +++ b/drivers/usb/core/hub.c
> @@ -1722,10 +1722,28 @@ static void hub_disconnect(struct usb_interface *intf)
>   kref_put(>kref, hub_release);
>  }
>  
> +static bool hub_check_descriptor_sanity(struct usb_host_interface *desc)
> +{
> + /* Some hubs have a subclass of 1, which AFAICT according to the */
> + /*  specs is not defined, but it works */
> + if (desc->desc.bInterfaceSubClass != 0 &&
> + desc->desc.bInterfaceSubClass != 1)
> + return false;
> +
> + /* Multiple endpoints? What kind of mutant ninja-hub is this? */
> + if (desc->desc.bNumEndpoints != 1)
> + return false;
> +
> + /* If the first endpoint is not interrupt IN, we'd better punt! */
> + if (!usb_endpoint_is_int_in(>endpoint[0].desc))
> + return false;
> +
> +return true;
> +}
> +
>  static int hub_probe(struct usb_interface *intf, const struct usb_device_id 
> *id)
>  {
>   struct usb_host_interface *desc;
> - struct usb_endpoint_descriptor *endpoint;
>   struct usb_device *hdev;
>   struct usb_hub *hub;
>  
> @@ -1800,25 +1818,11 @@ static int hub_probe(struct usb_interface *intf, 
> const struct usb_device_id *id)
>   }
>  #endif
>  
> - /* Some hubs have a subclass of 1, which AFAICT according to the */
> - /*  specs is not defined, but it works */
> - if ((desc->desc.bInterfaceSubClass != 0) &&
> - (desc->desc.bInterfaceSubClass != 1)) {
> -descriptor_error:
> + if (!hub_check_descriptor_sanity(desc)) {

Read that line out loud please, and tell me it makes sense:
If not hub_check_descriptor_sanity().

Doesn't:
If not hub_descriptor_is_sane()
make more sense?

thanks,

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


[PATCH v6 1/5] USB: ohci: da8xx: use ohci priv data instead of globals

2016-11-21 Thread Axel Haslam
Instead of global variables, use the extra_priv_size of
the ohci driver.

We cannot yet move the ocic mask because this is used on
the interrupt handler which is registerded through platform
data and does not have an hcd pointer. This will be moved
on a later patch.

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 73 +--
 1 file changed, 43 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index b3de8bc..aa6f904f 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -35,43 +35,50 @@ static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, 
u16 typeReq,
u16 wValue, u16 wIndex, char *buf, u16 wLength);
 static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
 
-static struct clk *usb11_clk;
-static struct phy *usb11_phy;
+struct da8xx_ohci_hcd {
+   struct clk *usb11_clk;
+   struct phy *usb11_phy;
+};
+
+#define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
 
 /* Over-current indicator change bitmask */
 static volatile u16 ocic_mask;
 
-static int ohci_da8xx_enable(void)
+static int ohci_da8xx_enable(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
int ret;
 
-   ret = clk_prepare_enable(usb11_clk);
+   ret = clk_prepare_enable(da8xx_ohci->usb11_clk);
if (ret)
return ret;
 
-   ret = phy_init(usb11_phy);
+   ret = phy_init(da8xx_ohci->usb11_phy);
if (ret)
goto err_phy_init;
 
-   ret = phy_power_on(usb11_phy);
+   ret = phy_power_on(da8xx_ohci->usb11_phy);
if (ret)
goto err_phy_power_on;
 
return 0;
 
 err_phy_power_on:
-   phy_exit(usb11_phy);
+   phy_exit(da8xx_ohci->usb11_phy);
 err_phy_init:
-   clk_disable_unprepare(usb11_clk);
+   clk_disable_unprepare(da8xx_ohci->usb11_clk);
 
return ret;
 }
 
-static void ohci_da8xx_disable(void)
+static void ohci_da8xx_disable(struct usb_hcd *hcd)
 {
-   phy_power_off(usb11_phy);
-   phy_exit(usb11_phy);
-   clk_disable_unprepare(usb11_clk);
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
+
+   phy_power_off(da8xx_ohci->usb11_phy);
+   phy_exit(da8xx_ohci->usb11_phy);
+   clk_disable_unprepare(da8xx_ohci->usb11_clk);
 }
 
 /*
@@ -97,7 +104,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
 
dev_dbg(dev, "starting USB controller\n");
 
-   result = ohci_da8xx_enable();
+   result = ohci_da8xx_enable(hcd);
if (result < 0)
return result;
 
@@ -109,7 +116,7 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
 
result = ohci_setup(hcd);
if (result < 0) {
-   ohci_da8xx_disable();
+   ohci_da8xx_disable(hcd);
return result;
}
 
@@ -231,6 +238,7 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
 static int ohci_da8xx_probe(struct platform_device *pdev)
 {
struct da8xx_ohci_root_hub *hub = dev_get_platdata(>dev);
+   struct da8xx_ohci_hcd *da8xx_ohci;
struct usb_hcd  *hcd;
struct resource *mem;
int error, irq;
@@ -238,25 +246,29 @@ static int ohci_da8xx_probe(struct platform_device *pdev)
if (hub == NULL)
return -ENODEV;
 
-   usb11_clk = devm_clk_get(>dev, "usb11");
-   if (IS_ERR(usb11_clk)) {
-   if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
+   hcd = usb_create_hcd(_da8xx_hc_driver, >dev,
+   dev_name(>dev));
+   if (!hcd)
+   return -ENOMEM;
+
+   da8xx_ohci = to_da8xx_ohci(hcd);
+
+   da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
+   if (IS_ERR(da8xx_ohci->usb11_clk)) {
+   error = PTR_ERR(da8xx_ohci->usb11_clk);
+   if (error != -EPROBE_DEFER)
dev_err(>dev, "Failed to get clock.\n");
-   return PTR_ERR(usb11_clk);
+   goto err;
}
 
-   usb11_phy = devm_phy_get(>dev, "usb-phy");
-   if (IS_ERR(usb11_phy)) {
-   if (PTR_ERR(usb11_phy) != -EPROBE_DEFER)
+   da8xx_ohci->usb11_phy = devm_phy_get(>dev, "usb-phy");
+   if (IS_ERR(da8xx_ohci->usb11_phy)) {
+   error = PTR_ERR(da8xx_ohci->usb11_phy);
+   if (error != -EPROBE_DEFER)
dev_err(>dev, "Failed to get phy.\n");
-   return PTR_ERR(usb11_phy);
+   goto err;
}
 
-   hcd = usb_create_hcd(_da8xx_hc_driver, >dev,
-   dev_name(>dev));
-   if (!hcd)
-   return -ENOMEM;
-
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
hcd->regs = devm_ioremap_resource(>dev, mem);
if (IS_ERR(hcd->regs)) {
@@ -320,7 +332,7 @@ static int 

[PATCH v6 3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-21 Thread Axel Haslam
Using a regulator to handle VBUS will eliminate the need for
platform data and callbacks, and make the driver more generic
allowing different types of regulators to handle VBUS.

The regulator equivalents to the platform callbacks are:
set_power   ->  regulator_enable/regulator_disable
get_power   ->  regulator_is_enabled
get_oci ->  regulator_get_error_flags
ocic_notify ->  regulator event notification

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 97 +--
 1 file changed, 94 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index 90763ad..d0eb754 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -36,8 +37,12 @@ static int (*orig_ohci_hub_control)(struct usb_hcd  *hcd, 
u16 typeReq,
 static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
 
 struct da8xx_ohci_hcd {
+   struct usb_hcd *hcd;
struct clk *usb11_clk;
struct phy *usb11_phy;
+   struct regulator *vbus_reg;
+   struct notifier_block nb;
+   unsigned int reg_enabled;
 };
 
 #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd *)(hcd_to_ohci(hcd)->priv)
@@ -83,56 +88,103 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)
 
 static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   int ret;
 
if (hub && hub->set_power)
return hub->set_power(1, on);
 
+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   if (on && !da8xx_ohci->reg_enabled) {
+   ret = regulator_enable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed to enable regulator: %d\n", ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 1;
+
+   } else if (!on && da8xx_ohci->reg_enabled) {
+   ret = regulator_disable(da8xx_ohci->vbus_reg);
+   if (ret) {
+   dev_err(dev, "Failed  to disable regulator: %d\n", ret);
+   return ret;
+   }
+   da8xx_ohci->reg_enabled = 0;
+   }
+
return 0;
 }
 
 static int ohci_da8xx_get_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
 
if (hub && hub->get_power)
return hub->get_power(1);
 
+   if (da8xx_ohci->vbus_reg)
+   return regulator_is_enabled(da8xx_ohci->vbus_reg);
+
return 1;
 }
 
 static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+   unsigned int flags;
+   int ret;
 
if (hub && hub->get_oci)
return hub->get_oci(1);
 
+   if (!da8xx_ohci->vbus_reg)
+   return 0;
+
+   ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, );
+   if (ret)
+   return ret;
+
+   if (flags & REGULATOR_ERROR_OVER_CURRENT)
+   return 1;
+
return 0;
 }
 
 static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
 
if (hub && hub->set_power)
return 1;
 
+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }
 
 static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
 {
+   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
struct device *dev  = hcd->self.controller;
struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
 
if (hub && hub->get_oci)
return 1;
 
+   if (da8xx_ohci->vbus_reg)
+   return 1;
+
return 0;
 }
 
@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct 
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }
 
+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+   unsigned long event, void *data)
+{
+   struct da8xx_ohci_hcd *da8xx_ohci =
+   container_of(nb, struct da8xx_ohci_hcd, nb);
+   struct device *dev = da8xx_ohci->hcd->self.controller;
+
+   if (event & REGULATOR_EVENT_OVER_CURRENT) {
+   dev_warn(dev, "over current event\n");
+   

[PATCH v6 5/5] USB: ohci: da8xx: Allow probing from DT

2016-11-21 Thread Axel Haslam
This adds the compatible string to the ohci driver
to be able to probe from DT

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index d0eb754..8b7479b 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -396,6 +396,13 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
 }
 
 /*-*/
+#ifdef CONFIG_OF
+static const struct of_device_id da8xx_ohci_ids[] = {
+   { .compatible = "ti,da830-ohci" },
+   { }
+};
+MODULE_DEVICE_TABLE(of, da8xx_ohci_ids);
+#endif
 
 static int ohci_da8xx_probe(struct platform_device *pdev)
 {
@@ -547,6 +554,7 @@ static struct platform_driver ohci_hcd_da8xx_driver = {
 #endif
.driver = {
.name   = DRV_NAME,
+   .of_match_table = of_match_ptr(da8xx_ohci_ids),
},
 };
 
-- 
2.9.3

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


[PATCH v6 0/5] USB: ohci-da8xx: Add device tree support

2016-11-21 Thread Axel Haslam
When booting using device tree, we can not make use of
platform callbacks to handle vbus and over current gpios.

This series allows the ohci-da8xx driver to use a regulator
instead of the platform callbacks to control vbus and adds
the device tree bindings to be able to probe using DT.

Once all users of the platform callbacks will be converted to
use a regulator, we will be able to remove platform data completely.

Changes from v5->v6
* Fix regulator over current flag check (David)
* Spelling fixes and code cleanups (David)
* add Ack for device tree binding

Changes from v4->v5
* Append the Device tree patches to v4.
* Submit only the first part of the series (no dependencies).
this can be applied and merged through the usb tree.

Changes from v3->v4
* separate the series into smaller series for driver and arch/arm code,
  to ease review and merging to different trees.

Changes form v2->v3
* drop patches that have been integrated to arch/arm
* drop regulator patches which will be integrated through regulator tree
* use of the accepted regulator API to get over current status
* better patch separation with the use of wrappers

Changes from v1->v2
* Rebased and added patch to make ohci a separate driver
* Use a regulator instead of handling Gpios (David Lechner)
* Add an over current mode to regulator framework
* Fixed regulator is able to register for and over current irq
* Added patch by Alexandre to remove build warnings
* Moved global variables into private hcd structure.
Axel Haslam (5):
  USB: ohci: da8xx: use ohci priv data instead of globals
  USB: ohci: da8xx: Add wrappers for platform callbacks
  USB: ohci: da8xx: Allow a regulator to handle VBUS
  USB: ohci: da8xx: Add devicetree bindings
  USB: ohci: da8xx: Allow probing from DT

 .../devicetree/bindings/usb/ohci-da8xx.txt |  23 ++
 drivers/usb/host/ohci-da8xx.c  | 291 +
 2 files changed, 264 insertions(+), 50 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/ohci-da8xx.txt

-- 
2.9.3

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


[PATCH v6 2/5] USB: ohci: da8xx: Add wrappers for platform callbacks

2016-11-21 Thread Axel Haslam
To migrate to a DT based boot, we will remove the use of platform
callbacks, in favor of using the regulator framework to handle
vbus and over current.

In preparation to use a regulator instead of callbacks, move the platform
data callbacks into separate functions. This provides well defined place
to for the regulator API to coexist with the platform callbacks before
all users are converted.

Signed-off-by: Axel Haslam 
---
 drivers/usb/host/ohci-da8xx.c | 125 ++
 1 file changed, 102 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
index aa6f904f..90763ad 100644
--- a/drivers/usb/host/ohci-da8xx.c
+++ b/drivers/usb/host/ohci-da8xx.c
@@ -81,6 +81,72 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)
clk_disable_unprepare(da8xx_ohci->usb11_clk);
 }
 
+static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->set_power)
+   return hub->set_power(1, on);
+
+   return 0;
+}
+
+static int ohci_da8xx_get_power(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->get_power)
+   return hub->get_power(1);
+
+   return 1;
+}
+
+static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->get_oci)
+   return hub->get_oci(1);
+
+   return 0;
+}
+
+static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->set_power)
+   return 1;
+
+   return 0;
+}
+
+static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->get_oci)
+   return 1;
+
+   return 0;
+}
+
+static int ohci_da8xx_has_potpgt(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->potpgt)
+   return 1;
+
+   return 0;
+}
+
 /*
  * Handle the port over-current indicator change.
  */
@@ -94,6 +160,26 @@ static void ohci_da8xx_ocic_handler(struct 
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }
 
+static int ohci_da8xx_register_notify(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->ocic_notify)
+   return hub->ocic_notify(ohci_da8xx_ocic_handler);
+
+   return 0;
+}
+
+static void ohci_da8xx_unregister_notify(struct usb_hcd *hcd)
+{
+   struct device *dev  = hcd->self.controller;
+   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
+
+   if (hub && hub->ocic_notify)
+   hub->ocic_notify(NULL);
+}
+
 static int ohci_da8xx_reset(struct usb_hcd *hcd)
 {
struct device *dev  = hcd->self.controller;
@@ -127,16 +213,18 @@ static int ohci_da8xx_reset(struct usb_hcd *hcd)
 * the correct hub descriptor...
 */
rh_a = ohci_readl(ohci, >regs->roothub.a);
-   if (hub->set_power) {
+   if (ohci_da8xx_has_set_power(hcd)) {
rh_a &= ~RH_A_NPS;
rh_a |=  RH_A_PSM;
}
-   if (hub->get_oci) {
+   if (ohci_da8xx_has_oci(hcd)) {
rh_a &= ~RH_A_NOCP;
rh_a |=  RH_A_OCPM;
}
-   rh_a &= ~RH_A_POTPGT;
-   rh_a |= hub->potpgt << 24;
+   if (ohci_da8xx_has_potpgt(hcd)) {
+   rh_a &= ~RH_A_POTPGT;
+   rh_a |= hub->potpgt << 24;
+   }
ohci_writel(ohci, rh_a, >regs->roothub.a);
 
return result;
@@ -169,7 +257,6 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, u16 
typeReq, u16 wValue,
  u16 wIndex, char *buf, u16 wLength)
 {
struct device *dev  = hcd->self.controller;
-   struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
int temp;
 
switch (typeReq) {
@@ -183,11 +270,11 @@ static int ohci_da8xx_hub_control(struct usb_hcd *hcd, 
u16 typeReq, u16 wValue,
temp = roothub_portstatus(hcd_to_ohci(hcd), wIndex - 1);
 
/* The port power status (PPS) bit defaults to 1 */
-   if (hub->get_power && hub->get_power(wIndex) == 0)
+   if (!ohci_da8xx_get_power(hcd))
temp &= 

[PATCH v6 4/5] USB: ohci: da8xx: Add devicetree bindings

2016-11-21 Thread Axel Haslam
This patch documents the device tree bindings required for
the ohci controller found in TI da8xx family of SoC's

Cc: robh...@kernel.org
Cc: mark.rutl...@arm.com
Cc: devicet...@vger.kernel.org
Acked-by: Rob Herring 
Signed-off-by: Axel Haslam 
---
 .../devicetree/bindings/usb/ohci-da8xx.txt | 23 ++
 1 file changed, 23 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ohci-da8xx.txt

diff --git a/Documentation/devicetree/bindings/usb/ohci-da8xx.txt 
b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
new file mode 100644
index 000..2dc8f67
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ohci-da8xx.txt
@@ -0,0 +1,23 @@
+DA8XX USB OHCI controller
+
+Required properties:
+
+ - compatible: Should be "ti,da830-ohci"
+ - reg:Should contain one register range i.e. start and length
+ - interrupts: Description of the interrupt line
+ - phys:   Phandle for the PHY device
+ - phy-names:  Should be "usb-phy"
+
+Optional properties:
+ - vbus-supply: phandle of regulator that controls vbus power / over-current
+
+Example:
+
+ohci: usb@0225000 {
+compatible = "ti,da830-ohci";
+reg = <0x225000 0x1000>;
+interrupts = <59>;
+phys = <_phy 1>;
+phy-names = "usb-phy";
+vbus-supply = <_usb_ohci>;
+};
-- 
2.9.3

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


Re: [v5,3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-21 Thread David Lechner

On 11/21/2016 04:22 AM, Axel Haslam wrote:

Hi David,

Thanks for the review,



You're welcome.



@@ -160,15 +212,41 @@ static void ohci_da8xx_ocic_handler(struct
da8xx_ohci_root_hub *hub,
hub->set_power(port, 0);
 }

+static int ohci_da8xx_regulator_event(struct notifier_block *nb,
+   unsigned long event, void *data)
+{
+   struct da8xx_ohci_hcd *da8xx_ohci =
+   container_of(nb, struct da8xx_ohci_hcd,
nb);
+   struct device *dev = da8xx_ohci->hcd->self.controller;
+
+   if (event & REGULATOR_EVENT_OVER_CURRENT) {
+   dev_warn(dev, "over current event\n");



Won't this result in duplicate overcurrent warnings in the kernel log? It
seems like in previous version of this patch series, we would get an
overcurrent error from the core usb driver.


you mean in the regulator driver? i did not make changes to core usb.
but, no,  i did not add a print in the fixed regulator driver itself. Since
the regulator is  a separate driver, and could be implemented with or without
a trace, i think its better to leave this print. It shows that the usb driver
has well received the notification.



No, I mean in drivers/usb/core/hub.c. There is

if (status & USB_PORT_STAT_OVERCURRENT)
dev_err(_dev->dev, "over-current condition\n");

and

if (status & HUB_STATUS_OVERCURRENT)
dev_err(hub_dev, "over-current condition\n");

In ohci_da8xx_hub_control(), we are setting RH_PS_POCI and RH_PS_OCIC, 
so these messages will be printed via the core hub driver. We don't need 
to print another message from the same event.




--
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: crash by cdc_acm driver in kernels 4.8-rc1/5

2016-11-21 Thread Wim Osterholt
On Mon, Nov 21, 2016 at 02:19:32PM +0100, Oliver Neukum wrote:
> On Thu, 2016-11-17 at 17:11 +0100, Wim Osterholt wrote:
> 
> > Nov 17 15:07:51 localhost kernel: Check point  10
> > Nov 17 15:07:51 localhost kernel: BUG: unable to handle kernel NULL pointer 
> > dereference at 0249
> > Nov 17 15:07:51 localhost kernel: IP: [] acm_probe+0x559/0xe53 
> > [cdc_acm]
> > Nov 17 15:07:51 localhost kernel: *pde =  
> > Nov 17 15:07:51 localhost kernel: Oops:  [#1] SMP
> 
> I don't understand it, bit please test the attached patch
> with dynamic debugging for cdc-acm and the kernel log level
> at maximum. And please repost "lsusb -v" for your device.

I didn't find traces of kernel-4.9-rc5 being ran on any of my laptops, so I
can't have seen a crash on rc5. It seems rc5 and rc6 is safe now.

I assume you want this on a crashing kernel, but I already removed the
sources. (Lack of space).
4.8.10 is now compiling, that was the fastest option. If that one doesn't
crash anymore I'll dig up 4.8.8 again.

lsusb -v:

Bus 004 Device 002: ID 0572:1340 Conexant Systems (Rockwell), Inc. 
Device Descriptor:
  bLength18
  bDescriptorType 1
  bcdUSB   1.10
  bDeviceClass2 Communications
  bDeviceSubClass 0 
  bDeviceProtocol 0 
  bMaxPacketSize064
  idVendor   0x0572 Conexant Systems (Rockwell), Inc.
  idProduct  0x1340 
  bcdDevice1.00
  iManufacturer   1 Conexant
  iProduct2 USB Modem
  iSerial 3 12345678
  bNumConfigurations  2
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   73
bNumInterfaces  2
bConfigurationValue 1
iConfiguration  0 
bmAttributes 0x80
  (Bus Powered)
MaxPower  100mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   1
  bInterfaceClass 2 Communications
  bInterfaceSubClass  2 Abstract (modem)
  bInterfaceProtocol  1 AT-commands (v.25ter)
  iInterface  0 
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81  EP 1 IN
bmAttributes3
  Transfer TypeInterrupt
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0040  1x 64 bytes
bInterval 128
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber1
  bAlternateSetting   0
  bNumEndpoints   2
  bInterfaceClass10 CDC Data
  bInterfaceSubClass  0 Unused
  bInterfaceProtocol  0 
  iInterface  0 
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x82  EP 2 IN
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0040  1x 64 bytes
bInterval   1
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x02  EP 2 OUT
bmAttributes2
  Transfer TypeBulk
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0040  1x 64 bytes
bInterval   1
  CDC Header:
bcdCDC   1.10
  CDC Call Management:
bmCapabilities   0x03
  call management
  use DataInterface
bDataInterface  1
  CDC ACM:
bmCapabilities   0x07
  sends break
  line coding and serial state
  get/set/clear comm features
  CDC Union:
bMasterInterface0
bSlaveInterface 1 
  Country Selection:
iCountryCodeRelDate4 04052004
wCountryCode  0x4803
  Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength   96
bNumInterfaces  3
bConfigurationValue 2
iConfiguration  0 
bmAttributes 0x80
  (Bus Powered)
MaxPower  100mA
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber0
  bAlternateSetting   0
  bNumEndpoints   1
  bInterfaceClass 2 Communications
  bInterfaceSubClass  2 Abstract (modem)
  bInterfaceProtocol  1 AT-commands (v.25ter)
  iInterface  0 
  Endpoint Descriptor:
bLength 7
bDescriptorType   

Re: [PATCH V2] usb: xhci: add support for performing fake doorbell

2016-11-21 Thread Mathias Nyman

On 21.11.2016 09:57, Rafał Miłecki wrote:

Hi Mathias,

On 17 October 2016 at 22:30, Rafał Miłecki  wrote:

From: Rafał Miłecki 

Broadcom's Northstar XHCI controllers seem to need a special start
procedure to work correctly. There isn't any official documentation of
this, the problem is that controller doesn't detect any connected
devices with default setup. Moreover connecting USB device to controller
that doesn't run properly can cause SoC's watchdog issues.

A workaround that was successfully tested on multiple devices is to
perform a fake doorbell. This patch adds code for doing this and enables
it on BCM4708 family.

Signed-off-by: Rafał Miłecki 
---
V2: Enable quirk for brcm,bcm4708 machines instead of adding separated binding
 for it. Thanks Rob for your comment on this.


Do you think you can pick & push this one? V2 follows Rob's suggestion
and he has some DT knowledge for sure, so I guess it should be OK.
--


Is there some more background information on this?

I don't have any contacts to Broadcom myself, adding the BMC Kernel Feedback 
list to CC.
Maybe someone over there has an errata, documentation or just general feedback.

How was this workaround even figured out? ringing the doorbell for the first
device doesn't seem like something found by trial and error,  especially when
xhci specs state that:

"Software shall not write the Doorbell of an endpoint until after it has issued 
a
Configure Endpoint Command for the endpoint and received a successful Command
Completion Event."

The whole workaround is a bit intrusive, allocating a fake device, ring a 
doorbell for a
fake device in the wrong state, clearing off HSE (host system error) which 
should only be set
when things really go bad, some random usleeps, and possible calling 
xhci_start() twice.

I can't take this as is without some more info.

-Mathias

--
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: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Guenter Roeck

On 11/21/2016 06:23 AM, Heikki Krogerus wrote:

On Mon, Nov 21, 2016 at 03:11:03PM +0200, Heikki Krogerus wrote:

Hi Greg,

On Mon, Nov 21, 2016 at 11:35:28AM +0100, Greg KH wrote:

+static void typec_partner_release(struct device *dev)
+{
+   struct typec_port *port = to_typec_port(dev->parent);
+
+   typec_unregister_altmodes(dev);
+   port->partner = NULL;
+}


This doesn't feel right, why are you both exporting
typec_unregister_altmodes() and also calling it from release callbacks?
That implies there is two way to clean stuff up, so what is a driver
writer to use?  Please simplify and force it to be one way or the other.


OK.


Guenter did you need to also remove the alternate modes in drivers, or
can we just do it here?



It is currently called explicitly on a data role change, when executing
a hard reset, on detach, and during error recovery. Most of those would
also unregister the partner, so I should be able to drop those calls
(or maybe I'll have to - I will see when testing), but I am not sure
how to handle data role changes.

Guenter

--
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/11] usb: musb: da8xx: Set phy in OTG mode by default

2016-11-21 Thread Bin Liu
From: Alexandre Bailon 

The DA8xx OTG PHY has some issues when it is forced in host or
peripheral mode. Actually, most of the time, OTG is the best mode
because host or peripheral mode are only required for hardware that
miss some circuitry.
Init the PHY mode OTG mode by default.

Signed-off-by: Alexandre Bailon 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/da8xx.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 373b61786fe0..e89708d839e5 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -343,6 +343,13 @@ static int da8xx_musb_set_mode(struct musb *musb, u8 
musb_mode)
struct da8xx_glue *glue = dev_get_drvdata(musb->controller->parent);
enum phy_mode phy_mode;
 
+   /*
+* The PHY has some issues when it is forced in device or host mode.
+* Unless the user request another mode, configure the PHY in OTG mode.
+*/
+   if (!musb->is_initialized)
+   return phy_set_mode(glue->phy, PHY_MODE_USB_OTG);
+
switch (musb_mode) {
case MUSB_HOST: /* Force VBUS valid, ID = 0 */
phy_mode = PHY_MODE_USB_HOST;
-- 
1.9.1

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


[PATCH 05/11] usb: musb: omap2430: use dev_err

2016-11-21 Thread Bin Liu
From: Ladislav Michl 

Replace pr_err with dev_err to print also device name.

Signed-off-by: Ladislav Michl 
Acked-by: Tony Lindgren 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/omap2430.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index cc1225485509..451b37252604 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -277,12 +277,12 @@ static int omap2430_musb_init(struct musb *musb)
if (status == -ENXIO)
return status;
 
-   pr_err("HS USB OTG: no transceiver configured\n");
+   dev_err(dev, "HS USB OTG: no transceiver configured\n");
return -EPROBE_DEFER;
}
 
if (IS_ERR(musb->phy)) {
-   pr_err("HS USB OTG: no PHY configured\n");
+   dev_err(dev, "HS USB OTG: no PHY configured\n");
return PTR_ERR(musb->phy);
}
musb->isr = omap2430_musb_interrupt;
@@ -301,7 +301,7 @@ static int omap2430_musb_init(struct musb *musb)
 
musb_writel(musb->mregs, OTG_INTERFSEL, l);
 
-   pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
+   dev_dbg(dev, "HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
"sysstatus 0x%x, intrfsel 0x%x, simenable  0x%x\n",
musb_readl(musb->mregs, OTG_REVISION),
musb_readl(musb->mregs, OTG_SYSCONFIG),
-- 
1.9.1

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


[PATCH 09/11] usb: musb: da8xx: Add DT support for the DA8xx driver

2016-11-21 Thread Bin Liu
From: Petr Kulhavy 

This adds DT support for TI DA8xx/OMAP-L1x/AM17xx/AM18xx MUSB driver

Signed-off-by: Petr Kulhavy 
Signed-off-by: Alexandre Bailon 
Tested-by: David Lechner 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/da8xx.c | 46 ++
 1 file changed, 46 insertions(+)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index 2440f88e07a3..f205a0381fcc 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -6,6 +6,9 @@
  * Based on the DaVinci "glue layer" code.
  * Copyright (C) 2005-2006 by Texas Instruments
  *
+ * DT support
+ * Copyright (c) 2016 Petr Kulhavy 
+ *
  * This file is part of the Inventra Controller Driver for Linux.
  *
  * The Inventra Controller Driver for Linux is free software; you
@@ -433,6 +436,21 @@ static int da8xx_musb_exit(struct musb *musb)
return 0;
 }
 
+static inline u8 get_vbus_power(struct device *dev)
+{
+   struct regulator *vbus_supply;
+   int current_uA;
+
+   vbus_supply = regulator_get_optional(dev, "vbus");
+   if (IS_ERR(vbus_supply))
+   return 255;
+   current_uA = regulator_get_current_limit(vbus_supply);
+   regulator_put(vbus_supply);
+   if (current_uA <= 0 || current_uA > 51)
+   return 255;
+   return current_uA / 1000 / 2;
+}
+
 static const struct musb_platform_ops da8xx_ops = {
.quirks = MUSB_DMA_CPPI | MUSB_INDEXED_EP,
.init   = da8xx_musb_init,
@@ -458,6 +476,12 @@ static int da8xx_musb_exit(struct musb *musb)
.dma_mask   = DMA_BIT_MASK(32),
 };
 
+static const struct musb_hdrc_config da8xx_config = {
+   .ram_bits = 10,
+   .num_eps = 5,
+   .multipoint = 1,
+};
+
 static int da8xx_probe(struct platform_device *pdev)
 {
struct resource musb_resources[2];
@@ -465,6 +489,7 @@ static int da8xx_probe(struct platform_device *pdev)
struct da8xx_glue   *glue;
struct platform_device_info pinfo;
struct clk  *clk;
+   struct device_node  *np = pdev->dev.of_node;
int ret;
 
glue = devm_kzalloc(>dev, sizeof(*glue), GFP_KERNEL);
@@ -487,6 +512,16 @@ static int da8xx_probe(struct platform_device *pdev)
glue->dev   = >dev;
glue->clk   = clk;
 
+   if (IS_ENABLED(CONFIG_OF) && np) {
+   pdata = devm_kzalloc(>dev, sizeof(*pdata), GFP_KERNEL);
+   if (!pdata)
+   return -ENOMEM;
+
+   pdata->config   = _config;
+   pdata->mode = musb_get_mode(>dev);
+   pdata->power= get_vbus_power(>dev);
+   }
+
pdata->platform_ops = _ops;
 
glue->usb_phy = usb_phy_generic_register();
@@ -537,11 +572,22 @@ static int da8xx_remove(struct platform_device *pdev)
return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id da8xx_id_table[] = {
+   {
+   .compatible = "ti,da830-musb",
+   },
+   {},
+};
+MODULE_DEVICE_TABLE(of, da8xx_id_table);
+#endif
+
 static struct platform_driver da8xx_driver = {
.probe  = da8xx_probe,
.remove = da8xx_remove,
.driver = {
.name   = "musb-da8xx",
+   .of_match_table = of_match_ptr(da8xx_id_table),
},
 };
 
-- 
1.9.1

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


[PATCH 07/11] dt/bindings: Add binding for the DA8xx MUSB driver

2016-11-21 Thread Bin Liu
From: Petr Kulhavy 

DT binding for the TI DA8xx/OMAP-L1x/AM17xx/AM18xx MUSB driver.

Signed-off-by: Petr Kulhavy 
Signed-off-by: Alexandre Bailon 
Acked-by: Rob Herring 
Signed-off-by: Bin Liu 
---
 .../devicetree/bindings/usb/da8xx-usb.txt  | 43 ++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/da8xx-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/da8xx-usb.txt 
b/Documentation/devicetree/bindings/usb/da8xx-usb.txt
new file mode 100644
index ..ccb844aba7d4
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/da8xx-usb.txt
@@ -0,0 +1,43 @@
+TI DA8xx MUSB
+~
+For DA8xx/OMAP-L1x/AM17xx/AM18xx platforms.
+
+Required properties:
+
+ - compatible : Should be set to "ti,da830-musb".
+
+ - reg: Offset and length of the USB controller register set.
+
+ - interrupts: The USB interrupt number.
+
+ - interrupt-names: Should be set to "mc".
+
+ - dr_mode: The USB operation mode. Should be one of "host", "peripheral" or 
"otg".
+
+ - phys: Phandle for the PHY device
+
+ - phy-names: Should be "usb-phy"
+
+Optional properties:
+
+ - vbus-supply: Phandle to a regulator providing the USB bus power.
+
+Example:
+   usb_phy: usb-phy {
+   compatible = "ti,da830-usb-phy";
+   #phy-cells = <0>;
+   status = "okay";
+   };
+   usb0: usb@20 {
+   compatible = "ti,da830-musb";
+   reg =   <0x0020 0x1>;
+   interrupts = <58>;
+   interrupt-names = "mc";
+
+   dr_mode = "host";
+   vbus-supply = <_vbus>;
+   phys = <_phy 0>;
+   phy-names = "usb-phy";
+
+   status = "okay";
+   };
-- 
1.9.1

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


[PATCH 08/11] usb: musb: core: added helper function for parsing DT

2016-11-21 Thread Bin Liu
From: Petr Kulhavy 

This adds the function musb_get_mode() to get the DT property "dr_mode"

Signed-off-by: Petr Kulhavy 
Acked-by: Sergei Shtylyov 
Signed-off-by: Alexandre Bailon 
Tested-by: David Lechner 
Reviewed-by: Kevin Hilman 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 19 +++
 drivers/usb/musb/musb_core.h |  6 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 3dc74d466a98..468171006e70 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -100,6 +100,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "musb_core.h"
 #include "musb_trace.h"
@@ -130,6 +131,24 @@ static inline struct musb *dev_to_musb(struct device *dev)
return dev_get_drvdata(dev);
 }
 
+enum musb_mode musb_get_mode(struct device *dev)
+{
+   enum usb_dr_mode mode;
+
+   mode = usb_get_dr_mode(dev);
+   switch (mode) {
+   case USB_DR_MODE_HOST:
+   return MUSB_HOST;
+   case USB_DR_MODE_PERIPHERAL:
+   return MUSB_PERIPHERAL;
+   case USB_DR_MODE_OTG:
+   case USB_DR_MODE_UNKNOWN:
+   default:
+   return MUSB_OTG;
+   }
+}
+EXPORT_SYMBOL_GPL(musb_get_mode);
+
 /*-*/
 
 #ifndef CONFIG_BLACKFIN
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index c04abf424c5c..ed5e354b0891 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -619,4 +619,10 @@ static inline void 
musb_platform_post_root_reset_end(struct musb *musb)
musb->ops->post_root_reset_end(musb);
 }
 
+/*
+ * gets the "dr_mode" property from DT and converts it into musb_mode
+ * if the property is not found or not recognized returns MUSB_OTG
+ */
+extern enum musb_mode musb_get_mode(struct device *dev);
+
 #endif /* __MUSB_CORE_H__ */
-- 
1.9.1

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


[PATCH 10/11] usb: musb: da8xx: Call earlier clk_prepare_enable()

2016-11-21 Thread Bin Liu
From: Alexandre Bailon 

The first attempt to read a register may fail because the clock may not
be enabled, and then the probe of musb driver will fail.
Call clk_prepare_enable() before the first register read.

Signed-off-by: Alexandre Bailon 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/da8xx.c | 17 -
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index f205a0381fcc..373b61786fe0 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -369,6 +369,12 @@ static int da8xx_musb_init(struct musb *musb)
 
musb->mregs += DA8XX_MENTOR_CORE_OFFSET;
 
+   ret = clk_prepare_enable(glue->clk);
+   if (ret) {
+   dev_err(glue->dev, "failed to enable clock\n");
+   return ret;
+   }
+
/* Returns zero if e.g. not clocked */
rev = musb_readl(reg_base, DA8XX_USB_REVISION_REG);
if (!rev)
@@ -380,12 +386,6 @@ static int da8xx_musb_init(struct musb *musb)
goto fail;
}
 
-   ret = clk_prepare_enable(glue->clk);
-   if (ret) {
-   dev_err(glue->dev, "failed to enable clock\n");
-   goto fail;
-   }
-
setup_timer(_workaround, otg_timer, (unsigned long)musb);
 
/* Reset the controller */
@@ -395,7 +395,7 @@ static int da8xx_musb_init(struct musb *musb)
ret = phy_init(glue->phy);
if (ret) {
dev_err(glue->dev, "Failed to init phy.\n");
-   goto err_phy_init;
+   goto fail;
}
 
ret = phy_power_on(glue->phy);
@@ -415,9 +415,8 @@ static int da8xx_musb_init(struct musb *musb)
 
 err_phy_power_on:
phy_exit(glue->phy);
-err_phy_init:
-   clk_disable_unprepare(glue->clk);
 fail:
+   clk_disable_unprepare(glue->clk);
return ret;
 }
 
-- 
1.9.1

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


[PATCH 06/11] usb: musb: omap2430: make complain on -EPROBE_DEFER dev_dbg

2016-11-21 Thread Bin Liu
From: Ladislav Michl 

There is no point having this complaint to be dev_err as it is just adding
noise to bootlog.

Signed-off-by: Ladislav Michl 
Acked-by: Tony Lindgren 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/omap2430.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 451b37252604..7c9aa5e78666 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -277,7 +277,7 @@ static int omap2430_musb_init(struct musb *musb)
if (status == -ENXIO)
return status;
 
-   dev_err(dev, "HS USB OTG: no transceiver configured\n");
+   dev_dbg(dev, "HS USB OTG: no transceiver configured\n");
return -EPROBE_DEFER;
}
 
-- 
1.9.1

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


[PATCH 04/11] usb: musb: don't complain on -EPROBE_DEFER when initializing controller

2016-11-21 Thread Bin Liu
From: Ladislav Michl 

Don't complain on -EPROBE_DEFER when initializing controller,
the driver probe will be retried later.

Signed-off-by: Ladislav Michl 
Acked-by: Tony Lindgren 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 7074b2c557ca..3dc74d466a98 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2323,8 +2323,9 @@ static void musb_deassert_reset(struct work_struct *work)
musb_platform_exit(musb);
 
 fail1:
-   dev_err(musb->controller,
-   "musb_init_controller failed with status %d\n", status);
+   if (status != -EPROBE_DEFER)
+   dev_err(musb->controller,
+   "%s failed with status %d\n", __func__, status);
 
musb_free(musb);
 
-- 
1.9.1

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


[PATCH 03/11] musb: sunxi: Force session end on babble errors in host-mode

2016-11-21 Thread Bin Liu
From: Hans de Goede 

The sunxi musb has a bug where sometimes it will generate a babble
error on device disconnect instead of a disconnect irq. When this
happens the musb-controller switches from host mode to device mode
(it clears MUSB_DEVCTL_SESSION and sets MUSB_DEVCTL_BDEVICE) and
gets stuck in this state.

Clearing this requires reporting Vbus low for 200 or more ms, but
on some devices Vbus is simply always high (host-only mode, no Vbus
control).

This commit adds a sunxi_musb_recover() callback which makes
sunxi_musb_work call phy_set_mode with the current mode, which
will force end the current session.

This fixes the musb controller getting stuck in this state on systems
without Vbus control; and also fixes the need to unplug the usb-b ->
usb-a cable to get out of this state on systems with Vbus control.

Signed-off-by: Hans de Goede 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/sunxi.c | 15 +++
 1 file changed, 15 insertions(+)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 82eba92284c0..d0be0eadd0d9 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -380,6 +380,20 @@ static int sunxi_musb_set_mode(struct musb *musb, u8 mode)
return 0;
 }
 
+static int sunxi_musb_recover(struct musb *musb)
+{
+   struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+
+   /*
+* Schedule a phy_set_mode with the current glue->phy_mode value,
+* this will force end the current session.
+*/
+   set_bit(SUNXI_MUSB_FL_PHY_MODE_PEND, >flags);
+   schedule_work(>work);
+
+   return 0;
+}
+
 /*
  * sunxi musb register layout
  * 0x00 - 0x17 fifo regs, 1 long per fifo
@@ -608,6 +622,7 @@ static void sunxi_musb_writew(void __iomem *addr, unsigned 
offset, u16 data)
.dma_init   = sunxi_musb_dma_controller_create,
.dma_exit   = sunxi_musb_dma_controller_destroy,
.set_mode   = sunxi_musb_set_mode,
+   .recover= sunxi_musb_recover,
.set_vbus   = sunxi_musb_set_vbus,
.pre_root_reset_end = sunxi_musb_pre_root_reset_end,
.post_root_reset_end = sunxi_musb_post_root_reset_end,
-- 
1.9.1

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


[PATCH 01/11] USB: musb: remove obsolete resume-signalling comments

2016-11-21 Thread Bin Liu
From: Johan Hovold 

Remove comments about resume signalling being stopped from
GetPortStatus, something which is no longer the case.

Fixes: 8ed1fb790ea2 ("usb: musb: finish suspend/reset work...")
Signed-off-by: Johan Hovold 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_core.c| 5 +
 drivers/usb/musb/musb_virthub.c | 1 -
 2 files changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index c95163f1edeb..7074b2c557ca 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -569,10 +569,7 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 
int_usb,
if (devctl & MUSB_DEVCTL_HM) {
switch (musb->xceiv->otg->state) {
case OTG_STATE_A_SUSPEND:
-   /* remote wakeup?  later, GetPortStatus
-* will stop RESUME signaling
-*/
-
+   /* remote wakeup? */
musb->port1_status |=
(USB_PORT_STAT_C_SUSPEND << 16)
| MUSB_PORT_STAT_RESUME;
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 61b5f1c3c5bc..0b4595439d51 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -132,7 +132,6 @@ void musb_port_suspend(struct musb *musb, bool do_suspend)
 
musb_dbg(musb, "Root port resuming, power %02x", power);
 
-   /* later, GetPortStatus will stop RESUME signaling */
musb->port1_status |= MUSB_PORT_STAT_RESUME;
schedule_delayed_work(>finish_resume_work,
  msecs_to_jiffies(USB_RESUME_TIMEOUT));
-- 
1.9.1

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


Re: [PATCH] USB: serial: cp210x: Use tcflag_t to fix incompatible pointer type

2016-11-21 Thread Johan Hovold
On Mon, Nov 21, 2016 at 01:19:31PM +0100, Geert Uytterhoeven wrote:
> On sparc32, tcflag_t is unsigned long, unlike all other architectures:
> 
> drivers/usb/serial/cp210x.c: In function 'cp210x_get_termios':
> drivers/usb/serial/cp210x.c:717:3: warning: passing argument 2 of 
> 'cp210x_get_termios_port' from incompatible pointer type
>cp210x_get_termios_port(tty->driver_data,
>^
> drivers/usb/serial/cp210x.c:35:13: note: expected 'unsigned int *' but 
> argument is of type 'tcflag_t *'
>  static void cp210x_get_termios_port(struct usb_serial_port *port,
>^
> 
> Consistently use tcflag_t to fix this.
>
> Signed-off-by: Geert Uytterhoeven 

Applied for -next as this an old warning for something that should be
benign on 32-bit.

Thanks,
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 02/11] musb: sunxi: Remove custom babble handling

2016-11-21 Thread Bin Liu
From: Hans de Goede 

The musb core already handles babble interrupts, so the sunxi glue
having its own custom handling is redundant.

Signed-off-by: Hans de Goede 
Signed-off-by: Bin Liu 
---
 drivers/usb/musb/sunxi.c | 10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index 1408245be18e..82eba92284c0 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -186,16 +186,6 @@ static irqreturn_t sunxi_musb_interrupt(int irq, void 
*__hci)
if (musb->int_usb)
writeb(musb->int_usb, musb->mregs + SUNXI_MUSB_INTRUSB);
 
-   /*
-* sunxi musb often signals babble on low / full speed device
-* disconnect, without ever raising MUSB_INTR_DISCONNECT, since
-* normally babble never happens treat it as disconnect.
-*/
-   if ((musb->int_usb & MUSB_INTR_BABBLE) && is_host_active(musb)) {
-   musb->int_usb &= ~MUSB_INTR_BABBLE;
-   musb->int_usb |= MUSB_INTR_DISCONNECT;
-   }
-
if ((musb->int_usb & MUSB_INTR_RESET) && !is_host_active(musb)) {
/* ep0 FADDR must be 0 when (re)entering peripheral mode */
musb_ep_select(musb->mregs, 0);
-- 
1.9.1

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


[PATCH 00/11] musb patches for v4.10-rc1

2016-11-21 Thread Bin Liu
Hi Greg,

This musb set is for next v4.10-rc. It adds DA8xx DT support, fixes babble
handling in sunxi driver. The rest of the patches are cleanup in comments or
log messages. Please let me know if any change is needed.

Thanks,
-Bin.
---

Alexandre Bailon (2):
  usb: musb: da8xx: Call earlier clk_prepare_enable()
  usb: musb: da8xx: Set phy in OTG mode by default

Hans de Goede (2):
  musb: sunxi: Remove custom babble handling
  musb: sunxi: Force session end on babble errors in host-mode

Johan Hovold (1):
  USB: musb: remove obsolete resume-signalling comments

Ladislav Michl (3):
  usb: musb: don't complain on -EPROBE_DEFER when initializing
controller
  usb: musb: omap2430: use dev_err
  usb: musb: omap2430: make complain on -EPROBE_DEFER dev_dbg

Petr Kulhavy (3):
  dt/bindings: Add binding for the DA8xx MUSB driver
  usb: musb: core: added helper function for parsing DT
  usb: musb: da8xx: Add DT support for the DA8xx driver

 .../devicetree/bindings/usb/da8xx-usb.txt  | 43 +
 drivers/usb/musb/da8xx.c   | 70 +++---
 drivers/usb/musb/musb_core.c   | 29 +++--
 drivers/usb/musb/musb_core.h   |  6 ++
 drivers/usb/musb/musb_virthub.c|  1 -
 drivers/usb/musb/omap2430.c|  6 +-
 drivers/usb/musb/sunxi.c   | 25 
 7 files changed, 151 insertions(+), 29 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/da8xx-usb.txt

-- 
1.9.1

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


Re: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Greg KH
On Mon, Nov 21, 2016 at 03:11:03PM +0200, Heikki Krogerus wrote:
> Hi Greg,
> 
> On Mon, Nov 21, 2016 at 11:35:28AM +0100, Greg KH wrote:
> > > +static void typec_partner_release(struct device *dev)
> > > +{
> > > + struct typec_port *port = to_typec_port(dev->parent);
> > > +
> > > + typec_unregister_altmodes(dev);
> > > + port->partner = NULL;
> > > +}
> > 
> > This doesn't feel right, why are you both exporting
> > typec_unregister_altmodes() and also calling it from release callbacks?
> > That implies there is two way to clean stuff up, so what is a driver
> > writer to use?  Please simplify and force it to be one way or the other.
> 
> OK.
> 
> > Also typec_unregister_altmodes() doesn't free memory, which release is
> > supposed to be doing, which also implies that the reference counting
> > logic is all wrong here.  Please fix, like I asked you to previously.
> 
> There is nothing wrong with the reference counting, and nothing has
> been allocated so there is nothing to free.

The device structure itself that this release call is for needs to
be freed, right?  If not, something is really wrong...

> Please note that the partner device is meant to just represent the
> partner in user space and not to be actually used for anything. And
> please also note that there can only be one partner for a port at a
> time.

Ok, but these are still reference counted devices, you need to handle
that properly.

> We could allocate an extra structure for the partner when
> typec_connect() is called, but we would do that just for the sake of
> having something to free in the release hook. It would not be useful
> for anything. It would not help us increase/decrease the reference
> count of the device, and the port driver would still have to provide
> details about the partner capabilities the moment it tells us the
> partner was connected.

Again, free the device for which this release function is being called
for, that is why it is there.

thanks,

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


Re: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Greg KH
On Mon, Nov 21, 2016 at 03:27:41PM +0200, Heikki Krogerus wrote:
> On Mon, Nov 21, 2016 at 11:33:11AM +0100, Greg KH wrote:
> > On Thu, Nov 17, 2016 at 12:50:35PM +0200, Heikki Krogerus wrote:
> > > The purpose of USB Type-C connector class is to provide
> > > unified interface for the user space to get the status and
> > > basic information about USB Type-C connectors on a system,
> > > control over data role swapping, and when the port supports
> > > USB Power Delivery, also control over power role swapping
> > > and Alternate Modes.
> > > 
> > > Signed-off-by: Heikki Krogerus 
> > 
> > I'd like to get some acks or reviewed-by from others, but one thing
> > jumped out at me, which implies you did not run checkpatch.pl on the
> > patch:
> > 
> > 644
> 
> OK.
> 
> > > --- a/drivers/usb/Kconfig
> > > +++ b/drivers/usb/Kconfig
> > > @@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig"
> > >  
> > >  source "drivers/usb/gadget/Kconfig"
> > >  
> > > +source "drivers/usb/typec/Kconfig"
> > > +
> > >  config USB_LED_TRIG
> > >   bool "USB LED Triggers"
> > >   depends on LEDS_CLASS && LEDS_TRIGGERS
> > > diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> > > index 7791af6..c7f4098 100644
> > > --- a/drivers/usb/Makefile
> > > +++ b/drivers/usb/Makefile
> > > @@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET)+= gadget/
> > >  obj-$(CONFIG_USB_COMMON) += common/
> > >  
> > >  obj-$(CONFIG_USBIP_CORE) += usbip/
> > > +
> > > +obj-$(CONFIG_TYPEC)  += typec/
> > > diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
> > > new file mode 100644
> > > index 000..b229fb9
> > > --- /dev/null
> > > +++ b/drivers/usb/typec/Kconfig
> > > @@ -0,0 +1,7 @@
> > > +
> > > +menu "USB PD and Type-C drivers"
> > 
> > What is "PD"?  (yes, I know, but very few people do...)  Spell it out.
> 
> OK.
> 
> > > +
> > > +config TYPEC
> > > + tristate
> > 
> > Hah, that says NOTHING about what this code is at all.
> 
> Alone the class driver does nothing. Why would the user need to be
> aware of if it when selecting the Type-C drivers, and what can the
> user use that information for?

If you see a blank Kconfig option, what are you supposed to do with it?
How do you know if you need to enable it or not?  Are you just supposed
to guess?

That is what the help text is for...

thanks,

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


Re: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Heikki Krogerus
On Mon, Nov 21, 2016 at 03:11:03PM +0200, Heikki Krogerus wrote:
> Hi Greg,
> 
> On Mon, Nov 21, 2016 at 11:35:28AM +0100, Greg KH wrote:
> > > +static void typec_partner_release(struct device *dev)
> > > +{
> > > + struct typec_port *port = to_typec_port(dev->parent);
> > > +
> > > + typec_unregister_altmodes(dev);
> > > + port->partner = NULL;
> > > +}
> > 
> > This doesn't feel right, why are you both exporting
> > typec_unregister_altmodes() and also calling it from release callbacks?
> > That implies there is two way to clean stuff up, so what is a driver
> > writer to use?  Please simplify and force it to be one way or the other.
> 
> OK.

Guenter did you need to also remove the alternate modes in drivers, or
can we just do it here?

Thanks,

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


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

2016-11-21 Thread Mauro Carvalho Chehab
Em Mon, 31 Oct 2016 12:48:05 +0200
Felipe Balbi  escreveu:

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

Good idea! Btw, we have something similar at em28xx, stk1160-core.c and
tm6000 drivers. On them, we have this:
/* high bandwidth multiplier, as encoded in highspeed endpoint 
descriptors */
#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))

PLease add the same changes for the above files on this patch.

Btw, are you planning to send this patch via USB tree or via the
media one? If you want to send via USB, after this change,
feel free to add my ack:

Acked-by: Mauro Carvalho Chehab 


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


Thanks,
Mauro
--
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: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Heikki Krogerus
On Mon, Nov 21, 2016 at 11:33:11AM +0100, Greg KH wrote:
> On Thu, Nov 17, 2016 at 12:50:35PM +0200, Heikki Krogerus wrote:
> > The purpose of USB Type-C connector class is to provide
> > unified interface for the user space to get the status and
> > basic information about USB Type-C connectors on a system,
> > control over data role swapping, and when the port supports
> > USB Power Delivery, also control over power role swapping
> > and Alternate Modes.
> > 
> > Signed-off-by: Heikki Krogerus 
> 
> I'd like to get some acks or reviewed-by from others, but one thing
> jumped out at me, which implies you did not run checkpatch.pl on the
> patch:
> 
> 644

OK.

> > --- a/drivers/usb/Kconfig
> > +++ b/drivers/usb/Kconfig
> > @@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig"
> >  
> >  source "drivers/usb/gadget/Kconfig"
> >  
> > +source "drivers/usb/typec/Kconfig"
> > +
> >  config USB_LED_TRIG
> > bool "USB LED Triggers"
> > depends on LEDS_CLASS && LEDS_TRIGGERS
> > diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> > index 7791af6..c7f4098 100644
> > --- a/drivers/usb/Makefile
> > +++ b/drivers/usb/Makefile
> > @@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET)  += gadget/
> >  obj-$(CONFIG_USB_COMMON)   += common/
> >  
> >  obj-$(CONFIG_USBIP_CORE)   += usbip/
> > +
> > +obj-$(CONFIG_TYPEC)+= typec/
> > diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
> > new file mode 100644
> > index 000..b229fb9
> > --- /dev/null
> > +++ b/drivers/usb/typec/Kconfig
> > @@ -0,0 +1,7 @@
> > +
> > +menu "USB PD and Type-C drivers"
> 
> What is "PD"?  (yes, I know, but very few people do...)  Spell it out.

OK.

> > +
> > +config TYPEC
> > +   tristate
> 
> Hah, that says NOTHING about what this code is at all.

Alone the class driver does nothing. Why would the user need to be
aware of if it when selecting the Type-C drivers, and what can the
user use that information for?


Thanks,

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


Re: crash by cdc_acm driver in kernels 4.8-rc1/5

2016-11-21 Thread Oliver Neukum
On Thu, 2016-11-17 at 17:11 +0100, Wim Osterholt wrote:

> Nov 17 15:07:51 localhost kernel: Check point  10
> Nov 17 15:07:51 localhost kernel: BUG: unable to handle kernel NULL pointer 
> dereference at 0249
> Nov 17 15:07:51 localhost kernel: IP: [] acm_probe+0x559/0xe53 
> [cdc_acm]
> Nov 17 15:07:51 localhost kernel: *pde =  
> Nov 17 15:07:51 localhost kernel: Oops:  [#1] SMP

I don't understand it, bit please test the attached patch
with dynamic debugging for cdc-acm and the kernel log level
at maximum. And please repost "lsusb -v" for your device.

Regards
Oliver

From 51665f8ce6e13ba11b93b856290135bfe529d835 Mon Sep 17 00:00:00 2001
From: Oliver Neukum 
Date: Mon, 21 Nov 2016 14:08:31 +0100
Subject: [PATCH] CDC-ACM: debugging for parsed descriptors

This is necessary to debug the parser on malformed headers.

Signed-off-by: Oliver Neukum 
---
 drivers/usb/class/cdc-acm.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6895f9e..f03b5db 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -1188,6 +1188,12 @@ static int acm_probe(struct usb_interface *intf,
 
 	cdc_parse_cdc_header(, intf, buffer, buflen);
 	union_header = h.usb_cdc_union_desc;
+
+	dev_dbg(>dev, "Parsed device header\n");
+	dev_dbg(>dev, "Union descriptor %p\n", h.usb_cdc_union_desc);
+	dev_dbg(>dev, "ACM descriptor %p\n", h.usb_cdc_acm_descriptor);
+	dev_dbg(>dev, "Country descriptor %p\n", h.usb_cdc_country_functional_desc);
+
 	cmgmd = h.usb_cdc_call_mgmt_descriptor;
 	if (cmgmd)
 		call_intf_num = cmgmd->bDataInterface;
-- 
2.1.4



Re: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Heikki Krogerus
Hi Greg,

On Mon, Nov 21, 2016 at 11:35:28AM +0100, Greg KH wrote:
> > +static void typec_partner_release(struct device *dev)
> > +{
> > +   struct typec_port *port = to_typec_port(dev->parent);
> > +
> > +   typec_unregister_altmodes(dev);
> > +   port->partner = NULL;
> > +}
> 
> This doesn't feel right, why are you both exporting
> typec_unregister_altmodes() and also calling it from release callbacks?
> That implies there is two way to clean stuff up, so what is a driver
> writer to use?  Please simplify and force it to be one way or the other.

OK.

> Also typec_unregister_altmodes() doesn't free memory, which release is
> supposed to be doing, which also implies that the reference counting
> logic is all wrong here.  Please fix, like I asked you to previously.

There is nothing wrong with the reference counting, and nothing has
been allocated so there is nothing to free.

Please note that the partner device is meant to just represent the
partner in user space and not to be actually used for anything. And
please also note that there can only be one partner for a port at a
time.

We could allocate an extra structure for the partner when
typec_connect() is called, but we would do that just for the sake of
having something to free in the release hook. It would not be useful
for anything. It would not help us increase/decrease the reference
count of the device, and the port driver would still have to provide
details about the partner capabilities the moment it tells us the
partner was connected.


Thanks,

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


Re: [PATCH v2 1/3] usb: xhci: add quirk flag for broken PED bits

2016-11-21 Thread Roger Quadros
On 21/11/16 13:56, Felipe Balbi wrote:
> 
> Hi,
> 
> Roger Quadros  writes:
>> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
>> index f945380..6553903 100644
>> --- a/drivers/usb/host/xhci.h
>> +++ b/drivers/usb/host/xhci.h
>> @@ -1656,6 +1656,9 @@ struct xhci_hcd {
>>  #define XHCI_SSIC_PORT_UNUSED   (1 << 22)
>>  #define XHCI_NO_64BIT_SUPPORT   (1 << 23)
>>  #define XHCI_MISSING_CAS(1 << 24)
>> +/* For controller with a broken Port Disable implementation */
>> +#define XHCI_BROKEN_PORT_PED(1 << 21)
> 
> since back when I first wrote this, bit 21 has been taken. You should be
> using bit 25 here.
> 
My bad. I'll fix this up.

cheers,
-roger



signature.asc
Description: OpenPGP digital signature


[PATCH v3 1/3] usb: xhci: add quirk flag for broken PED bits

2016-11-21 Thread Roger Quadros
From: Felipe Balbi 

Some devices from Texas Instruments [1] suffer from
a silicon bug where Port Enabled/Disabled bit
should not be used to silence an erroneous device.

The bug is so that if port is disabled with PED
bit, an IRQ for device removal (or attachment)
will never fire.

Just for the sake of completeness, the actual
problem lies with SNPS USB IP and this affects
all known versions up to 3.00a. A separate
patch will be added to dwc3 to enabled this
quirk flag if version is <= 3.00a.

[1] - AM572x Silicon Errata http://www.ti.com/lit/er/sprz429j/sprz429j.pdf
Section i896— USB xHCI Port Disable Feature Does Not Work

Signed-off-by: Felipe Balbi 
Signed-off-by: Roger Quadros 
---
 drivers/usb/host/xhci-hub.c | 6 ++
 drivers/usb/host/xhci.h | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0ef1690..1d41637 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -458,6 +458,12 @@ static void xhci_disable_port(struct usb_hcd *hcd, struct 
xhci_hcd *xhci,
return;
}
 
+   if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
+   xhci_dbg(xhci,
+"Broken Port Enabled/Disabled, ignoring port disable 
request.\n");
+   return;
+   }
+
/* Write 1 to disable the port */
writel(port_status | PORT_PE, addr);
port_status = readl(addr);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f945380..585af71 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1656,6 +1656,9 @@ struct xhci_hcd {
 #define XHCI_SSIC_PORT_UNUSED  (1 << 22)
 #define XHCI_NO_64BIT_SUPPORT  (1 << 23)
 #define XHCI_MISSING_CAS   (1 << 24)
+/* For controller with a broken Port Disable implementation */
+#define XHCI_BROKEN_PORT_PED   (1 << 25)
+
unsigned intnum_active_eps;
unsigned intlimit_active_eps;
/* There are two roothubs to keep track of bus suspend info for */
-- 
2.7.4


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


[PATCH] USB: serial: cp210x: Use tcflag_t to fix incompatible pointer type

2016-11-21 Thread Geert Uytterhoeven
On sparc32, tcflag_t is unsigned long, unlike all other architectures:

drivers/usb/serial/cp210x.c: In function 'cp210x_get_termios':
drivers/usb/serial/cp210x.c:717:3: warning: passing argument 2 of 
'cp210x_get_termios_port' from incompatible pointer type
   cp210x_get_termios_port(tty->driver_data,
   ^
drivers/usb/serial/cp210x.c:35:13: note: expected 'unsigned int *' but 
argument is of type 'tcflag_t *'
 static void cp210x_get_termios_port(struct usb_serial_port *port,
 ^

Consistently use tcflag_t to fix this.

Signed-off-by: Geert Uytterhoeven 
---
 drivers/usb/serial/cp210x.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/serial/cp210x.c b/drivers/usb/serial/cp210x.c
index f61477bed3a8d3b1..e138decfc844dff8 100644
--- a/drivers/usb/serial/cp210x.c
+++ b/drivers/usb/serial/cp210x.c
@@ -33,7 +33,7 @@
 static void cp210x_close(struct usb_serial_port *);
 static void cp210x_get_termios(struct tty_struct *, struct usb_serial_port *);
 static void cp210x_get_termios_port(struct usb_serial_port *port,
-   unsigned int *cflagp, unsigned int *baudp);
+   tcflag_t *cflagp, unsigned int *baudp);
 static void cp210x_change_speed(struct tty_struct *, struct usb_serial_port *,
struct ktermios *);
 static void cp210x_set_termios(struct tty_struct *, struct usb_serial_port *,
@@ -718,7 +718,7 @@ static void cp210x_get_termios(struct tty_struct *tty,
>termios.c_cflag, );
tty_encode_baud_rate(tty, baud, baud);
} else {
-   unsigned int cflag;
+   tcflag_t cflag;
cflag = 0;
cp210x_get_termios_port(port, , );
}
@@ -729,10 +729,10 @@ static void cp210x_get_termios(struct tty_struct *tty,
  * This is the heart of cp210x_get_termios which always uses a 
_serial_port.
  */
 static void cp210x_get_termios_port(struct usb_serial_port *port,
-   unsigned int *cflagp, unsigned int *baudp)
+   tcflag_t *cflagp, unsigned int *baudp)
 {
struct device *dev = >dev;
-   unsigned int cflag;
+   tcflag_t cflag;
struct cp210x_flow_ctl flow_ctl;
u32 baud;
u16 bits;
-- 
1.9.1

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


Re: [PATCH v2 1/3] usb: xhci: add quirk flag for broken PED bits

2016-11-21 Thread Felipe Balbi

Hi,

Roger Quadros  writes:
> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
> index f945380..6553903 100644
> --- a/drivers/usb/host/xhci.h
> +++ b/drivers/usb/host/xhci.h
> @@ -1656,6 +1656,9 @@ struct xhci_hcd {
>  #define XHCI_SSIC_PORT_UNUSED(1 << 22)
>  #define XHCI_NO_64BIT_SUPPORT(1 << 23)
>  #define XHCI_MISSING_CAS (1 << 24)
> +/* For controller with a broken Port Disable implementation */
> +#define XHCI_BROKEN_PORT_PED (1 << 21)

since back when I first wrote this, bit 21 has been taken. You should be
using bit 25 here.

-- 
balbi


signature.asc
Description: PGP signature


Re: [PATCH 1/3] usb: xhci: add quirk flag for broken PED bits

2016-11-21 Thread Roger Quadros
On 18/11/16 12:49, Sergei Shtylyov wrote:
> Hello.
> 
> On 11/17/2016 6:01 PM, Roger Quadros wrote:
> 
>> From: Felipe Balbi 
>>
>> Some devices from Texas Instruments [1] suffer from
>> a silicon bug where Port Enabled/Disabled bit
>> should not be used to silence an erroneous device.
>>
>> The bug is so that if port is disabled with PED
>> bit, an IRQ for device removal (or attachment)
>> will never fire.
>>
>> Just for the sake of completeness, the actual
>> problem lies with SNPS USB IP and this affects
>> all known versions up to 3.00a. A separate
>> patch will be added to dwc3 to enabled this
>> quirk flag if version is <= 3.00a.
>>
>> [1] - AM572x Silicon Errata http://www.ti.com/lit/er/sprz429j/sprz429j.pdf
>> Section i896— USB xHCI Port Disable Feature Does Not Work
>>
>> Signed-off-by: Felipe Balbi 
>> Signed-off-by: Roger Quadros 
>> ---
>>  drivers/usb/host/xhci-hub.c | 6 ++
>>  drivers/usb/host/xhci.h | 3 +++
>>  2 files changed, 9 insertions(+)
>>
>> diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
>> index 0ef1690..c3c051d 100644
>> --- a/drivers/usb/host/xhci-hub.c
>> +++ b/drivers/usb/host/xhci-hub.c
>> @@ -458,6 +458,12 @@ static void xhci_disable_port(struct usb_hcd *hcd, 
>> struct xhci_hcd *xhci,
>>  return;
>>  }
>>
>> +if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
>> +xhci_dbg(xhci, "Broken Port Enabled/Disabled, ignoring "
>> +"port disable request.\n");
> 
>The messages shouldn't be broken up to facilitate grepping.
> 
> [...]
>> diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
>> index f945380..4f724aa 100644
>> --- a/drivers/usb/host/xhci.h
>> +++ b/drivers/usb/host/xhci.h
>> @@ -1656,6 +1656,9 @@ struct xhci_hcd {
>>  #define XHCI_SSIC_PORT_UNUSED(1 << 22)
>>  #define XHCI_NO_64BIT_SUPPORT(1 << 23)
>>  #define XHCI_MISSING_CAS(1 << 24)
>> +/* For controller with a broken Port Disable implementation */
>> +#define XHCI_BROKEN_PORT_PED(1 << 21)
> 
>Indent with tabs as above, please.
> 
> [...]
> 

Thanks. I've fixed both issues and sent a v2.

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


[PATCH v2 1/3] usb: xhci: add quirk flag for broken PED bits

2016-11-21 Thread Roger Quadros
From: Felipe Balbi 

Some devices from Texas Instruments [1] suffer from
a silicon bug where Port Enabled/Disabled bit
should not be used to silence an erroneous device.

The bug is so that if port is disabled with PED
bit, an IRQ for device removal (or attachment)
will never fire.

Just for the sake of completeness, the actual
problem lies with SNPS USB IP and this affects
all known versions up to 3.00a. A separate
patch will be added to dwc3 to enabled this
quirk flag if version is <= 3.00a.

[1] - AM572x Silicon Errata http://www.ti.com/lit/er/sprz429j/sprz429j.pdf
Section i896— USB xHCI Port Disable Feature Does Not Work

Signed-off-by: Felipe Balbi 
Signed-off-by: Roger Quadros 
---
 drivers/usb/host/xhci-hub.c | 6 ++
 drivers/usb/host/xhci.h | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 0ef1690..1d41637 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -458,6 +458,12 @@ static void xhci_disable_port(struct usb_hcd *hcd, struct 
xhci_hcd *xhci,
return;
}
 
+   if (xhci->quirks & XHCI_BROKEN_PORT_PED) {
+   xhci_dbg(xhci,
+"Broken Port Enabled/Disabled, ignoring port disable 
request.\n");
+   return;
+   }
+
/* Write 1 to disable the port */
writel(port_status | PORT_PE, addr);
port_status = readl(addr);
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index f945380..6553903 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1656,6 +1656,9 @@ struct xhci_hcd {
 #define XHCI_SSIC_PORT_UNUSED  (1 << 22)
 #define XHCI_NO_64BIT_SUPPORT  (1 << 23)
 #define XHCI_MISSING_CAS   (1 << 24)
+/* For controller with a broken Port Disable implementation */
+#define XHCI_BROKEN_PORT_PED   (1 << 21)
+
unsigned intnum_active_eps;
unsigned intlimit_active_eps;
/* There are two roothubs to keep track of bus suspend info for */
-- 
2.7.4


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


Re: [PATCH v3 10/10] ARM: dts: da850: add usb device node

2016-11-21 Thread Axel Haslam
On Mon, Nov 21, 2016 at 11:49 AM, Sekhar Nori  wrote:
> On Monday 21 November 2016 04:16 PM, Sekhar Nori wrote:
 In commit 2957e36e76c836b167e5e0c1edb578d8a9bd7af6 in the linux-davinci
 >> tree, the alias for the musb device is usb0. So, I think we should use 
 >> usb1
 >> here instead of ohci - or change the usb0 alias to musb.
 >>
 >> https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/commit/?h=v4.10/dt=2957e36e76c836b167e5e0c1edb578d8a9bd7af6
>>> >
>>> > ok, i will change to usb1, since i will be resubmiting this.
>
>> I have already applied a version of this patch. Please re-base against
>> linux-davinci/master and send a delta patch.
>
> Hmm, no. scratch that. I mixed this up with the musb patch I applied.
> usb1 sounds good. Please also separate out the soc and board specific
> dts additions for your next version.

Ok will do.


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


Re: [PATCH v3 10/10] ARM: dts: da850: add usb device node

2016-11-21 Thread Sekhar Nori
On Monday 21 November 2016 04:16 PM, Sekhar Nori wrote:
>>> In commit 2957e36e76c836b167e5e0c1edb578d8a9bd7af6 in the linux-davinci
>>> >> tree, the alias for the musb device is usb0. So, I think we should use 
>>> >> usb1
>>> >> here instead of ohci - or change the usb0 alias to musb.
>>> >>
>>> >> https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/commit/?h=v4.10/dt=2957e36e76c836b167e5e0c1edb578d8a9bd7af6
>> > 
>> > ok, i will change to usb1, since i will be resubmiting this.

> I have already applied a version of this patch. Please re-base against
> linux-davinci/master and send a delta patch.

Hmm, no. scratch that. I mixed this up with the musb patch I applied.
usb1 sounds good. Please also separate out the soc and board specific
dts additions for your next version.

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


Re: [PATCH v3 10/10] ARM: dts: da850: add usb device node

2016-11-21 Thread Sekhar Nori
On Monday 21 November 2016 03:57 PM, Axel Haslam wrote:
> On Mon, Nov 21, 2016 at 3:42 AM, David Lechner  wrote:
>> On 11/07/2016 02:39 PM, Axel Haslam wrote:
>>>
>>> This adds the ohci device node for the da850 soc.
>>> It also enables it for the omapl138 hawk board.
>>>
>>> Signed-off-by: Axel Haslam 
>>> ---
>>>  arch/arm/boot/dts/da850-lcdk.dts | 8 
>>>  arch/arm/boot/dts/da850.dtsi | 8 
>>>  2 files changed, 16 insertions(+)
>>>
>>> diff --git a/arch/arm/boot/dts/da850-lcdk.dts
>>> b/arch/arm/boot/dts/da850-lcdk.dts
>>> index 7b8ab21..aaf533e 100644
>>> --- a/arch/arm/boot/dts/da850-lcdk.dts
>>> +++ b/arch/arm/boot/dts/da850-lcdk.dts
>>> @@ -86,6 +86,14 @@
>>> };
>>>  };
>>>
>>> +_phy {
>>> +   status = "okay";
>>> +};
>>> +
>>> + {
>>> +   status = "okay";
>>> +};
>>> +
>>>   {
>>> pinctrl-names = "default";
>>> pinctrl-0 = <_rxtx_pins>;
>>> diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
>>> index 2534aab..50e86da 100644
>>> --- a/arch/arm/boot/dts/da850.dtsi
>>> +++ b/arch/arm/boot/dts/da850.dtsi
>>> @@ -405,6 +405,14 @@
>>> >;
>>> status = "disabled";
>>> };
>>> +   ohci: usb@0225000 {
>>
>>
>> In commit 2957e36e76c836b167e5e0c1edb578d8a9bd7af6 in the linux-davinci
>> tree, the alias for the musb device is usb0. So, I think we should use usb1
>> here instead of ohci - or change the usb0 alias to musb.
>>
>> https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/commit/?h=v4.10/dt=2957e36e76c836b167e5e0c1edb578d8a9bd7af6
> 
> ok, i will change to usb1, since i will be resubmiting this.

I have already applied a version of this patch. Please re-base against
linux-davinci/master and send a delta patch.

Thanks,
Sekhar
--
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: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Greg KH
On Thu, Nov 17, 2016 at 12:50:35PM +0200, Heikki Krogerus wrote:
> The purpose of USB Type-C connector class is to provide
> unified interface for the user space to get the status and
> basic information about USB Type-C connectors on a system,
> control over data role swapping, and when the port supports
> USB Power Delivery, also control over power role swapping
> and Alternate Modes.
> 
> Signed-off-by: Heikki Krogerus 
> ---
>  Documentation/ABI/testing/sysfs-class-typec |  222 ++
>  Documentation/usb/typec.txt |  103 +++
>  MAINTAINERS |9 +
>  drivers/usb/Kconfig |2 +
>  drivers/usb/Makefile|2 +
>  drivers/usb/typec/Kconfig   |7 +
>  drivers/usb/typec/Makefile  |1 +
>  drivers/usb/typec/typec.c   | 1012 
> +++
>  include/linux/usb/typec.h   |  252 +++
>  9 files changed, 1610 insertions(+)
>  create mode 100644 Documentation/ABI/testing/sysfs-class-typec
>  create mode 100644 Documentation/usb/typec.txt
>  create mode 100644 drivers/usb/typec/Kconfig
>  create mode 100644 drivers/usb/typec/Makefile
>  create mode 100644 drivers/usb/typec/typec.c
>  create mode 100644 include/linux/usb/typec.h
> 
> diff --git a/Documentation/ABI/testing/sysfs-class-typec 
> b/Documentation/ABI/testing/sysfs-class-typec
> new file mode 100644
> index 000..4fac77c
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-class-typec
> @@ -0,0 +1,222 @@
> +USB Type-C port devices (eg. /sys/class/typec/usbc0/)
> +
> +What:/sys/class/typec//current_data_role
> +Date:December 2016
> +Contact: Heikki Krogerus 
> +Description:
> + The current USB data role the port is operating in. This
> + attribute can be used for requesting data role swapping on the
> + port. Swapping is supported as synchronous operation, so
> + write(2) to the attribute will not return until the operation
> + has finished. The attribute is notified about role changes so
> + that poll(2) on the attribute wakes up. Change on the role will
> + also generate uevent KOBJ_CHANGE on the port.
> +
> + Valid values:
> + - host
> + - device
> +
> +What:/sys/class/typec//current_power_role
> +Date:December 2016
> +Contact: Heikki Krogerus 
> +Description:
> + The current power role of the port. This attribute can be used
> + to request power role swap on the port when the port supports
> + USB Power Delivery. Swapping is supported as synchronous
> + operation, so write(2) to the attribute will not return until
> + the operation has finished. The attribute is notified about role
> + changes so that poll(2) on the attribute wakes up. Change on the
> + role will also generate uevent KOBJ_CHANGE.
> +
> + Valid values:
> + - source
> + - sink
> +
> +What:/sys/class/typec//vconn_source
> +Date:December 2016
> +Contact: Heikki Krogerus 
> +Description:
> + Shows is the port VCONN Source. This attribute can be used to
> + request VCONN swap to change the VCONN Source during connection
> + when both the port and the partner support USB Power Delivery.
> + Swapping is supported as synchronous operation, so write(2) to
> + the attribute will not return until the operation has finished.
> + The attribute is notified about VCONN source changes so that
> + poll(2) on the attribute wakes up. Change on VCONN source also
> + generates uevent KOBJ_CHANGE.
> +
> + Valid values are:
> + - 0 when the port is not the VCONN Source
> + - 1 when the port is the VCONN Source
> +
> +What:/sys/class/typec//power_operation_mode
> +Date:December 2016
> +Contact: Heikki Krogerus 
> +Description:
> + Shows the current power operational mode the port is in.
> +
> + Valid values:
> + - USB - Normal power levels defined in USB specifications
> + - BC1.2 - Power levels defined in Battery Charging Specification
> +   v1.2
> + - USB Type-C 1.5A - Higher 1.5A current defined in USB Type-C
> + specification.
> + - USB Type-C 3.0A - Higher 3A current defined in USB Type-C
> + specification.
> +- USB Power Delivery - The voltages and currents defined in 
> USB

Re: [PATCHv11 2/3] usb: USB Type-C connector class

2016-11-21 Thread Greg KH
On Thu, Nov 17, 2016 at 12:50:35PM +0200, Heikki Krogerus wrote:
> The purpose of USB Type-C connector class is to provide
> unified interface for the user space to get the status and
> basic information about USB Type-C connectors on a system,
> control over data role swapping, and when the port supports
> USB Power Delivery, also control over power role swapping
> and Alternate Modes.
> 
> Signed-off-by: Heikki Krogerus 

I'd like to get some acks or reviewed-by from others, but one thing
jumped out at me, which implies you did not run checkpatch.pl on the
patch:

644
> --- a/drivers/usb/Kconfig
> +++ b/drivers/usb/Kconfig
> @@ -152,6 +152,8 @@ source "drivers/usb/phy/Kconfig"
>  
>  source "drivers/usb/gadget/Kconfig"
>  
> +source "drivers/usb/typec/Kconfig"
> +
>  config USB_LED_TRIG
>   bool "USB LED Triggers"
>   depends on LEDS_CLASS && LEDS_TRIGGERS
> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> index 7791af6..c7f4098 100644
> --- a/drivers/usb/Makefile
> +++ b/drivers/usb/Makefile
> @@ -62,3 +62,5 @@ obj-$(CONFIG_USB_GADGET)+= gadget/
>  obj-$(CONFIG_USB_COMMON) += common/
>  
>  obj-$(CONFIG_USBIP_CORE) += usbip/
> +
> +obj-$(CONFIG_TYPEC)  += typec/
> diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
> new file mode 100644
> index 000..b229fb9
> --- /dev/null
> +++ b/drivers/usb/typec/Kconfig
> @@ -0,0 +1,7 @@
> +
> +menu "USB PD and Type-C drivers"

What is "PD"?  (yes, I know, but very few people do...)  Spell it out.

> +
> +config TYPEC
> + tristate

Hah, that says NOTHING about what this code is at all.

Please fix.

thanks,

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


Re: [PATCH v3 10/10] ARM: dts: da850: add usb device node

2016-11-21 Thread Axel Haslam
On Mon, Nov 21, 2016 at 3:42 AM, David Lechner  wrote:
> On 11/07/2016 02:39 PM, Axel Haslam wrote:
>>
>> This adds the ohci device node for the da850 soc.
>> It also enables it for the omapl138 hawk board.
>>
>> Signed-off-by: Axel Haslam 
>> ---
>>  arch/arm/boot/dts/da850-lcdk.dts | 8 
>>  arch/arm/boot/dts/da850.dtsi | 8 
>>  2 files changed, 16 insertions(+)
>>
>> diff --git a/arch/arm/boot/dts/da850-lcdk.dts
>> b/arch/arm/boot/dts/da850-lcdk.dts
>> index 7b8ab21..aaf533e 100644
>> --- a/arch/arm/boot/dts/da850-lcdk.dts
>> +++ b/arch/arm/boot/dts/da850-lcdk.dts
>> @@ -86,6 +86,14 @@
>> };
>>  };
>>
>> +_phy {
>> +   status = "okay";
>> +};
>> +
>> + {
>> +   status = "okay";
>> +};
>> +
>>   {
>> pinctrl-names = "default";
>> pinctrl-0 = <_rxtx_pins>;
>> diff --git a/arch/arm/boot/dts/da850.dtsi b/arch/arm/boot/dts/da850.dtsi
>> index 2534aab..50e86da 100644
>> --- a/arch/arm/boot/dts/da850.dtsi
>> +++ b/arch/arm/boot/dts/da850.dtsi
>> @@ -405,6 +405,14 @@
>> >;
>> status = "disabled";
>> };
>> +   ohci: usb@0225000 {
>
>
> In commit 2957e36e76c836b167e5e0c1edb578d8a9bd7af6 in the linux-davinci
> tree, the alias for the musb device is usb0. So, I think we should use usb1
> here instead of ohci - or change the usb0 alias to musb.
>
> https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/commit/?h=v4.10/dt=2957e36e76c836b167e5e0c1edb578d8a9bd7af6

ok, i will change to usb1, since i will be resubmiting this.

>
>> +   compatible = "ti,da830-ohci";
>> +   reg = <0x225000 0x1000>;
>> +   interrupts = <59>;
>> +   phys = <_phy 1>;
>> +   phy-names = "usb-phy";
>> +   status = "disabled";
>> +   };
>> gpio: gpio@226000 {
>> compatible = "ti,dm6441-gpio";
>> gpio-controller;
>>
>
--
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: [v5,3/5] USB: ohci: da8xx: Allow a regulator to handle VBUS

2016-11-21 Thread Axel Haslam
Hi David,

Thanks for the review,


On Sun, Nov 20, 2016 at 4:31 AM, David Lechner  wrote:
> On 11/14/2016 08:41 AM, ahas...@baylibre.com wrote:
>>
>> Using a regulator to handle VBUS will eliminate the need for
>> platform data and callbacks, and make the driver more generic
>> allowing different types of regulators to handle VBUS.
>>
>> The regulator equivalents to the platform callbacks are:
>> set_power   ->  regulator_enable/regulator_disable
>> get_power   ->  regulator_is_enabled
>> get_oci ->  regulator_get_error_flags
>> ocic_notify ->  regulator event notification
>>
>> Signed-off-by: Axel Haslam 
>> ---
>>  drivers/usb/host/ohci-da8xx.c | 95
>> ++-
>>  1 file changed, 93 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
>> index 83e3c98..42eaeb9 100644
>> --- a/drivers/usb/host/ohci-da8xx.c
>> +++ b/drivers/usb/host/ohci-da8xx.c
>> @@ -20,6 +20,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -36,8 +37,12 @@ static int (*orig_ohci_hub_control)(struct usb_hcd
>> *hcd, u16 typeReq,
>>  static int (*orig_ohci_hub_status_data)(struct usb_hcd *hcd, char *buf);
>>
>>  struct da8xx_ohci_hcd {
>> +   struct usb_hcd *hcd;
>> struct clk *usb11_clk;
>> struct phy *usb11_phy;
>> +   struct regulator *vbus_reg;
>> +   struct notifier_block nb;
>> +   unsigned int is_powered;
>
>
> Since is_powered is only used to indicate if we have called
> regulator_enable(), I think it would make more sense to name it reg_enabled
> instead.

ok.

>
>>  };
>>
>>  #define to_da8xx_ohci(hcd) (struct da8xx_ohci_hcd
>> *)(hcd_to_ohci(hcd)->priv)
>> @@ -83,56 +88,103 @@ static void ohci_da8xx_disable(struct usb_hcd *hcd)
>>
>>  static int ohci_da8xx_set_power(struct usb_hcd *hcd, int on)
>>  {
>> +   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
>> struct device *dev  = hcd->self.controller;
>> struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
>> +   int ret;
>>
>> if (hub && hub->set_power)
>> return hub->set_power(1, on);
>>
>> +   if (!da8xx_ohci->vbus_reg)
>> +   return 0;
>> +
>> +   if (on && !da8xx_ohci->is_powered) {
>> +   ret = regulator_enable(da8xx_ohci->vbus_reg);
>> +   if (ret) {
>> +   dev_err(dev, "Fail to enable regulator: %d\n",
>> ret);
>
>
> s/Fail/Failed/

will fix in both places.

>
>> +   return ret;
>> +   }
>> +   da8xx_ohci->is_powered = 1;
>> +
>> +   } else if (!on && da8xx_ohci->is_powered) {
>> +   ret = regulator_disable(da8xx_ohci->vbus_reg);
>> +   if (ret) {
>> +   dev_err(dev, "Fail to disable regulator: %d\n",
>> ret);
>
>
> s/Fail/Failed/
>
>> +   return ret;
>> +   }
>> +   da8xx_ohci->is_powered = 0;
>> +   }
>> +
>> return 0;
>>  }
>>
>>  static int ohci_da8xx_get_power(struct usb_hcd *hcd)
>>  {
>> +   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
>> struct device *dev  = hcd->self.controller;
>> struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
>>
>> if (hub && hub->get_power)
>> return hub->get_power(1);
>>
>> +   if (da8xx_ohci->vbus_reg)
>> +   return regulator_is_enabled(da8xx_ohci->vbus_reg);
>> +
>> return 1;
>>  }
>>
>>  static int ohci_da8xx_get_oci(struct usb_hcd *hcd)
>>  {
>> +   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
>> struct device *dev  = hcd->self.controller;
>> struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
>> +   unsigned int flags;
>> +   int ret;
>>
>> if (hub && hub->get_oci)
>> return hub->get_oci(1);
>>
>> +   if (!da8xx_ohci->vbus_reg)
>> +   return 0;
>> +
>> +   ret = regulator_get_error_flags(da8xx_ohci->vbus_reg, );
>> +   if (ret)
>> +   return ret;
>> +
>> +   if (flags && REGULATOR_ERROR_OVER_CURRENT)
>
>
> Is this supposed to be...

yes!

>
> if (flags & REGULATOR_ERROR_OVER_CURRENT)
>
>
>> +   return 1;
>> +
>> return 0;
>>  }
>>
>>  static int ohci_da8xx_has_set_power(struct usb_hcd *hcd)
>>  {
>> +   struct da8xx_ohci_hcd *da8xx_ohci = to_da8xx_ohci(hcd);
>> struct device *dev  = hcd->self.controller;
>> struct da8xx_ohci_root_hub *hub = dev_get_platdata(dev);
>>
>> if (hub && hub->set_power)
>> return 1;
>>
>> +   if (da8xx_ohci->vbus_reg)
>> +   return 1;
>> +
>> return 0;
>>  }
>>
>>  static int ohci_da8xx_has_oci(struct usb_hcd *hcd)
>>  {
>> +   struct da8xx_ohci_hcd 

Re: Issue with Telit LE922 and cdc_mbim

2016-11-21 Thread Bjørn Mork
Daniele Palmas  writes:

> it turned out that resetting the interface in cdc_ncm_init after
> getting the NTB parameters removes the need for the sleep, making the
> modem to work fine.

Sounds very good, although I must admit that it isn't perfectly clear to
me what kind of reset we're talking about here.  But no worries, the
patch will make that clear :)

> I wonder if this is an acceptable solution and can be applied also for MC7455.

Quite possible.  I will definitely test it.  If we can avoid an
arbitrary and pointless delay, then that's great.  But I guess this also
requires testing with a wide range of other MBIM devices to find out if
we can apply it unconditionally without breaking anything. Avoiding
device-specific or vendor-specific code is important in a class driver,
if possible.


Bjørn
--
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: [v5,1/5] USB: ohci: da8xx: use ohci priv data instead of globals

2016-11-21 Thread Axel Haslam
On Sun, Nov 20, 2016 at 3:58 AM, David Lechner  wrote:
> On 11/14/2016 08:40 AM, ahas...@baylibre.com wrote:
>>
>> Instead of global variables, use the extra_priv_size of
>> the ohci driver.
>>
>> We cannot yet move the ocic mask because this is used on
>> the interrupt handler which is registerded through platform
>> data and does not have an hcd pointer. This will be moved
>> on a later patch.
>>
>> Signed-off-by: Axel Haslam 
>> ---
>>  drivers/usb/host/ohci-da8xx.c | 73
>> +--
>>  1 file changed, 43 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/usb/host/ohci-da8xx.c b/drivers/usb/host/ohci-da8xx.c
>> index b3de8bc..438970b 100644
>> --- a/drivers/usb/host/ohci-da8xx.c
>> +++ b/drivers/usb/host/ohci-da8xx.c
>
> ...
>>
>> @@ -238,25 +246,29 @@ static int ohci_da8xx_probe(struct platform_device
>> *pdev)
>> if (hub == NULL)
>> return -ENODEV;
>>
>> -   usb11_clk = devm_clk_get(>dev, "usb11");
>> -   if (IS_ERR(usb11_clk)) {
>> -   if (PTR_ERR(usb11_clk) != -EPROBE_DEFER)
>> +   hcd = usb_create_hcd(_da8xx_hc_driver, >dev,
>> +   dev_name(>dev));
>> +   if (!hcd)
>> +   return -ENOMEM;
>> +
>> +   da8xx_ohci = to_da8xx_ohci(hcd);
>> +
>> +   da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
>> +   if (IS_ERR(da8xx_ohci->usb11_clk)) {
>> +   if (PTR_ERR(da8xx_ohci->usb11_clk) != -EPROBE_DEFER)
>> dev_err(>dev, "Failed to get clock.\n");
>> -   return PTR_ERR(usb11_clk);
>> +   error = PTR_ERR(da8xx_ohci->usb11_clk);
>> +   goto err;
>> }
>
>
> Small thing, but this could be written slightly cleaner as:
>
> da8xx_ohci->usb11_clk = devm_clk_get(>dev, "usb11");
> if (IS_ERR(da8xx_ohci->usb11_clk)) {
> error = PTR_ERR(da8xx_ohci->usb11_clk);
> if (error != -EPROBE_DEFER)
> dev_err(>dev, "Failed to get clock.\n");
> goto err;
> }
>

Yes, right, i will change it,
Thanks.

>>
>> -   usb11_phy = devm_phy_get(>dev, "usb-phy");
>> -   if (IS_ERR(usb11_phy)) {
>> -   if (PTR_ERR(usb11_phy) != -EPROBE_DEFER)
>> +   da8xx_ohci->usb11_phy = devm_phy_get(>dev, "usb-phy");
>> +   if (IS_ERR(da8xx_ohci->usb11_phy)) {
>> +   if (PTR_ERR(da8xx_ohci->usb11_phy) != -EPROBE_DEFER)
>> dev_err(>dev, "Failed to get phy.\n");
>> -   return PTR_ERR(usb11_phy);
>> +   error = PTR_ERR(da8xx_ohci->usb11_phy);
>> +   goto err;
>> }
>
>
> same here
>
> ...
>
>
> Tested-by: David Lechner 
>
--
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


[BUG 4.9] New led trigger usbport gets the kernel to panic

2016-11-21 Thread Ralph Sennhauser
Hi Rafał,

I tried your new usbport trigger in Linux 4.9 with little luck as can be seen in
the following output of the serial console.

  root@wrt1900acs:/# cd /sys/class/leds/pca963x\:shelby\:white\:usb2/
  
root@wrt1900acs:/sys/devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-0068/leds/pca963x:shelby:white:usb2#
 echo usbport > trigger
  
root@wrt1900acs:/sys/devices/platform/soc/soc:internal-regs/f1011000.i2c/i2c-0/0-0068/leds/pca963x:shelby:white:usb2#
 echo 1 > ports/usb2-port1
  [ 1461.761528] Unable to handle kernel NULL pointer dereference at virtual 
address 
  [ 1461.769734] pgd = de33c000
  [ 1461.772454] [] *pgd=1cb2a831, *pte=, *ppte=
  [ 1461.778791] Internal error: Oops: 8007 [#1] SMP ARM
  [ 1461.784036] Modules linked in: iptable_nat nft_chain_nat_ipv4 
nf_tables_inet
  nf_nat_ipv4 nf_conntrack_ipv6 nf_conntrack_ipv4 ipt_REJECT ipt_MASQUERADE
  xt_time xt_tcpudp xt_state xt_nat xt_multiport xt_mark xt_mac xt_limit
  xt_conntrack xt_comment xt_TCP MSS xt_REDIRECT xt_LOG xt_CT nft_set_rbtree
  nft_set_hash nft_reject_inet nft_reject nft_redir_ipv4 nft_redir nft_nat
  nft_meta nft_masq_ipv4 nft_masq nft_log nft_limit nft_hash nft_exthdr nft_ct
  nft_counter nft_chain_route_ipv6 nft_chain_route_ipv4 nf_tabl es_ipv6
  nf_tables_ipv4 nf_tables nf_reject_ipv4 nf_nat_redirect nf_nat_masquerade_ipv4
  nf_nat nf_log_ipv4 nf_defrag_ipv6 nf_defrag_ipv4 nf_conntrack_netlink
  nf_conntrack macvlan libcrc32c iptable_raw iptable_mangle iptable_filter
  ip_tables act_skbedit act _mirred em_u32 cls_u32 cls_tcindex cls_flow 
cls_route
  cls_fw sch_hfsc sch_ingress mwlwifi(O) mac80211 cfg80211 ledtrig_netdev(O)
  ip_set_list_set ip_set_hash_netiface ip_set_hash_netport ip_set_hash_netnet
  ip_set_hash_net ip_set_hash_netportnet ip_set_hash _mac ip_set_hash_ipportnet
  ip_set_hash_ipportip ip_set_hash_ipport ip_set_hash_ipmark ip_set_hash_ip
  ip_set_bitmap_port ip_set_bitmap_ipmac ip_set_bitmap_ip ip_set nfnetlink
  ip6t_REJECT nf_reject_ipv6 nf_log_ipv6 nf_log_common ip6table_raw
  ip6table_mangle ip6table_filter ip6_tables x_tables ifb sit tunnel4 ip_tunnel
  vfat fat nls_utf8 nls_iso8859_1 nls_cp850 nls_cp437 rfkill input_core
  sha256_generic seqiv jitterentropy_rng drbg hmac ghash_generic gf128mul gcm 
ctr
  ccm ledtrig_usbport ext4 jbd2 mbcache btrf s xor raid6_pq crc32c_generic ubifs
  ubi
  [ 1461.922401] CPU: 0 PID: 759 Comm: ash Tainted: G   O4.9.0-rc6 
#2
  [ 1461.929476] Hardware name: Marvell Armada 380/385 (Device Tree)
  [ 1461.935418] task: df621080 task.stack: dee0e000
  [ 1461.939966] PC is at 0x0
  [ 1461.942510] LR is at usbport_trig_port_store+0x8c/0xd8 [ledtrig_usbport]
  [ 1461.949238] pc : [<>]lr : []psr: 6013
  [ 1461.949238] sp : dee0fe50  ip : dee0fe10  fp : dee0fe6c
  [ 1461.960761] r10:   r9 :   r8 : 
  [ 1461.966006] r7 : dcabc7c0  r6 : df4164ec  r5 : 0002  r4 : dcabc040
  [ 1461.972558] r3 :   r2 : 001a  r1 :   r0 : df4164ec
  [ 1461.979112] Flags: nZCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment 
none
  [ 1461.986275] Control: 10c5387d  Table: 1e33c04a  DAC: 0051
  [ 1461.992043] Process ash (pid: 759, stack limit = 0xdee0e210)
  [ 1461.997724] Stack: (0xdee0fe50 to 0xdee1)
  [ 1462.002097] fe40: bf228164 0002 
dee0ff80 dcabc7c0
  [ 1462.010309] fe60: dee0fe84 dee0fe70 c023f758 bf228170 c023f738 0002 
dee0fe9c dee0fe88
  [ 1462.018520] fe80: c0169310 c023f744 df4a1000 0002 dee0fedc dee0fea0 
c0168ab8 c01692d4
  [ 1462.026731] fea0:   df747c10 df4a100c d4aca1c9 df727a80 
c01689c0 dee0ff80
  [ 1462.034943] fec0: 0002 c000fc24 dee0e000  dee0ff4c dee0fee0 
c0100c78 c01689cc
  [ 1462.043153] fee0:  dee0fee8 dee0ff14 dee0fef8 dee0ff14 dee0ff00 
c0060668 c04640a0
  [ 1462.051365] ff00: dee0ff50 df621350 dee0ff4c dee0ff18 c00298f8 c0060630 
fff6 dee0ff68
  [ 1462.059576] ff20: c00ff23c 0007 0002 df727a80 b6f092d0 dee0ff80 
c000fc24 dee0e000
  [ 1462.067786] ff40: dee0ff7c dee0ff50 c0101ae4 c0100c50 0003 0007 
df727a80 df727a80
  [ 1462.075997] ff60: b6f092d0 0002 c000fc24 dee0e000 dee0ffa4 dee0ff80 
c01028dc c0101a44
  [ 1462.084208] ff80:      0004 
 dee0ffa8
  [ 1462.092419] ffa0: c000fa60 c010289c   0001 b6f092d0 
0002 
  [ 1462.100630] ffc0:    0004 b6f092d0 0020 
00059ec0 00059ea0
  [ 1462.108841] ffe0: beb744f8 beb744e4 b6ee1904 b6ee0dc8 6010 0001 
 
  [ 1462.117049] Backtrace:
  [ 1462.119521] [] (usbport_trig_port_store [ledtrig_usbport]) from 
[] (dev_attr_store+0x20/0x2c)
  [ 1462.129826]  r7:dcabc7c0 r6:dee0ff80 r5:0002 r4:bf228164
  [ 1462.135511] [] (dev_attr_store) from [] 
(sysfs_kf_write+0x48/0x4c)
  [ 1462.143459]  r5:0002 r4:c023f738
  [ 1462.147049] [] (sysfs_kf_write) from []