Re: time source unstable on usb/serial/pl2303 (globalsat br-353)

2013-05-24 Thread Philippe De Muyter
On Thu, May 23, 2013 at 08:31:18AM -0700, Greg Kroah-Hartman wrote:
> On Thu, May 23, 2013 at 03:07:09PM +0200, Philippe De Muyter wrote:
> > Hi all,
> > 
> > I have a lot of linux computers equipped with a GlobalSat Br-353 GPS 
> > receiver,
> > which is connected via USB (an integrated PL2303).  The GPS receiver emits
> > one multi-line message every second, giving position and time.  I listen
> > to this messages in a user program running in the highest priority,
> > and I have noticed that under load, the messages are not delivered to my
> > process every second, but often delayed, which is not great for a time 
> > source.
> > 
> > I looked at the sources of pl2303 and added a diagnostic message if the
> > beginning of a message came more than one second later than the beginning
> > of the previous one, and I noticed that the delay was already present
> > in the kernel: often even more than one second delay after the expected
> > beginning time.
> 
> Then that implies that the device itself is holding on to the message,
> right?

I hoped it was the configuration on the host-side.  I have read internet
pages that implied that for USB mice it was possible to increase the polling
rate.  I hoped that it would be the same for serial lines.

Is it possible to make bulk_read_requests at the "interrupt" priority ?

> 
> > Can you give me some advice on how to avoid that delay ?  How
> > can I increase the polling priority of this serial line, or how may I get
> > some usefull debugging about the USB polling for this serial line ?
> 
> There is no "polling" of USB serial devices (well, there is, but it's a
> USB thing, and the hardware does it for us, not the software).  The
> pl2303 is a _very_ cheap chip, and it might buffer the message for a
> long time before it decides to send it to the USB host.
> 
> The delay might also be in the GPS device itself, it has to send serial
> data to the pl2303 device, and who knows at what baud rate that is
> coming in at.

The baud rate is the default nmea baud rate (4800bps), and I noticed that
I only get one byte at a time in the kernel when the messages are not
delayed, so it seems that the pl2303 dos not wait for a number of bytes
before answering bulk requests, hence I thought that the delay was caused
by a delayed polling.  I will add debugging to see if I get more than one byte
at a time when messages are delayed.

> 
> USB is not something that you can rely on for very high-frequency, low
> latency, timing things.  Although to be fair, second delays are quite
> rare, which implies that your hardware is to blame here.

Yes, I think that there must be something wrong but more on a software
side, because I do not get such big delays on an unloaded computer.

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


[PATCH v4 2/8] usb/gadget: rndis: convert into module

2013-05-24 Thread Andrzej Pietrasiewicz
In order to convert to configfs the usb functions need to be converted
to a new interface and compiled as modules. This patch creates an rndis
module which will be used by the new functions. After all users of
f_rndis are converted to the new interface, this module can be
merged with f_rndis module.

This edition of the patch fixes an obvious oversight and adds
a MODULE_LICENSE("GPL") entry.

The patch without the said entry was:
Acked-by: Michal Nazarewicz 

I believe Michal can keep his ACK, but don't write the above line
below "Signed-off-by" because adding the MODULE_LICENSE obviously
changes the file.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig  |6 ++
 drivers/usb/gadget/Makefile |2 ++
 drivers/usb/gadget/ether.c  |4 +++-
 drivers/usb/gadget/g_ffs.c  |2 +-
 drivers/usb/gadget/multi.c  |2 +-
 drivers/usb/gadget/rndis.c  |   18 ++
 drivers/usb/gadget/rndis.h  |1 +
 7 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 9152428..91b6eab 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -554,6 +554,9 @@ config USB_U_SERIAL
 config USB_U_ETHER
tristate
 
+config USB_U_RNDIS
+   tristate
+
 config USB_F_SERIAL
tristate
 
@@ -651,6 +654,7 @@ config USB_ETH
depends on NET
select USB_LIBCOMPOSITE
select USB_U_ETHER
+   select USB_U_RNDIS
select CRC32
help
  This driver implements Ethernet style communication, in one of
@@ -776,6 +780,7 @@ config USB_FUNCTIONFS_RNDIS
bool "Include configuration with RNDIS (Ethernet)"
depends on USB_FUNCTIONFS && NET
select USB_U_ETHER
+   select USB_U_RNDIS
help
  Include a configuration with RNDIS function (Ethernet) and the 
Filesystem.
 
@@ -923,6 +928,7 @@ config USB_G_MULTI
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_U_ETHER
+   select USB_U_RNDIS
select USB_F_ACM
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 061abec..3f51952 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -47,6 +47,8 @@ obj-$(CONFIG_USB_F_SERIAL)+= usb_f_serial.o
 usb_f_obex-y   := f_obex.o
 obj-$(CONFIG_USB_F_OBEX)   += usb_f_obex.o
 obj-$(CONFIG_USB_U_ETHER)  += u_ether.o
+u_rndis-y  := rndis.o
+obj-$(CONFIG_USB_U_RNDIS)  += u_rndis.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 75418c7..6bff24f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -91,6 +91,8 @@ static inline bool has_rndis(void)
 #endif
 }
 
+#include 
+
 /*-*/
 
 /*
@@ -104,7 +106,7 @@ static inline bool has_rndis(void)
 #include "f_subset.c"
 #ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
-#include "rndis.c"
+#include "rndis.h"
 #endif
 #include "f_eem.c"
 
diff --git a/drivers/usb/gadget/g_ffs.c b/drivers/usb/gadget/g_ffs.c
index 45f26be..fbfdb53 100644
--- a/drivers/usb/gadget/g_ffs.c
+++ b/drivers/usb/gadget/g_ffs.c
@@ -32,7 +32,7 @@
 #  include "f_subset.c"
 #  ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
-#include "rndis.c"
+#include "rndis.h"
 #  endif
 #  include "u_ether.h"
 
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index d0dd603..b8222c4 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -47,7 +47,7 @@ MODULE_LICENSE("GPL");
 #include "f_subset.c"
 #ifdef USB_ETH_RNDIS
 #  include "f_rndis.c"
-#  include "rndis.c"
+#  include "rndis.h"
 #endif
 #include "u_ether.h"
 
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index d9297ee..4e84964 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -761,6 +761,7 @@ int rndis_signal_connect(int configNr)
return rndis_indicate_status_msg(configNr,
  RNDIS_STATUS_MEDIA_CONNECT);
 }
+EXPORT_SYMBOL(rndis_signal_connect);
 
 int rndis_signal_disconnect(int configNr)
 {
@@ -769,6 +770,7 @@ int rndis_signal_disconnect(int configNr)
return rndis_indicate_status_msg(configNr,
  RNDIS_STATUS_MEDIA_DISCONNECT);
 }
+EXPORT_SYMBOL(rndis_signal_disconnect);
 
 void rndis_uninit(int configNr)
 {
@@ -783,11 +785,13 @@ void rndis_uninit(int configNr)
while ((buf = rndis_get_next_response(configNr, &length)))
rndis_free_response(configNr, buf);
 }
+EXPORT_SYMBOL(rndis_uninit);
 
 void rndis_set_host_mac(int configNr, const u8 *addr)
 {
rndis_per_dev_params[configNr].host_mac = addr;
 }
+EXPORT_SYMBOL(rndis_set_host_mac);
 
 /*
  * Message Parser
@@ -870,6 +874,7 @@ int rndis_msg_par

[PATCH] usbfs: Increase arbitrary limit for USB 3 isopkt length

2013-05-24 Thread Federico Manzan
Increase the current arbitrary limit for isocronous packet size to a
value large enough to account for USB 3.0 super bandwidth streams,
bMaxBurst (0~15 allowed, 1~16 packets)
bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
so the size max for one USB 3 isocronous transfer is
1024 byte * 16 * 3 = 49152 byte

Signed-off-by: Federico Manzan 
---
 drivers/usb/core/devio.c |8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index caefc80..7ac137e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1287,9 +1287,11 @@ static int proc_do_submiturb(struct dev_state *ps, 
struct usbdevfs_urb *uurb,
goto error;
}
for (totlen = u = 0; u < uurb->number_of_packets; u++) {
-   /* arbitrary limit,
-* sufficient for USB 2.0 high-bandwidth iso */
-   if (isopkt[u].length > 8192) {
+   /* arbitrary limit need for USB 3.0
+* bMaxBurst (0~15 allowed, 1~16 packets)
+* bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
+* sizemax: 1024 * 16 * 3 = 49152*/
+   if (isopkt[u].length > 65536) {
ret = -EINVAL;
goto error;
}
-- 
1.7.10.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] serial: Add Option GTM681W to qcserial device table.

2013-05-24 Thread Richard Weinberger
The Option GTM681W uses a qualcomm chip and can be
served by the qcserial device driver.

Signed-off-by: Richard Weinberger 
---
 drivers/usb/serial/qcserial.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index 59b32b7..bd794b4 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -118,6 +118,7 @@ static const struct usb_device_id id_table[] = {
{USB_DEVICE(0x1199, 0x901b)},   /* Sierra Wireless MC7770 */
{USB_DEVICE(0x12D1, 0x14F0)},   /* Sony Gobi 3000 QDL */
{USB_DEVICE(0x12D1, 0x14F1)},   /* Sony Gobi 3000 Composite */
+   {USB_DEVICE(0x0AF0, 0x8120)},   /* Option GTM681W */
 
/* non Gobi Qualcomm serial devices */
{USB_DEVICE_INTERFACE_NUMBER(0x0f3d, 0x68a2, 0)},   /* Sierra 
Wireless MC7700 Device Management */
-- 
1.8.2.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 01/17] usb/gadget: u_ether: allow getting binary-form host address

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/u_ether.c |   11 +++
 drivers/usb/gadget/u_ether.h |   10 ++
 2 files changed, 21 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 6d3ccdc..aa7ed15 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -963,6 +963,17 @@ int gether_get_host_addr_cdc(struct net_device *net, char 
*host_addr, int len)
 }
 EXPORT_SYMBOL(gether_get_host_addr_cdc);
 
+void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN])
+{
+   struct eth_dev *dev;
+
+   dev = netdev_priv(net);
+   host_mac[0] = dev->host_mac[0]; host_mac[1] = dev->host_mac[1];
+   host_mac[2] = dev->host_mac[2]; host_mac[3] = dev->host_mac[3];
+   host_mac[4] = dev->host_mac[4]; host_mac[5] = dev->host_mac[5];
+}
+EXPORT_SYMBOL(gether_get_host_addr_u8);
+
 void gether_set_qmult(struct net_device *net, unsigned qmult)
 {
struct eth_dev *dev;
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 1671a79..5efa657 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -210,6 +210,16 @@ int gether_get_host_addr(struct net_device *net, char 
*host_addr, int len);
 int gether_get_host_addr_cdc(struct net_device *net, char *host_addr, int len);
 
 /**
+ * gether_get_host_addr_u8 - get an ethernet-over-usb link host address
+ * @net: device representing this link
+ * @host_mac: place to store the eth address of the host
+ *
+ * This gets the binary formatted host-side Ethernet address of this
+ * ethernet-over-usb link.
+ */
+void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN]);
+
+/**
  * gether_set_qmult - initialize an ethernet-over-usb link with a multiplier
  * @net: device representing this link
  * @qmult: queue multiplier
-- 
1.7.0.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 00/17] Equivalent of g_ether.ko with configfs

2013-05-24 Thread Andrzej Pietrasiewicz
Here I present the conversion of everything that is required to provide
the equivalent of g_ether.ko with configfs.

A branch will be available here (from 24th May 2013, afternoon UTC):
git://git.infradead.org/users/kmpark/linux-samsung usb-gadget-configfs

This series requires the following series to be applied:

http://comments.gmane.org/gmane.linux.usb.general/86773
http://comments.gmane.org/gmane.linux.usb.general/86783
http://www.spinics.net/lists/linux-usb/msg85307.html
http://comments.gmane.org/gmane.linux.usb.general/86790

The g_ether consists of 4 USB functions, and 3 of them needed to be converted
to the new interface and equipped with configfs support (a few patches per
function), so this patch series is a bit lengthy (17 patches), but I tried
to do the conversion in small, readable steps.

BACKWARD COMPATIBILITY
==

Please note that the old g_ether.ko is still available and works.


USING THE NEW "GADGET"
==

Please refer to this post:

http://www.spinics.net/lists/linux-usb/msg76388.html

for general information from Sebastian on how to use configfs-based
gadgets (*).

Here is the description specific to using g_ether.ko equivalent.

Original g_ether


The original g_ether can contain CDC EEM, CDC ECM (or CDC ECM subset for devices
which do not support full ECM) and RNDIS, depending on what is set in .config.
Even if all of them are selected in .config, only one of them can be used at
runtime. The above functions are assigned to two configurations: either EEM
or ECM or ECM subset is the only function in one configuration, and RNDIS
is the only function in the other.

If the EEM/ECM/ECM subset configuration is selected by the host, then
depending on the use_eem module parameter either EEM or ECM/ECM subset
is used. The decision to use either ECM or ECM subset is made based
on the can_support_ecm() static inline function found in u_ether.h.

If no idVendor, idProduct module parameters are specified, the gadget
uses different default values depending on which function will
actually be used.

No matter which function is actually used, only one network interface
is created and registered.

Configfs-based
--

It is possible to create a gadget which is pretty close to the original
g_ether with three exceptions: (1) for each function a new network interface
is created, (2) a configuration's composition of a number of functions
is done by user creating appropriate symbolic links and (3) idVendor/idProduct
must be explicitly specified.

What does that mean?

As far as (1) is concerned, a gadget which has two configurations,
one containing RNDIS and the other containing EEM, will cause two network
interfaces to appear on the device(after bind): usb0 and usb1, while in the
old gadget only one would be used (which, on the other hand, means that with
the old gadget it is impossible to have e.g. EEM and RNDIS at the same time
in the same configuration).
The two interfaces created here could be an issue, but on the other hand
on many (most?) systems udev will handle interfaces naming anyway.

As for the (2), configurations in a configfs-based gadget can be composed
at will of any available functions, but once a gadget is bound, the composition
is fixed. The old gadget created the configuration programmaticaly at gadget's
bind and included only one of EEM/ECM/ECM subset depending on the use_eem
parameter and can_support_ecm() function's result. In other words, with configfs
it is not possible to say "this configuration will contain either this function
or that", but rather it is possible to say "this configuration will contain
this set of functions".
This could be an issue as well, but with configfs the gadgets are composed
AT RUNTIME. This makes a huge difference compared to the old approach.
The old approach was: if you want a USB gadget which contains this number
of configurations and in each configuration it contains these functions,
go create a new .c and compile it. Plus, if you want that
in mainline, persuade Felipe and Greg to take it. But with configfs
you have your building blocks in mainline (hopefully; Felipe?), and out of those
you compose the gadget you want, and if you want a gadget which consists of
different configurations/functions depending on some circumstances, everything
can be achieved at runtime. No need to write C code at all.

As far as g_ether.ko's equivalent is concerned, the equivalent of use_eem=1
module parameter boils down to instantiating the EEM function, while
the equivalent of use_eem=0 module parameter boils down to having some userspace
tool answer the "can_support_ecm()" question and instantiating either ECM or
ECM subset.

As for the (3), the ids are important for hosts to decide which drivers to use
to talk to the interfaces in the newly enumerated gadget. In the old gadget
there were some sensible defaults hardcoded and selected together with
the functions at gadget's bind. Now the functions selection

[PATCH 07/17] usb/gadget: f_eem: add configfs support

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 Documentation/ABI/testing/configfs-usb-gadget-eem |   14 ++
 drivers/usb/gadget/Kconfig|   15 ++
 drivers/usb/gadget/f_eem.c|   49 +
 drivers/usb/gadget/u_eem.h|9 
 4 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-eem

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-eem 
b/Documentation/ABI/testing/configfs-usb-gadget-eem
new file mode 100644
index 000..10e87d6
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-eem
@@ -0,0 +1,14 @@
+What:  /config/usb-gadget/gadget/functions/eem.name
+Date:  May 2013
+KenelVersion:  3.11
+Description:
+   The attributes:
+
+   ifname  - network device interface name associated with
+   this function instance
+   qmult   - queue length multiplier for high and
+   super speed
+   host_addr   - MAC address of host's end of this
+   Ethernet over USB link
+   dev_addr- MAC address of device's end of this
+   Ethernet over USB link
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index e432694..a874d7f 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -660,6 +660,21 @@ config USB_CONFIGFS_ECM
  favor of simpler vendor-specific hardware, but is widely
  supported by firmware for smart network devices.
 
+config USB_CONFIGFS_EEM
+   bool "Ethernet Emulation Model (EEM)"
+   depends on USB_CONFIGFS
+   depends on NET
+   select USB_U_ETHER
+   select USB_F_EEM
+   help
+ CDC EEM is a newer USB standard that is somewhat simpler than CDC ECM
+ and therefore can be supported by more hardware.  Technically ECM and
+ EEM are designed for different applications.  The ECM model extends
+ the network interface to the target (e.g. a USB cable modem), and the
+ EEM model is for mobile devices to communicate with hosts using
+ ethernet over USB.  For Linux gadgets, however, the interface with
+ the host is the same (a usbX device), so the differences are minimal.
+
 config USB_CONFIGFS_PHONET
boolean "Phonet protocol"
depends on USB_CONFIGFS
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index b06e462..d726b47 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -19,6 +19,7 @@
 #include 
 
 #include "u_ether.h"
+#include "u_ether_configfs.h"
 #include "u_eem.h"
 
 #define EEM_HLEN 2
@@ -263,8 +264,10 @@ static int eem_bind(struct usb_configuration *c, struct 
usb_function *f)
 * with regard to eem_opts->bound access
 */
if (!eem_opts->bound) {
+   mutex_lock(&eem_opts->lock);
gether_set_gadget(eem_opts->net, cdev->gadget);
status = gether_register_netdev(eem_opts->net);
+   mutex_unlock(&eem_opts->lock);
if (status)
return status;
eem_opts->bound = true;
@@ -533,6 +536,41 @@ error:
return status;
 }
 
+static inline struct f_eem_opts *to_f_eem_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct f_eem_opts,
+   func_inst.group);
+}
+
+/* f_eem_item_ops */
+USB_ETHERNET_CONFIGFS_ITEM(eem);
+
+/* f_eem_opts_dev_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(eem);
+
+/* f_eem_opts_host_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(eem);
+
+/* f_eem_opts_qmult */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(eem);
+
+/* f_eem_opts_ifname */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(eem);
+
+static struct configfs_attribute *eem_attrs[] = {
+   &f_eem_opts_dev_addr.attr,
+   &f_eem_opts_host_addr.attr,
+   &f_eem_opts_qmult.attr,
+   &f_eem_opts_ifname.attr,
+   NULL,
+};
+
+static struct config_item_type eem_func_type = {
+   .ct_item_ops= &eem_item_ops,
+   .ct_attrs   = eem_attrs,
+   .ct_owner   = THIS_MODULE,
+};
+
 static void eem_free_inst(struct usb_function_instance *f)
 {
struct f_eem_opts *opts;
@@ -552,20 +590,28 @@ static struct usb_function_instance *eem_alloc_inst(void)
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
return ERR_PTR(-ENOMEM);
+   mutex_init(&opts->lock);
opts->func_inst.free_func_inst = eem_free_inst;
opts->net = gether_setup_default();
if (IS_ERR(opts->net))
return ERR_PTR(PTR_ERR(opts->net));
 
+   config_group_init_type_name(&opts->func_inst.group, "", &eem_func_type);
+
return &opts->func_inst;
 }
 
 static void eem_free(struct usb_f

[PATCH 06/17] usb/gadget: f_eem: use usb_gstrings_attach

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_eem.c |   17 ++---
 1 files changed, 6 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index 57fc6bd..b06e462 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -248,6 +248,7 @@ static int eem_bind(struct usb_configuration *c, struct 
usb_function *f)
 {
struct usb_composite_dev *cdev = c->cdev;
struct f_eem*eem = func_to_eem(f);
+   struct usb_string   *us;
int status;
struct usb_ep   *ep;
 
@@ -269,16 +270,11 @@ static int eem_bind(struct usb_configuration *c, struct 
usb_function *f)
eem_opts->bound = true;
}
 
-   /* maybe allocate device-global string IDs */
-   if (eem_string_defs[0].id == 0) {
-
-   /* control interface label */
-   status = usb_string_id(c->cdev);
-   if (status < 0)
-   return status;
-   eem_string_defs[0].id = status;
-   eem_intf.iInterface = status;
-   }
+   us = usb_gstrings_attach(cdev, eem_strings,
+ARRAY_SIZE(eem_string_defs));
+   if (IS_ERR(us))
+   return PTR_ERR(us);
+   eem_intf.iInterface = us[0].id;
 
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
@@ -595,7 +591,6 @@ struct usb_function *eem_alloc(struct usb_function_instance 
*fi)
eem->port.cdc_filter = DEFAULT_FILTER;
 
eem->port.func.name = "cdc_eem";
-   eem->port.func.strings = eem_strings;
/* descriptors are per-instance copies */
eem->port.func.bind = eem_bind;
eem->port.func.unbind = eem_unbind;
-- 
1.7.0.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 04/17] usb/gadget: ether: convert to new interface of f_eem

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/ether.c |   54 ---
 2 files changed, 46 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 5f68ad3..e432694 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -743,6 +743,7 @@ config USB_ETH
select USB_U_ETHER
select USB_U_RNDIS
select USB_F_ECM
+   select USB_F_EEM
select CRC32
help
  This driver implements Ethernet style communication, in one of
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 397609d..2078e6c 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -109,8 +109,7 @@ static inline bool has_rndis(void)
 #include "rndis.h"
 #endif
 
-#define USB_FEEM_INCLUDED
-#include "f_eem.c"
+#include "u_eem.h"
 
 /*-*/
 USB_GADGET_COMPOSITE_OPTIONS();
@@ -217,6 +216,9 @@ static struct eth_dev *the_dev;
 static struct usb_function_instance *fi_ecm;
 static struct usb_function *f_ecm;
 
+static struct usb_function_instance *fi_eem;
+static struct usb_function *f_eem;
+
 /*-*/
 
 /*
@@ -267,9 +269,17 @@ static int __init eth_do_config(struct usb_configuration 
*c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   if (use_eem)
-   return eem_bind_config(c, the_dev);
-   else if (can_support_ecm(c->cdev->gadget)) {
+   if (use_eem) {
+   f_eem = usb_get_function(fi_eem);
+   if (IS_ERR(f_eem))
+   return PTR_ERR(f_eem);
+
+   status = usb_add_function(c, f_eem);
+   if (status < 0)
+   usb_put_function(f_eem);
+
+   return status;
+   } else if (can_support_ecm(c->cdev->gadget)) {
f_ecm = usb_get_function(fi_ecm);
if (IS_ERR(f_ecm))
return PTR_ERR(f_ecm);
@@ -296,10 +306,11 @@ static struct usb_configuration eth_config_driver = {
 static int __init eth_bind(struct usb_composite_dev *cdev)
 {
struct usb_gadget   *gadget = cdev->gadget;
+   struct f_eem_opts   *eem_opts = NULL;
struct f_ecm_opts   *ecm_opts = NULL;
int status;
 
-   if (use_eem || !can_support_ecm(gadget)) {
+   if (!use_eem && !can_support_ecm(gadget)) {
/* set up network link layer */
the_dev = gether_setup(cdev->gadget, dev_addr, host_addr,
host_mac, qmult);
@@ -310,6 +321,20 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
/* set up main config label and device descriptor */
if (use_eem) {
/* EEM */
+   fi_eem = usb_get_function_instance("eem");
+   if (IS_ERR(fi_eem))
+   return PTR_ERR(fi_eem);
+
+   eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
+
+   gether_set_qmult(eem_opts->net, qmult);
+   if (!gether_set_host_addr(eem_opts->net, host_addr))
+   pr_info("using host ethernet address: %s", host_addr);
+   if (!gether_set_dev_addr(eem_opts->net, dev_addr))
+   pr_info("using self ethernet address: %s", dev_addr);
+
+   the_dev = netdev_priv(eem_opts->net);
+
eth_config_driver.label = "CDC Ethernet (EEM)";
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
@@ -343,7 +368,14 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
if (has_rndis()) {
/* RNDIS plus ECM-or-Subset */
-   if (!use_eem && can_support_ecm(gadget)) {
+   if (use_eem) {
+   gether_set_gadget(eem_opts->net, cdev->gadget);
+   status = gether_register_netdev(eem_opts->net);
+   if (status)
+   goto fail;
+   eem_opts->bound = true;
+   gether_get_host_addr_u8(eem_opts->net, host_mac);
+   } else if (can_support_ecm(gadget)) {
gether_set_gadget(ecm_opts->net, cdev->gadget);
status = gether_register_netdev(ecm_opts->net);
if (status)
@@ -386,8 +418,10 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
return 0;
 
 fail:
-   if (use_eem || !can_support_ecm(gadget))
+   if (!use_eem && !can_support_ecm(gadget))
gether_cleanup(the_dev);
+   else if (use_eem)
+   usb_put_function_instance(fi_eem);
else
usb_put

[PATCH 13/17] usb/gadget: f_rndis: convert to new function interface with backward compatibility

2013-05-24 Thread Andrzej Pietrasiewicz
Converting rndis to the new function interface requires converting
the USB rndis' function code and its users.
This patch converts the f_rndis.c to the new function interface.
The file is now compiled into a separate usb_f_rndis.ko module.
The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig   |3 +
 drivers/usb/gadget/Makefile  |2 +
 drivers/usb/gadget/ether.c   |1 +
 drivers/usb/gadget/f_rndis.c |  203 --
 drivers/usb/gadget/g_ffs.c   |1 +
 drivers/usb/gadget/multi.c   |1 +
 drivers/usb/gadget/u_rndis.h |   32 +++
 7 files changed, 215 insertions(+), 28 deletions(-)
 create mode 100644 drivers/usb/gadget/u_rndis.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a369197..a4a6416 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -578,6 +578,9 @@ config USB_F_EEM
 config USB_F_SUBSET
tristate
 
+config USB_F_RNDIS
+   tristate
+
 choice
tristate "USB Gadget Drivers"
default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 99655e5..8cd7770 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -59,6 +59,8 @@ usb_f_eem-y   := f_eem.o
 obj-$(CONFIG_USB_F_EEM)+= usb_f_eem.o
 usb_f_ecm_subset-y := f_subset.o
 obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
+usb_f_rndis-y  := f_rndis.o
+obj-$(CONFIG_USB_F_RNDIS)  += usb_f_rndis.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 9e96d55..4d7290a 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -106,6 +106,7 @@ static inline bool has_rndis(void)
 #include "u_ecm.h"
 #include "u_gether.h"
 #ifdef USB_ETH_RNDIS
+#define USB_FRNDIS_INCLUDED
 #include "f_rndis.c"
 #include "rndis.h"
 #endif
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 36e8c44..b3cf661 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -17,15 +17,16 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
 #include 
 
 #include "u_ether.h"
+#include "u_rndis.h"
 #include "rndis.h"
 
-
 /*
  * This function is an RNDIS Ethernet port -- a Microsoft protocol that's
  * been promoted instead of the standard CDC Ethernet.  The published RNDIS
@@ -655,6 +656,13 @@ static void rndis_close(struct gether *geth)
 
 /*-*/
 
+/* Some controllers can't support RNDIS ... */
+static inline bool can_support_rndis(struct usb_configuration *c)
+{
+   /* everything else is *presumably* fine */
+   return true;
+}
+
 /* ethernet function driver setup/binding */
 
 static int
@@ -665,6 +673,45 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
int status;
struct usb_ep   *ep;
 
+#ifndef USB_FRNDIS_INCLUDED
+   struct f_rndis_opts *rndis_opts;
+
+   if (!can_support_rndis(c))
+   return -EINVAL;
+
+   rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
+
+   /*
+* in drivers/usb/gadget/configfs.c:configfs_composite_bind()
+* configurations are bound in sequence with list_for_each_entry,
+* in each configuration its functions are bound in sequence
+* with list_for_each_entry, so we assume no race condition
+* with regard to rndis_opts->bound access
+*/
+   if (!rndis_opts->bound) {
+   gether_set_gadget(rndis_opts->net, cdev->gadget);
+   status = gether_register_netdev(rndis_opts->net);
+   if (status)
+   return status;
+   rndis_opts->bound = true;
+   }
+#endif
+
+   if (rndis_string_defs[0].id == 0) {
+   /* ... and setup RNDIS itself */
+   status = rndis_init();
+   if (status < 0)
+   return status;
+
+   status = usb_string_ids_tab(c->cdev, rndis_string_defs);
+   if (status)
+   return status;
+
+   rndis_control_intf.iInterface = rndis_string_defs[0].id;
+   rndis_data_intf.iInterface = rndis_string_defs[1].id;
+   rndis_iad_descriptor.iFunction = rndis_string_defs[2].id;
+   }
+
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
if (status < 0)
@@ -741,10 +788,12 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
rndis->port.open = rndis_open;
rndis->port.close = rndis_close;
 
+#ifdef USB_FRNDIS_INCLUDED
status = rndis_register(rndis_response_available, rndis);
 

[PATCH 05/17] usb/gadget: f_eem: remove compatibility layer

2013-05-24 Thread Andrzej Pietrasiewicz
There are no old function interface users left, so the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_eem.c   |   59 --
 drivers/usb/gadget/u_ether.h |1 -
 2 files changed, 0 insertions(+), 60 deletions(-)

diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index 431a3e2..57fc6bd 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -251,7 +251,6 @@ static int eem_bind(struct usb_configuration *c, struct 
usb_function *f)
int status;
struct usb_ep   *ep;
 
-#ifndef USB_FEEM_INCLUDED
struct f_eem_opts   *eem_opts;
 
eem_opts = container_of(f->fi, struct f_eem_opts, func_inst);
@@ -269,7 +268,6 @@ static int eem_bind(struct usb_configuration *c, struct 
usb_function *f)
return status;
eem_opts->bound = true;
}
-#endif
 
/* maybe allocate device-global string IDs */
if (eem_string_defs[0].id == 0) {
@@ -539,61 +537,6 @@ error:
return status;
 }
 
-#ifdef USB_FEEM_INCLUDED
-
-static void eem_old_unbind(struct usb_configuration *c, struct usb_function *f)
-{
-   struct f_eem*eem = func_to_eem(f);
-
-   DBG(c->cdev, "eem unbind\n");
-
-   usb_free_all_descriptors(f);
-   kfree(eem);
-}
-
-/**
- * eem_bind_config - add CDC Ethernet (EEM) network link to a configuration
- * @c: the configuration to support the network link
- * Context: single threaded during gadget setup
- *
- * Returns zero on success, else negative errno.
- *
- * Caller must have called @gether_setup().  Caller is also responsible
- * for calling @gether_cleanup() before module unload.
- */
-int __init eem_bind_config(struct usb_configuration *c, struct eth_dev *dev)
-{
-   struct f_eem*eem;
-   int status;
-
-   /* allocate and initialize one new instance */
-   eem = kzalloc(sizeof *eem, GFP_KERNEL);
-   if (!eem)
-   return -ENOMEM;
-
-   eem->port.ioport = dev;
-   eem->port.cdc_filter = DEFAULT_FILTER;
-
-   eem->port.func.name = "cdc_eem";
-   eem->port.func.strings = eem_strings;
-   /* descriptors are per-instance copies */
-   eem->port.func.bind = eem_bind;
-   eem->port.func.unbind = eem_old_unbind;
-   eem->port.func.set_alt = eem_set_alt;
-   eem->port.func.setup = eem_setup;
-   eem->port.func.disable = eem_disable;
-   eem->port.wrap = eem_wrap;
-   eem->port.unwrap = eem_unwrap;
-   eem->port.header_len = EEM_HLEN;
-
-   status = usb_add_function(c, &eem->port.func);
-   if (status)
-   kfree(eem);
-   return status;
-}
-
-#else
-
 static void eem_free_inst(struct usb_function_instance *f)
 {
struct f_eem_opts *opts;
@@ -670,5 +613,3 @@ struct usb_function *eem_alloc(struct usb_function_instance 
*fi)
 DECLARE_USB_FUNCTION_INIT(eem, eem_alloc_inst, eem_alloc);
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("David Brownell");
-
-#endif
diff --git a/drivers/usb/gadget/u_ether.h b/drivers/usb/gadget/u_ether.h
index 5efa657..fb23d1f 100644
--- a/drivers/usb/gadget/u_ether.h
+++ b/drivers/usb/gadget/u_ether.h
@@ -272,7 +272,6 @@ int geth_bind_config(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
struct eth_dev *dev);
 int ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN],
struct eth_dev *dev);
-int eem_bind_config(struct usb_configuration *c, struct eth_dev *dev);
 
 #ifdef USB_ETH_RNDIS
 
-- 
1.7.0.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 11/17] usb/gadget: f_subset: use usb_gstrings_attach

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_subset.c |   18 --
 1 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index e7ec10c..d2d2d36 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -296,6 +296,7 @@ geth_bind(struct usb_configuration *c, struct usb_function 
*f)
 {
struct usb_composite_dev *cdev = c->cdev;
struct f_gether *geth = func_to_geth(f);
+   struct usb_string   *us;
int status;
struct usb_ep   *ep;
 
@@ -319,14 +320,13 @@ geth_bind(struct usb_configuration *c, struct 
usb_function *f)
gether_opts->bound = true;
}
 #endif
-   /* maybe allocate device-global string IDs */
-   if (geth_string_defs[0].id == 0) {
-   status = usb_string_ids_tab(c->cdev, geth_string_defs);
-   if (status < 0)
-   return status;
-   subset_data_intf.iInterface = geth_string_defs[0].id;
-   ether_desc.iMACAddress = geth_string_defs[1].id;
-   }
+   us = usb_gstrings_attach(cdev, geth_strings,
+ARRAY_SIZE(geth_string_defs));
+   if (IS_ERR(us))
+   return PTR_ERR(us);
+
+   subset_data_intf.iInterface = us[0].id;
+   ether_desc.iMACAddress = us[1].id;
 
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
@@ -431,7 +431,6 @@ int geth_bind_config(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
geth->port.cdc_filter = DEFAULT_FILTER;
 
geth->port.func.name = "cdc_subset";
-   geth->port.func.strings = geth_strings;
geth->port.func.bind = geth_bind;
geth->port.func.unbind = geth_old_unbind;
geth->port.func.set_alt = geth_set_alt;
@@ -513,7 +512,6 @@ struct usb_function *geth_alloc(struct 
usb_function_instance *fi)
geth->port.cdc_filter = DEFAULT_FILTER;
 
geth->port.func.name = "cdc_subset";
-   geth->port.func.strings = geth_strings;
geth->port.func.bind = geth_bind;
geth->port.func.unbind = geth_unbind;
geth->port.func.set_alt = geth_set_alt;
-- 
1.7.0.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 17/17] usb/gadget: f_rndis: add configfs support

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 .../ABI/testing/configfs-usb-gadget-rndis  |   14 ++
 drivers/usb/gadget/Kconfig |   16 ++
 drivers/usb/gadget/f_rndis.c   |   49 +++-
 drivers/usb/gadget/u_rndis.h   |9 
 4 files changed, 87 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-rndis

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-rndis 
b/Documentation/ABI/testing/configfs-usb-gadget-rndis
new file mode 100644
index 000..ff127dd
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-rndis
@@ -0,0 +1,14 @@
+What:  /config/usb-gadget/gadget/functions/rndis.name
+Date:  May 2013
+KenelVersion:  3.11
+Description:
+   The attributes:
+
+   ifname  - network device interface name associated with
+   this function instance
+   qmult   - queue length multiplier for high and
+   super speed
+   host_addr   - MAC address of host's end of this
+   Ethernet over USB link
+   dev_addr- MAC address of device's end of this
+   Ethernet over USB link
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a33a307..55da18c 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -676,6 +676,22 @@ config USB_CONFIGFS_ECM_SUBSET
  On hardware that can't implement the full protocol,
  a simple CDC subset is used, placing fewer demands on USB.
 
+config USB_CONFIGFS_RNDIS
+   bool "RNDIS"
+   depends on USB_CONFIGFS
+   depends on NET
+   select USB_U_ETHER
+   select USB_F_RNDIS
+   help
+  Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
+  and Microsoft provides redistributable binary RNDIS drivers for
+  older versions of Windows.
+
+  To make MS-Windows work with this, use Documentation/usb/linux.inf
+  as the "driver info file".  For versions of MS-Windows older than
+  XP, you'll need to download drivers from Microsoft's website; a URL
+  is given in comments found in that info file.
+
 config USB_CONFIGFS_EEM
bool "Ethernet Emulation Model (EEM)"
depends on USB_CONFIGFS
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index da95e18..b8a8081 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -24,6 +24,7 @@
 #include 
 
 #include "u_ether.h"
+#include "u_ether_configfs.h"
 #include "u_rndis.h"
 #include "rndis.h"
 
@@ -903,6 +904,41 @@ void rndis_borrow_net(struct usb_function_instance *f, 
struct net_device *net)
 }
 EXPORT_SYMBOL(rndis_borrow_net);
 
+static inline struct f_rndis_opts *to_f_rndis_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct f_rndis_opts,
+   func_inst.group);
+}
+
+/* f_rndis_item_ops */
+USB_ETHERNET_CONFIGFS_ITEM(rndis);
+
+/* f_rndis_opts_dev_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(rndis);
+
+/* f_rndis_opts_host_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(rndis);
+
+/* f_rndis_opts_qmult */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
+
+/* f_rndis_opts_ifname */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
+
+static struct configfs_attribute *rndis_attrs[] = {
+   &f_rndis_opts_dev_addr.attr,
+   &f_rndis_opts_host_addr.attr,
+   &f_rndis_opts_qmult.attr,
+   &f_rndis_opts_ifname.attr,
+   NULL,
+};
+
+static struct config_item_type rndis_func_type = {
+   .ct_item_ops= &rndis_item_ops,
+   .ct_attrs   = rndis_attrs,
+   .ct_owner   = THIS_MODULE,
+};
+
 static void rndis_free_inst(struct usb_function_instance *f)
 {
struct f_rndis_opts *opts;
@@ -924,22 +960,30 @@ static struct usb_function_instance 
*rndis_alloc_inst(void)
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
return ERR_PTR(-ENOMEM);
-
+   mutex_init(&opts->lock);
opts->func_inst.free_func_inst = rndis_free_inst;
opts->net = gether_setup_default();
if (IS_ERR(opts->net))
return ERR_CAST(opts->net);
 
+   config_group_init_type_name(&opts->func_inst.group, "",
+   &rndis_func_type);
+
return &opts->func_inst;
 }
 
 static void rndis_free(struct usb_function *f)
 {
struct f_rndis *rndis;
+   struct f_rndis_opts *opts;
 
rndis = func_to_rndis(f);
rndis_deregister(rndis->config);
+   opts = container_of(f->fi, struct f_rndis_opts, func_inst);
kfree(rndis);
+   mutex_lock(&opts->lock);
+   opts->refcnt--;
+   mutex_unlock(&opts->lock);
 }
 
 static void rndis_unbind(struct usb_configur

[PATCH 16/17] usb/gadget: f_rndis: use usb_gstrings_attach

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_rndis.c |   22 --
 1 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 2d4aaa1..da95e18 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -670,6 +670,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function 
*f)
 {
struct usb_composite_dev *cdev = c->cdev;
struct f_rndis  *rndis = func_to_rndis(f);
+   struct usb_string   *us;
int status;
struct usb_ep   *ep;
 
@@ -696,16 +697,13 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
rndis_opts->bound = true;
}
 #endif
-
-   if (rndis_string_defs[0].id == 0) {
-   status = usb_string_ids_tab(c->cdev, rndis_string_defs);
-   if (status)
-   return status;
-
-   rndis_control_intf.iInterface = rndis_string_defs[0].id;
-   rndis_data_intf.iInterface = rndis_string_defs[1].id;
-   rndis_iad_descriptor.iFunction = rndis_string_defs[2].id;
-   }
+   us = usb_gstrings_attach(cdev, rndis_strings,
+ARRAY_SIZE(rndis_string_defs));
+   if (IS_ERR(us))
+   return PTR_ERR(us);
+   rndis_control_intf.iInterface = us[0].id;
+   rndis_data_intf.iInterface = us[1].id;
+   rndis_iad_descriptor.iFunction = us[2].id;
 
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
@@ -840,7 +838,6 @@ rndis_old_unbind(struct usb_configuration *c, struct 
usb_function *f)
 
rndis_deregister(rndis->config);
 
-   rndis_string_defs[0].id = 0;
usb_free_all_descriptors(f);
 
kfree(rndis->notify_req->buf);
@@ -876,7 +873,6 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
rndis->port.unwrap = rndis_rm_hdr;
 
rndis->port.func.name = "rndis";
-   rndis->port.func.strings = rndis_strings;
/* descriptors are per-instance copies */
rndis->port.func.bind = rndis_bind;
rndis->port.func.unbind = rndis_old_unbind;
@@ -950,7 +946,6 @@ static void rndis_unbind(struct usb_configuration *c, 
struct usb_function *f)
 {
struct f_rndis  *rndis = func_to_rndis(f);
 
-   rndis_string_defs[0].id = 0;
usb_free_all_descriptors(f);
 
kfree(rndis->notify_req->buf);
@@ -984,7 +979,6 @@ struct usb_function *rndis_alloc(struct 
usb_function_instance *fi)
rndis->port.unwrap = rndis_rm_hdr;
 
rndis->port.func.name = "rndis";
-   rndis->port.func.strings = rndis_strings;
/* descriptors are per-instance copies */
rndis->port.func.bind = rndis_bind;
rndis->port.func.unbind = rndis_unbind;
-- 
1.7.0.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 15/17] usb/gadget: rndis: init & exit rndis at module load/unload

2013-05-24 Thread Andrzej Pietrasiewicz
This is required in preparation for using usb_gstrings_attach.
The rndis initialization so far has been performed on the first
occurence of rndis_bind(), but the condition to check it (first
or not first) was "borrowed" from strings handling.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_rndis.c |   15 ++-
 drivers/usb/gadget/rndis.c   |4 ++--
 drivers/usb/gadget/rndis.h   |3 ---
 3 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index b3cf661..2d4aaa1 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -698,11 +698,6 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
 #endif
 
if (rndis_string_defs[0].id == 0) {
-   /* ... and setup RNDIS itself */
-   status = rndis_init();
-   if (status < 0)
-   return status;
-
status = usb_string_ids_tab(c->cdev, rndis_string_defs);
if (status)
return status;
@@ -844,7 +839,6 @@ rndis_old_unbind(struct usb_configuration *c, struct 
usb_function *f)
struct f_rndis  *rndis = func_to_rndis(f);
 
rndis_deregister(rndis->config);
-   rndis_exit();
 
rndis_string_defs[0].id = 0;
usb_free_all_descriptors(f);
@@ -891,11 +885,9 @@ rndis_bind_config_vendor(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
rndis->port.func.disable = rndis_disable;
 
status = usb_add_function(c, &rndis->port.func);
-   if (status) {
+   if (status)
kfree(rndis);
 fail:
-   rndis_exit();
-   }
return status;
 }
 
@@ -958,7 +950,6 @@ static void rndis_unbind(struct usb_configuration *c, 
struct usb_function *f)
 {
struct f_rndis  *rndis = func_to_rndis(f);
 
-   rndis_exit();
rndis_string_defs[0].id = 0;
usb_free_all_descriptors(f);
 
@@ -974,10 +965,8 @@ struct usb_function *rndis_alloc(struct 
usb_function_instance *fi)
 
/* allocate and initialize one new instance */
rndis = kzalloc(sizeof(*rndis), GFP_KERNEL);
-   if (!rndis) {
-   rndis_exit();
+   if (!rndis)
return ERR_PTR(-ENOMEM);
-   }
 
opts = container_of(fi, struct f_rndis_opts, func_inst);
 
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 4e84964..45f1114 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1174,7 +1174,7 @@ int rndis_init(void)
 
return 0;
 }
-EXPORT_SYMBOL(rndis_init);
+module_init(rndis_init);
 
 void rndis_exit(void)
 {
@@ -1188,6 +1188,6 @@ void rndis_exit(void)
}
 #endif
 }
-EXPORT_SYMBOL(rndis_exit);
+module_exit(rndis_exit);
 
 MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/rndis.h b/drivers/usb/gadget/rndis.h
index 6e79615..0f4abb4 100644
--- a/drivers/usb/gadget/rndis.h
+++ b/drivers/usb/gadget/rndis.h
@@ -217,7 +217,4 @@ int  rndis_signal_disconnect (int configNr);
 int  rndis_state (int configNr);
 extern void rndis_set_host_mac (int configNr, const u8 *addr);
 
-int rndis_init(void);
-void rndis_exit (void);
-
 #endif  /* _LINUX_RNDIS_H */
-- 
1.7.0.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 14/17] usb/gadget: ether: convert to new interface of f_rndis

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/ether.c |   54 +--
 2 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a4a6416..a33a307 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -812,6 +812,7 @@ config USB_ETH_RNDIS
bool "RNDIS support"
depends on USB_ETH
select USB_LIBCOMPOSITE
+   select USB_F_RNDIS
default y
help
   Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 4d7290a..71fc52f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -94,23 +94,12 @@ static inline bool has_rndis(void)
 
 #include 
 
-/*-*/
-
-/*
- * Kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
- */
 #include "u_ecm.h"
 #include "u_gether.h"
 #ifdef USB_ETH_RNDIS
-#define USB_FRNDIS_INCLUDED
-#include "f_rndis.c"
+#include "u_rndis.h"
 #include "rndis.h"
 #endif
-
 #include "u_eem.h"
 
 /*-*/
@@ -212,9 +201,6 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
-static u8 host_mac[ETH_ALEN];
-static struct eth_dev *the_dev;
-
 static struct usb_function_instance *fi_ecm;
 static struct usb_function *f_ecm;
 
@@ -224,6 +210,9 @@ static struct usb_function *f_eem;
 static struct usb_function_instance *fi_geth;
 static struct usb_function *f_geth;
 
+static struct usb_function_instance *fi_rndis;
+static struct usb_function *f_rndis;
+
 /*-*/
 
 /*
@@ -233,6 +222,8 @@ static struct usb_function *f_geth;
  */
 static int __init rndis_do_config(struct usb_configuration *c)
 {
+   int status;
+
/* FIXME alloc iConfiguration string, set it in c->strings */
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -240,7 +231,15 @@ static int __init rndis_do_config(struct usb_configuration 
*c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   return rndis_bind_config(c, host_mac, the_dev);
+   f_rndis = usb_get_function(fi_rndis);
+   if (IS_ERR(f_rndis))
+   return PTR_ERR(f_rndis);
+
+   status = usb_add_function(c, f_rndis);
+   if (status < 0)
+   usb_put_function(f_rndis);
+
+   return status;
 }
 
 static struct usb_configuration rndis_config_driver = {
@@ -336,7 +335,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
 
net = eem_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (EEM)";
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
@@ -351,7 +349,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
 
net = ecm_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (ECM)";
} else {
@@ -365,7 +362,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 func_inst);
 
net = geth_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Subset/SAFE";
 
@@ -387,7 +383,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
status = gether_register_netdev(net);
if (status)
goto fail;
-   gether_get_host_addr_u8(net, host_mac);
 
if (use_eem)
eem_opts->bound = true;
@@ -396,6 +391,14 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
else
geth_opts->bound = true;
 
+   fi_rndis = usb_get_function_instance("rndis");
+   if (IS_ERR(fi_rndis)) {
+   status = PTR_ERR(fi_rndis);
+   goto fail;
+   }
+
+   rndis_borrow_net(fi_rndis, net);
+
device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
device_desc.bNumConfigurations = 2;
@@ -407,7 +410,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
status = usb_string_ids_t

[PATCH 12/17] usb/gadget: f_subset: add configfs support

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 .../ABI/testing/configfs-usb-gadget-subset |   14 ++
 drivers/usb/gadget/Kconfig |   10 
 drivers/usb/gadget/f_subset.c  |   46 +++-
 drivers/usb/gadget/u_gether.h  |9 
 4 files changed, 78 insertions(+), 1 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-subset

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-subset 
b/Documentation/ABI/testing/configfs-usb-gadget-subset
new file mode 100644
index 000..f47170a
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-subset
@@ -0,0 +1,14 @@
+What:  /config/usb-gadget/gadget/functions/geth.name
+Date:  May 2013
+KenelVersion:  3.11
+Description:
+   The attributes:
+
+   ifname  - network device interface name associated with
+   this function instance
+   qmult   - queue length multiplier for high and
+   super speed
+   host_addr   - MAC address of host's end of this
+   Ethernet over USB link
+   dev_addr- MAC address of device's end of this
+   Ethernet over USB link
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 066f7e6..a369197 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -663,6 +663,16 @@ config USB_CONFIGFS_ECM
  favor of simpler vendor-specific hardware, but is widely
  supported by firmware for smart network devices.
 
+config USB_CONFIGFS_ECM_SUBSET
+   boolean "Ethernet Control Model (CDC ECM) subset"
+   depends on USB_CONFIGFS
+   depends on NET
+   select USB_U_ETHER
+   select USB_F_SUBSET
+   help
+ On hardware that can't implement the full protocol,
+ a simple CDC subset is used, placing fewer demands on USB.
+
 config USB_CONFIGFS_EEM
bool "Ethernet Emulation Model (EEM)"
depends on USB_CONFIGFS
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index d2d2d36..fc8b5ef 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -17,6 +17,7 @@
 #include 
 
 #include "u_ether.h"
+#include "u_ether_configfs.h"
 #include "u_gether.h"
 
 /*
@@ -313,8 +314,10 @@ geth_bind(struct usb_configuration *c, struct usb_function 
*f)
 * with regard to gether_opts->bound access
 */
if (!gether_opts->bound) {
+   mutex_lock(&gether_opts->lock);
gether_set_gadget(gether_opts->net, cdev->gadget);
status = gether_register_netdev(gether_opts->net);
+   mutex_unlock(&gether_opts->lock);
if (status)
return status;
gether_opts->bound = true;
@@ -444,6 +447,41 @@ int geth_bind_config(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
 
 #else
 
+static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct f_gether_opts,
+   func_inst.group);
+}
+
+/* f_gether_item_ops */
+USB_ETHERNET_CONFIGFS_ITEM(gether);
+
+/* f_gether_opts_dev_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(gether);
+
+/* f_gether_opts_host_addr */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(gether);
+
+/* f_gether_opts_qmult */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);
+
+/* f_gether_opts_ifname */
+USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether);
+
+static struct configfs_attribute *gether_attrs[] = {
+   &f_gether_opts_dev_addr.attr,
+   &f_gether_opts_host_addr.attr,
+   &f_gether_opts_qmult.attr,
+   &f_gether_opts_ifname.attr,
+   NULL,
+};
+
+static struct config_item_type gether_func_type = {
+   .ct_item_ops= &gether_item_ops,
+   .ct_attrs   = gether_attrs,
+   .ct_owner   = THIS_MODULE,
+};
+
 static void geth_free_inst(struct usb_function_instance *f)
 {
struct f_gether_opts *opts;
@@ -463,12 +501,15 @@ static struct usb_function_instance *geth_alloc_inst(void)
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
if (!opts)
return ERR_PTR(-ENOMEM);
-
+   mutex_init(&opts->lock);
opts->func_inst.free_func_inst = geth_free_inst;
opts->net = gether_setup_default();
if (IS_ERR(opts->net))
return ERR_CAST(opts->net);
 
+   config_group_init_type_name(&opts->func_inst.group, "",
+   &gether_func_type);
+
return &opts->func_inst;
 }
 
@@ -499,6 +540,8 @@ struct usb_function *geth_alloc(struct 
usb_function_instance *fi)
 
opts = container_of(fi, struct f_gether_opts, func_inst);
 
+   mutex_lock(&opts->lock);
+   opts->refcnt++;
/* export host's Etherne

[PATCH 09/17] usb/gadget: f_subset: convert to new function interface with backward compatibility

2013-05-24 Thread Andrzej Pietrasiewicz
Converting ecm subset to the new function interface requires converting
the USB subset's function code and its users.
This patch converts the f_subset.c to the new function interface.
The file is now compiled into a separate usb_f_subset.ko module.
The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig|3 +
 drivers/usb/gadget/Makefile   |2 +
 drivers/usb/gadget/ether.c|1 +
 drivers/usb/gadget/f_subset.c |  136 -
 drivers/usb/gadget/g_ffs.c|1 +
 drivers/usb/gadget/u_gether.h |   27 
 6 files changed, 155 insertions(+), 15 deletions(-)
 create mode 100644 drivers/usb/gadget/u_gether.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a874d7f..2642549 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -575,6 +575,9 @@ config USB_F_PHONET
 config USB_F_EEM
tristate
 
+config USB_F_SUBSET
+   tristate
+
 choice
tristate "USB Gadget Drivers"
default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index a8f6655..99655e5 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -57,6 +57,8 @@ usb_f_phonet-y:= f_phonet.o
 obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o
 usb_f_eem-y:= f_eem.o
 obj-$(CONFIG_USB_F_EEM)+= usb_f_eem.o
+usb_f_ecm_subset-y := f_subset.o
+obj-$(CONFIG_USB_F_SUBSET) += usb_f_ecm_subset.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 2078e6c..3173966 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -103,6 +103,7 @@ static inline bool has_rndis(void)
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
 #include "u_ecm.h"
+#define USB_FSUBSET_INCLUDED
 #include "f_subset.c"
 #ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index 185d6f5..e7ec10c 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -12,11 +12,12 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
 #include "u_ether.h"
-
+#include "u_gether.h"
 
 /*
  * This function packages a simple "CDC Subset" Ethernet port with no real
@@ -298,6 +299,35 @@ geth_bind(struct usb_configuration *c, struct usb_function 
*f)
int status;
struct usb_ep   *ep;
 
+#ifndef USB_FSUBSET_INCLUDED
+   struct f_gether_opts*gether_opts;
+
+   gether_opts = container_of(f->fi, struct f_gether_opts, func_inst);
+
+   /*
+* in drivers/usb/gadget/configfs.c:configfs_composite_bind()
+* configurations are bound in sequence with list_for_each_entry,
+* in each configuration its functions are bound in sequence
+* with list_for_each_entry, so we assume no race condition
+* with regard to gether_opts->bound access
+*/
+   if (!gether_opts->bound) {
+   gether_set_gadget(gether_opts->net, cdev->gadget);
+   status = gether_register_netdev(gether_opts->net);
+   if (status)
+   return status;
+   gether_opts->bound = true;
+   }
+#endif
+   /* maybe allocate device-global string IDs */
+   if (geth_string_defs[0].id == 0) {
+   status = usb_string_ids_tab(c->cdev, geth_string_defs);
+   if (status < 0)
+   return status;
+   subset_data_intf.iInterface = geth_string_defs[0].id;
+   ether_desc.iMACAddress = geth_string_defs[1].id;
+   }
+
/* allocate instance-specific interface IDs */
status = usb_interface_id(c, f);
if (status < 0)
@@ -360,8 +390,10 @@ fail:
return status;
 }
 
+#ifdef USB_FSUBSET_INCLUDED
+
 static void
-geth_unbind(struct usb_configuration *c, struct usb_function *f)
+geth_old_unbind(struct usb_configuration *c, struct usb_function *f)
 {
geth_string_defs[0].id = 0;
usb_free_all_descriptors(f);
@@ -386,18 +418,6 @@ int geth_bind_config(struct usb_configuration *c, u8 
ethaddr[ETH_ALEN],
struct f_gether *geth;
int status;
 
-   if (!ethaddr)
-   return -EINVAL;
-
-   /* maybe allocate device-global string IDs */
-   if (geth_string_defs[0].id == 0) {
-   status = usb_string_ids_tab(c->cdev, geth_string_defs);
-   if (status < 0)
-   return status;
-   subset_data_intf.iInterface = geth_string_defs[0].id;
-   ether_desc.iMACAddress = geth_string_defs[1].id;
-   }
-
/* allocate and initialize one new instance */
geth = kzalloc

[PATCH 08/17] usb/gadget: multi: Remove unused include

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/multi.c |1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index f9e07c0..66f756f 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -45,7 +45,6 @@ MODULE_LICENSE("GPL");
 
 #define USBF_ECM_INCLUDED
 #include "f_ecm.c"
-#include "f_subset.c"
 #ifdef USB_ETH_RNDIS
 #  include "f_rndis.c"
 #  include "rndis.h"
-- 
1.7.0.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 03/17] usb/gadget: f_eem: convert to new function interface with backward compatibility

2013-05-24 Thread Andrzej Pietrasiewicz
Converting eem to the new function interface requires converting
the USB eem's function code and its users.
This patch converts the f_eem.c to the new function interface.
The file is now compiled into a separate usb_f_eem.ko module.
The old function interface is provided by means of a preprocessor
conditional directives. After all users are converted, the old interface
can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig  |3 +
 drivers/usb/gadget/Makefile |2 +
 drivers/usb/gadget/ether.c  |2 +
 drivers/usb/gadget/f_eem.c  |  174 ++-
 drivers/usb/gadget/u_eem.h  |   27 +++
 5 files changed, 172 insertions(+), 36 deletions(-)
 create mode 100644 drivers/usb/gadget/u_eem.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index ae0ac04..5f68ad3 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -572,6 +572,9 @@ config USB_F_ECM
 config USB_F_PHONET
tristate
 
+config USB_F_EEM
+   tristate
+
 choice
tristate "USB Gadget Drivers"
default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index f065e67..a8f6655 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -55,6 +55,8 @@ usb_f_ecm-y   := f_ecm.o
 obj-$(CONFIG_USB_F_ECM)+= usb_f_ecm.o
 usb_f_phonet-y := f_phonet.o
 obj-$(CONFIG_USB_F_PHONET) += usb_f_phonet.o
+usb_f_eem-y:= f_eem.o
+obj-$(CONFIG_USB_F_EEM)+= usb_f_eem.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index f4d46d7..397609d 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -108,6 +108,8 @@ static inline bool has_rndis(void)
 #include "f_rndis.c"
 #include "rndis.h"
 #endif
+
+#define USB_FEEM_INCLUDED
 #include "f_eem.c"
 
 /*-*/
diff --git a/drivers/usb/gadget/f_eem.c b/drivers/usb/gadget/f_eem.c
index f4e0bbe..431a3e2 100644
--- a/drivers/usb/gadget/f_eem.c
+++ b/drivers/usb/gadget/f_eem.c
@@ -12,12 +12,14 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 
 #include "u_ether.h"
+#include "u_eem.h"
 
 #define EEM_HLEN 2
 
@@ -40,7 +42,7 @@ static inline struct f_eem *func_to_eem(struct usb_function 
*f)
 
 /* interface descriptor: */
 
-static struct usb_interface_descriptor eem_intf __initdata = {
+static struct usb_interface_descriptor eem_intf = {
.bLength =  sizeof eem_intf,
.bDescriptorType =  USB_DT_INTERFACE,
 
@@ -54,7 +56,7 @@ static struct usb_interface_descriptor eem_intf __initdata = {
 
 /* full speed support: */
 
-static struct usb_endpoint_descriptor eem_fs_in_desc __initdata = {
+static struct usb_endpoint_descriptor eem_fs_in_desc = {
.bLength =  USB_DT_ENDPOINT_SIZE,
.bDescriptorType =  USB_DT_ENDPOINT,
 
@@ -62,7 +64,7 @@ static struct usb_endpoint_descriptor eem_fs_in_desc 
__initdata = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
 };
 
-static struct usb_endpoint_descriptor eem_fs_out_desc __initdata = {
+static struct usb_endpoint_descriptor eem_fs_out_desc = {
.bLength =  USB_DT_ENDPOINT_SIZE,
.bDescriptorType =  USB_DT_ENDPOINT,
 
@@ -70,7 +72,7 @@ static struct usb_endpoint_descriptor eem_fs_out_desc 
__initdata = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
 };
 
-static struct usb_descriptor_header *eem_fs_function[] __initdata = {
+static struct usb_descriptor_header *eem_fs_function[] = {
/* CDC EEM control descriptors */
(struct usb_descriptor_header *) &eem_intf,
(struct usb_descriptor_header *) &eem_fs_in_desc,
@@ -80,7 +82,7 @@ static struct usb_descriptor_header *eem_fs_function[] 
__initdata = {
 
 /* high speed support: */
 
-static struct usb_endpoint_descriptor eem_hs_in_desc __initdata = {
+static struct usb_endpoint_descriptor eem_hs_in_desc = {
.bLength =  USB_DT_ENDPOINT_SIZE,
.bDescriptorType =  USB_DT_ENDPOINT,
 
@@ -89,7 +91,7 @@ static struct usb_endpoint_descriptor eem_hs_in_desc 
__initdata = {
.wMaxPacketSize =   cpu_to_le16(512),
 };
 
-static struct usb_endpoint_descriptor eem_hs_out_desc __initdata = {
+static struct usb_endpoint_descriptor eem_hs_out_desc = {
.bLength =  USB_DT_ENDPOINT_SIZE,
.bDescriptorType =  USB_DT_ENDPOINT,
 
@@ -98,7 +100,7 @@ static struct usb_endpoint_descriptor eem_hs_out_desc 
__initdata = {
.wMaxPacketSize =   cpu_to_le16(512),
 };
 
-static struct usb_descriptor_header *eem_hs_function[] __initdata = {
+static struct usb_descriptor_header *eem_hs_function[] = {
/* CDC EEM control descriptors */
(struct usb_descriptor_header *) &eem_intf,
(struct usb_descrip

[PATCH 10/17] usb/gadget: ether: convert to new interface of f_subset

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/ether.c |  104 
 2 files changed, 58 insertions(+), 47 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 2642549..066f7e6 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -762,6 +762,7 @@ config USB_ETH
select USB_U_RNDIS
select USB_F_ECM
select USB_F_EEM
+   select USB_F_SUBSET
select CRC32
help
  This driver implements Ethernet style communication, in one of
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 3173966..9e96d55 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -14,6 +14,7 @@
 /* #define VERBOSE_DEBUG */
 
 #include 
+#include 
 
 #if defined USB_ETH_RNDIS
 #  undef USB_ETH_RNDIS
@@ -103,8 +104,7 @@ static inline bool has_rndis(void)
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
 #include "u_ecm.h"
-#define USB_FSUBSET_INCLUDED
-#include "f_subset.c"
+#include "u_gether.h"
 #ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
 #include "rndis.h"
@@ -220,6 +220,9 @@ static struct usb_function *f_ecm;
 static struct usb_function_instance *fi_eem;
 static struct usb_function *f_eem;
 
+static struct usb_function_instance *fi_geth;
+static struct usb_function *f_geth;
+
 /*-*/
 
 /*
@@ -290,8 +293,17 @@ static int __init eth_do_config(struct usb_configuration 
*c)
usb_put_function(f_ecm);
 
return status;
-   } else
-   return geth_bind_config(c, host_mac, the_dev);
+   } else {
+   f_geth = usb_get_function(fi_geth);
+   if (IS_ERR(f_geth))
+   return PTR_ERR(f_geth);
+
+   status = usb_add_function(c, f_geth);
+   if (status < 0)
+   usb_put_function(f_geth);
+
+   return status;
+   }
 
 }
 
@@ -309,16 +321,10 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
struct usb_gadget   *gadget = cdev->gadget;
struct f_eem_opts   *eem_opts = NULL;
struct f_ecm_opts   *ecm_opts = NULL;
+   struct f_gether_opts*geth_opts = NULL;
+   struct net_device   *net;
int status;
 
-   if (!use_eem && !can_support_ecm(gadget)) {
-   /* set up network link layer */
-   the_dev = gether_setup(cdev->gadget, dev_addr, host_addr,
-   host_mac, qmult);
-   if (IS_ERR(the_dev))
-   return PTR_ERR(the_dev);
-   }
-
/* set up main config label and device descriptor */
if (use_eem) {
/* EEM */
@@ -328,13 +334,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
 
-   gether_set_qmult(eem_opts->net, qmult);
-   if (!gether_set_host_addr(eem_opts->net, host_addr))
-   pr_info("using host ethernet address: %s", host_addr);
-   if (!gether_set_dev_addr(eem_opts->net, dev_addr))
-   pr_info("using self ethernet address: %s", dev_addr);
-
-   the_dev = netdev_priv(eem_opts->net);
+   net = eem_opts->net;
+   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (EEM)";
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
@@ -348,17 +349,23 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
 
-   gether_set_qmult(ecm_opts->net, qmult);
-   if (!gether_set_host_addr(ecm_opts->net, host_addr))
-   pr_info("using host ethernet address: %s", host_addr);
-   if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
-   pr_info("using self ethernet address: %s", dev_addr);
-
-   the_dev = netdev_priv(ecm_opts->net);
+   net = ecm_opts->net;
+   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (ECM)";
} else {
/* CDC Subset */
+
+   fi_geth = usb_get_function_instance("geth");
+   if (IS_ERR(fi_geth))
+   return PTR_ERR(fi_geth);
+
+   geth_opts = container_of(fi_geth, struct f_gether_opts,
+func_inst);
+
+   net = geth_opts->net;
+   the_dev = netdev_priv(net);
+
eth_config_driver.label = "CDC Subset/SAFE";
 
device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
@@ -367,23 +374,26 @@ static 

[PATCH 02/17] usb/gadget: ether: convert to new interface of f_ecm

2013-05-24 Thread Andrzej Pietrasiewicz
Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/ether.c |   73 
 2 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 6dd2192..ae0ac04 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -739,6 +739,7 @@ config USB_ETH
select USB_LIBCOMPOSITE
select USB_U_ETHER
select USB_U_RNDIS
+   select USB_F_ECM
select CRC32
help
  This driver implements Ethernet style communication, in one of
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 862ef65..f4d46d7 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -102,8 +102,7 @@ static inline bool has_rndis(void)
  * the runtime footprint, and giving us at least some parts of what
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
-#define USBF_ECM_INCLUDED
-#include "f_ecm.c"
+#include "u_ecm.h"
 #include "f_subset.c"
 #ifdef USB_ETH_RNDIS
 #include "f_rndis.c"
@@ -212,6 +211,10 @@ static struct usb_gadget_strings *dev_strings[] = {
 
 static u8 host_mac[ETH_ALEN];
 static struct eth_dev *the_dev;
+
+static struct usb_function_instance *fi_ecm;
+static struct usb_function *f_ecm;
+
 /*-*/
 
 /*
@@ -253,6 +256,8 @@ MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
  */
 static int __init eth_do_config(struct usb_configuration *c)
 {
+   int status = 0;
+
/* FIXME alloc iConfiguration string, set it in c->strings */
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -262,10 +267,19 @@ static int __init eth_do_config(struct usb_configuration 
*c)
 
if (use_eem)
return eem_bind_config(c, the_dev);
-   else if (can_support_ecm(c->cdev->gadget))
-   return ecm_bind_config(c, host_mac, the_dev);
-   else
+   else if (can_support_ecm(c->cdev->gadget)) {
+   f_ecm = usb_get_function(fi_ecm);
+   if (IS_ERR(f_ecm))
+   return PTR_ERR(f_ecm);
+
+   status = usb_add_function(c, f_ecm);
+   if (status < 0)
+   usb_put_function(f_ecm);
+
+   return status;
+   } else
return geth_bind_config(c, host_mac, the_dev);
+
 }
 
 static struct usb_configuration eth_config_driver = {
@@ -280,13 +294,16 @@ static struct usb_configuration eth_config_driver = {
 static int __init eth_bind(struct usb_composite_dev *cdev)
 {
struct usb_gadget   *gadget = cdev->gadget;
+   struct f_ecm_opts   *ecm_opts = NULL;
int status;
 
-   /* set up network link layer */
-   the_dev = gether_setup(cdev->gadget, dev_addr, host_addr, host_mac,
-  qmult);
-   if (IS_ERR(the_dev))
-   return PTR_ERR(the_dev);
+   if (use_eem || !can_support_ecm(gadget)) {
+   /* set up network link layer */
+   the_dev = gether_setup(cdev->gadget, dev_addr, host_addr,
+   host_mac, qmult);
+   if (IS_ERR(the_dev))
+   return PTR_ERR(the_dev);
+   }
 
/* set up main config label and device descriptor */
if (use_eem) {
@@ -294,8 +311,23 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
eth_config_driver.label = "CDC Ethernet (EEM)";
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
-   } else if (can_support_ecm(cdev->gadget)) {
+   } else if (can_support_ecm(gadget)) {
/* ECM */
+
+   fi_ecm = usb_get_function_instance("ecm");
+   if (IS_ERR(fi_ecm))
+   return PTR_ERR(fi_ecm);
+
+   ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
+
+   gether_set_qmult(ecm_opts->net, qmult);
+   if (!gether_set_host_addr(ecm_opts->net, host_addr))
+   pr_info("using host ethernet address: %s", host_addr);
+   if (!gether_set_dev_addr(ecm_opts->net, dev_addr))
+   pr_info("using self ethernet address: %s", dev_addr);
+
+   the_dev = netdev_priv(ecm_opts->net);
+
eth_config_driver.label = "CDC Ethernet (ECM)";
} else {
/* CDC Subset */
@@ -309,6 +341,15 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 
if (has_rndis()) {
/* RNDIS plus ECM-or-Subset */
+   if (!use_eem && can_support_ecm(gadget)) {
+   gether_set_gadget(ecm_opts->net, cdev->gadget);
+   status = gether_register_netdev(ecm_opts->net);
+   if (status)
+ 

Re: Scanner fails on USB3 port

2013-05-24 Thread Martin van Es
Is noone interested in taking this up with me?

Martin

On Mon, May 13, 2013 at 1:20 PM, Martin van Es  wrote:
> Hi,
>
> I have exactly the same problem as described by Harald Judt in this mail:
> http://www.spinics.net/lists/linux-usb/msg58841.html
>
> The thread ends here, in mid conversation with Sarah Sharp:
> http://www.spinics.net/lists/linux-usb/msg69636.html
>
> ... so I'd like to take it up from there.
>
> The scanner is a Canoscan N670U (LiDE 20).
>
> sane-fine-scanner finds the scanner:
> found USB scanner (vendor=0x04a9 [Canon], product=0x220d [CanoScan])
> at libusb:003:003
>
> but scanimage -L fails (no output)
>
> The attached (3.9.2) kernel log is from boot, to supply all usb
> initialisation messages.
> Around 46.650933 I did the sane-find-scanner.
> Starting 60.438552 you see output of scanimage -L and 707.400622 again
> so it's isolated from possible noise.
>
> The scanner is fully functional on my old laptop with USB2 ports.
>
> Hope this helps resolving the bug.
>
> Best regards,
> Martin van Es
> --
> If 'but' was any useful, it would be a logic operator
--
To unsubscribe from this list: send the line "unsubscribe 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: time source unstable on usb/serial/pl2303 (globalsat br-353)

2013-05-24 Thread Greg Kroah-Hartman
On Fri, May 24, 2013 at 09:27:17AM +0200, Philippe De Muyter wrote:
> On Thu, May 23, 2013 at 08:31:18AM -0700, Greg Kroah-Hartman wrote:
> > On Thu, May 23, 2013 at 03:07:09PM +0200, Philippe De Muyter wrote:
> > > Hi all,
> > > 
> > > I have a lot of linux computers equipped with a GlobalSat Br-353 GPS 
> > > receiver,
> > > which is connected via USB (an integrated PL2303).  The GPS receiver emits
> > > one multi-line message every second, giving position and time.  I listen
> > > to this messages in a user program running in the highest priority,
> > > and I have noticed that under load, the messages are not delivered to my
> > > process every second, but often delayed, which is not great for a time 
> > > source.
> > > 
> > > I looked at the sources of pl2303 and added a diagnostic message if the
> > > beginning of a message came more than one second later than the beginning
> > > of the previous one, and I noticed that the delay was already present
> > > in the kernel: often even more than one second delay after the expected
> > > beginning time.
> > 
> > Then that implies that the device itself is holding on to the message,
> > right?
> 
> I hoped it was the configuration on the host-side.  I have read internet
> pages that implied that for USB mice it was possible to increase the polling
> rate.  I hoped that it would be the same for serial lines.

You can increase the interrupt request rate some, but if the device
doesn't have any data to send, it doesn't matter how often you ask it
for data.

> Is it possible to make bulk_read_requests at the "interrupt" priority ?

There is no difference in the "priority" of the two requests at all,
they are the same.

> > USB is not something that you can rely on for very high-frequency, low
> > latency, timing things.  Although to be fair, second delays are quite
> > rare, which implies that your hardware is to blame here.
> 
> Yes, I think that there must be something wrong but more on a software
> side, because I do not get such big delays on an unloaded computer.

That's odd, let us know if you find anything out with your tests.

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] serial: Add Option GTM681W to qcserial device table.

2013-05-24 Thread Bjørn Mork
Richard Weinberger  writes:

> The Option GTM681W uses a qualcomm chip and can be
> served by the qcserial device driver.

Should it also be added to the qmi_wwan driver?


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: time source unstable on usb/serial/pl2303 (globalsat br-353)

2013-05-24 Thread Alan Stern
On Fri, 24 May 2013, Philippe De Muyter wrote:

> On Thu, May 23, 2013 at 08:31:18AM -0700, Greg Kroah-Hartman wrote:
> > On Thu, May 23, 2013 at 03:07:09PM +0200, Philippe De Muyter wrote:
> > > Hi all,
> > > 
> > > I have a lot of linux computers equipped with a GlobalSat Br-353 GPS 
> > > receiver,
> > > which is connected via USB (an integrated PL2303).  The GPS receiver emits
> > > one multi-line message every second, giving position and time.  I listen
> > > to this messages in a user program running in the highest priority,
> > > and I have noticed that under load, the messages are not delivered to my
> > > process every second, but often delayed, which is not great for a time 
> > > source.
> > > 
> > > I looked at the sources of pl2303 and added a diagnostic message if the
> > > beginning of a message came more than one second later than the beginning
> > > of the previous one, and I noticed that the delay was already present
> > > in the kernel: often even more than one second delay after the expected
> > > beginning time.
> > 
> > Then that implies that the device itself is holding on to the message,
> > right?
> 
> I hoped it was the configuration on the host-side.  I have read internet
> pages that implied that for USB mice it was possible to increase the polling
> rate.  I hoped that it would be the same for serial lines.

Have you tried usbmon?  The detailed information about the timing of 
the URBs might give you some clues.

> > USB is not something that you can rely on for very high-frequency, low
> > latency, timing things.  Although to be fair, second delays are quite
> > rare, which implies that your hardware is to blame here.
> 
> Yes, I think that there must be something wrong but more on a software
> side, because I do not get such big delays on an unloaded computer.

It's possible that the delays are at the user level and not in the 
kernel.

Alan Stern

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


Re: [PATCH] usbfs: Increase arbitrary limit for USB 3 isopkt length

2013-05-24 Thread Alan Stern
On Fri, 24 May 2013, Federico Manzan wrote:

> Increase the current arbitrary limit for isocronous packet size to a
> value large enough to account for USB 3.0 super bandwidth streams,
> bMaxBurst (0~15 allowed, 1~16 packets)
> bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
> so the size max for one USB 3 isocronous transfer is
> 1024 byte * 16 * 3 = 49152 byte
> 
> Signed-off-by: Federico Manzan 

So you decided to take matters into your own hands.  Good for you!

> diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
> index caefc80..7ac137e 100644
> --- a/drivers/usb/core/devio.c
> +++ b/drivers/usb/core/devio.c
> @@ -1287,9 +1287,11 @@ static int proc_do_submiturb(struct dev_state *ps, 
> struct usbdevfs_urb *uurb,
>   goto error;
>   }
>   for (totlen = u = 0; u < uurb->number_of_packets; u++) {
> - /* arbitrary limit,
> -  * sufficient for USB 2.0 high-bandwidth iso */
> - if (isopkt[u].length > 8192) {
> + /* arbitrary limit need for USB 3.0
> +  * bMaxBurst (0~15 allowed, 1~16 packets)
> +  * bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
> +  * sizemax: 1024 * 16 * 3 = 49152*/
> + if (isopkt[u].length > 65536) {
>   ret = -EINVAL;
>   goto error;
>   }

A couple of suggestions for improvements:

First, new or updated multi-line comments should follow the accepted
formatting standard:

/*
 * Start comment here...
 * and end here.
 */

Second, it's confusing for the comment to mention that the limit is
49152 and the code to set the limit to 65536.  They should agree on a
single value (probably 49152).

If you make those two changes, you can add

Acked-by: Alan Stern 

Alan Stern

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


Re: [PATCH V3] usb: ehci-s5p: skip phy setup for Exynos5440 based platforms

2013-05-24 Thread Alan Stern
On Fri, 24 May 2013, Jingoo Han wrote:

> From: Thomas Abraham 
> 
> Exynos5440 does not require any explict USB phy configuration. So skip
> the USB phy configuration for Exynos5440 based platforms.
> 
> Signed-off-by: Thomas Abraham 
> Signed-off-by: Jingoo Han 
> ---
> Changes since v2:
> - changed all occurrences of s5p_ehci->pdata->phy*.
> - set s5p_ehci->pdata to NULL.
> 
> Changes since v1:
> - re-based on the latest 'linux-next' tree

Did you not understand the change I recommended?  If you do the patch 
that way, it will look like this:

Index: usb-3.9/drivers/usb/host/ehci-s5p.c
===
--- usb-3.9.orig/drivers/usb/host/ehci-s5p.c
+++ usb-3.9/drivers/usb/host/ehci-s5p.c
@@ -73,6 +73,8 @@ static void s5p_setup_vbus_gpio(struct p
 
 static u64 ehci_s5p_dma_mask = DMA_BIT_MASK(32);
 
+static struct s5p_ehci_platdata empty_platdata;
+
 static int s5p_ehci_probe(struct platform_device *pdev)
 {
struct s5p_ehci_platdata *pdata = pdev->dev.platform_data;
@@ -103,6 +105,13 @@ static int s5p_ehci_probe(struct platfor
return -ENOMEM;
}
s5p_ehci = to_s5p_ehci(hcd);
+
+   if (of_device_is_compatible(pdev->dev.of_node,
+   "samsung,exynos5440-ehci")) {
+   s5p_ehci->pdata = &empty_platdata;
+   goto skip_phy;
+   }
+
phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
if (IS_ERR(phy)) {
/* Fallback to pdata */
@@ -117,6 +126,8 @@ static int s5p_ehci_probe(struct platfor
s5p_ehci->otg = phy->otg;
}
 
+skip_phy:
+
s5p_ehci->clk = devm_clk_get(&pdev->dev, "usbhost");
 
if (IS_ERR(s5p_ehci->clk)) {
@@ -278,6 +289,7 @@ static const struct dev_pm_ops s5p_ehci_
 #ifdef CONFIG_OF
 static const struct of_device_id exynos_ehci_match[] = {
{ .compatible = "samsung,exynos4210-ehci" },
+   { .compatible = "samsung,exynos5440-ehci" },
{},
 };
 MODULE_DEVICE_TABLE(of, exynos_ehci_match);

This is shorter and more robust than your version.  Still, if you want 
to use your longer version, you can add

Acked-by: Alan Stern 

Alan Stern

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


[PATCH 0/3] palmas usb driver

2013-05-24 Thread Kishon Vijay Abraham I
This patch series adds driver for palmas usb which is used to detect
attach/detach events of usb device and usb host.

[PATCH v5 2/3] extcon: Palmas Extcon Driver which was sent previously
is added in this patch series itself. The revision history is added
in the patch comments section.

A checkpatch warning "WARNING: static const char * array should
probably be static const char * const"is ignored since it introduces a
compilation warning.

Graeme Gregory (2):
  drivers: regulator: palmas: add an API to set/clear the switch bit on
SMPS10
  extcon: Palmas Extcon Driver

Kishon Vijay Abraham I (1):
  usb: dwc3: use extcon fwrk to receive connect/disconnect notification

 .../devicetree/bindings/extcon/extcon-twl.txt  |  16 +
 drivers/extcon/Kconfig |   7 +
 drivers/extcon/Makefile|   1 +
 drivers/extcon/extcon-palmas.c | 341 +
 drivers/regulator/palmas-regulator.c   |  26 ++
 drivers/usb/dwc3/dwc3-omap.c   |  80 +++--
 include/linux/mfd/palmas.h |  27 +-
 include/linux/usb/dwc3-omap.h  |  30 --
 8 files changed, 470 insertions(+), 58 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c
 delete mode 100644 include/linux/usb/dwc3-omap.h

-- 
1.8.1.2

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


[PATCH v5 2/3] extcon: Palmas Extcon Driver

2013-05-24 Thread Kishon Vijay Abraham I
From: Graeme Gregory 

This is the driver for the USB comparator built into the palmas chip. It
handles the various USB OTG events that can be generated by cable
insertion/removal.

Signed-off-by: Graeme Gregory 
Signed-off-by: Moiz Sonasath 
Signed-off-by: Ruchika Kharwar 
Signed-off-by: Kishon Vijay Abraham I 
Signed-off-by: George Cherian 
[kis...@ti.com: adapted palmas usb driver to use the extcon framework]
Signed-off-by: Sebastien Guiriec 
---
Changes from v4:
* removed no_control_vbus property (to be used if the platform wants to use
its own vbus control.
* removed unnecessary headers
* moved the palmas_usb_state to palmas.h
* misc cleanups
*A checkpatch warning "WARNING: static const char * array should
 probably be static const char * const"is ignored since it introduces a
 compilation warning.
Changes from v3:
* adapted the driver to extcon framework (so moved to drivers/extcon)
* removed palmas_usb_(write/read) and replaced all calls with
  palmas_(read/write).
* ignored a checkpatch warning in the line 
static const char *palmas_extcon_cable[] = {
  as it seemed to be incorrect?
* removed all references to OMAP in this driver.
* couldn't test this driver with mainline as omap5 panda is not booting
  with mainline.
* A comment to change to platform_get_irq from regmap is not done as I felt
  the data should come from regmap in this case. Graeme?
Changes from v2:
* Moved the driver to drivers/usb/phy/
* Added a bit more explanation in Kconfig
 .../devicetree/bindings/extcon/extcon-twl.txt  |  16 +
 drivers/extcon/Kconfig |   7 +
 drivers/extcon/Makefile|   1 +
 drivers/extcon/extcon-palmas.c | 341 +
 include/linux/mfd/palmas.h |  25 +-
 5 files changed, 380 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/extcon/extcon-twl.txt
 create mode 100644 drivers/extcon/extcon-palmas.c

diff --git a/Documentation/devicetree/bindings/extcon/extcon-twl.txt 
b/Documentation/devicetree/bindings/extcon/extcon-twl.txt
new file mode 100644
index 000..8ffdeed
--- /dev/null
+++ b/Documentation/devicetree/bindings/extcon/extcon-twl.txt
@@ -0,0 +1,15 @@
+EXTCON FOR TWL CHIPS
+
+PALMAS USB COMPARATOR
+Required Properties:
+ - compatible : Should be "ti,palmas-usb" or "ti,twl6035-usb"
+ - vbus-supply : phandle to the regulator device tree node.
+
+Optional Properties:
+ - ti,wakeup : To enable the wakeup comparator in probe
+
+palmas-usb {
+   compatible = "ti,twl6035-usb", "ti,palmas-usb";
+   vbus-supply = <&smps10_reg>;
+   ti,wakeup;
+};
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig
index 3297301..63f454e 100644
--- a/drivers/extcon/Kconfig
+++ b/drivers/extcon/Kconfig
@@ -53,4 +53,11 @@ config EXTCON_ARIZONA
  with Wolfson Arizona devices. These are audio CODECs with
  advanced audio accessory detection support.
 
+config EXTCON_PALMAS
+   tristate "Palmas USB EXTCON support"
+   depends on MFD_PALMAS
+   help
+ Say Y here to enable support for USB peripheral and USB host
+ detection by palmas usb.
+
 endif # MULTISTATE_SWITCH
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile
index f98a3c4..540e2c3 100644
--- a/drivers/extcon/Makefile
+++ b/drivers/extcon/Makefile
@@ -8,3 +8,4 @@ obj-$(CONFIG_EXTCON_ADC_JACK)   += extcon-adc-jack.o
 obj-$(CONFIG_EXTCON_MAX77693)  += extcon-max77693.o
 obj-$(CONFIG_EXTCON_MAX8997)   += extcon-max8997.o
 obj-$(CONFIG_EXTCON_ARIZONA)   += extcon-arizona.o
+obj-$(CONFIG_EXTCON_PALMAS)+= extcon-palmas.o
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
new file mode 100644
index 000..9e613e9
--- /dev/null
+++ b/drivers/extcon/extcon-palmas.c
@@ -0,0 +1,341 @@
+/*
+ * Palmas USB transceiver driver
+ *
+ * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com
+ * 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.
+ *
+ * Author: Graeme Gregory 
+ * Author: Kishon Vijay Abraham I 
+ *
+ * Based on twl6030_usb.c
+ *
+ * Author: Hema HK 
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static const char *palmas_extcon_cable[] = {
+   [0] = "USB",
+   [1] = "USB-HOST",
+   NULL,
+};
+
+static const int mutually_exclusive[] = {0x3, 0x0};
+
+static void palmas_usb_wakeup(struct palmas *palmas, int enable)
+{
+   if (enable)
+   palmas_write(palmas, PALMAS_USB_OTG_BASE, 

[PATCH 1/3] drivers: regulator: palmas: add an API to set/clear the switch bit on SMPS10

2013-05-24 Thread Kishon Vijay Abraham I
From: Graeme Gregory 

Added an API to set/clear the switch bit on SMPS10 which can be used by
palmas usb. The switch bit should be set in order for palmas to
supply VBUS and is needed when OMAP is acting as USB HOST.

Signed-off-by: Graeme Gregory 
Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/regulator/palmas-regulator.c | 26 ++
 include/linux/mfd/palmas.h   |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/drivers/regulator/palmas-regulator.c 
b/drivers/regulator/palmas-regulator.c
index 92ceed0..d57ab55 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -465,6 +465,32 @@ static int palmas_smps_set_ramp_delay(struct regulator_dev 
*rdev,
return ret;
 }
 
+/**
+ * palmas_set_switch_smps10() - set or clear the switch bit on SMPS10
+ * @param palmas pointer to the palmas mfd structure
+ * @param sw boolean to indicate switch status
+ *
+ * There is not a way to represent this function within the regulator
+ * framework. This sets/clears the switch of SMPS10 so SMPS10_OUT1 and
+ * SMPS10_OUT2 are shorted together.
+ */
+int palmas_set_switch_smps10(struct palmas *palmas, int sw)
+{
+   unsigned int reg;
+
+   palmas_smps_read(palmas, PALMAS_SMPS10_CTRL, ®);
+
+   if (sw)
+   reg |= SMPS10_SWITCH_EN;
+   else
+   reg &= ~SMPS10_SWITCH_EN;
+
+   palmas_smps_write(palmas, PALMAS_SMPS10_CTRL, reg);
+
+   return 0;
+}
+EXPORT_SYMBOL(palmas_set_switch_smps10);
+
 static struct regulator_ops palmas_ops_smps = {
.is_enabled = palmas_is_enabled_smps,
.enable = palmas_enable_smps,
diff --git a/include/linux/mfd/palmas.h b/include/linux/mfd/palmas.h
index 8f21daf..6df375d 100644
--- a/include/linux/mfd/palmas.h
+++ b/include/linux/mfd/palmas.h
@@ -404,6 +404,8 @@ enum usb_irq_events {
N_PALMAS_USB_VOTG_SESS_VLD,
 };
 
+extern int palmas_set_switch_smps10(struct palmas *palmas, int sw);
+
 /* defines so we can store the mux settings */
 #define PALMAS_GPIO_0_MUXED(1 << 0)
 #define PALMAS_GPIO_1_MUXED(1 << 1)
-- 
1.8.1.2

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


[PATCH 3/3] usb: dwc3: use extcon fwrk to receive connect/disconnect notification

2013-05-24 Thread Kishon Vijay Abraham I
Modified dwc3-omap to receive connect and disconnect notification using
extcon framework. Also did the necessary cleanups required after
adapting to extcon framework.

Signed-off-by: Kishon Vijay Abraham I 
---
 drivers/usb/dwc3/dwc3-omap.c  | 80 +--
 include/linux/usb/dwc3-omap.h | 30 
 2 files changed, 62 insertions(+), 48 deletions(-)
 delete mode 100644 include/linux/usb/dwc3-omap.h

diff --git a/drivers/usb/dwc3/dwc3-omap.c b/drivers/usb/dwc3/dwc3-omap.c
index 34638b9..771f936 100644
--- a/drivers/usb/dwc3/dwc3-omap.c
+++ b/drivers/usb/dwc3/dwc3-omap.c
@@ -43,13 +43,13 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -124,9 +124,19 @@ struct dwc3_omap {
u32 utmi_otg_status;
 
u32 dma_status:1;
+
+   struct extcon_specific_cable_nb extcon_vbus_dev;
+   struct extcon_specific_cable_nb extcon_id_dev;
+   struct notifier_block   vbus_nb;
+   struct notifier_block   id_nb;
 };
 
-static struct dwc3_omap*_omap;
+enum omap_dwc3_vbus_id_status {
+   OMAP_DWC3_ID_FLOAT,
+   OMAP_DWC3_ID_GROUND,
+   OMAP_DWC3_VBUS_OFF,
+   OMAP_DWC3_VBUS_VALID,
+};
 
 static inline u32 dwc3_omap_readl(void __iomem *base, u32 offset)
 {
@@ -138,13 +148,10 @@ static inline void dwc3_omap_writel(void __iomem *base, 
u32 offset, u32 value)
writel(value, base + offset);
 }
 
-int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
+static void dwc3_omap_set_mailbox(struct dwc3_omap *omap,
+   enum omap_dwc3_vbus_id_status status)
 {
-   u32 val;
-   struct dwc3_omap*omap = _omap;
-
-   if (!omap)
-   return -EPROBE_DEFER;
+   u32 val;
 
switch (status) {
case OMAP_DWC3_ID_GROUND:
@@ -185,12 +192,9 @@ int dwc3_omap_mailbox(enum omap_dwc3_vbus_id_status status)
break;
 
default:
-   dev_dbg(omap->dev, "ID float\n");
+   dev_dbg(omap->dev, "invalid state\n");
}
-
-   return 0;
 }
-EXPORT_SYMBOL_GPL(dwc3_omap_mailbox);
 
 static irqreturn_t dwc3_omap_interrupt(int irq, void *_omap)
 {
@@ -282,6 +286,32 @@ static void dwc3_omap_disable_irqs(struct dwc3_omap *omap)
 
 static u64 dwc3_omap_dma_mask = DMA_BIT_MASK(32);
 
+static int dwc3_omap_id_notifier(struct notifier_block *nb,
+   unsigned long event, void *ptr)
+{
+   struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, id_nb);
+
+   if (event)
+   dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_GROUND);
+   else
+   dwc3_omap_set_mailbox(omap, OMAP_DWC3_ID_FLOAT);
+
+   return NOTIFY_DONE;
+}
+
+static int dwc3_omap_vbus_notifier(struct notifier_block *nb,
+   unsigned long event, void *ptr)
+{
+   struct dwc3_omap *omap = container_of(nb, struct dwc3_omap, vbus_nb);
+
+   if (event)
+   dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+   else
+   dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_OFF);
+
+   return NOTIFY_DONE;
+}
+
 static int dwc3_omap_probe(struct platform_device *pdev)
 {
struct device_node  *node = pdev->dev.of_node;
@@ -289,6 +319,7 @@ static int dwc3_omap_probe(struct platform_device *pdev)
struct dwc3_omap*omap;
struct resource *res;
struct device   *dev = &pdev->dev;
+   struct extcon_dev   *edev;
 
int ret = -ENOMEM;
int irq;
@@ -330,19 +361,25 @@ static int dwc3_omap_probe(struct platform_device *pdev)
return -ENOMEM;
}
 
+   edev = extcon_get_extcon_dev("palmas-usb");
+   if (!edev) {
+   dev_dbg(dev, "couldn't get extcon device\n");
+   return -EPROBE_DEFER;
+   }
+
spin_lock_init(&omap->lock);
 
omap->dev   = dev;
omap->irq   = irq;
omap->base  = base;
+   omap->vbus_nb.notifier_call = dwc3_omap_vbus_notifier;
+   extcon_register_interest(&omap->extcon_vbus_dev, "palmas-usb", "USB",
+   &omap->vbus_nb);
+   omap->id_nb.notifier_call = dwc3_omap_id_notifier;
+   extcon_register_interest(&omap->extcon_id_dev, "palmas-usb", "USB-HOST",
+   &omap->id_nb);
dev->dma_mask   = &dwc3_omap_dma_mask;
 
-   /*
-* REVISIT if we ever have two instances of the wrapper, we will be
-* in big trouble
-*/
-   _omap   = omap;
-
pm_runtime_enable(dev);
ret = pm_runtime_get_sync(dev);
if (ret < 0) {
@@ -387,6 +424,11 @@ static int dwc3_omap_probe(struct platform_device *pdev)
return ret;
}
 
+   if (extcon_get_cable_state(edev, "USB") == true)
+   dwc3_omap_set_mailbox(omap, OMAP_DWC3_VBUS_VALID);
+   if (extcon_get_cable_state

Re: [PATCH v1 2/9] usb: musb: nop: remove unused nop_xceiv_(un)register APIs from glue

2013-05-24 Thread Sergei Shtylyov

Hello.

On 24-05-2013 9:34, B, Ravi wrote:


removed unused nop xceiv (un_)register API's from all musb platform
drivers



 Since when are they unused?



Please refer to commit id 662dca54 : usb: otg: support for multiple 
transceivers by a single controller.
Usb_get_phy() is used to get the of phy used by controller, phy bindings are 
done through DT.



Why are you sure that all these platforms support DT (in all 
configurations)?
It seems to me that you're simply breaking the patched glue layers with this 
patch.
I'll let Felipe decide the fate of this patch though...



You are correct, the bindings of phy and controller need not to done through DT 
alone, there is a saperate API
Phy API's available for such bindings done in respective board platform files.


   I don't see any such code in e.g. DaVinci/DA8xx platform files.


Signed-off-by: Ravi Babu 

--
Ravi B


WBR, Sergei

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


[PATCH 14/17] usb/gadget: ether: convert to new interface of f_rndis

2013-05-24 Thread Andrzej Pietrasiewicz
Conversion to new interface is required to move to configfs.

This patch edition fixes compilation error if RNDIS is not selected in Kconfig.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/ether.c |   56 ++--
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index a4a6416..a33a307 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -812,6 +812,7 @@ config USB_ETH_RNDIS
bool "RNDIS support"
depends on USB_ETH
select USB_LIBCOMPOSITE
+   select USB_F_RNDIS
default y
help
   Microsoft Windows XP bundles the "Remote NDIS" (RNDIS) protocol,
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 4d7290a..f48712f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -94,23 +94,14 @@ static inline bool has_rndis(void)
 
 #include 
 
-/*-*/
-
-/*
- * Kbuild is not very cooperative with respect to linking separately
- * compiled library objects into one module.  So for now we won't use
- * separate compilation ... ensuring init/exit sections work to shrink
- * the runtime footprint, and giving us at least some parts of what
- * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
- */
 #include "u_ecm.h"
 #include "u_gether.h"
 #ifdef USB_ETH_RNDIS
-#define USB_FRNDIS_INCLUDED
-#include "f_rndis.c"
+#include "u_rndis.h"
 #include "rndis.h"
+#else
+#define rndis_borrow_net(...) do {} while (0)
 #endif
-
 #include "u_eem.h"
 
 /*-*/
@@ -212,9 +203,6 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
-static u8 host_mac[ETH_ALEN];
-static struct eth_dev *the_dev;
-
 static struct usb_function_instance *fi_ecm;
 static struct usb_function *f_ecm;
 
@@ -224,6 +212,9 @@ static struct usb_function *f_eem;
 static struct usb_function_instance *fi_geth;
 static struct usb_function *f_geth;
 
+static struct usb_function_instance *fi_rndis;
+static struct usb_function *f_rndis;
+
 /*-*/
 
 /*
@@ -233,6 +224,8 @@ static struct usb_function *f_geth;
  */
 static int __init rndis_do_config(struct usb_configuration *c)
 {
+   int status;
+
/* FIXME alloc iConfiguration string, set it in c->strings */
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -240,7 +233,15 @@ static int __init rndis_do_config(struct usb_configuration 
*c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   return rndis_bind_config(c, host_mac, the_dev);
+   f_rndis = usb_get_function(fi_rndis);
+   if (IS_ERR(f_rndis))
+   return PTR_ERR(f_rndis);
+
+   status = usb_add_function(c, f_rndis);
+   if (status < 0)
+   usb_put_function(f_rndis);
+
+   return status;
 }
 
 static struct usb_configuration rndis_config_driver = {
@@ -336,7 +337,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
 
net = eem_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (EEM)";
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
@@ -351,7 +351,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
 
net = ecm_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Ethernet (ECM)";
} else {
@@ -365,7 +364,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
 func_inst);
 
net = geth_opts->net;
-   the_dev = netdev_priv(net);
 
eth_config_driver.label = "CDC Subset/SAFE";
 
@@ -387,7 +385,6 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
status = gether_register_netdev(net);
if (status)
goto fail;
-   gether_get_host_addr_u8(net, host_mac);
 
if (use_eem)
eem_opts->bound = true;
@@ -396,6 +393,14 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
else
geth_opts->bound = true;
 
+   fi_rndis = usb_get_function_instance("rndis");
+   if (IS_ERR(fi_rndis)) {
+   status = PTR_ERR(fi_rndis);
+   goto fail;
+   }
+
+   rndis_borrow_net(fi_rndis, net);
+
device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
device_desc.idProduct = 

Re: [PATCH] usbfs: Increase arbitrary limit for USB 3 isopkt length

2013-05-24 Thread Sergei Shtylyov

Hello.

On 24-05-2013 12:47, Federico Manzan wrote:


Increase the current arbitrary limit for isocronous packet size to a
value large enough to account for USB 3.0 super bandwidth streams,
bMaxBurst (0~15 allowed, 1~16 packets)
bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
so the size max for one USB 3 isocronous transfer is
1024 byte * 16 * 3 = 49152 byte



Signed-off-by: Federico Manzan 
---
  drivers/usb/core/devio.c |8 +---
  1 file changed, 5 insertions(+), 3 deletions(-)



diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index caefc80..7ac137e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1287,9 +1287,11 @@ static int proc_do_submiturb(struct dev_state *ps, 
struct usbdevfs_urb *uurb,
goto error;
}
for (totlen = u = 0; u < uurb->number_of_packets; u++) {
-   /* arbitrary limit,
-* sufficient for USB 2.0 high-bandwidth iso */
-   if (isopkt[u].length > 8192) {
+   /* arbitrary limit need for USB 3.0
+* bMaxBurst (0~15 allowed, 1~16 packets)
+* bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
+* sizemax: 1024 * 16 * 3 = 49152*/


   The preferred style of the multi-line comments is this:

/*
 * bla
 * bla
 */

WBR, Sergei

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


Freescale P1022 SoC hangs when initializing USB

2013-05-24 Thread Thumshirn, Johannes Tobias
Hi list,

I'm experiencing problems while booting on a Freescale P1013 based board. It 
hangs on USB initialization:
[3.763584] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[3.770519] ehci-pci: EHCI PCI platform driver
[3.775116] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[3.781972] fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller
[3.788812] fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus number 
1

The corresponding device-tree:
usb@22000 {
 #address-cells = <1>;
 #size-cells = <0>;
 compatible = "fsl-usb2-dr";
 reg = <0x22000 0x1000>;
 interrupt-parent = <&mpic>;
 interrupts = <28 0x2 0 0>;
 phy_type = "ulpi";
};

usb@23000 {
  #address-cells = <1>;
  #size-cells = <0>;
  compatible = "fsl-usb2-dr";
  reg = <0x23000 0x1000>;
  interrupt-parent = <&mpic>;
  interrupts = <46 0x2 0 0>;
  phy_type = "ulpi";
};

It also seems I'm not the only one having this problem: 
https://lists.ozlabs.org/pipermail/linuxppc-dev/2013-January/103344.html
though my configuration uses ULPI instead of UTMI mode and a warm reset doesn't
get it up as well.

I can verify that the 1st write to ehci->regs->port_status[0] in 
ehci_fsl_setup_phy()
causes the hang and the P1022 Datasheet  states:
"A write to registers in the USB controller memory map may cause the
system to hang if PORTSC[PHCD]=0 when no USB PHY clock is applied."
- (Ch. 18.2 - p. 1098).
Setting PORTSC[PHCD]=1 solves the hang for exactly one write.
I can verify it on 3.4.18 as well as on 3.10-rc2.

A hardware problem can be eliminated as U-Boot and VxWorks have no trouble 
initializing the EHCI.
Does anyone have similar problems or a solution to this?

Copying U-Boot's PHY initialization routine to enable the ULPI clock did not 
get it up either.

Thanks in advance,
Johannes
--
To unsubscribe from this list: send the line "unsubscribe 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 01/17] usb/gadget: u_ether: allow getting binary-form host address

2013-05-24 Thread Sergei Shtylyov

Hello.

On 24-05-2013 16:17, Andrzej Pietrasiewicz wrote:


Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
  drivers/usb/gadget/u_ether.c |   11 +++
  drivers/usb/gadget/u_ether.h |   10 ++
  2 files changed, 21 insertions(+), 0 deletions(-)



diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 6d3ccdc..aa7ed15 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -963,6 +963,17 @@ int gether_get_host_addr_cdc(struct net_device *net, char 
*host_addr, int len)
  }
  EXPORT_SYMBOL(gether_get_host_addr_cdc);

+void gether_get_host_addr_u8(struct net_device *net, u8 host_mac[ETH_ALEN])
+{
+   struct eth_dev *dev;
+
+   dev = netdev_priv(net);
+   host_mac[0] = dev->host_mac[0]; host_mac[1] = dev->host_mac[1];
+   host_mac[2] = dev->host_mac[2]; host_mac[3] = dev->host_mac[3];
+   host_mac[4] = dev->host_mac[4]; host_mac[5] = dev->host_mac[5];


   Documentation/CodingStyle, chapter 1:

<<
Don't put multiple statements on a single line unless you have
something to hide:

if (condition) do_this;
  do_something_everytime;

Don't put multiple assignments on a single line either.  Kernel coding 
style is super simple.  Avoid tricky expressions.

>>

WBR, Sergei

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


Re: [PATCH 1/3] drivers: regulator: palmas: add an API to set/clear the switch bit on SMPS10

2013-05-24 Thread Sergei Shtylyov

Hello.

On 24-05-2013 18:31, Kishon Vijay Abraham I wrote:


From: Graeme Gregory 



Added an API to set/clear the switch bit on SMPS10 which can be used by
palmas usb. The switch bit should be set in order for palmas to
supply VBUS and is needed when OMAP is acting as USB HOST.



Signed-off-by: Graeme Gregory 
Signed-off-by: Kishon Vijay Abraham I 
---
  drivers/regulator/palmas-regulator.c | 26 ++
  include/linux/mfd/palmas.h   |  2 ++
  2 files changed, 28 insertions(+)



diff --git a/drivers/regulator/palmas-regulator.c 
b/drivers/regulator/palmas-regulator.c
index 92ceed0..d57ab55 100644
--- a/drivers/regulator/palmas-regulator.c
+++ b/drivers/regulator/palmas-regulator.c
@@ -465,6 +465,32 @@ static int palmas_smps_set_ramp_delay(struct regulator_dev 
*rdev,
return ret;
  }

+/**
+ * palmas_set_switch_smps10() - set or clear the switch bit on SMPS10
+ * @param palmas pointer to the palmas mfd structure
+ * @param sw boolean to indicate switch status


   Please follow the kernel-doc style described in 
Documentation/kernel-doc-nano-HOWTO.txt.


[...]

WBR, Sergei

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


Re: [PATCH] usbfs: Increase arbitrary limit for USB 3 isopkt length

2013-05-24 Thread Federico Manzan

On 05/24/2013 03:51 PM, Alan Stern wrote:

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index caefc80..7ac137e 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1287,9 +1287,11 @@ static int proc_do_submiturb(struct dev_state *ps, 
struct usbdevfs_urb *uurb,
goto error;
}
for (totlen = u = 0; u<  uurb->number_of_packets; u++) {
-   /* arbitrary limit,
-* sufficient for USB 2.0 high-bandwidth iso */
-   if (isopkt[u].length>  8192) {
+   /* arbitrary limit need for USB 3.0
+* bMaxBurst (0~15 allowed, 1~16 packets)
+* bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
+* sizemax: 1024 * 16 * 3 = 49152*/
+   if (isopkt[u].length>  65536) {
ret = -EINVAL;
goto error;
}

A couple of suggestions for improvements:

First, new or updated multi-line comments should follow the accepted
formatting standard:

/*
 * Start comment here...
 * and end here.
 */

ok, I change the comment in the suggested way

Second, it's confusing for the comment to mention that the limit is
49152 and the code to set the limit to 65536.  They should agree on a
single value (probably 49152).

In the USB 2 isochronous the limit is 1024 byte x 3 pkts = 3072, but in 
the code is write 8192. I don't understand why, for the memory page 
size? for have a tolerant limits? for rounding to a nice number?
So I wrote a limit some more big and round, but I agree with you the 
best way is write the correct limit, so I modify in this way, soon.


Federico Manzan

--
To unsubscribe from this list: send the line "unsubscribe 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] serial: Add Option GTM681W to qcserial device table.

2013-05-24 Thread Richard Weinberger

Am 24.05.2013 15:18, schrieb Bjørn Mork:

Richard Weinberger  writes:


The Option GTM681W uses a qualcomm chip and can be
served by the qcserial device driver.


Should it also be added to the qmi_wwan driver?


Don't know. But I can happily test it. :)
Can you please explain me how to use the qmi_wwan driver?
I've never used it.

Thanks,
//richard

--
To unsubscribe from this list: send the line "unsubscribe 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] usbfs: Increase arbitrary limit for USB 3 isopkt length

2013-05-24 Thread Federico Manzan
Increase the current arbitrary limit for isocronous packet size to a
value large enough to account for USB 3.0 super bandwidth streams,
bMaxBurst (0~15 allowed, 1~16 packets)
bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
so the size max for one USB 3 isocronous transfer is
1024 byte * 16 * 3 = 49152 byte

Acked-by: Alan Stern 
Signed-off-by: Federico Manzan 
---
Changes from v1:
  - fixed comment style
  - changed length value according to the comment

 drivers/usb/core/devio.c |   10 +++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index caefc80..c88c4fb 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1287,9 +1287,13 @@ static int proc_do_submiturb(struct dev_state *ps, 
struct usbdevfs_urb *uurb,
goto error;
}
for (totlen = u = 0; u < uurb->number_of_packets; u++) {
-   /* arbitrary limit,
-* sufficient for USB 2.0 high-bandwidth iso */
-   if (isopkt[u].length > 8192) {
+   /*
+* arbitrary limit need for USB 3.0
+* bMaxBurst (0~15 allowed, 1~16 packets)
+* bmAttributes (bit 1:0, mult 0~2, 1~3 packets)
+* sizemax: 1024 * 16 * 3 = 49152
+*/
+   if (isopkt[u].length > 49152) {
ret = -EINVAL;
goto error;
}
-- 
1.7.10.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] xhci: Add BayTrail to list of Intel switchable hosts

2013-05-24 Thread Sarah Sharp
At this point the port switchover quirk is getting unwieldy.  I know of
at least two more platforms that will need the switchover quirk, and
it's silly to keep adding them to the list.

Heikki, can you change the code to always try to switchover the ports
from EHCI to xHCI if an Intel xHCI host is found, and fail gracefully if
there isn't an EHCI host controller on board?

I suspect Intel will include the port switchover mechanism until they
decide to only include xHCI hosts and no EHCI hosts.  In the meantime,
we can avoid breaking USB 3.0 new platforms by always attempting to do
the switchover.

Sarah Sharp

On Tue, May 21, 2013 at 09:08:16AM +0300, Heikki Krogerus wrote:
> From: "Chew, Chiau Ee" 
> 
> Like the xHCI controller on Intel Panther Point and Lynx Point
> chipsets, the xHCI controller on Intel BayTrail has also ports that
> can be switched between the EHCI host controller.
> 
> This patch should be backported to stable kernels as old as 3.0,
> that contain commit 69e848c2090aebba5698a1620604c7dccb448684
> "Intel xhci: Support EHCI/xHCI port switching.
> 
> Signed-off-by: Chew, Chiau Ee 
> Signed-off-by: Heikki Krogerus 
> Cc: sta...@vger.kernel.org
> ---
>  drivers/usb/host/ehci-pci.c   |3 ++-
>  drivers/usb/host/pci-quirks.c |   12 +++-
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
> index 595d210..a5708d9 100644
> --- a/drivers/usb/host/ehci-pci.c
> +++ b/drivers/usb/host/ehci-pci.c
> @@ -322,7 +322,8 @@ static bool usb_is_intel_switchable_ehci(struct pci_dev 
> *pdev)
>   (pdev->device == 0x1E26 ||
>pdev->device == 0x8C2D ||
>pdev->device == 0x8C26 ||
> -  pdev->device == 0x9C26);
> +  pdev->device == 0x9C26 ||
> +  pdev->device == 0x0F34);
>  }
>  
>  static void ehci_enable_xhci_companion(void)
> diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
> index 4c338ec..6062822 100644
> --- a/drivers/usb/host/pci-quirks.c
> +++ b/drivers/usb/host/pci-quirks.c
> @@ -724,6 +724,7 @@ static int handshake(void __iomem *ptr, u32 mask, u32 
> done,
>  
>  #define PCI_DEVICE_ID_INTEL_LYNX_POINT_XHCI  0x8C31
>  #define PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI   0x9C31
> +#define PCI_DEVICE_ID_INTEL_BYT_XHCI 0x0F35
>  
>  bool usb_is_intel_ppt_switchable_xhci(struct pci_dev *pdev)
>  {
> @@ -741,10 +742,19 @@ bool usb_is_intel_lpt_switchable_xhci(struct pci_dev 
> *pdev)
>pdev->device == PCI_DEVICE_ID_INTEL_LYNX_POINT_LP_XHCI);
>  }
>  
> +/* And so does the Intel BayTrail. */
> +bool usb_is_intel_byt_switchable_xhci(struct pci_dev *pdev)
> +{
> + return pdev->class == PCI_CLASS_SERIAL_USB_XHCI &&
> + pdev->vendor == PCI_VENDOR_ID_INTEL &&
> + pdev->device == PCI_DEVICE_ID_INTEL_BYT_XHCI;
> +}
> +
>  bool usb_is_intel_switchable_xhci(struct pci_dev *pdev)
>  {
>   return usb_is_intel_ppt_switchable_xhci(pdev) ||
> - usb_is_intel_lpt_switchable_xhci(pdev);
> + usb_is_intel_lpt_switchable_xhci(pdev) ||
> + usb_is_intel_byt_switchable_xhci(pdev);
>  }
>  EXPORT_SYMBOL_GPL(usb_is_intel_switchable_xhci);
>  
> -- 
> 1.7.10.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] xhci: Add BayTrail to list of Intel switchable hosts

2013-05-24 Thread Sarah Sharp
On Tue, May 21, 2013 at 04:26:43PM +0400, Sergei Shtylyov wrote:
> Hello.
> 
> On 21-05-2013 10:08, Heikki Krogerus wrote:
> 
> >From: "Chew, Chiau Ee" 
> 
> >Like the xHCI controller on Intel Panther Point and Lynx Point
> >chipsets, the xHCI controller on Intel BayTrail has also ports that
> >can be switched between the EHCI host controller.
> 
>s/between/to/

Sergei, DO NOT REVIEW PATCHES TO THE XHCI DRIVER.

Your grammar comments and complaints about extra parenthesis are not
constructive and cause unnecessary patch churn.

Sarah Sharp
--
To unsubscribe from this list: send the line "unsubscribe 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: Freescale P1022 SoC hangs when initializing USB

2013-05-24 Thread Anatolij Gustschin
On Fri, 24 May 2013 14:42:46 +
"Thumshirn, Johannes Tobias"  wrote:

> Hi list,
> 
> I'm experiencing problems while booting on a Freescale P1013 based board. It 
> hangs on USB initialization:
> [3.763584] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
> [3.770519] ehci-pci: EHCI PCI platform driver
> [3.775116] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
> [3.781972] fsl-ehci fsl-ehci.0: Freescale On-Chip EHCI Host Controller
> [3.788812] fsl-ehci fsl-ehci.0: new USB bus registered, assigned bus 
> number 1
> 
> The corresponding device-tree:
> usb@22000 {
>  #address-cells = <1>;
>  #size-cells = <0>;
>  compatible = "fsl-usb2-dr";
>  reg = <0x22000 0x1000>;
>  interrupt-parent = <&mpic>;
>  interrupts = <28 0x2 0 0>;
>  phy_type = "ulpi";
> };
> 
> usb@23000 {
>   #address-cells = <1>;
>   #size-cells = <0>;
>   compatible = "fsl-usb2-dr";
>   reg = <0x23000 0x1000>;
>   interrupt-parent = <&mpic>;
>   interrupts = <46 0x2 0 0>;
>   phy_type = "ulpi";
> };

please change compatible property in both nodes to

 compatible = "fsl-usb2-dr-v1.6", "fsl-usb2-dr";

and try again to see if it helps.

Thanks,

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


Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Sarah Sharp
Do we have support for the new extensions for USB communication devices
that use the Mobile Broadband Interface Model (MBIM) spec?

http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip

The spec was released pretty recently, which is why I'm asking on the
mailing lists, rather than digging around the kernel tree for a driver.

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


Re: linux-3.9.3 - hit limit of 255 usb->serial devices

2013-05-24 Thread Greg KH
On Fri, May 24, 2013 at 03:56:37PM +0200, Tobias Winter wrote:
> Hi there,
> 
> since my propblem is with usb to serial adapters I was unsure if this is
> the right place. If not, please let me know.

Not really, linux-usb@ is the proper one, I've included that on the cc:

> After equipping a server with a lot of ftdi singleport usb2serial
> devices, I ran into a serial device limit that is included in
> include/linux/usb/serial.h .
> 
> The limit of devices seems to be 255, resulting in ttyUSB254 to be the
> last supported device.
> 
> The codesnippet in question is:
> 
> #define SERIAL_TTY_MINORS 254 /* loads of devices :) */
> #define SERIAL_TTY_NO_MINOR 255 /* No minor was assigned */

Yes, that's the limit of usb-serial devices in the system at the moment.
In 10+ years, no one has complained yet, so it's been a good number :)

> Output of `lsusb | sort` with 256 usb2serial devices connected:
> http://pastebin.com/wqrYUbwZ

Nice job.

> In case you end up agreeing with me that there are no reasons to limit
> the devices to 255, would you be inclined to fix this in the main kernel
> tree? Do I have to open up a bug somewhere?

You can send a patch making the number dynamic, that would be great to
have.

> I also tried increasing the numbers further but I run into rollover
> issues as the kernel tries to reassign ttyUSB0 ttyUSB1 which is already
> taken. It seems without some other modification 256 devices is the limit?

Yes, there might be some limits in the tty layer as well for only 256
tty devices, but I haven't looked there in a long time, perhaps that is
now no longer the case.

> Bus 001 Device 091: ID 0403:6001 Future Technology Devices International, Ltd 
> FT232 USB-Serial (UART) IC

I'm just glad to see we can support 91 different devices on a single
root hub, that's good to see, as I don't think anyone has tested that in
a very long time :)

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


Resend: [PATCH] xhci: Compute last_ctx from complete set of endpoints.

2013-05-24 Thread Reilly Grant
The context entries field of the slot context must be set to one more
than the highest endpoint index currently active. The previous logic
only included the set of endpoints currently being added, meaning that
if an endpoint where dropped then the field would be reset to 1,
deactivating all configured endpoints.

The xHCI spec is decidedly unclear on whether this field includes all
configured endpoints or only those being modified by a configure
endpoint command. My interpretation is the former and is the behavior
observed in the Apple's xHCI driver.
---
 drivers/usb/host/xhci.c | 52 +
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 53b8f89..5c40d3e 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1557,12 +1557,10 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
struct xhci_hcd *xhci;
struct xhci_container_ctx *in_ctx, *out_ctx;
struct xhci_input_control_ctx *ctrl_ctx;
-   struct xhci_slot_ctx *slot_ctx;
-   unsigned int last_ctx;
unsigned int ep_index;
struct xhci_ep_ctx *ep_ctx;
u32 drop_flag;
-   u32 new_add_flags, new_drop_flags, new_slot_info;
+   u32 new_add_flags, new_drop_flags;
int ret;
 
ret = xhci_check_args(hcd, udev, ep, 1, true, __func__);
@@ -1603,24 +1601,13 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
ctrl_ctx->add_flags &= cpu_to_le32(~drop_flag);
new_add_flags = le32_to_cpu(ctrl_ctx->add_flags);
 
-   last_ctx = xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags));
-   slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
-   /* Update the last valid endpoint context, if we deleted the last one */
-   if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) >
-   LAST_CTX(last_ctx)) {
-   slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
-   slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
-   }
-   new_slot_info = le32_to_cpu(slot_ctx->dev_info);
-
xhci_endpoint_zero(xhci, xhci->devs[udev->slot_id], ep);
 
-   xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add 
flags = %#x, new slot info = %#x\n",
+   xhci_dbg(xhci, "drop ep 0x%x, slot id %d, new drop flags = %#x, new add 
flags = %#x\n",
(unsigned int) ep->desc.bEndpointAddress,
udev->slot_id,
(unsigned int) new_drop_flags,
-   (unsigned int) new_add_flags,
-   (unsigned int) new_slot_info);
+   (unsigned int) new_add_flags);
return 0;
 }
 
@@ -1643,11 +1630,9 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
struct xhci_hcd *xhci;
struct xhci_container_ctx *in_ctx, *out_ctx;
unsigned int ep_index;
-   struct xhci_slot_ctx *slot_ctx;
struct xhci_input_control_ctx *ctrl_ctx;
u32 added_ctxs;
-   unsigned int last_ctx;
-   u32 new_add_flags, new_drop_flags, new_slot_info;
+   u32 new_add_flags, new_drop_flags;
struct xhci_virt_device *virt_dev;
int ret = 0;
 
@@ -1662,7 +1647,6 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
return -ENODEV;
 
added_ctxs = xhci_get_endpoint_flag(&ep->desc);
-   last_ctx = xhci_last_valid_endpoint(added_ctxs);
if (added_ctxs == SLOT_FLAG || added_ctxs == EP0_FLAG) {
/* FIXME when we have to issue an evaluate endpoint command to
 * deal with ep0 max packet size changing once we get the
@@ -1723,24 +1707,14 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
 */
new_drop_flags = le32_to_cpu(ctrl_ctx->drop_flags);
 
-   slot_ctx = xhci_get_slot_ctx(xhci, in_ctx);
-   /* Update the last valid endpoint context, if we just added one past */
-   if ((le32_to_cpu(slot_ctx->dev_info) & LAST_CTX_MASK) <
-   LAST_CTX(last_ctx)) {
-   slot_ctx->dev_info &= cpu_to_le32(~LAST_CTX_MASK);
-   slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(last_ctx));
-   }
-   new_slot_info = le32_to_cpu(slot_ctx->dev_info);
-
/* Store the usb_device pointer for later use */
ep->hcpriv = udev;
 
-   xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add 
flags = %#x, new slot info = %#x\n",
+   xhci_dbg(xhci, "add ep 0x%x, slot id %d, new drop flags = %#x, new add 
flags = %#x\n",
(unsigned int) ep->desc.bEndpointAddress,
udev->slot_id,
(unsigned int) new_drop_flags,
-   (unsigned int) new_add_flags,
-   (unsigned int) new_slot_info);
+   (unsigned int) new_add_flags);
return 0;
 }
 

[RFC] imx21-hcd: implement updated URB_ISO_ASAP semantics

2013-05-24 Thread Alan Stern
Martin:

The patch below should implement the new behavior of the URB_ISO_ASAP
flag (as described in the kerneldoc for usb_submit_urb) for the
imx21-hcd driver.  I can't test it -- I haven't even tried to
cross-compile it.

Does it look okay to you?

Alan Stern



Index: usb-3.9/drivers/usb/host/imx21-hcd.c
===
--- usb-3.9.orig/drivers/usb/host/imx21-hcd.c
+++ usb-3.9/drivers/usb/host/imx21-hcd.c
@@ -809,26 +809,36 @@ static int imx21_hc_urb_enqueue_isoc(str
 
/* calculate frame */
cur_frame = imx21_hc_get_frame(hcd);
-   if (urb->transfer_flags & URB_ISO_ASAP) {
-   if (list_empty(&ep_priv->td_list))
-   urb->start_frame = cur_frame + 5;
-   else
-   urb->start_frame = list_entry(
-   ep_priv->td_list.prev,
-   struct td, list)->frame + urb->interval;
-   }
-   urb->start_frame = wrap_frame(urb->start_frame);
-   if (frame_after(cur_frame, urb->start_frame)) {
-   dev_dbg(imx21->dev,
-   "enqueue: adjusting iso start %d (cur=%d) asap=%d\n",
-   urb->start_frame, cur_frame,
-   (urb->transfer_flags & URB_ISO_ASAP) != 0);
-   urb->start_frame = wrap_frame(cur_frame + 1);
+   i = 0;
+   if (list_empty(&ep_priv->td_list)) {
+   urb->start_frame = wrap_frame(cur_frame + 5);
+   } else {
+   urb->start_frame = wrap_frame(list_entry(ep_priv->td_list.prev,
+   struct td, list)->frame + urb->interval);
+
+   if (frame_after(cur_frame, urb->start_frame)) {
+   dev_dbg(imx21->dev,
+   "enqueue: adjusting iso start %d (cur=%d) 
asap=%d\n",
+   urb->start_frame, cur_frame,
+   (urb->transfer_flags & URB_ISO_ASAP) != 0);
+   i = DIV_ROUND_UP(wrap_frame(
+   cur_frame - urb->start_frame),
+   urb->interval);
+   if (urb->transfer_flags & URB_ISO_ASAP) {
+   urb->start_frame = wrap_frame(urb->start_frame
+   + i * urb->interval);
+   i = 0;
+   } else if (i >= urb->number_of_packets) {
+   ret = -EXDEV;
+   goto alloc_dmem_failed;
+   }
+   }
}
 
/* set up transfers */
+   urb_priv->isoc_remaining = urb->number_of_packets - i;
td = urb_priv->isoc_td;
-   for (i = 0; i < urb->number_of_packets; i++, td++) {
+   for (; i < urb->number_of_packets; i++, td++) {
unsigned int offset = urb->iso_frame_desc[i].offset;
td->ep = ep;
td->urb = urb;
@@ -840,7 +850,6 @@ static int imx21_hc_urb_enqueue_isoc(str
list_add_tail(&td->list, &ep_priv->td_list);
}
 
-   urb_priv->isoc_remaining = urb->number_of_packets;
dev_vdbg(imx21->dev, "setup %d packets for iso frame %d->%d\n",
urb->number_of_packets, urb->start_frame, td->frame);
 

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


Re: [PATCH] xhci: Add BayTrail to list of Intel switchable hosts

2013-05-24 Thread Sergei Shtylyov

Hello.

On 05/24/2013 08:56 PM, Sarah Sharp wrote:


From: "Chew, Chiau Ee" 
Like the xHCI controller on Intel Panther Point and Lynx Point
chipsets, the xHCI controller on Intel BayTrail has also ports that
can be switched between the EHCI host controller.

s/between/to/

Sergei, DO NOT REVIEW PATCHES TO THE XHCI DRIVER.


   OK, I'll try to follow another rule from you, though I'm getting 
tired of you telling me what not to do.



Your grammar comments and complaints about extra parenthesis are not
constructive and cause unnecessary patch churn.


   As if I haven't ever found more serious issues in your own XHCI patches
(even after you forbade me to review them).


Sarah Sharp


WBR, Sergei

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


Re: Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Sarah Sharp
Ccing Dan Williams, since Johannes Berg mentioned on IRC that Dan might
know the status of MBIM support.

On Fri, May 24, 2013 at 10:09:15AM -0700, Sarah Sharp wrote:
> Do we have support for the new extensions for USB communication devices
> that use the Mobile Broadband Interface Model (MBIM) spec?
> 
> http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip
> 
> The spec was released pretty recently, which is why I'm asking on the
> mailing lists, rather than digging around the kernel tree for a driver.
> 
> Sarah Sharp
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: xhci: Disable runtime PM suspend for quirky controllers.

2013-05-24 Thread Shawn Nematbakhsh
If a USB controller with XHCI_RESET_ON_RESUME goes to runtime suspend,
a reset will be performed upon runtime resume. Any previously suspended
devices attached to the controller will be re-enumerated at this time.
This will cause problems, for example, if an open system call on the
device triggered the resume (the open call will fail).

Note that this change is only relevant when persist_enabled is not set
for USB devices.

Signed-off-by: Shawn Nematbakhsh 
---
 drivers/usb/host/xhci.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index b4aa79d..7455156 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4687,6 +4687,12 @@ int xhci_gen_setup(struct usb_hcd *hcd, 
xhci_get_quirks_t get_quirks)
 
get_quirks(dev, xhci);
 
+   /* If we are resetting upon resume, we must disable runtime PM.
+* Otherwise, an open() syscall to a device on our runtime suspended
+* controller will trigger controller reset and device re-enumeration */
+   if (xhci->quirks & XHCI_RESET_ON_RESUME)
+   pm_runtime_get_noresume(dev);
+
/* Make sure the HC is halted. */
retval = xhci_halt(xhci);
if (retval)
-- 
1.7.12.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] serial: Add Option GTM681W to qcserial device table.

2013-05-24 Thread Bjørn Mork
Richard Weinberger  writes:
> Am 24.05.2013 15:18, schrieb Bjørn Mork:
>> Richard Weinberger  writes:
>>
>>> The Option GTM681W uses a qualcomm chip and can be
>>> served by the qcserial device driver.
>>
>> Should it also be added to the qmi_wwan driver?
>
> Don't know. But I can happily test it. :)
> Can you please explain me how to use the qmi_wwan driver?
> I've never used it.

The QMI management protocol is delegated to userspace using a
/dev/cdc-wdmX character device.  So you need a userspace component to
test the driver, like for example libqmi. See 
http://sigquit.wordpress.com/2012/08/20/an-introduction-to-libqmi/ for a
short intro.

This library is packaged in Debian.  Don't know the status of other
distros. 

The driver supports dynamic device IDs, so if you have qcserial bound to
all serial ports, and there is a QMI interface with no driver bound yet,
then testing should be as easy as

 modprobe qmi_wwan
 echo "0af0 8120" >/sys/bus/usb/drivers/qmi_wwan/new_id
 qmicli -d /dev/cdc-wdm0 --dms-get-manufacturer



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: Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Bjørn Mork
[resending due to an unreliable smtp smarthost - apologies if you
 receive any duplicates]

Sarah Sharp  writes:

> Do we have support for the new extensions for USB communication devices
> that use the Mobile Broadband Interface Model (MBIM) spec?

We do. See drivers/net/usb/cdc_mbim.c. It's a usbnet minidriver based on
reusing parts of cdc_ncm.  It should be fairly complete, but the IP
session multiplexing and Device Service Streams features are not tested
on actual devices.  I just haven't found any device with those features
yet.  Any hints are appreciated...

The management protocol implementation is completely delegated to
userspace. The driver isn't involved at all. One implementation is
libmbim, which just had its 1.0.0 release:
http://www.freedesktop.org/software/libmbim/

The next ModemManager release will support MBIM devices using this
library.

> http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip

Thanks for that pointer.  I haven't seen the errata before. Will study
it, but fortunately we are protected against anything involving
management protocol updates.

> The spec was released pretty recently, which is why I'm asking on the
> mailing lists, rather than digging around the kernel tree for a driver.

Well, a "git grep MBIM drivers/" would be enough.   But I'm happy to
answer your questions :)


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: Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Bjørn Mork
Sarah Sharp  writes:

> Do we have support for the new extensions for USB communication devices
> that use the Mobile Broadband Interface Model (MBIM) spec?

We do. See drivers/net/usb/cdc_mbim.c. It's a usbnet minidriver based on
reusing parts of cdc_ncm.  It should be fairly complete, but the IP
session multiplexing and Device Service Streams features are not tested
on actual devices.  I just haven't found any device with those features
yet.  Any hints are appreciated...

The management protocol implementation is completely delegated to
userspace. The driver isn't involved at all. One implementation is
libmbim, which just had its 1.0.0 release:
http://www.freedesktop.org/software/libmbim/

The next ModemManager release will support MBIM devices using this
library.

> http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip

Thanks for that pointer.  I haven't seen the errata before. Will study
it, but fortunately we are protected against anything involving
management protocol updates.

> The spec was released pretty recently, which is why I'm asking on the
> mailing lists, rather than digging around the kernel tree for a driver.

Well, a "git grep MBIM drivers/" would be enough.   But I'm happy to
answer your questions :)


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: Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Bjørn Mork
Bjørn Mork  writes:

>> http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip
>
> Thanks for that pointer.  I haven't seen the errata before. Will study
> it, but fortunately we are protected against anything involving
> management protocol updates.

Yuck.  When did the USB-IF start publishing the erratas merged with the
original with absolutely no indication about what they changed?  This
sucks.

And the changes I notice also suck.  WTF do they need another functional
descriptor for?  For these two numbers? :

 bMaxOutstandingCommand - Max number of outstanding Command Messages the
device can handle simultaneously. Shall be greater than 0.
 wMTU - Operator preferred MTU for home network. wMTU applies to IP Data
Streams.

This is just plain stupid.  Sorry.  I don't know how else to describe
it. They already have an extensible management protocol.  These numbers
could easily have been published through that.   And "Operator preferred
MTU for home network" cannot possibly be a device specific attribute.
That's obviously a network attribute.  How the heck can you put that
into a functional descriptor?  It may change with the SIM card.

And then there are the things they didn't correct.  I've been looking
for the "MBIMRegistry" they refer to ever since the initial version was
published.  AFAICS there is none.  I tried mailing ad...@usb.org about
it in February, but haven't received any replies. As expected.

There are already several vendor specific UUIDs in use.  The registry is
needed if we are expected to support any of these. Microsoft is the only
one documenting theirs AFAIK:
 http://msdn.microsoft.com/en-us/library/windows/hardware/jj248720.aspx
 http://msdn.microsoft.com/en-us/library/windows/hardware/jj248721.aspx
 http://msdn.microsoft.com/en-us/library/windows/hardware/jj149393.aspx

But I've also seen vendor specific services from Qualcomm, AT&T,
Ericsson, Huawei and MediaTek.  All completely undocumented wrt open
source implementations, although I have successfully guessed how to use
the Qualcomm service (it embeds Qualcomms proprietary, but partly openly
documented, QMI protocol in MBIM).


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


[PATCH] usb: chipidea: usbmisc_imx: Staticize usbmisc_imx_drv_init/exit

2013-05-24 Thread Fabio Estevam
From: Fabio Estevam 

Fix the following sparse warnings:

drivers/usb/chipidea/usbmisc_imx.c:246:5: warning: symbol 
'usbmisc_imx_drv_init' was not declared. Should it be static?
drivers/usb/chipidea/usbmisc_imx.c:252:6: warning: symbol 
'usbmisc_imx_drv_exit' was not declared. Should it be static?

Signed-off-by: Fabio Estevam 
---
 drivers/usb/chipidea/usbmisc_imx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/chipidea/usbmisc_imx.c 
b/drivers/usb/chipidea/usbmisc_imx.c
index 714a6bd..1c6610a 100644
--- a/drivers/usb/chipidea/usbmisc_imx.c
+++ b/drivers/usb/chipidea/usbmisc_imx.c
@@ -243,13 +243,13 @@ static struct platform_driver usbmisc_imx_driver = {
 },
 };
 
-int usbmisc_imx_drv_init(void)
+static int usbmisc_imx_drv_init(void)
 {
return platform_driver_register(&usbmisc_imx_driver);
 }
 subsys_initcall(usbmisc_imx_drv_init);
 
-void usbmisc_imx_drv_exit(void)
+static void usbmisc_imx_drv_exit(void)
 {
platform_driver_unregister(&usbmisc_imx_driver);
 }
-- 
1.8.1.2

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


ehci_hcd nonfunctional in 3.9.0,3.9.3

2013-05-24 Thread Eric Buddington
(apologies if this is duplicate; I've tried posting several times over the
past few days, but it seems to be getting silently dropped)


This problem occurs in 3.9.0 and 3.9.3, but not in 3.6.11. Stock
kernel, not tainted, most things (including USB drivers) compiled as
modules.

modprobing ehci_hcd (with no HCD modules loaded) logs only one line in
dmesg:

ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver

I expect it to take control of my USB card, which is this:

00:12.2 USB controller: Advanced Micro Devices [AMD] nee ATI
SB7x0/SB8x0/SB9x0 USB EHCI Controller

Also, /sys/bus/pci/drivers/ehci_hcd does not exist.

Also also, 'modinfo ehci_hcd' shows no 'alias' lines.

Modprobe of ohci_hcd does what I expect:
 - shows the appropriate messages about finding the chipsets.
 - creates /sys/bus/pci/drivers/ohci_hcd
 - registers all my USB hubs and devices, which work at <= 12Mbps

So ehci_hcd is just sitting there like a lump - no errors, no
activity.

Please let me know what other information would be helpful.

-Eric


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


RE: dwc2: Transaction errors with device connected at boot

2013-05-24 Thread Paul Zimmerman
> From: Paul Zimmerman
> Sent: Monday, May 13, 2013 11:58 AM
> 
> > From: Matthijs Kooijman [mailto:matth...@stdin.nl]
> > Sent: Wednesday, May 08, 2013 2:02 PM
> >
> > I'm running into an issue with the dwc2 driver. When I power on my board
> > with an usb device (mass storage in this case) connected, the hardware
> > is returning transaction errors (e.g., triggering channel halted +
> > xacterr interrupts) for every transfer scheduled, starting with the
> > first ones.
> >
> > This condition stays even through a reboot, though a power cycle cures
> > the condition (provided I remove the USB device for the boot). If I
> > insert the USB device after the board has booted and the driver has
> > loaded, everything works as expected, also after a reboot (with the
> > device still plugged in).
> >
> > This leads me to suspect there is some issue when the time between the
> > first hardware initialization and the first host channel start is too
> > small or something like that? Any ideas?
> >
> > Also, is there any fixed list of what could cause a transaction error,
> > or is this just a catchall meaning "Something went wrong"?

Hi Matthijs,

I did see a different issue when booting/rebooting the system.
I discovered that the DMA_BIT_MASK(31)'s in dwc2_hcd_init() were
randomly preventing the controller from working after boot. When
I changed both of them to DMA_BIT_MASK(32) the problem went away.
I am going to submit a patch with that change shortly, maybe you
could try that and see if it makes a difference for you?

After making that change, I am unable to reproduce any boot problem
on my platform (PC with the dwc2 controller on a PCIe bus). I wonder
if this could be some issue with the Phy on your platform? Maybe you
could play around with the Phy initialization/resets in the driver
and see if that makes a difference.

I remember when bringing up the driver, that the sleep at the end of
dwc2_core_reset() was very critical to making host mode work. Maybe
you could experiment with that also.

-- 
Paul

--
To unsubscribe from this list: send the line "unsubscribe 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: xhci: Disable runtime PM suspend for quirky controllers.

2013-05-24 Thread Sarah Sharp
On Fri, May 24, 2013 at 11:12:57AM -0700, Shawn Nematbakhsh wrote:
> If a USB controller with XHCI_RESET_ON_RESUME goes to runtime suspend,
> a reset will be performed upon runtime resume. Any previously suspended
> devices attached to the controller will be re-enumerated at this time.
> This will cause problems, for example, if an open system call on the
> device triggered the resume (the open call will fail).

That's ugly, but disabling runtime PM is going to have a big impact on
the power consumption of those systems.

Alan, do you think this is really the right thing to be doing here?  It
feels like userspace should just be able to deal with devices
disconnecting on resume.  After all, there are lots of USB devices that
can't handle USB device suspend at all.

Shouldn't userspace just disable runtime PM for the USB device classes
that don't have a reset resume callback?

> Note that this change is only relevant when persist_enabled is not set
> for USB devices.

Could we at least wrap the call in an ifdef CONFIG_USB_DEFAULT_PERSIST?
That way if people have USB persist turned off in their configuration,
their host will still be able to suspend.

Sarah Sharp

> 
> Signed-off-by: Shawn Nematbakhsh 
> ---
>  drivers/usb/host/xhci.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
> index b4aa79d..7455156 100644
> --- a/drivers/usb/host/xhci.c
> +++ b/drivers/usb/host/xhci.c
> @@ -4687,6 +4687,12 @@ int xhci_gen_setup(struct usb_hcd *hcd, 
> xhci_get_quirks_t get_quirks)
>  
>   get_quirks(dev, xhci);
>  
> + /* If we are resetting upon resume, we must disable runtime PM.
> +  * Otherwise, an open() syscall to a device on our runtime suspended
> +  * controller will trigger controller reset and device re-enumeration */
> + if (xhci->quirks & XHCI_RESET_ON_RESUME)
> + pm_runtime_get_noresume(dev);
> +
>   /* Make sure the HC is halted. */
>   retval = xhci_halt(xhci);
>   if (retval)
> -- 
> 1.7.12.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] xhci: Add BayTrail to list of Intel switchable hosts

2013-05-24 Thread Sarah Sharp
On Fri, May 24, 2013 at 10:05:01PM +0400, Sergei Shtylyov wrote:
> Hello.
> 
> On 05/24/2013 08:56 PM, Sarah Sharp wrote:
> 
> >>>From: "Chew, Chiau Ee" 
> >>>Like the xHCI controller on Intel Panther Point and Lynx Point
> >>>chipsets, the xHCI controller on Intel BayTrail has also ports that
> >>>can be switched between the EHCI host controller.
> >>s/between/to/
> >Sergei, DO NOT REVIEW PATCHES TO THE XHCI DRIVER.
> 
>OK, I'll try to follow another rule from you, though I'm getting
> tired of you telling me what not to do.

I've told you not to review patches to the xHCI driver three times now.
This is not "another rule", this is something I've asked you to avoid
already.

I've been asking you to change how you review your patches because you
can't seem to pick up on the social cues that nitpicking patches about
only grammar and random code style issues is not constructive.  You
don't seem to be getting the hint, hence the ALL CAPS and blunt words.

> >Your grammar comments and complaints about extra parenthesis are not
> >constructive and cause unnecessary patch churn.
> 
>As if I haven't ever found more serious issues in your own XHCI patches
> (even after you forbade me to review them).

Serious issues are fine to bring up, either for my patches or for
patches that people send for the xHCI.  However, the vast majority of
comments I see from you are simply grammar comments or nitpicking of
code style that checkpatch.pl doesn't complain about.

At some point, your signal to noise ratio is so low that most kernel
developers are just going to start tuning you out.  Greg already put
your email into /dev/null.  Do you want other kernel developers to do so
as well?

If you want *serious bugs* to be acted on, then just send email about
*serious bugs*.  Or include a mix of comments about grammar/code style
in with comments about serious code issues.

Please increase your signal to noise ratio, or I will continue to send
you scathing emails when you nitpick xHCI patches.

Sarah Sharp
--
To unsubscribe from this list: send the line "unsubscribe 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] serial: Add Option GTM681W to qcserial device table.

2013-05-24 Thread Dan Williams
On Fri, 2013-05-24 at 20:25 +0200, Bjørn Mork wrote:
> Richard Weinberger  writes:
> > Am 24.05.2013 15:18, schrieb Bjørn Mork:
> >> Richard Weinberger  writes:
> >>
> >>> The Option GTM681W uses a qualcomm chip and can be
> >>> served by the qcserial device driver.
> >>
> >> Should it also be added to the qmi_wwan driver?
> >
> > Don't know. But I can happily test it. :)
> > Can you please explain me how to use the qmi_wwan driver?
> > I've never used it.
> 
> The QMI management protocol is delegated to userspace using a
> /dev/cdc-wdmX character device.  So you need a userspace component to
> test the driver, like for example libqmi. See 
> http://sigquit.wordpress.com/2012/08/20/an-introduction-to-libqmi/ for a
> short intro.

Various marketing collateral suggests the 681W is a Gobi3K and thus it
most certainly should also get added to qmi_wwan.  lsusb -v output for
it would be helpful too I think?

http://www.option.com/product/gtm681wgtm689w/

Dan

> This library is packaged in Debian.  Don't know the status of other
> distros. 
> 
> The driver supports dynamic device IDs, so if you have qcserial bound to
> all serial ports, and there is a QMI interface with no driver bound yet,
> then testing should be as easy as
> 
>  modprobe qmi_wwan
>  echo "0af0 8120" >/sys/bus/usb/drivers/qmi_wwan/new_id
>  qmicli -d /dev/cdc-wdm0 --dms-get-manufacturer
> 
> 
> 
> 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


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


Re: [PATCH] xhci: Add BayTrail to list of Intel switchable hosts

2013-05-24 Thread Sergei Shtylyov

Hello.

On 05/25/2013 01:54 AM, Sarah Sharp wrote:


From: "Chew, Chiau Ee" 
Like the xHCI controller on Intel Panther Point and Lynx Point
chipsets, the xHCI controller on Intel BayTrail has also ports that
can be switched between the EHCI host controller.

s/between/to/

Sergei, DO NOT REVIEW PATCHES TO THE XHCI DRIVER.

OK, I'll try to follow another rule from you, though I'm getting
tired of you telling me what not to do.

I've told you not to review patches to the xHCI driver three times now.
This is not "another rule", this is something I've asked you to avoid
already.


   Strange, I would have remembered if you told me *thrice*, yet what I 
clearly

remember you told me is not to comment on your own patches.


I've been asking you to change how you review your patches because you
can't seem to pick up on the social cues that nitpicking patches about
only grammar and random code style issues is not constructive.  You
don't seem to be getting the hint, hence the ALL CAPS and blunt words.


Maybe because you are the only one (plus maybe Greg) having issues
with my reviews. I've never been harassed for my review style on any other
mailing lists I'm subscribed to. Usually people are even grateful for 
whatever

review is provided.




Your grammar comments and complaints about extra parenthesis are not
constructive and cause unnecessary patch churn.

As if I haven't ever found more serious issues in your own XHCI patches
(even after you forbade me to review them).

Serious issues are fine to bring up, either for my patches or for
patches that people send for the xHCI.  However, the vast majority of
comments I see from you are simply grammar comments or nitpicking of
code style that checkpatch.pl doesn't complain about.


checkpatch.pl unfortunately is not perfect, there's CodingStyle 
violations
it doesn't complain about. And not everybody even runs checkpatch.pl 
unfortunately

(I myself often forget that).


At some point, your signal to noise ratio is so low that most kernel
developers are just going to start tuning you out.


   As I said, so far I had serious issues due to my reviews only with 
one or two people
in the past several years. I started appearing on the Linux mailing 
lists since 2004.



Greg already put
your email into /dev/null.  Do you want other kernel developers to do so
as well?


   I remember Greg has commented to my patches not so long ago.
Maybe he did put me into his killfile recently but I don't know what 
accident

might have triggered that.


If you want *serious bugs* to be acted on, then just send email about
*serious bugs*.  Or include a mix of comments about grammar/code style
in with comments about serious code issues.


   Fortunately, serious issues are rare and unfortunately, it's harder 
to see

them (in the xHCI driver particularly, as I'm not familiar with its code).


Please increase your signal to noise ratio, or I will continue to send
you scathing emails when you nitpick xHCI patches.


I've already consented not to review them (at least unless I see 
something

serious enough).


Sarah Sharp


WBR, Sergei

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


[Pull Request] xhci: Misc bug fixes for 3.10

2013-05-24 Thread Sarah Sharp
The following changes since commit 2a0ebf80aa95cc758d4725f74a7016e992606a39:

  USB: cxacru: potential underflow in cxacru_cm_get_array() (2013-05-20 
11:35:47 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/sarah/xhci.git 
for-usb-linus-2013-05-24

for you to fetch changes up to c3897aa5386faba77e5bbdf94902a1658d3a5b11:

  xhci: Disable D3cold for buggy TI redrivers. (2013-05-24 15:23:59 -0700)


xhci: Misc bug fixes for 3.10.

Hi Greg,

Here's four xHCI bug fixes that should be queued for 3.10.

The first two are generic bug fixes, and have been in my queue for a while
because I've been doing the OPW internship coordination.  I suspect you'll be
seeing more pull requests from me now that the intern selection process is
almost over. :)

The last two patches fix a nasty kernel crash on resume from S3 for TI hosts
that have the compliance mode quirk.  Tony has confirmed that the patches fix
the issue on the effected systems.

All four patches are marked for stable.

Sarah Sharp


Sarah Sharp (1):
  xhci: Disable D3cold for buggy TI redrivers.

Sergio Aguirre (1):
  xhci-mem: init list heads at the beginning of init

Tony Camuso (1):
  xhci - correct comp_mode_recovery_timer on return from hibernate

Vladimir Murzin (1):
  xhci: fix list access before init

 drivers/usb/host/xhci-mem.c |   10 +++---
 drivers/usb/host/xhci-pci.c |8 
 drivers/usb/host/xhci.c |   16 +---
 drivers/usb/host/xhci.h |3 +++
 4 files changed, 31 insertions(+), 6 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] xhci: fix list access before init

2013-05-24 Thread Sarah Sharp
From: Vladimir Murzin 

If for whatever reason we fall into fail path in xhci_mem_init()
before bw table gets initialized we may access the uninitialized lists
in xhci_mem_cleanup().

Check for bw table before traversing lists in cleanup routine.

This patch should be backported to kernels as old as 3.2, that contain
the commit 839c817ce67178ca3c7c7ad534c571bba1e69ebe "xhci: Store
information about roothubs and TTs."

Reported-by: Sergey Dyasly 
Tested-by: Sergey Dyasly 
Signed-off-by: Vladimir Murzin 
Signed-off-by: Sarah Sharp 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index bda2c51..fbf75e5 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1827,6 +1827,9 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
}
spin_unlock_irqrestore(&xhci->lock, flags);
 
+   if (!xhci->rh_bw)
+   goto no_bw;
+
num_ports = HCS_MAX_PORTS(xhci->hcs_params1);
for (i = 0; i < num_ports; i++) {
struct xhci_interval_bw_table *bwt = &xhci->rh_bw[i].bw_table;
@@ -1845,6 +1848,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
}
}
 
+no_bw:
xhci->num_usb2_ports = 0;
xhci->num_usb3_ports = 0;
xhci->num_active_eps = 0;
-- 
1.7.9

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


[PATCH 4/4] xhci: Disable D3cold for buggy TI redrivers.

2013-05-24 Thread Sarah Sharp
Some xHCI hosts contain a "redriver" from TI that silently drops port
status connect changes if the port slips into Compliance Mode.  If the
port slips into compliance mode while the host is in D0, there will not
be a port status change event.  If the port slips into compliance mode
while the host is in D3, the host will not send a PME.  This includes
when the system is suspended (S3) or hibernated (S4).

If this happens when the system is in S3/S4, there is nothing software
can do.  Other port status change events that would normally cause the
host to wake the system from S3/S4 may also be lost.  This includes
remote wakeup, disconnects and connects on other ports, and overrcurrent
events.  A decision was made to _NOT_ disable system suspend/hibernate
on these systems, since users are unlikely to enable wakeup from S3/S4
for the xHCI host.

Software can deal with this issue when the system is in S0.  A work
around was put in to poll the port status registers for Compliance Mode.
The xHCI driver will continue to poll the registers while the host is
runtime suspended.  Unfortunately, that means we can't allow the PCI
device to go into D3cold, because power will be removed from the host,
and the config space will read as all Fs.

Disable D3cold in the xHCI PCI runtime suspend function.

This patch should be backported to kernels as old as 3.2, that
contain the commit 71c731a296f1b08a3724bd1b514b64f1bda87a23 "usb: host:
xhci: Fix Compliance Mode on SN65LVPE502CP Hardware"

Signed-off-by: Sarah Sharp 
Cc: Huang Ying 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-pci.c |8 
 drivers/usb/host/xhci.c |4 ++--
 drivers/usb/host/xhci.h |3 +++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 1a30c38..cc24e39 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -221,6 +221,14 @@ static void xhci_pci_remove(struct pci_dev *dev)
 static int xhci_pci_suspend(struct usb_hcd *hcd, bool do_wakeup)
 {
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
+   struct pci_dev  *pdev = to_pci_dev(hcd->self.controller);
+
+   /*
+* Systems with the TI redriver that loses port status change events
+* need to have the registers polled during D3, so avoid D3cold.
+*/
+   if (xhci_compliance_mode_recovery_timer_quirk_check())
+   pdev->no_d3cold = true;
 
return xhci_suspend(xhci);
 }
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index ae59119..d8f640b 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -466,7 +466,7 @@ static void compliance_mode_recovery_timer_init(struct 
xhci_hcd *xhci)
  * Systems:
  * Vendor: Hewlett-Packard -> System Models: Z420, Z620 and Z820
  */
-static bool compliance_mode_recovery_timer_quirk_check(void)
+bool xhci_compliance_mode_recovery_timer_quirk_check(void)
 {
const char *dmi_product_name, *dmi_sys_vendor;
 
@@ -517,7 +517,7 @@ int xhci_init(struct usb_hcd *hcd)
xhci_dbg(xhci, "Finished xhci_init\n");
 
/* Initializing Compliance Mode Recovery Data If Needed */
-   if (compliance_mode_recovery_timer_quirk_check()) {
+   if (xhci_compliance_mode_recovery_timer_quirk_check()) {
xhci->quirks |= XHCI_COMP_MODE_QUIRK;
compliance_mode_recovery_timer_init(xhci);
}
diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h
index 29c978e..77600ce 100644
--- a/drivers/usb/host/xhci.h
+++ b/drivers/usb/host/xhci.h
@@ -1853,4 +1853,7 @@ struct xhci_input_control_ctx 
*xhci_get_input_control_ctx(struct xhci_hcd *xhci,
 struct xhci_slot_ctx *xhci_get_slot_ctx(struct xhci_hcd *xhci, struct 
xhci_container_ctx *ctx);
 struct xhci_ep_ctx *xhci_get_ep_ctx(struct xhci_hcd *xhci, struct 
xhci_container_ctx *ctx, unsigned int ep_index);
 
+/* xHCI quirks */
+bool xhci_compliance_mode_recovery_timer_quirk_check(void);
+
 #endif /* __LINUX_XHCI_HCD_H */
-- 
1.7.9

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


[PATCH 3/4] xhci - correct comp_mode_recovery_timer on return from hibernate

2013-05-24 Thread Sarah Sharp
From: Tony Camuso 

Commit 71c731a2 (usb: host: xhci: Fix Compliance Mode on SN65LVPE502CP
Hardware) was a workaround for systems using the SN65LVPE502CP,
controller, but it introduced a bug in resume from hibernate.

The fix created a timer, comp_mode_recovery_timer, which is deleted from
a timer list when xhci_suspend() is called. However, the hibernate image,
including the timer list containing the comp_mode_recovery_timer, had
already been saved before the timer was deleted.

Upon resume from hibernate, the list containing the comp_mode_recovery_timer
is restored from the image saved to disk, and xhci_resume(), assuming that
the timer had been deleted by xhci_suspend(), makes a call to
compliance_mode_recoery_timer_init(), which creates a new instance of the
comp_mode_recovery_timer and attempts to place it into the same list in which
it is already active, thus corrupting the list during the list_add() call.

At this point, a call trace is emitted indicating the list corruption.
Soon afterward, the system locks up, the watchdog times out, and the
ensuing NMI crashes the system.

The problem did not occur when resuming from suspend. In suspend, the
image in RAM remains exactly as it was when xhci_suspend() deleted the
comp_mode_recovery_timer, so there is no problem when xhci_resume()
creates a new instance of this timer and places it in the still empty
list.

This patch avoids the problem by deleting the timer in xhci_resume()
when resuming from hibernate. Now xhci_resume() can safely make the
call to create a new instance of this timer, whether returning from
suspend or hibernate.

Thanks to Alan Stern for his help with understanding the problem.

[Sarah reworked this patch to cover the case where the xHCI restore
register operation fails, and (temp & STS_SRE) is true (and we re-init
the host, including re-init for the compliance mode), but hibernate is
false.  The original patch would have caused list corruption in this
case.]

This patch should be backported to kernels as old as 3.2, that
contain the commit 71c731a296f1b08a3724bd1b514b64f1bda87a23 "usb: host:
xhci: Fix Compliance Mode on SN65LVPE502CP Hardware"

Signed-off-by: Tony Camuso 
Tested-by: Tony Camuso 
Acked-by: Don Zickus 
Signed-off-by: Sarah Sharp 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci.c |   12 +++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index b4aa79d..ae59119 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -956,6 +956,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
struct usb_hcd  *hcd = xhci_to_hcd(xhci);
struct usb_hcd  *secondary_hcd;
int retval = 0;
+   boolcomp_timer_running = false;
 
/* Wait a bit if either of the roothubs need to settle from the
 * transition into bus suspend.
@@ -993,6 +994,13 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
 
/* If restore operation fails, re-initialize the HC during resume */
if ((temp & STS_SRE) || hibernated) {
+
+   if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) &&
+   !(xhci_all_ports_seen_u0(xhci))) {
+   del_timer_sync(&xhci->comp_mode_recovery_timer);
+   xhci_dbg(xhci, "Compliance Mode Recovery Timer 
deleted!\n");
+   }
+
/* Let the USB core know _both_ roothubs lost power. */
usb_root_hub_lost_power(xhci->main_hcd->self.root_hub);
usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub);
@@ -1035,6 +1043,8 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
retval = xhci_init(hcd->primary_hcd);
if (retval)
return retval;
+   comp_timer_running = true;
+
xhci_dbg(xhci, "Start the primary HCD\n");
retval = xhci_run(hcd->primary_hcd);
if (!retval) {
@@ -1076,7 +1086,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated)
 * to suffer the Compliance Mode issue again. It doesn't matter if
 * ports have entered previously to U0 before system's suspension.
 */
-   if (xhci->quirks & XHCI_COMP_MODE_QUIRK)
+   if ((xhci->quirks & XHCI_COMP_MODE_QUIRK) && !comp_timer_running)
compliance_mode_recovery_timer_init(xhci);
 
/* Re-enable port polling. */
-- 
1.7.9

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


[PATCH 1/4] xhci-mem: init list heads at the beginning of init

2013-05-24 Thread Sarah Sharp
From: Sergio Aguirre 

It is possible that we fail on xhci_mem_init, just before doing
the INIT_LIST_HEAD, and calling xhci_mem_cleanup.

Problem is that, the list_for_each_entry_safe macro, assumes
list heads are initialized (not NULL), and dereferences their 'next'
pointer, causing a kernel panic if this is not yet initialized.

Let's protect from that by moving inits to the beginning.

This patch should be backported to kernels as old as 3.2, that
contain the commit 9574323c39d1f8359a04843075d89c9f32d8b7e6 "xHCI: test
USB2 software LPM".

Signed-off-by: Sergio Aguirre 
Acked-by: David Cohen 
Signed-off-by: Sarah Sharp 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 2cfc465..bda2c51 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -2256,6 +2256,9 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
u32 page_size, temp;
int i;
 
+   INIT_LIST_HEAD(&xhci->lpm_failed_devs);
+   INIT_LIST_HEAD(&xhci->cancel_cmd_list);
+
page_size = xhci_readl(xhci, &xhci->op_regs->page_size);
xhci_dbg(xhci, "Supported page size register = 0x%x\n", page_size);
for (i = 0; i < 16; i++) {
@@ -2334,7 +2337,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
xhci->cmd_ring = xhci_ring_alloc(xhci, 1, 1, TYPE_COMMAND, flags);
if (!xhci->cmd_ring)
goto fail;
-   INIT_LIST_HEAD(&xhci->cancel_cmd_list);
xhci_dbg(xhci, "Allocated command ring at %p\n", xhci->cmd_ring);
xhci_dbg(xhci, "First segment DMA is 0x%llx\n",
(unsigned long long)xhci->cmd_ring->first_seg->dma);
@@ -2445,8 +2447,6 @@ int xhci_mem_init(struct xhci_hcd *xhci, gfp_t flags)
if (xhci_setup_port_arrays(xhci, flags))
goto fail;
 
-   INIT_LIST_HEAD(&xhci->lpm_failed_devs);
-
/* Enable USB 3.0 device notifications for function remote wake, which
 * is necessary for allowing USB 3.0 devices to do remote wakeup from
 * U3 (device suspend).
-- 
1.7.9

--
To unsubscribe from this list: send the line "unsubscribe 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] staging: dwc2: fix value of dma_mask

2013-05-24 Thread Paul Zimmerman
Passing the value DMA_BIT_MASK(31) to dma_set_mask() causes the
dwc2-pci driver to sometimes fail (cannot enumerate the connected
device). Change it to DMA_BIT_MASK(32) instead, which is a more
sensible value anyway.

Signed-off-by: Paul Zimmerman 
---
This should be sent to Linus for the next -rc, since without it
the dwc2-pci driver may not work when DMA mode is enabled.

 drivers/staging/dwc2/hcd.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/dwc2/hcd.c b/drivers/staging/dwc2/hcd.c
index 827ab78..8551cce 100644
--- a/drivers/staging/dwc2/hcd.c
+++ b/drivers/staging/dwc2/hcd.c
@@ -2804,9 +2804,8 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
 
/* Set device flags indicating whether the HCD supports DMA */
if (hsotg->core_params->dma_enable > 0) {
-   if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(31)) < 0)
-   dev_warn(hsotg->dev,
-"can't enable workaround for >2GB RAM\n");
+   if (dma_set_mask(hsotg->dev, DMA_BIT_MASK(32)) < 0)
+   dev_warn(hsotg->dev, "can't set DMA mask\n");
if (dma_set_coherent_mask(hsotg->dev, DMA_BIT_MASK(31)) < 0)
dev_warn(hsotg->dev,
 "can't enable workaround for >2GB RAM\n");
-- 
1.8.2.rc0.16.g20a599e

--
To unsubscribe from this list: send the line "unsubscribe 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] staging: dwc2: change some dev_dbg() messages to dev_vdbg()

2013-05-24 Thread Paul Zimmerman
Change some dev_dbg() messages in dwc2_hcd_hub_control() to
dev_vdbg(), to prevent massive spew to the dmesg log when a device
is disconnected.

Signed-off-by: Paul Zimmerman 
---
 drivers/staging/dwc2/hcd.c | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/dwc2/hcd.c b/drivers/staging/dwc2/hcd.c
index 2b09199..2ed54b1 100644
--- a/drivers/staging/dwc2/hcd.c
+++ b/drivers/staging/dwc2/hcd.c
@@ -1563,9 +1563,9 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, 
u16 typereq,
break;
 
case GetPortStatus:
-   dev_dbg(hsotg->dev,
-   "GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex,
-   hsotg->flags.d32);
+   dev_vdbg(hsotg->dev,
+"GetPortStatus wIndex=0x%04x flags=0x%08x\n", windex,
+hsotg->flags.d32);
if (!windex || windex > 1)
goto error;
 
@@ -1598,7 +1598,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, 
u16 typereq,
}
 
hprt0 = readl(hsotg->regs + HPRT0);
-   dev_dbg(hsotg->dev, "  HPRT0: 0x%08x\n", hprt0);
+   dev_vdbg(hsotg->dev, "  HPRT0: 0x%08x\n", hprt0);
 
if (hprt0 & HPRT0_CONNSTS)
port_status |= USB_PORT_STAT_CONNECTION;
@@ -1623,7 +1623,7 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg *hsotg, 
u16 typereq,
port_status |= USB_PORT_STAT_TEST;
/* USB_PORT_FEAT_INDICATOR unsupported always 0 */
 
-   dev_dbg(hsotg->dev, "port_status=%08x\n", port_status);
+   dev_vdbg(hsotg->dev, "port_status=%08x\n", port_status);
*(__le32 *)buf = cpu_to_le32(port_status);
break;
 
-- 
1.8.2.rc0.16.g20a599e

--
To unsubscribe from this list: send the line "unsubscribe 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: Mobile Broadband Interface Model (MBIM) support?

2013-05-24 Thread Dan Williams
On Fri, 2013-05-24 at 11:10 -0700, Sarah Sharp wrote:
> Ccing Dan Williams, since Johannes Berg mentioned on IRC that Dan might
> know the status of MBIM support.

As Bjorn mentioned, libmbim just got a 1.0 release, and ModemManager
0.7.x (git master, basically) has support for MBIM devices via libmbim.
0.7.x will turn into an official 0.8 release Real Soon Now; it's already
built for Fedora 20, though we don't have libmbim capability in F20
quite yet.

Dan

> On Fri, May 24, 2013 at 10:09:15AM -0700, Sarah Sharp wrote:
> > Do we have support for the new extensions for USB communication devices
> > that use the Mobile Broadband Interface Model (MBIM) spec?
> > 
> > http://www.usb.org/developers/devclass_docs/MBIM10Errata1.zip
> > 
> > The spec was released pretty recently, which is why I'm asking on the
> > mailing lists, rather than digging around the kernel tree for a driver.
> > 
> > Sarah Sharp
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> > the body of a message to majord...@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


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


[RFC 0/6] xHCI and USB security bug fixes

2013-05-24 Thread Sarah Sharp
This patchset address some (but not all) of the security issues found
with the Klockwork static analysis tool.  I have not reviewed these in
detail to see if these could be used by attackers, so someone with more
security experience may want to look these over.

Sarah Sharp

The following changes since commit c3897aa5386faba77e5bbdf94902a1658d3a5b11:

  xhci: Disable D3cold for buggy TI redrivers. (2013-05-24 15:23:59 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/sarah/xhci.git ful-klockwork

for you to fetch changes up to c3a0a3ea1c2ece9596b6e3ae3fcb4540fc9b6e31:

  usb: check usb_hub_to_struct_hub() return value (2013-05-24 17:26:48 -0700)


Mathias Nyman (4):
  xhci: Remove BUG in xhci_setup_addressable_virt_dev
  xhci: remove BUG() in xhci_get_endpoint_type()
  xhci: check for failed dma pool allocation
  usb: check usb_hub_to_struct_hub() return value

Sarah Sharp (2):
  xhci: Remove BUG_ON() in xhci_alloc_container_ctx.
  xhci: Remove BUG_ON in xhci_get_input_control_ctx.

 drivers/usb/core/hub.c   |  107 ++
 drivers/usb/host/xhci-dbg.c  |5 ++
 drivers/usb/host/xhci-mem.c  |   65 +-
 drivers/usb/host/xhci-ring.c |4 +
 drivers/usb/host/xhci.c  |  148 --
 5 files changed, 234 insertions(+), 95 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC 1/6] xhci: Remove BUG_ON() in xhci_alloc_container_ctx.

2013-05-24 Thread Sarah Sharp
It's horrible coding style to panic the kernel when someone passes you
an argument value you didn't expect.

This patch should be backported to kernels as old as 2.6.31, that
contain the commit d115b04818e57bdbc7ccde4d0660b15e33013dc8 "USB: xhci:
Support for 64-byte contexts".

Signed-off-by: Sarah Sharp 
Cc: John Youn 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |8 ++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index fbf75e5..1a2052d 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -358,11 +358,15 @@ int xhci_ring_expansion(struct xhci_hcd *xhci, struct 
xhci_ring *ring,
 static struct xhci_container_ctx *xhci_alloc_container_ctx(struct xhci_hcd 
*xhci,
int type, gfp_t flags)
 {
-   struct xhci_container_ctx *ctx = kzalloc(sizeof(*ctx), flags);
+   struct xhci_container_ctx *ctx;
+
+   if ((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT))
+   return NULL;
+
+   ctx = kzalloc(sizeof(*ctx), flags);
if (!ctx)
return NULL;
 
-   BUG_ON((type != XHCI_CTX_TYPE_DEVICE) && (type != XHCI_CTX_TYPE_INPUT));
ctx->type = type;
ctx->size = HCC_64BYTE_CONTEXT(xhci->hcc_params) ? 2048 : 1024;
if (type == XHCI_CTX_TYPE_INPUT)
-- 
1.7.9

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


[RFC 4/6] xhci: remove BUG() in xhci_get_endpoint_type()

2013-05-24 Thread Sarah Sharp
From: Mathias Nyman 

If the endpoint type is unknown, set it to 0 and fail gracefully
instead of causing a kernel panic.

This patch should be backported to kernels as old as 2.6.31, that
contain the commit f94e0186312b0fc39f41eed4e21836ed74b7efe1 "USB: xhci:
Bandwidth allocation support"

Signed-off-by: Mathias Nyman 
Signed-off-by: Sarah Sharp 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |   14 +-
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 9f06aa8..94412ec 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1329,7 +1329,7 @@ static u32 xhci_get_endpoint_type(struct usb_device *udev,
else
type = EP_TYPE(INT_OUT_EP);
} else {
-   BUG();
+   type = 0;
}
return type;
 }
@@ -1375,10 +1375,16 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
unsigned int max_burst;
enum xhci_ring_type type;
u32 max_esit_payload;
+   u32 endpoint_type;
 
ep_index = xhci_get_endpoint_index(&ep->desc);
ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
 
+   endpoint_type = xhci_get_endpoint_type(udev, ep);
+   if (!endpoint_type)
+   return -EINVAL;
+   ep_ctx->ep_info2 = cpu_to_le32(endpoint_type);
+
type = usb_endpoint_type(&ep->desc);
/* Set up the endpoint ring */
virt_dev->eps[ep_index].new_ring =
@@ -1407,11 +1413,9 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
 * CErr shall be set to 0 for Isoch endpoints.
 */
if (!usb_endpoint_xfer_isoc(&ep->desc))
-   ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(3));
+   ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(3));
else
-   ep_ctx->ep_info2 = cpu_to_le32(ERROR_COUNT(0));
-
-   ep_ctx->ep_info2 |= cpu_to_le32(xhci_get_endpoint_type(udev, ep));
+   ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(0));
 
/* Set the max packet size and max burst */
max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc));
-- 
1.7.9

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


[RFC 6/6] usb: check usb_hub_to_struct_hub() return value

2013-05-24 Thread Sarah Sharp
From: Mathias Nyman 

usb_hub_to_struct_hub() can return NULL in the unlikely cases a hub
without active configuration, or a hub without ports is found.

Even if unlikely we need to handle those cases properly.

[Note from Sarah: I'm not sure which stable kernels need parts of this
patch applied.  I think parts of it will need to be backported to
kernels as old as 2.6.32.

Commit 25118084ef03f4fc314ab33ef6a9d9271d0e616a "USB: check for hub
driver not bound to root hub device" (which was merged in 2.6.32)
changed hdev_to_hub() to return NULL if the driver wasn't bound to the
roothub.  Any commits after that commit that don't check for the NULL
pointer need to be fixed.

This is further complicated by the fact that commit
ad493e5e580546e6c3024b76a41535476da1546a "usb: add usb port auto power
off mechanism" renamed hdev_to_hub() to usb_hub_to_struct_hub(), and
thus this patch will not apply to kernels older than 3.9.

Also, commit 84ebc10294a3d7be4c66f51070b7aedbaa24de9b "USB: remove
CONFIG_USB_SUSPEND option" (which was merged in 3.10) removed one
instance of a potential NULL pointer dereference in the version of
usb_port_resume() that is used in older kernels when CONFIG_USB_SUSPEND
is turned off.

I will have to create separate patches for the older stable kernels.]

Signed-off-by: Mathias Nyman 
Signed-off-by: Sarah Sharp 
Cc: Alan Stern 
Cc: sta...@vger.kernel.org
---
 drivers/usb/core/hub.c |  107 +++
 1 files changed, 79 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index feef935..ff6f12b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -730,7 +730,12 @@ int usb_hub_set_port_power(struct usb_device *hdev, int 
port1,
 {
int ret;
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
-   struct usb_port *port_dev = hub->ports[port1 - 1];
+   struct usb_port *port_dev;
+
+   if (!hub)
+   return -EINVAL;
+
+   port_dev = hub->ports[port1 - 1];
 
if (set)
ret = set_port_feature(hdev, port1, USB_PORT_FEAT_POWER);
@@ -964,6 +969,10 @@ int usb_remove_device(struct usb_device *udev)
if (!udev->parent)  /* Can't remove a root hub */
return -EINVAL;
hub = usb_hub_to_struct_hub(udev->parent);
+
+   if (!hub)
+   return -EINVAL;
+
intf = to_usb_interface(hub->intfdev);
 
usb_autopm_get_interface(intf);
@@ -1733,6 +1742,9 @@ hub_ioctl(struct usb_interface *intf, unsigned int code, 
void *user_data)
struct usb_device *hdev = interface_to_usbdev (intf);
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
 
+   if (!hub)
+   return -EINVAL;
+
/* assert ifno == 0 (part of hub spec) */
switch (code) {
case USBDEVFS_HUB_PORTINFO: {
@@ -1769,15 +1781,17 @@ hub_ioctl(struct usb_interface *intf, unsigned int 
code, void *user_data)
 static int find_port_owner(struct usb_device *hdev, unsigned port1,
struct dev_state ***ppowner)
 {
+   struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
+
if (hdev->state == USB_STATE_NOTATTACHED)
return -ENODEV;
-   if (port1 == 0 || port1 > hdev->maxchild)
+   if (port1 == 0 || port1 > hdev->maxchild || !hub)
return -EINVAL;
 
/* This assumes that devices not managed by the hub driver
 * will always have maxchild equal to 0.
 */
-   *ppowner = &(usb_hub_to_struct_hub(hdev)->ports[port1 - 1]->port_owner);
+   *ppowner = &(hub->ports[port1 - 1]->port_owner);
return 0;
 }
 
@@ -1817,6 +1831,9 @@ void usb_hub_release_all_ports(struct usb_device *hdev, 
struct dev_state *owner)
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
int n;
 
+   if (!hub)
+   return;
+
for (n = 0; n < hdev->maxchild; n++) {
if (hub->ports[n]->port_owner == owner)
hub->ports[n]->port_owner = NULL;
@@ -1832,6 +1849,9 @@ bool usb_device_is_owned(struct usb_device *udev)
if (udev->state == USB_STATE_NOTATTACHED || !udev->parent)
return false;
hub = usb_hub_to_struct_hub(udev->parent);
+   if (!hub)
+   return false;
+
return !!hub->ports[udev->portnum - 1]->port_owner;
 }
 
@@ -1841,7 +1861,7 @@ static void recursively_mark_NOTATTACHED(struct 
usb_device *udev)
int i;
 
for (i = 0; i < udev->maxchild; ++i) {
-   if (hub->ports[i]->child)
+   if (hub && hub->ports[i]->child)
recursively_mark_NOTATTACHED(hub->ports[i]->child);
}
if (udev->state == USB_STATE_SUSPENDED)
@@ -2021,7 +2041,7 @@ void usb_disconnect(struct usb_device **pdev)
 
/* Free up all the children before we remove this device */
for (i = 0; i < udev->maxchild; i++) {
-   if (hub->ports[i]->child)
+   if (hub

[RFC 5/6] xhci: check for failed dma pool allocation

2013-05-24 Thread Sarah Sharp
From: Mathias Nyman 

Fail and free the container context in case dma_pool_alloc() can't allocate
the raw context data part of it

This patch should be backported to kernels as old as 2.6.31, that
contain the commit d115b04818e57bdbc7ccde4d0660b15e33013dc8 "USB: xhci:
Support for 64-byte contexts".

Signed-off-by: Mathias Nyman 
Signed-off-by: Sarah Sharp 
Cc: John Youn 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 94412ec..82d4677 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -373,6 +373,10 @@ static struct xhci_container_ctx 
*xhci_alloc_container_ctx(struct xhci_hcd *xhci
ctx->size += CTX_SIZE(xhci->hcc_params);
 
ctx->bytes = dma_pool_alloc(xhci->device_pool, flags, &ctx->dma);
+   if (!ctx->bytes) {
+   kfree(ctx);
+   return NULL;
+   }
memset(ctx->bytes, 0, ctx->size);
return ctx;
 }
-- 
1.7.9

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


[RFC 3/6] xhci: Remove BUG in xhci_setup_addressable_virt_dev

2013-05-24 Thread Sarah Sharp
From: Mathias Nyman 

We may have more speed types in the future, so fail gracefully, rather
than causing the kernel to panic.

BUG() was called if the device speed was unknown when setting max packet
size.  Set the max packet size at the same time as the slot speed and
get rid of one switch statement with BUG() option completely.

[Note: Sarah merged a patch that she wrote that touched the
xhci_setup_addressable_virt_dev function with this patch from Mathias
for clarity.]

This patch should be backported to kernels as old as 2.6.31, that
contain the commit 3ffbba9511b4148cbe1f6b6238686adaeaca8feb "USB: xhci:
Allocate and address USB devices"

Signed-off-by: Mathias Nyman 
Signed-off-by: Sarah Sharp 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-mem.c |   35 ++-
 1 files changed, 10 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index e68aafe..9f06aa8 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -1055,6 +1055,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd 
*xhci, struct usb_device *ud
struct xhci_ep_ctx  *ep0_ctx;
struct xhci_slot_ctx*slot_ctx;
u32 port_num;
+   u32 max_packets;
struct usb_device *top_dev;
 
dev = xhci->devs[udev->slot_id];
@@ -1072,15 +1073,20 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd 
*xhci, struct usb_device *ud
switch (udev->speed) {
case USB_SPEED_SUPER:
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS);
+   max_packets = MAX_PACKET(512);
break;
case USB_SPEED_HIGH:
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_HS);
+   max_packets = MAX_PACKET(64);
break;
+   /* USB core guesses at a 64-byte max packet first for FS devices */
case USB_SPEED_FULL:
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_FS);
+   max_packets = MAX_PACKET(64);
break;
case USB_SPEED_LOW:
slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_LS);
+   max_packets = MAX_PACKET(8);
break;
case USB_SPEED_WIRELESS:
xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
@@ -1088,7 +1094,7 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd 
*xhci, struct usb_device *ud
break;
default:
/* Speed was set earlier, this shouldn't happen. */
-   BUG();
+   return -EINVAL;
}
/* Find the root hub port this device is under */
port_num = xhci_find_real_port_number(xhci, udev);
@@ -1147,31 +1153,10 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd 
*xhci, struct usb_device *ud
/* Step 4 - ring already allocated */
/* Step 5 */
ep0_ctx->ep_info2 = cpu_to_le32(EP_TYPE(CTRL_EP));
-   /*
-* XXX: Not sure about wireless USB devices.
-*/
-   switch (udev->speed) {
-   case USB_SPEED_SUPER:
-   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(512));
-   break;
-   case USB_SPEED_HIGH:
-   /* USB core guesses at a 64-byte max packet first for FS devices */
-   case USB_SPEED_FULL:
-   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(64));
-   break;
-   case USB_SPEED_LOW:
-   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(8));
-   break;
-   case USB_SPEED_WIRELESS:
-   xhci_dbg(xhci, "FIXME xHCI doesn't support wireless speeds\n");
-   return -EINVAL;
-   break;
-   default:
-   /* New speed? */
-   BUG();
-   }
+
/* EP 0 can handle "burst" sizes of 1, so Max Burst Size field is 0 */
-   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3));
+   ep0_ctx->ep_info2 |= cpu_to_le32(MAX_BURST(0) | ERROR_COUNT(3) |
+max_packets);
 
ep0_ctx->deq = cpu_to_le64(dev->eps[0].ring->first_seg->dma |
   dev->eps[0].ring->cycle_state);
-- 
1.7.9

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


[RFC 2/6] xhci: Remove BUG_ON in xhci_get_input_control_ctx.

2013-05-24 Thread Sarah Sharp
Fail gracefully, instead of causing the kernel to panic, if the input
control context doesn't have the right type (XHCI_CTX_TYPE_INPUT).  Push
finding the pointer to the input control context up into functions that
can fail.

This patch should be backported to kernels as old as 2.6.31, that
contain the commit d115b04818e57bdbc7ccde4d0660b15e33013dc8 "USB: xhci:
Support for 64-byte contexts".

Signed-off-by: Sarah Sharp 
Cc: John Youn 
Cc: sta...@vger.kernel.org
---
 drivers/usb/host/xhci-dbg.c  |5 ++
 drivers/usb/host/xhci-mem.c  |4 +-
 drivers/usb/host/xhci-ring.c |4 +
 drivers/usb/host/xhci.c  |  148 --
 4 files changed, 126 insertions(+), 35 deletions(-)

diff --git a/drivers/usb/host/xhci-dbg.c b/drivers/usb/host/xhci-dbg.c
index 5f3a7c7..8e0be37 100644
--- a/drivers/usb/host/xhci-dbg.c
+++ b/drivers/usb/host/xhci-dbg.c
@@ -550,6 +550,11 @@ void xhci_dbg_ctx(struct xhci_hcd *xhci,
if (ctx->type == XHCI_CTX_TYPE_INPUT) {
struct xhci_input_control_ctx *ctrl_ctx =
xhci_get_input_control_ctx(xhci, ctx);
+   if (!ctrl_ctx) {
+   xhci_warn(xhci, "Could not get input context, bad 
type.\n");
+   return;
+   }
+
xhci_dbg(xhci, "@%p (virt) @%08llx (dma) %#08x - drop flags\n",
 &ctrl_ctx->drop_flags, (unsigned long long)dma,
 ctrl_ctx->drop_flags);
diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c
index 1a2052d..e68aafe 100644
--- a/drivers/usb/host/xhci-mem.c
+++ b/drivers/usb/host/xhci-mem.c
@@ -389,7 +389,9 @@ static void xhci_free_container_ctx(struct xhci_hcd *xhci,
 struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_hcd 
*xhci,
  struct xhci_container_ctx *ctx)
 {
-   BUG_ON(ctx->type != XHCI_CTX_TYPE_INPUT);
+   if (ctx->type != XHCI_CTX_TYPE_INPUT)
+   return NULL;
+
return (struct xhci_input_control_ctx *)ctx->bytes;
 }
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 1969c00..0cceb21 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1424,6 +1424,10 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
 */
ctrl_ctx = xhci_get_input_control_ctx(xhci,
virt_dev->in_ctx);
+   if (!ctrl_ctx) {
+   xhci_warn(xhci, "Could not get input context, bad 
type.\n");
+   break;
+   }
/* Input ctx add_flags are the endpoint index plus one */
ep_index = 
xhci_last_valid_endpoint(le32_to_cpu(ctrl_ctx->add_flags)) - 1;
/* A usb_set_interface() call directly after clearing a halted
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index d8f640b..daeceb7 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -1225,19 +1225,25 @@ static int xhci_check_maxpacket(struct xhci_hcd *xhci, 
unsigned int slot_id,
hw_max_packet_size);
xhci_dbg(xhci, "Issuing evaluate context command.\n");
 
+   /* Set up the input context flags for the command */
+   /* FIXME: This won't work if a non-default control endpoint
+* changes max packet sizes.
+*/
+   in_ctx = xhci->devs[slot_id]->in_ctx;
+   ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
+   if (!ctrl_ctx) {
+   xhci_warn(xhci, "%s: Could not get input context, bad 
type.\n",
+   __func__);
+   return -ENOMEM;
+   }
/* Set up the modified control endpoint 0 */
xhci_endpoint_copy(xhci, xhci->devs[slot_id]->in_ctx,
xhci->devs[slot_id]->out_ctx, ep_index);
-   in_ctx = xhci->devs[slot_id]->in_ctx;
+
ep_ctx = xhci_get_ep_ctx(xhci, in_ctx, ep_index);
ep_ctx->ep_info2 &= cpu_to_le32(~MAX_PACKET_MASK);
ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet_size));
 
-   /* Set up the input context flags for the command */
-   /* FIXME: This won't work if a non-default control endpoint
-* changes max packet sizes.
-*/
-   ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
ctrl_ctx->add_flags = cpu_to_le32(EP0_FLAG);
ctrl_ctx->drop_flags = 0;
 
@@ -1597,6 +1603,12 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct 
usb_device *udev,
in_ctx = xhci->devs[udev->slot_id]->in_ctx;
out_ctx = xhci->devs[udev->slot_id]->out_ctx;
ctrl_ctx = xhci_get_input_control_ctx(xhci, in_ctx);
+   if (!ctrl_ctx) {
+   

[PATCH] usb: xhci: Fix Command Ring Stopped Event handling

2013-05-24 Thread Julius Werner
The current XHCI code treats a command completion event with the
COMP_CMD_STOP code as a slightly different version of COMP_CMD_ABORT. In
particular, it puts the pointed-to command TRB through the normal
command completion handlers. This is not how this event works.

As XHCI spec 4.6.1.1 describes, unlike other command completion events
Command Ring Stopped sets the Command TRB Pointer to the *current*
Command Ring Dequeue Pointer. This is the command TRB that the XHCI will
execute next, and not a command that has already been executed. The
driver's internal command ring dequeue pointer should not be increased
after this event, since it does not really mark a command completion...
it's just a hint for the driver that execution is stopped now and where
it will be picked up again if the ring gets restarted.

This patch gets rid of the handle_stopped_command_ring() function and
splits its behavior into two distinct parts for COMP_CMD_STOP and
COMP_CMD_ABORT events. It ensures that the former no longer messes with
the dequeue pointer, while the latter's behavior is unchanged. This
prevents the hardware and software dequeue pointer from going out of
sync during command cancellations, which can lead to a variety of
problems (up to a total HCD death if the next command after the one that
was cancelled is Stop Endpoint, and the stop_endpoint_watchdog won't see
the command's completion because it got skipped by the software dequeue
pointer).

This patch should be backported to kernels as far as 3.0 that contain
the commit b63f4053cc8aa22a98e3f9a97845afe6c15d0a0d "xHCI: handle
command after aborting the command ring".

Signed-off-by: Julius Werner 
---
 drivers/usb/host/xhci-ring.c | 85 +---
 1 file changed, 33 insertions(+), 52 deletions(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 1969c00..98b7673 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -1314,47 +1314,11 @@ static int xhci_search_cmd_trb_in_cd_list(struct 
xhci_hcd *xhci,
return 0;
 }
 
-/*
- * If the cmd_trb_comp_code is COMP_CMD_ABORT, we just check whether the
- * trb pointed by the command ring dequeue pointer is the trb we want to
- * cancel or not. And if the cmd_trb_comp_code is COMP_CMD_STOP, we will
- * traverse the cancel_cmd_list to trun the all of the commands according
- * to command descriptor to NO-OP trb.
- */
-static int handle_stopped_cmd_ring(struct xhci_hcd *xhci,
-   int cmd_trb_comp_code)
-{
-   int cur_trb_is_good = 0;
-
-   /* Searching the cmd trb pointed by the command ring dequeue
-* pointer in command descriptor list. If it is found, free it.
-*/
-   cur_trb_is_good = xhci_search_cmd_trb_in_cd_list(xhci,
-   xhci->cmd_ring->dequeue);
-
-   if (cmd_trb_comp_code == COMP_CMD_ABORT)
-   xhci->cmd_ring_state = CMD_RING_STATE_STOPPED;
-   else if (cmd_trb_comp_code == COMP_CMD_STOP) {
-   /* traversing the cancel_cmd_list and canceling
-* the command according to command descriptor
-*/
-   xhci_cancel_cmd_in_cd_list(xhci);
-
-   xhci->cmd_ring_state = CMD_RING_STATE_RUNNING;
-   /*
-* ring command ring doorbell again to restart the
-* command ring
-*/
-   if (xhci->cmd_ring->dequeue != xhci->cmd_ring->enqueue)
-   xhci_ring_cmd_db(xhci);
-   }
-   return cur_trb_is_good;
-}
-
 static void handle_cmd_completion(struct xhci_hcd *xhci,
struct xhci_event_cmd *event)
 {
int slot_id = TRB_TO_SLOT_ID(le32_to_cpu(event->flags));
+   int comp_code = GET_COMP_CODE(le32_to_cpu(event->status));
u64 cmd_dma;
dma_addr_t cmd_dequeue_dma;
struct xhci_input_control_ctx *ctrl_ctx;
@@ -1377,16 +1341,34 @@ static void handle_cmd_completion(struct xhci_hcd *xhci,
return;
}
 
-   if ((GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_ABORT) ||
-   (GET_COMP_CODE(le32_to_cpu(event->status)) == COMP_CMD_STOP)) {
-   /* If the return value is 0, we think the trb pointed by
-* command ring dequeue pointer is a good trb. The good
-* trb means we don't want to cancel the trb, but it have
-* been stopped by host. So we should handle it normally.
-* Otherwise, driver should invoke inc_deq() and return.
-*/
-   if (handle_stopped_cmd_ring(xhci,
-   GET_COMP_CODE(le32_to_cpu(event->status {
+   /*
+* Command Ring Stopped events point at the xHC's *current* dequeue
+* pointer, i.e. the next command that will be executed. That TRB may
+* or may not have been issued yet. Just overwrite all canceled commands
+* with NOOPs and restart the ring, lea

[PATCH] usb: xhci: Use non-interruptible sleep for XHCI commands

2013-05-24 Thread Julius Werner
The XHCI stack usually uses wait_for_completion_interruptible_timeout()
to wait for the completion of an XHCI command, and treats both timeouts
and interruptions as errors. This is a bad idea, since these commands
are often essential for the correct operation of the USB stack, and
their failure can leave devices in a misconfigured and/or unusable
state. While a timeout probably means a real problem that needs to be
dealt with, a random signal to the controlling user-space process should
not cause such harsh consequences.

This patch changes that behavior to use uninterruptible waits instead.
It fixes an easy to reproduce bug that occurs when you kill -9 a
process that reads from a UVC camera. The UVC driver's release code
tries to set the camera's alternate setting back to 0, but the lingering
SIGKILL instantly aborts any Stop Endpoint or Configure Endpoint command
sent to the xHC. The code dies halfway through the bandwidth allocation
process, leaving the device in an active configuration and preventing
future access to it due to the now out-of-sync bandwidth calculation.

This patch should be backported to kernels as far 2.6.31 that contain
the commit 3ffbba9511b4148cbe1f6b6238686adaeaca8feb "USB: xhci: Allocate
and address USB devices".

Signed-off-by: Julius Werner 
---
 drivers/usb/host/xhci-hub.c |  7 +++
 drivers/usb/host/xhci.c | 26 +++---
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 187a3ec..c1bcfa8 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.c
@@ -293,12 +293,11 @@ static int xhci_stop_device(struct xhci_hcd *xhci, int 
slot_id, int suspend)
spin_unlock_irqrestore(&xhci->lock, flags);
 
/* Wait for last stop endpoint command to finish */
-   timeleft = wait_for_completion_interruptible_timeout(
+   timeleft = wait_for_completion_timeout(
cmd->completion,
-   USB_CTRL_SET_TIMEOUT);
+   XHCI_CMD_DEFAULT_TIMEOUT);
if (timeleft <= 0) {
-   xhci_warn(xhci, "%s while waiting for stop endpoint command\n",
-   timeleft == 0 ? "Timeout" : "Signal");
+   xhci_warn(xhci, "Timeout while waiting for Stop Endpoint\n");
spin_lock_irqsave(&xhci->lock, flags);
/* The timeout might have raced with the event ring handler, so
 * only delete from the list if the item isn't poisoned.
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index b4aa79d..302f992 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -2613,15 +2613,14 @@ static int xhci_configure_endpoint(struct xhci_hcd 
*xhci,
spin_unlock_irqrestore(&xhci->lock, flags);
 
/* Wait for the configure endpoint command to complete */
-   timeleft = wait_for_completion_interruptible_timeout(
+   timeleft = wait_for_completion_timeout(
cmd_completion,
XHCI_CMD_DEFAULT_TIMEOUT);
if (timeleft <= 0) {
-   xhci_warn(xhci, "%s while waiting for %s command\n",
-   timeleft == 0 ? "Timeout" : "Signal",
+   xhci_warn(xhci, "Timeout while waiting for %s\n",
ctx_change == 0 ?
-   "configure endpoint" :
-   "evaluate context");
+   "Configure Endpoint" :
+   "Evaluate Context");
/* cancel the configure endpoint command */
ret = xhci_cancel_cmd(xhci, command, cmd_trb);
if (ret < 0)
@@ -3399,12 +3398,11 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, 
struct usb_device *udev)
spin_unlock_irqrestore(&xhci->lock, flags);
 
/* Wait for the Reset Device command to finish */
-   timeleft = wait_for_completion_interruptible_timeout(
+   timeleft = wait_for_completion_timeout(
reset_device_cmd->completion,
-   USB_CTRL_SET_TIMEOUT);
+   XHCI_CMD_DEFAULT_TIMEOUT);
if (timeleft <= 0) {
-   xhci_warn(xhci, "%s while waiting for reset device command\n",
-   timeleft == 0 ? "Timeout" : "Signal");
+   xhci_warn(xhci, "Timeout while waiting for Reset Device\n");
spin_lock_irqsave(&xhci->lock, flags);
/* The timeout might have raced with the event ring handler, so
 * only delete from the list if the item isn't poisoned.
@@ -3588,11 +3586,10 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct 
usb_device *udev)
spin_unlock_irqrestore(&xhci->lock, flags);
 
/* XXX: how much time for xHC slot assignment? */
-   timeleft = wait_for_completion_interruptible_timeout(&xh

[PATCH] ARM: OMAP4: USB_EHCI_HCD needs USB_PHY and NOP_USB_XCEIV

2013-05-24 Thread Adrien Vergé
On OMAP4 platforms, EHCI HCD needs the physical layer signalling
activated, along with the NOP USB Transceiver driver. Otherwise, the
kernel boots without registering any USB device.

This patch applies to Linux 3.10-rc2.

Signed-off-by: Adrien Vergé 
---
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index de94f26..47959d7 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -44,6 +44,8 @@ endif # USB_XHCI_HCD
 config USB_EHCI_HCD
tristate "EHCI HCD (USB 2.0) support"
depends on USB_ARCH_HAS_EHCI
+   select USB_PHY if ARCH_OMAP4
+   select NOP_USB_XCEIV if ARCH_OMAP4
---help---
  The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0
  "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware.
--
To unsubscribe from this list: send the line "unsubscribe 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] staging: dwc2: fix value of dma_mask

2013-05-24 Thread Matthijs Kooijman
Hi Paul,

On Fri, May 24, 2013 at 04:27:56PM -0700, Paul Zimmerman wrote:
> Passing the value DMA_BIT_MASK(31) to dma_set_mask() causes the
> dwc2-pci driver to sometimes fail (cannot enumerate the connected
> device). Change it to DMA_BIT_MASK(32) instead, which is a more
> sensible value anyway.
Isn't 32 the default value usually? Not sure a about PCI devices,
though. It also made sense to set it to 31, since the comment talks
about a workaround for > 2GB ram (and 2GB ~~ 31 bits).

Or, is the workaround really only needed in the coherent mask and is
that the reason why you didn't change the coherent dma mask to 32?

If this is so, wouldn't it make sense to only set the coherent dma mask
and leave the dma mask at whatever default (just guessing here...).

Gr.

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