Re: [PATCH v2 1/1] usb: gadget: f_fs: Add support for SuperSpeed Mode

2013-09-26 Thread Manu Gautam

On 9/26/2013 2:10 AM, Felipe Balbi wrote:

Hi,

(please avoid top-posting)

On Tue, Sep 24, 2013 at 03:00:20PM +0530, Manu Gautam wrote:

Hi Felipe,

I wanted to mention one point with respect to this patch: Below
changes in the functionfs.h to add ss_count (super speed descriptors
count) in desc_header (which is passed from userspace) make the driver
incompatible with existing userspace applications compiled against old
header file. Let me know if that is acceptable.  We are using this
driver with Android for adbd (android debug bridge) and these changes
are required to support adb over Super Speed controllers e.g. DWC3
along with changed in adbd to pass SS EP and companion descriptors.


Good you mentioned, it saves me the trouble of reviewing this patch :-)

It's not acceptable to break userspace ABI at all. If you want
SuperSpeed support on function fs, we need to figure out a way to do so
without breaking userspace.

This might mean adding a separate userspace interface to be used with
superspeed. While at that, we might want to add a few bytes of reserved,
unused space in our structures for situations where we need to add more
data into it, just to make it slightly future proof.



Thanks for your reply.
As you suggested we can have a different interface for super speed
which would be optional to workaround ABI compatibility issue.
Let me know if below interface looks fine to you, I will then implement
accordingly:

diff --git a/include/uapi/linux/usb/functionfs.h 
b/include/uapi/linux/usb/functionfs.h

index d6b0128..b8cb740 100644
--- a/include/uapi/linux/usb/functionfs.h
+++ b/include/uapi/linux/usb/functionfs.h
@@ -9,8 +9,9 @@


 enum {
-   FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
-   FUNCTIONFS_STRINGS_MAGIC = 2
+   FUNCTIONFS_DESCRIPTORS_MAGIC = 1,
+   FUNCTIONFS_STRINGS_MAGIC = 2,
+   FUNCTIONFS_SS_DESCRIPTORS_MAGIC  = 3
 };


@@ -60,6 +61,25 @@ struct usb_functionfs_descs_head {
  * |   2 | payload |  | descriptor's payload |
  */

+struct usb_functionfs_ss_descs_head {
+   __le32 magic;
+   __le32 length;
+   __le32 reserved;
+   __le32 ss_count;
+} __attribute__((packed));
+
+/*
+ * SS Descriptors format:
+ *
+ * | off | name  | type | description 
|
+ * 
|-+---+--+--|
+ * |   0 | magic | LE32 | FUNCTIONFS_SS_DESCRIPTORS_MAGIC 
|
+ * |   4 | length| LE32 | length of the whole data chunk 
|
+ * |   8 | ss_count  | LE32 | number of super-speed descriptors 
   |
+ * |  12 | reserved field 
|
+ * |  16 | ss_descrs | Descriptor[] | list of super-speed descriptors 
|

+ */
+
 struct usb_functionfs_strings_head {
__le32 magic;
__le32 length;

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


[PATCH] usb: gadget: Use ERR_CAST inlined function instead of ERR_PTR(PTR_ERR(...))

2013-09-26 Thread Duan Jiong


Signed-off-by: Duan Jiong 
---
 drivers/usb/gadget/configfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 8f0d614..1bfacbf 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -557,7 +557,7 @@ static struct config_group *function_make(
 
fi = usb_get_function_instance(func_name);
if (IS_ERR(fi))
-   return ERR_PTR(PTR_ERR(fi));
+   return ERR_CAST(fi);
 
ret = config_item_set_name(&fi->group.cg_item, name);
if (ret) {
-- 
1.8.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [alsa-devel] Cannot load snd-usb-audio on 3.12-rc2

2013-09-26 Thread David Henningsson
On 09/24/2013 05:52 PM, Daniel Mack wrote:
> Hi Sarah,
> 
> On 24.09.2013 01:41, Sarah Sharp wrote:
>> The snd-usb-audio driver no longer loads properly on 3.12-rc2 when I
>> plug in my USB headset.  It worked fine on 3.11-rc4 (not sure about
>> vanilla 3.11).
>>
>> Trying to manually load the driver fails:
>>
>> sarah@xanatos:~$ sudo modprobe snd-usb-audio
>> FATAL: Error inserting snd_usb_audio
>> (/lib/modules/3.12.0-rc2/kernel/sound/usb/snd-usb-audio.ko): Invalid argument
>>
>> dmesg shows:
>>
>> [   44.231668] snd_usb_audio: `-2' invalid for parameter `index'
> 
> That's really strange. I just tested on an ARM board where I currently
> run 3.12-rc2 as well, and I can load the module without problems. Also,
> sound/usb/card.c (where the params are declared) hasn't seen an update
> in 3.12.
> 
> I suspect your OS is passing "index=-2" from something like
> /etc/modprobe.d/* or cmdline settings. Could you investigate in that
> direction?

Ubuntu has passed

options snd-usb-audio index=-2

...since ages. It is, AFAIK, a very valid way of trying to make "some
other card" be card 0.
This is because card 0 is the default in some apps which are not using
PulseAudio, so it's mostly there for historical reasons.

-- 
David Henningsson, Canonical Ltd.
https://launchpad.net/~diwic
--
To unsubscribe from this list: send the line "unsubscribe 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 4/5] dma: cppi41: only allocate descriptor memory once

2013-09-26 Thread Sebastian Andrzej Siewior
* Daniel Mack | 2013-09-22 16:50:03 [+0200]:

>cdd->cd and cdd->descs_phys are allocated DESCS_AREAS times from
>init_descs() and freed as often from purge_descs(). This leads to both
>memory leaks and double-frees.
>
>Fix this by pulling the calls to dma_{alloc,free}_coherent() out of the
>loops.
>
>While at it, remove the intermediate variable mem_decs (I guess it was
>only there to make the code comply to the 80-chars CodingSytle rule).
>
>Signed-off-by: Daniel Mack 

Please don't merge the memory descriptors. The idea was initially to
allocate multiple small descriptors instead one big. The descrriptor
turned out to be enough so it looks like the way it looks.
If you want to clean this up, please either remove the for loop and
allocate only one memory area or please prepare for multiple descripors
(I think two is the upper limit).

Sebastian
--
To unsubscribe from this list: send the line "unsubscribe 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: Cannot load snd-usb-audio on 3.12-rc2

2013-09-26 Thread Takashi Iwai
At Mon, 23 Sep 2013 16:41:07 -0700,
Sarah Sharp wrote:
> 
> The snd-usb-audio driver no longer loads properly on 3.12-rc2 when I
> plug in my USB headset.  It worked fine on 3.11-rc4 (not sure about
> vanilla 3.11).
> 
> Trying to manually load the driver fails:
> 
> sarah@xanatos:~$ sudo modprobe snd-usb-audio
> FATAL: Error inserting snd_usb_audio
> (/lib/modules/3.12.0-rc2/kernel/sound/usb/snd-usb-audio.ko): Invalid argument
> 
> dmesg shows:
> 
> [   44.231668] snd_usb_audio: `-2' invalid for parameter `index'

There is no corresponding code change in the USB audio driver side, so
I guess it must be in the module parameter parser that got broken.

Does the patch below fix?


thanks,

Takashi

---
diff --git a/kernel/params.c b/kernel/params.c
index 81c4e78..c00d5b5 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -254,11 +254,11 @@ int parse_args(const char *doing,
 
 
 STANDARD_PARAM_DEF(byte, unsigned char, "%hhu", unsigned long, kstrtoul);
-STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtoul);
+STANDARD_PARAM_DEF(short, short, "%hi", long, kstrtol);
 STANDARD_PARAM_DEF(ushort, unsigned short, "%hu", unsigned long, kstrtoul);
-STANDARD_PARAM_DEF(int, int, "%i", long, kstrtoul);
+STANDARD_PARAM_DEF(int, int, "%i", long, kstrtol);
 STANDARD_PARAM_DEF(uint, unsigned int, "%u", unsigned long, kstrtoul);
-STANDARD_PARAM_DEF(long, long, "%li", long, kstrtoul);
+STANDARD_PARAM_DEF(long, long, "%li", long, kstrtol);
 STANDARD_PARAM_DEF(ulong, unsigned long, "%lu", unsigned long, kstrtoul);
 
 int param_set_charp(const char *val, const struct kernel_param *kp)
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] net: qmi_wwan: fix checkpatch warnings

2013-09-26 Thread Fabio Porcedda
Hi Bjørn,
thanks for reviewing.

On Wed, Sep 25, 2013 at 3:31 PM, Bjørn Mork  wrote:
> Sorry, I really don't see the point of this.  Yes, the lines are longer
> than 80 columns, but breaking them don't improve the readability at
> all.  On the contrary, IMHO.
>
> So NAK from me for this part.

Which changes do you think do not improve the readability?
I'm sure that at least some of them actually improve the readability.

Best regards
Fabio Porcedda

> Fabio Porcedda  writes:
>
>> Signed-off-by: Fabio Porcedda 
>> ---
>>  drivers/net/usb/qmi_wwan.c | 56 
>> +-
>>  1 file changed, 36 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
>> index 5f6b6fa..0e59f9e 100644
>> --- a/drivers/net/usb/qmi_wwan.c
>> +++ b/drivers/net/usb/qmi_wwan.c
>> @@ -143,16 +143,22 @@ static const struct net_device_ops qmi_wwan_netdev_ops 
>> = {
>>   .ndo_validate_addr  = eth_validate_addr,
>>  };
>>
>> -/* using a counter to merge subdriver requests with our own into a combined 
>> state */
>> +/* using a counter to merge subdriver requests with our own into a
>> + * combined state
>> + */
>>  static int qmi_wwan_manage_power(struct usbnet *dev, int on)
>>  {
>>   struct qmi_wwan_state *info = (void *)&dev->data;
>>   int rv = 0;
>>
>> - dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__, 
>> atomic_read(&info->pmcount), on);
>> + dev_dbg(&dev->intf->dev, "%s() pmcount=%d, on=%d\n", __func__,
>> + atomic_read(&info->pmcount), on);
>>
>> - if ((on && atomic_add_return(1, &info->pmcount) == 1) || (!on && 
>> atomic_dec_and_test(&info->pmcount))) {
>> - /* need autopm_get/put here to ensure the usbcore sees the new 
>> value */
>> + if ((on && atomic_add_return(1, &info->pmcount) == 1) ||
>> + (!on && atomic_dec_and_test(&info->pmcount))) {
>> + /* need autopm_get/put here to ensure the usbcore sees
>> +  * the new value
>> +  */
>>   rv = usb_autopm_get_interface(dev->intf);
>>   if (rv < 0)
>>   goto err;
>> @@ -199,7 +205,8 @@ static int qmi_wwan_register_subdriver(struct usbnet 
>> *dev)
>>   atomic_set(&info->pmcount, 0);
>>
>>   /* register subdriver */
>> - subdriver = usb_cdc_wdm_register(info->control, &dev->status->desc, 
>> 4096, &qmi_wwan_cdc_wdm_manage_power);
>> + subdriver = usb_cdc_wdm_register(info->control, &dev->status->desc,
>> +  4096, &qmi_wwan_cdc_wdm_manage_power);
>>   if (IS_ERR(subdriver)) {
>>   dev_err(&info->control->dev, "subdriver registration 
>> failed\n");
>>   rv = PTR_ERR(subdriver);
>> @@ -228,7 +235,8 @@ static int qmi_wwan_bind(struct usbnet *dev, struct 
>> usb_interface *intf)
>>   struct usb_driver *driver = driver_of(intf);
>>   struct qmi_wwan_state *info = (void *)&dev->data;
>>
>> - BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) < sizeof(struct 
>> qmi_wwan_state)));
>> + BUILD_BUG_ON((sizeof(((struct usbnet *)0)->data) <
>> +   sizeof(struct qmi_wwan_state)));
>>
>>   /* set up initial state */
>>   info->control = intf;
>> @@ -250,7 +258,8 @@ static int qmi_wwan_bind(struct usbnet *dev, struct 
>> usb_interface *intf)
>>   goto err;
>>   }
>>   if (h->bLength != sizeof(struct usb_cdc_header_desc)) {
>> - dev_dbg(&intf->dev, "CDC header len %u\n", 
>> h->bLength);
>> + dev_dbg(&intf->dev, "CDC header len %u\n",
>> + h->bLength);
>>   goto err;
>>   }
>>   break;
>> @@ -260,7 +269,8 @@ static int qmi_wwan_bind(struct usbnet *dev, struct 
>> usb_interface *intf)
>>   goto err;
>>   }
>>   if (h->bLength != sizeof(struct usb_cdc_union_desc)) {
>> - dev_dbg(&intf->dev, "CDC union len %u\n", 
>> h->bLength);
>> + dev_dbg(&intf->dev, "CDC union len %u\n",
>> + h->bLength);
>>   goto err;
>>   }
>>   cdc_union = (struct usb_cdc_union_desc *)buf;
>> @@ -271,15 +281,15 @@ static int qmi_wwan_bind(struct usbnet *dev, struct 
>> usb_interface *intf)
>>   goto err;
>>   }
>>   if (h->bLength != sizeof(struct usb_cdc_ether_desc)) {
>> - dev_dbg(&intf->dev, "CDC ether len %u\n",  
>> h->bLength);
>> + dev_dbg(&intf->dev, "CDC ether len %u\n",
>> + h->bLength);
>>   goto err;
>>  

Re: [PATCH v3 1/2] staging: dwc2: validate urb->actual_length for OUT endpoints

2013-09-26 Thread Matthijs Kooijman
Hi folks,

On Tue, Sep 24, 2013 at 11:08:53AM -0500, Felipe Balbi wrote:
> > > On Mon, Sep 23, 2013 at 02:23:33PM -0700, Paul Zimmerman wrote:
> > > > +   if ((urb->actual_length < 0 || urb->actual_length > 
> > > > urb->length) &&
> > > > +   !dwc2_hcd_is_pipe_in(&urb->pipe_info))
> > > > +   urb->actual_length = urb->length;
> >
> > I assume it was to fix some issue seen by our developers. We don't have
> > detailed commit logs for that driver, so I am unable to say for certain.
> > But since it is part of the downstream RaspberryPi driver, which has
> > seen a lot of testing, I thought it best to include it.
> 
> Maybe RPi folks can give some details ? Because I really wonder if we'd
> not be masking a bug somewhere else and this would make it a lot harder
> to pin-point that bug.

Agreed. Perhaps there should be a message printed or a WARN() there so
we can pinpoint in which cases this case actually occurs?

Paul, did you see if this case actually triggers with your hardware?

Gr.

Matthijs


signature.asc
Description: Digital signature


Re: [PATCH v4 1/3] usb: dwc3: msm: Add device tree binding information

2013-09-26 Thread Mark Rutland
On Mon, Sep 23, 2013 at 08:31:48PM +0100, Felipe Balbi wrote:
> Hi,
> 
> On Tue, Aug 20, 2013 at 12:56:03PM +0300, Ivan T. Ivanov wrote:
> > From: "Ivan T. Ivanov" 
> > 
> > MSM USB3.0 core wrapper consist of USB3.0 IP from Synopsys
> > (SNPS) and HS, SS PHY's control and configuration registers.
> > 
> > It could operate in device mode (SS, HS, FS) and host
> > mode (SS, HS, FS, LS).
> > 
> > Signed-off-by: Ivan T. Ivanov 
> 
> Any acks for the DT part ? This patch has been pending forever.

Apologies for the delay. I have a couple of comments that would be nice
to fix up now.

> 
> > ---
> >  .../devicetree/bindings/usb/msm-ssusb.txt  |  104 
> > 
> >  1 file changed, 104 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/usb/msm-ssusb.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/usb/msm-ssusb.txt 
> > b/Documentation/devicetree/bindings/usb/msm-ssusb.txt
> > new file mode 100644
> > index 000..cacbd3b
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/usb/msm-ssusb.txt
> > @@ -0,0 +1,104 @@
> > +MSM SuperSpeed DWC3 USB SoC controller
> > +
> > +
> > +DWC3 Highspeed USB PHY
> > +==
> > +Required properities :
> > +- compatible : sould be "qcom,dwc3-hsphy";

s/sould/should/

In general, compatible properties are "should contain" rather than
"should be", as we might have backwards compatible hardware in future.

> > +- reg : offset and length of the register set in the memory map
> > +- clocks : phandles to clock instances of the device tree nodes

Clocks are referred to be phandle + clock-specifier pairs rather than
phandles, it would be nice to fix the terminology here

> > +- clock-names :
> > +   "xo" : External reference clock 19 MHz
> > +   "sleep_a" : Sleep clock, used when USB3 core goes into low
> > +   power mode (U3).

I think it would be nicer to say:
- clocks : A list of phandle + clock-specifier pairs for the clocks
   listed in clock-names
- clock-names: Should contain the following:
   "xo"  - External reference clock (19MHz)
   "sleep_a" - Sleep clock used when USB3 core goes into low
   power mode (U3).

I'm not sure we need to describe the frequency of the xo clock -- either
it's a requriement of the IP and thus doesn't need to be a part of the
binding, or it's configurable by the driver and thus doesn't need to be
documented.

> > +-supply : phandle to the regulator device tree node
> > +Required "supply-name" are:
> > +   "v1p8" : 1.8v supply for HSPHY
> > +   "v3p3" : 3.3v supply for HSPHY
> > +   "vbus" : vbus supply for host mode
> > +   "vddcx" : vdd supply for HS-PHY digital circuit operation

Any reason for the HSPHY/HS-PHY difference?

I'd list these separately with their full names:

- v1p8-supply: phandle to the regulator for the 1.8v supply to HSPHY.
- v3p3-supply: phandle to the regulator for the 3.3v supply to HSPHY.
- vbus-supply: phandle to the regulator for the vbus supply for host
   mode.
- vddcx-supply: phandle to the regulator for the vdd supply for HSPHY
  digital circuit operation.

> > +
> > +DWC3 Superspeed USB PHY
> > +===
> > +Required properities :
> > +- compatible : sould be "qcom,dwc3-ssphy";
> > +- reg : offset and length of the register set in the memory map
> > +- clocks : phandles to clock instances of the device tree nodes
> > +- clock-names :
> > +   "xo" : External reference clock 19 MHz
> > +   "ref" : Reference clock - used in host mode.
> > +-supply : phandle to the regulator device tree node
> > +Required "supply-name" are:
> > +   "v1p8" : 1.8v supply for SS-PHY
> > +   "vddcx" : vdd supply for SS-PHY digital circuit operation

The commments on compatible, clocks, clock-names and the regulators
apply here.

> > +
> > +DWC3 controller wrapper
> > +===
> > +Required properties :
> > +- compatible : should be "qcom,dwc3"
> > +- reg : offset and length of the register set in the memory map
> > +   offset and length of the TCSR register for routing USB
> > +   signals to either picoPHY0 or picoPHY1.
> > +- clocks : phandles to clock instances of the device tree nodes
> > +- clock-names :
> > +   "core" : Master/Core clock, have to be >= 125 MHz for SS
> > +   operation and >= 60MHz for HS operation
> > +   "iface" : System bus AXI clock
> > +   "sleep" : Sleep clock, used when USB3 core goes into low
> > +   power mode (U3).
> > +   "utmi" : Generated by HS-PHY. Used to clock the low power
> > +   parts of thr HS Link layer.
> > +Optional properties :
> > +- gdsc-supply : phandle to the globally distributed switch controller
> > +  regulator node to the USB controller.

The commments on compatible, clocks, and clock-names apply here too. I
see the regulator is defined individually :)

I'm fine with the binding itself, I'd just like the documentation fixed
up.

Cheers,
Mark.

> > +Required child node:
> > +A child node must exist to represent t

Re: [PATCH 5/7] staging: usbip: Add encryption support to kernel

2013-09-26 Thread Dominik Paulus
Hi,

thank you very much for your feedback!

On Mon, Sep 23, 2013 at 12:59:29PM +0300, Dan Carpenter wrote:
> > +   while (total < size) {
> > +   uint32_t packetsize;
> > +   struct kvec recvvec;
> > +
> > +   /*
> > +* We use a global kfifo to buffer unrequested plaintext bytes.
> > +* Flush this buffer first before receiving new data.
> > +*/
> > +   if (kfifo_len(&ud->recv_queue)) {
> > +   size_t next = min_t(size_t, kfifo_len(&ud->recv_queue),
> > +   size - total);
> > +   /* No error checking necessary - see previous line */
> > +   ret = kfifo_out(&ud->recv_queue, ((char *)
> > +   vec[0].iov_base)+total, next);
> 
> 
> The comment assume there is only one reader and one writer at a time,
> yes?  The casting is not needed:

Actually, we have not only one reader and one writer, but exactly one
thread doing all the work on the fifo. No parallel access is done at
all.

>   ret = kfifo_out(&ud->recv_queue,
>   vec[0].iov_base + total, next);
> 
> 
> v> +  total += next;
> > +   continue;
> > +   }
> > +
> > +   /* See usbip_sendmsg() for the format of one encrypted packet */
> > +
> > +   /*
> > +* Receive size of next crypto packet
> > +*/
> > +   recvvec.iov_base = &packetsize;
> > +   recvvec.iov_len = sizeof(packetsize);
> > +
> > +   ret = kernel_recvmsg(ud->tcp_socket, msg, &recvvec, 1,
> > +   sizeof(packetsize), flags);
> > +   packetsize = be32_to_cpu(packetsize);
> > +   if (ret <= 0) {
> 
> I think a return of zero should mean total = -EBADMSG;.  In other words
> this check should be "if (ret < 0) {" and we hit the next else if.
> Same below again.

As we are wrapping kernel_recvmsg here, we wanted to leave the semantics
intact as far as possible. The calling code already checks for the correct
size.

> > +   total = ret;
> > +   goto err;
> > +   } else if (ret != sizeof(packetsize)) {
> > +   total = -EBADMSG;
> > +   goto err;
> > +   }

On Mon, Sep 23, 2013 at 01:35:04PM +0300, Dan Carpenter wrote:
> On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> > +   if (crypto_aead_setkey(ud->tfm_send, sendkey, USBIP_KEYSIZE) != 0 ||
> > +   crypto_aead_setkey(ud->tfm_recv, recvkey,
> > +   USBIP_KEYSIZE) != 0 ||
> > +   crypto_aead_setauthsize(ud->tfm_send,
> > +   USBIP_AUTHSIZE) != 0 ||
> > +   crypto_aead_setauthsize(ud->tfm_recv,
> > +   USBIP_AUTHSIZE)) {
> > +   crypto_free_aead(ud->tfm_recv);
> > +   crypto_free_aead(ud->tfm_send);
> > +   kfifo_free(&ud->recv_queue);
> > +   }
> 
> This returns success on error instead of failure.

Indeed, that was horribly broken. Thanks.

On Mon, Sep 23, 2013 at 01:58:42PM +0300, Dan Carpenter wrote:
> On Thu, Sep 19, 2013 at 04:11:57PM +0200, Dominik Paulus wrote:
> > +{
> > +   struct crypto_aead *tfm;
> > +   struct aead_request *req;
> > +   struct tcrypt_result result;
> > +   struct scatterlist plain, cipher, assoc;
> > +   char iv[16];
> > +   u64 *iv_num;
> > +   u64 iv_net;
> > +   const int plainsize = packetsize - USBIP_AUTHSIZE;
> 
> Is it possible that packetsize is less than USBIP_AUTHSIZE?

No, currently, the caller (usbip_sendmsg() / usbip_recvmsg() are the
only functions calling usbip_crypt(), which itself is static) ensures
this.
Admittedly, this isn't great design. We added a check for packetsize <
USBIP_AUTHSIZE and an appropiate return here.

> > +   if (encrypt)
> > +   ret = crypto_aead_encrypt(req);
> > +   else
> > +   ret = crypto_aead_decrypt(req);
> > +
> 
> Good on you for figuring out what crypto_aead_en/decrypt() returns.
> Where are these functions documented?
> 
> > +switch (ret) {
> > +case 0: /* Success */
> > +break;
> > +case -EINPROGRESS:
> > +case -EBUSY:
> > +wait_for_completion(&result.completion);
> > +break;
> > +default:
> > +aead_request_free(req);
> > +return ret;
> > +}
> > +

They aren't, actually. Documentation/crypto/api-intro.txt refers to the
regression test module, which uses exactly those return-values in
crypto/testmgr.c.
We noticed that wait_for_completion might not be the best idea, since it could
hang indefinitely, testmgr.c uses wait_for_completion_interruptible. Do we
want 'interruptible' or 'killable' here?
(Also we forgot to error-check result.err afterwards. We also fixed that.)

Regards,
Dominik Paulus, Tobias Polzer
--
To unsubscrib

Re: [PATCH 2/2] net: qmi_wwan: fix checkpatch warnings

2013-09-26 Thread Bjørn Mork
Fabio Porcedda  writes:

> Hi Bjørn,
> thanks for reviewing.
>
> On Wed, Sep 25, 2013 at 3:31 PM, Bjørn Mork  wrote:
>> Sorry, I really don't see the point of this.  Yes, the lines are longer
>> than 80 columns, but breaking them don't improve the readability at
>> all.  On the contrary, IMHO.
>>
>> So NAK from me for this part.
>
> Which changes do you think do not improve the readability?

Anything that breaks a previously unbroken argument list will reduce the
readability in my opinion.  The lines can of course not be unlimited,
but there is no need to set the limit as low as 80 columns.  Feedback
I've got from developers using e.g. 80 column braille devices is that
longer lines isn't really a problem for them either.

The point is that the properly broken lines aren't that much more
readable than a line broken by your terminal, even if you set it to 80
columns.  You do of course not get the proper indendation of the broken
lines, but you get a terminal hint telling you that it is a continuation
line.  Which is often better that having to figure it out based on the
code.

This isn't to say that I don't think writing shorter lines is a goal.
I'd really like the code to be nice and compact, avoiding this
discussion completely by just keeping every line shorter than 80.  But
I'm just not that good a programmer :-)

I'd surely appreciate any patch moving the code in that direction.

> I'm sure that at least some of them actually improve the readability.

Yes, reformatting the comments improves the readability.  I just don't
think that makes any sense on it's own, if the surrounding lines are
kept longer.

If the code can be rewritten to actually *be* shorter than 80 columns
instead of just breaking too long code lines, then that is a definite
improvement.  You didn't have many examples of this, I believe.  But
reducing the indent level, removing unnecessary function parameters, or
splitting declaration and initialization are changes which often reduce
the line length while improving the readability at the same time.
Breaking lines rarely do.

This is the only one of your code changes which I can be convinced to
agreeing may improve readability:

- if ((on && atomic_add_return(1, &info->pmcount) == 1) || (!on && 
atomic_dec_and_test(&info->pmcount))) {
+ if ((on && atomic_add_return(1, &info->pmcount) == 1) ||
+ (!on && atomic_dec_and_test(&info->pmcount))) {


But it mostly points out a piece of code which is too complex in the
first place, begging to be rewritten in a more elegant form.

Just for the record:  All this is of course only my personal opinions,
and I am fine with being overridden even if I originally wrote the ugly
code :-)

David decides.


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: [PATCH 39/51] DMA-API: others: use dma_set_coherent_mask()

2013-09-26 Thread Archit Taneja

Hi,

On Friday 20 September 2013 04:41 AM, Russell King wrote:

The correct way for a driver to specify the coherent DMA mask is
not to directly access the field in the struct device, but to use
dma_set_coherent_mask().  Only arch and bus code should access this
member directly.

Convert all direct write accesses to using the correct API.

Signed-off-by: Russell King 
---
  drivers/ata/pata_ixp4xx_cf.c |5 -
  drivers/gpu/drm/exynos/exynos_drm_drv.c  |6 +-
  drivers/gpu/drm/omapdrm/omap_dmm_tiler.c |5 +++--
  3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 1ec53f8..ddf470c 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -144,6 +144,7 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
struct ata_host *host;
struct ata_port *ap;
struct ixp4xx_pata_data *data = dev_get_platdata(&pdev->dev);
+   int ret;

cs0 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
cs1 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -157,7 +158,9 @@ static int ixp4xx_pata_probe(struct platform_device *pdev)
return -ENOMEM;

/* acquire resources and fill host */
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;

data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000);
data->cs1 = devm_ioremap(&pdev->dev, cs1->start, 0x1000);
diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c 
b/drivers/gpu/drm/exynos/exynos_drm_drv.c
index bb82ef7..81192d0 100644
--- a/drivers/gpu/drm/exynos/exynos_drm_drv.c
+++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c
@@ -286,7 +286,11 @@ static struct drm_driver exynos_drm_driver = {

  static int exynos_drm_platform_probe(struct platform_device *pdev)
  {
-   pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   int ret;
+
+   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   return ret;

return drm_platform_init(&exynos_drm_driver, pdev);
  }
diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c 
b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
index acf6678..701c4c1 100644
--- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
+++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c
@@ -664,8 +664,9 @@ static int omap_dmm_probe(struct platform_device *dev)
}

/* set dma mask for device */
-   /* NOTE: this is a workaround for the hwmod not initializing properly */
-   dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
+   ret = dma_set_coherent_mask(&dev->dev, DMA_BIT_MASK(32));
+   if (ret)
+   goto fail;


Tested with omapdrm on omap4 panda es board.

Thanks,
Archit

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


Re: [PATCH] usb: gadget: mv_u3d_core: fix memory leaks

2013-09-26 Thread Valentin Ilie
On 21 September 2013 12:30, Valentin Ilie  wrote:
> When trb_hw is NULL, trb should be free'd before return.
>
> Signed-off-by: Valentin Ilie 
> ---
>  drivers/usb/gadget/mv_u3d_core.c |2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/usb/gadget/mv_u3d_core.c 
> b/drivers/usb/gadget/mv_u3d_core.c
> index 561b30e..4d31177 100644
> --- a/drivers/usb/gadget/mv_u3d_core.c
> +++ b/drivers/usb/gadget/mv_u3d_core.c
> @@ -310,6 +310,7 @@ static struct mv_u3d_trb *mv_u3d_build_trb_one(struct 
> mv_u3d_req *req,
>  */
> trb_hw = dma_pool_alloc(u3d->trb_pool, GFP_ATOMIC, dma);
> if (!trb_hw) {
> +   kfree(trb);
> dev_err(u3d->dev,
> "%s, dma_pool_alloc fail\n", __func__);
> return NULL;
> @@ -454,6 +455,7 @@ static int mv_u3d_req_to_trb(struct mv_u3d_req *req)
>
> trb_hw = kcalloc(trb_num, sizeof(*trb_hw), GFP_ATOMIC);
> if (!trb_hw) {
> +   kfree(trb);
> dev_err(u3d->dev,
> "%s, trb_hw alloc fail\n", __func__);
> return -ENOMEM;
> --
> 1.7.9.5
>

Can anyone look into this?

Thank you

-- 
Valentin Ilie
+(40) 746 188 558
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 2/2] net: qmi_wwan: fix checkpatch warnings

2013-09-26 Thread David Laight
> Anything that breaks a previously unbroken argument list will reduce the
> readability in my opinion.  The lines can of course not be unlimited,
> but there is no need to set the limit as low as 80 columns.  Feedback
> I've got from developers using e.g. 80 column braille devices is that
> longer lines isn't really a problem for them either.

The main reason for limiting the line length is so that things look
'sensible' when you have a lot of screen windows displaying different
files. You don't want wrapped code, and you definitely don't want
the RHS of long lines hidden.
With a 1600x1200 monitor I'll display six 80x40 windows (and probably
have some more partially visible ones).

Personally I indent continuation lines by 4 chars if using 8 char
'normal' indentation and 8 chars if using 4. This gives a lot more
room on the continuation lines than the Linux 'line up with the
previous line'.

> This is the only one of your code changes which I can be convinced to
> agreeing may improve readability:
> 
> - if ((on && || (!on && atomic_dec_and_test(&info->pmcount))) {
> + if ((on && atomic_add_return(1, &info->pmcount) == 1) ||
> + (!on && atomic_dec_and_test(&info->pmcount))) {

That can be written succinctly as:
if (on ? atomic_add_return(1, &info->pmcount) == 1)
   : atomic_dec_and_test(&info->pmcount)) {
although that construct is somewhat frowned upon!

David



Re: [PATCH 5/7] staging: usbip: Add encryption support to kernel

2013-09-26 Thread Dan Carpenter
On Thu, Sep 26, 2013 at 12:18:34PM +0200, Dominik Paulus wrote:
> > I think a return of zero should mean total = -EBADMSG;.  In other words
> > this check should be "if (ret < 0) {" and we hit the next else if.
> > Same below again.
> 
> As we are wrapping kernel_recvmsg here, we wanted to leave the semantics
> intact as far as possible. The calling code already checks for the correct
> size.

Hm...  Ok.  Sometimes zero is interpretted as a connection closed and
sometimes reading less than expected is considered a TCP error.

> No, currently, the caller (usbip_sendmsg() / usbip_recvmsg() are the
> only functions calling usbip_crypt(), which itself is static) ensures
> this.
> Admittedly, this isn't great design. We added a check for packetsize <
> USBIP_AUTHSIZE and an appropiate return here.
> 
> > > + if (encrypt)
> > > + ret = crypto_aead_encrypt(req);
> > > + else
> > > + ret = crypto_aead_decrypt(req);
> > > +
> > 
> > Good on you for figuring out what crypto_aead_en/decrypt() returns.
> > Where are these functions documented?
> > 
> > > +switch (ret) {
> > > +case 0: /* Success */
> > > +break;
> > > +case -EINPROGRESS:
> > > +case -EBUSY:
> > > +wait_for_completion(&result.completion);
> > > +break;
> > > +default:
> > > +aead_request_free(req);
> > > +return ret;
> > > +}
> > > +
> 
> They aren't, actually. Documentation/crypto/api-intro.txt refers to the
> regression test module, which uses exactly those return-values in
> crypto/testmgr.c.

Well that sucks.

> We noticed that wait_for_completion might not be the best idea, since it could
> hang indefinitely, testmgr.c uses wait_for_completion_interruptible. Do we
> want 'interruptible' or 'killable' here?

I think you want the interruptible one wait_for_completion_interruptible()

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


Re: [PATCH] USB: fix substandard locking for the sysfs files

2013-09-26 Thread Hans de Goede

Hi,

On 09/24/2013 09:43 PM, Alan Stern wrote:

This patch straightens out some locking issues in the USB sysfs
interface:

Deauthorization will destroy existing configurations.
Attributes that read from udev->actconfig need to lock the
device to prevent races.  Likewise for the rawdescriptor
values.

Attributes that access an interface's current alternate
setting should use ACCESS_ONCE() to obtain the cur_altsetting
pointer, to protect against concurrent altsetting changes.

The supports_autosuspend() attribute routine accesses values
from an interface's driver, so it should lock the interface
(rather than the usb_device) to protect against concurrent
unbinds.  Once this is done, the routine can be simplified
considerably.

Scalar values that are stored directly in the usb_device structure are
always available.  They do not require any locking.  The same is true
of the cached interface string descriptor, because it is not
deallocated until the usb_host_interface structure is destroyed.

Signed-off-by: Alan Stern 
CC: Hans de Goede 


Looks good, thanks for fixing this!

Regards,

Hans
--
To unsubscribe from this list: send the line "unsubscribe 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 01/19] usb/gadget: configfs: add a method to unregister the gadget

2013-09-26 Thread Andrzej Pietrasiewicz
Add a method to unregister the gadget using its config_item.

There can be functions (e.g. mass storage), which in some circumstances
need the gadget stopped. Add a method of stopping the gadget.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/configfs.c |8 
 drivers/usb/gadget/configfs.h |6 ++
 2 files changed, 14 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/configfs.h

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 8f0d614..37e475b 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -991,6 +991,14 @@ static struct configfs_subsystem gadget_subsys = {
.su_mutex = __MUTEX_INITIALIZER(gadget_subsys.su_mutex),
 };
 
+void unregister_gadget_item(struct config_item *item)
+{
+   struct gadget_info *gi = to_gadget_info(item);
+
+   unregister_gadget(gi);
+}
+EXPORT_SYMBOL(unregister_gadget_item);
+
 static int __init gadget_cfs_init(void)
 {
int ret;
diff --git a/drivers/usb/gadget/configfs.h b/drivers/usb/gadget/configfs.h
new file mode 100644
index 000..a7b564a
--- /dev/null
+++ b/drivers/usb/gadget/configfs.h
@@ -0,0 +1,6 @@
+#ifndef USB__GADGET__CONFIGFS__H
+#define USB__GADGET__CONFIGFS__H
+
+void unregister_gadget_item(struct config_item *item);
+
+#endif /*  USB__GADGET__CONFIGFS__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 v4 16/19] usb/gadget: mass_storage: convert to new interface of f_mass_storage

2013-09-26 Thread Andrzej Pietrasiewicz
Convert old mass_storage gadget to use the new interface of f_mass_storage
so that later the compatibility layer in f_mass_storage can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig|1 +
 drivers/usb/gadget/mass_storage.c |  107 +++-
 2 files changed, 81 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 40adaf0..7d64e47 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -885,6 +885,7 @@ config USB_MASS_STORAGE
depends on BLOCK
select USB_LIBCOMPOSITE
select USB_U_MS
+   select USB_F_MASS_STORAGE
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
  As its storage repository it can use a regular file or a block
diff --git a/drivers/usb/gadget/mass_storage.c 
b/drivers/usb/gadget/mass_storage.c
index f670251..580f23e 100644
--- a/drivers/usb/gadget/mass_storage.c
+++ b/drivers/usb/gadget/mass_storage.c
@@ -46,17 +46,7 @@
 #define FSG_VENDOR_ID  0x0525  /* NetChip */
 #define FSG_PRODUCT_ID 0xa4a5  /* Linux-USB File-backed Storage Gadget */
 
-/*-*/
-
-/*
- * 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.
- */
-#define USB_FMS_INCLUDED
-#include "f_mass_storage.c"
+#include "f_mass_storage.h"
 
 /*-*/
 USB_GADGET_COMPOSITE_OPTIONS();
@@ -107,6 +97,9 @@ static struct usb_gadget_strings *dev_strings[] = {
NULL,
 };
 
+static struct usb_function_instance *fi_msg;
+static struct usb_function *f_msg;
+
 /** Configurations **/
 
 static struct fsg_module_parameters mod_data = {
@@ -139,13 +132,7 @@ static int msg_thread_exits(struct fsg_common *common)
 
 static int __init msg_do_config(struct usb_configuration *c)
 {
-   static const struct fsg_operations ops = {
-   .thread_exits = msg_thread_exits,
-   };
-   static struct fsg_common common;
-
-   struct fsg_common *retp;
-   struct fsg_config config;
+   struct fsg_opts *opts;
int ret;
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -153,15 +140,24 @@ static int __init msg_do_config(struct usb_configuration 
*c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
-   config.ops = &ops;
+   opts = container_of(fi_msg, struct fsg_opts, func_inst);
+
+   f_msg = usb_get_function(fi_msg);
+   if (IS_ERR(f_msg))
+   return PTR_ERR(f_msg);
 
-   retp = fsg_common_init(&common, c->cdev, &config);
-   if (IS_ERR(retp))
-   return PTR_ERR(retp);
+   ret = fsg_common_run_thread(opts->common);
+   if (ret)
+   goto put_func;
 
-   ret = fsg_bind_config(c->cdev, c, &common);
-   fsg_common_put(&common);
+   ret = usb_add_function(c, f_msg);
+   if (ret)
+   goto put_func;
+
+   return 0;
+
+put_func:
+   usb_put_function(f_msg);
return ret;
 }
 
@@ -176,23 +172,79 @@ static struct usb_configuration msg_config_driver = {
 
 static int __init msg_bind(struct usb_composite_dev *cdev)
 {
+   static const struct fsg_operations ops = {
+   .thread_exits = msg_thread_exits,
+   };
+   struct fsg_opts *opts;
+   struct fsg_config config;
int status;
 
+   fi_msg = usb_get_function_instance("mass_storage");
+   if (IS_ERR(fi_msg))
+   return PTR_ERR(fi_msg);
+
+   fsg_config_from_params(&config, &mod_data, fsg_num_buffers);
+   opts = container_of(fi_msg, struct fsg_opts, func_inst);
+
+   opts->no_configfs = true;
+   status = fsg_common_set_num_buffers(opts->common, fsg_num_buffers);
+   if (status)
+   goto fail;
+
+   status = fsg_common_set_nluns(opts->common, config.nluns);
+   if (status)
+   goto fail_set_nluns;
+
+   fsg_common_set_ops(opts->common, &ops);
+
+   status = fsg_common_set_cdev(opts->common, cdev, config.can_stall);
+   if (status)
+   goto fail_set_cdev;
+
+   fsg_common_set_sysfs(opts->common, true);
+   status = fsg_common_create_luns(opts->common, &config);
+   if (status)
+   goto fail_set_cdev;
+
+   fsg_common_set_inquiry_string(opts->common, config.vendor_name,
+ config.product_name);
+
status = usb_string_ids_tab(cdev, strings_dev);
if (status < 0)

[PATCH v4 03/19] usb/gadget: f_mass_storage: factor out a header file

2013-09-26 Thread Andrzej Pietrasiewicz
In order to prepare for the new function interface the f_mass_storage.c
needs to be compiled as a module, and so a header file will be required.
This patch factors out some code to a new f_mass_storage.h.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |  117 ++--
 drivers/usb/gadget/f_mass_storage.h |  126 +++
 2 files changed, 133 insertions(+), 110 deletions(-)
 create mode 100644 drivers/usb/gadget/f_mass_storage.h

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index a7c33c0..c6e34e1 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -229,6 +229,7 @@
 static const char fsg_string_interface[] = "Mass Storage";
 
 #include "storage_common.h"
+#include "f_mass_storage.h"
 
 /* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
 static struct usb_string   fsg_strings[] = {
@@ -246,18 +247,6 @@ static struct usb_gadget_strings   fsg_stringtab = {
 struct fsg_dev;
 struct fsg_common;
 
-/* FSF callback functions */
-struct fsg_operations {
-   /*
-* Callback function to call when thread exits.  If no
-* callback is set or it returns value lower then zero MSF
-* will force eject all LUNs it operates on (including those
-* marked as non-removable or with prevent_medium_removal flag
-* set).
-*/
-   int (*thread_exits)(struct fsg_common *common);
-};
-
 /* Data shared by all the FSG instances. */
 struct fsg_common {
struct usb_gadget   *gadget;
@@ -324,28 +313,6 @@ struct fsg_common {
struct kref ref;
 };
 
-struct fsg_config {
-   unsigned nluns;
-   struct fsg_lun_config {
-   const char *filename;
-   char ro;
-   char removable;
-   char cdrom;
-   char nofua;
-   } luns[FSG_MAX_LUNS];
-
-   /* Callback functions. */
-   const struct fsg_operations *ops;
-   /* Gadget's private data. */
-   void*private_data;
-
-   const char *vendor_name;/*  8 characters or less */
-   const char *product_name;   /* 16 characters or less */
-
-   charcan_stall;
-   unsigned intfsg_num_buffers;
-};
-
 struct fsg_dev {
struct usb_function function;
struct usb_gadget   *gadget;/* Copy of cdev->gadget */
@@ -2642,12 +2609,12 @@ static void fsg_lun_release(struct device *dev)
/* Nothing needs to be done */
 }
 
-static inline void fsg_common_get(struct fsg_common *common)
+void fsg_common_get(struct fsg_common *common)
 {
kref_get(&common->ref);
 }
 
-static inline void fsg_common_put(struct fsg_common *common)
+void fsg_common_put(struct fsg_common *common)
 {
kref_put(&common->ref, fsg_common_release);
 }
@@ -2662,9 +2629,9 @@ static inline int fsg_num_buffers_validate(unsigned int 
fsg_num_buffers)
return -EINVAL;
 }
 
-static struct fsg_common *fsg_common_init(struct fsg_common *common,
- struct usb_composite_dev *cdev,
- struct fsg_config *cfg)
+struct fsg_common *fsg_common_init(struct fsg_common *common,
+  struct usb_composite_dev *cdev,
+  struct fsg_config *cfg)
 {
struct usb_gadget *gadget = cdev->gadget;
struct fsg_buffhd *bh;
@@ -3041,62 +3008,8 @@ static int fsg_bind_config(struct usb_composite_dev 
*cdev,
 
 /* Module parameters */
 
-struct fsg_module_parameters {
-   char*file[FSG_MAX_LUNS];
-   boolro[FSG_MAX_LUNS];
-   boolremovable[FSG_MAX_LUNS];
-   boolcdrom[FSG_MAX_LUNS];
-   boolnofua[FSG_MAX_LUNS];
-
-   unsigned intfile_count, ro_count, removable_count, cdrom_count;
-   unsigned intnofua_count;
-   unsigned intluns;   /* nluns */
-   boolstall;  /* can_stall */
-};
-
-#define _FSG_MODULE_PARAM_ARRAY(prefix, params, name, type, desc)  \
-   module_param_array_named(prefix ## name, params.name, type, \
-&prefix ## params.name ## _count,  \
-S_IRUGO);  \
-   MODULE_PARM_DESC(prefix ## name, desc)
-
-#define _FSG_MODULE_PARAM(prefix, params, name, type, desc)\
-   module_param_named(prefix ## name, params.name, type,   \
-  S_IRUGO);\
-   MODULE_PARM_DESC(prefix ## name, desc)
-
-#define __FSG_MODULE_PARAMETERS(prefix, params)
\
-   _FSG_MODULE_PARAM_ARRAY(prefix, params, file, cha

[PATCH v4 04/19] usb/gadget: f_mass_storage: add a level of indirection for luns storage

2013-09-26 Thread Andrzej Pietrasiewicz
This is needed to prepare for configfs integration.

So far the luns have been allocated during gadget's initialization, based
on the nluns module parameter's value; the exact number is known when the
gadget is initialized and that number of luns is allocated in one go; they
all will be used.

When configfs is in place, the luns will be created one-by-one by the user.
Once the user is satisfied with the number of luns, they activate the
gadget. The number of luns must be <= FSG_MAX_LUN (currently 8), but other
than that it is not known up front and the user need not use contiguous
numbering (apart from the default lun #0). On the other hand, the function
code uses lun numbers to identify them and the number needs to be used
as an index into an array.

Given the above, an array needs to be allocated, but it might happen that
7 out of its 8 elements will not be used. On my machine
sizeof(struct fsg_lun) == 462, so > 3k of memory is allocated but not used
in the worst case.

By adding another level of indirection (allocating an array of pointers
to struct fsg_lun and then allocating individual luns instead of an array
of struct fsg_luns) at most 7 pointers are wasted, which is much less.

This patch also changes some for/while loops to cope with the fact
that in the luns array some entries are potentially empty.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   60 ---
 1 files changed, 41 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index c6e34e1..bc512b1 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -274,7 +274,7 @@ struct fsg_common {
 
unsigned intnluns;
unsigned intlun;
-   struct fsg_lun  *luns;
+   struct fsg_lun  **luns;
struct fsg_lun  *curlun;
 
unsigned intbulk_out_maxpacket;
@@ -2151,7 +2151,7 @@ static int received_cbw(struct fsg_dev *fsg, struct 
fsg_buffhd *bh)
common->data_dir = DATA_DIR_NONE;
common->lun = cbw->Lun;
if (common->lun < common->nluns)
-   common->curlun = &common->luns[common->lun];
+   common->curlun = common->luns[common->lun];
else
common->curlun = NULL;
common->tag = cbw->Tag;
@@ -2297,7 +2297,9 @@ reset:
 
common->running = 1;
for (i = 0; i < common->nluns; ++i)
-   common->luns[i].unit_attention_data = SS_RESET_OCCURRED;
+   if (common->luns[i])
+   common->luns[i]->unit_attention_data =
+   SS_RESET_OCCURRED;
return rc;
 }
 
@@ -2397,7 +2399,9 @@ static void handle_exception(struct fsg_common *common)
common->state = FSG_STATE_STATUS_PHASE;
else {
for (i = 0; i < common->nluns; ++i) {
-   curlun = &common->luns[i];
+   curlun = common->luns[i];
+   if (!curlun)
+   continue;
curlun->prevent_medium_removal = 0;
curlun->sense_data = SS_NO_SENSE;
curlun->unit_attention_data = SS_NO_SENSE;
@@ -2439,8 +2443,9 @@ static void handle_exception(struct fsg_common *common)
 * CONFIG_CHANGE cases.
 */
/* for (i = 0; i < common->nluns; ++i) */
-   /*  common->luns[i].unit_attention_data = */
-   /*  SS_RESET_OCCURRED;  */
+   /*  if (common->luns[i]) */
+   /*  common->luns[i]->unit_attention_data = */
+   /*  SS_RESET_OCCURRED;  */
break;
 
case FSG_STATE_CONFIG_CHANGE:
@@ -2536,12 +2541,13 @@ static int fsg_main_thread(void *common_)
 
if (!common->ops || !common->ops->thread_exits
 || common->ops->thread_exits(common) < 0) {
-   struct fsg_lun *curlun = common->luns;
+   struct fsg_lun **curlun_it = common->luns;
unsigned i = common->nluns;
 
down_write(&common->filesem);
-   for (; i--; ++curlun) {
-   if (!fsg_lun_is_open(curlun))
+   for (; i--; ++curlun_it) {
+   struct fsg_lun *curlun = *curlun_it;
+   if (!curlun || !fsg_lun_is_open(curlun))
continue;
 
fsg_lun_close(curlun);
@@ -2635,7 +2641,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 {
struct usb_gadget *gadget = cdev->gadget;
struct fsg_buffhd *bh;
-   struct fsg_lun *curlun;
+   struct fsg_lun **curlun_it;
struct fsg_lun_config *lcfg;
int nluns, i, rc;
char *pathbuf;
@@ -26

[PATCH v4 07/19] usb/gadget: f_mass_storage: use fsg_common_setup in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   19 +++
 1 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 0bf7503..d94d9d6 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3051,16 +3051,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
return ERR_PTR(-EINVAL);
}
 
-   /* Allocate? */
-   if (!common) {
-   common = kzalloc(sizeof *common, GFP_KERNEL);
-   if (!common)
-   return ERR_PTR(-ENOMEM);
-   common->free_storage_on_release = 1;
-   } else {
-   memset(common, 0, sizeof *common);
-   common->free_storage_on_release = 0;
-   }
+   common = fsg_common_setup(common, !!common);
+   if (IS_ERR(common))
+   return common;
common->sysfs = true;
common->state = FSG_STATE_IDLE;
 
@@ -3100,8 +3093,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
common->luns = curlun_it;
 
-   init_rwsem(&common->filesem);
-
for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
struct fsg_lun *curlun;
 
@@ -3201,8 +3192,6 @@ buffhds_first_it:
common->can_stall = cfg->can_stall &&
!(gadget_is_at91(common->gadget));
 
-   spin_lock_init(&common->lock);
-   kref_init(&common->ref);
 
/* Tell the thread to start working */
common->thread_task =
@@ -3211,8 +3200,6 @@ buffhds_first_it:
rc = PTR_ERR(common->thread_task);
goto error_release;
}
-   init_completion(&common->thread_notifier);
-   init_waitqueue_head(&common->fsg_wait);
 
/* Information */
INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
-- 
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 v4 00/19] Equivalent of g_mass_storage with configfs

2013-09-26 Thread Andrzej Pietrasiewicz
This series aims at integrating configfs into mass storage, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex and phonet.
It contains everything that is required to provide the equivalent of
g_mass_storage.ko with configfs.

Mass storage itself is quite large, so the resulting patch series is a bit
lengthy. However, it is supposed to be done in steps like this:

1) preliminary work, e.g. factoring out a header file, creating a utility
u_ms.ko module, use usb_gstrings_attach
2) prepare for initializing the fsg_common structure in smaller steps instead
of in one big step
3) usual stuff, similar to functions previously converted to configfs

v1..v2:

- simpified adding a level of indirection for fsg_lun storing
- reworked lun debugging macros in order not to use struct device
[both after discussion with Alan, thanks]

v2..v3:

- implemented changes resulting from Michal's comments [thanks, Michal]
- used static inline fsg_common_remove_sysfs wherever possible
- some small bugfixes

v3..v4:

-rebased onto 3.12-rc1

A branch 'usb-gadget-configfs-for-3.12' is available at:
git://git.linaro.org/people/mszyprowski/linux-srpol.git

BACKWARD COMPATIBILITY
==

Please note that the old g_mass_storage.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 (*).

With configfs the procedure is as follows, compared to the information
mentioned above (*):

instead of mkdir functions/acm.ttyS1 do

mkdir functions/.

e.g. mkdir functions/mass_storage.0

In functions/. there will be the following attribute
files:

stall   - Set to permit function to halt bulk endpoints.
Disabled on some USB devices known not to work
correctly. You should set it to true.
num_buffers - Number of pipeline buffers. Valid numbers
are 2..4. Available only if
CONFIG_USB_GADGET_DEBUG_FILES is set.

and a default lun.0 directory corresponding to SCSI LUN #0.

A new lun can be added with mkdir:

$ mkdir functions/mass_storage.0/partition.5

Lun numbering does not have to be continuous, except for lun #0 which is
created by default. A maximum of 8 luns can be specified and they all must be
named following the . scheme. The numbers can be 0..8.
Probably a good convention is to name the luns "lun.",
although it is not mandatory.

In each lun directory there are the following attribute files:

file- The path to the backing file for the LUN.
Required if LUN is not marked as removable.
ro  - Flag specifying access to the LUN shall be
read-only. This is implied if CD-ROM emulation
is enabled as well as when it was impossible
to open "filename" in R/W mode.
removable   - Flag specifying that LUN shall be indicated as
being removable.
cdrom   - Flag specifying that LUN shall be reported as
being a CD-ROM.
nofua   - Flag specifying that FUA flag
in SCSI WRITE(10,12)

The rest of the procedure (*) remains the same.

An example gadget with two luns:

$ modprobe libcomposite
 
$ mount none cfg -t configfs
 
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
 
$ mkdir configs/c.1
$ mkdir functions/mass_storage.0
$ echo /root/lun0.img > functions/mass_storage.0/lun.0/file
$ mkdir functions/mass_storage.0/lun.1
$ echo /root/lun1.img > functions/mass_storage.0/lun.1/file
$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
 
$ echo 0xa4a2 > idProduct
$ echo 0x0525 > idVendor
$ echo my-serial-num > strings/0x409/serialnumber
$ echo my-manufacturer > strings/0x409/manufacturer
$ echo "Mass Storage Gadget" > strings/0x409/product
 
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
$ echo 120 > configs/c.1/MaxPower
$ ln -s functions/mass_storage.0 configs/c.1
 
$ echo s3c-hsotg > UDC

After unbinding the gadget with echo "" > UDC
the symbolic links in the configuration directory can be removed,
the strings/* subdirectories in the configuration directory can
be removed, the strings/* subdirectories at the gadget level can
be removed and the configs/* subdirectories can be removed.
The functions/* subdirectories can be removed.
After that the gadget directory can be removed.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS (actually there is only one)
=

mass_storage)

device: connect the gadget, enable it
host: dmesg, see the USB drives appear (if system configured to automatically
mount)

Andrzej Pietrasiewicz (19):
  usb/gadget: configfs: add a method to unregister the gadget
  usb/gadget: create a utility module for mass_sto

[PATCH v4 10/19] usb/gadget: f_mass_storage: use fsg_common_set_ops/_private_data in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 45b44d7..ab1458b 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3052,8 +3052,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
kfree(common);
return ERR_PTR(rc);
}
-   common->ops = cfg->ops;
-   common->private_data = cfg->private_data;
+
+   fsg_common_set_ops(common, cfg->ops);
+   fsg_common_set_private_data(common, cfg->private_data);
 
common->gadget = gadget;
common->ep0 = gadget->ep0;
-- 
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 v4 17/19] usb/gadget: storage_common: make attribute operations more generic

2013-09-26 Thread Andrzej Pietrasiewicz
Show/store methods for sysfs attributes contain code which can be used
also by configfs. Make them abstract the source the lun and rw_semaphore
are taken from.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   27 +--
 drivers/usb/gadget/storage_common.c |   31 ++-
 drivers/usb/gadget/storage_common.h |   21 +++--
 3 files changed, 38 insertions(+), 41 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index b55b874..50f7612 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2572,37 +2572,52 @@ static int fsg_main_thread(void *common_)
 
 static ssize_t ro_show(struct device *dev, struct device_attribute *attr, char 
*buf)
 {
-   return fsg_show_ro(dev, attr, buf);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_show_ro(curlun, buf);
 }
 
 static ssize_t nofua_show(struct device *dev, struct device_attribute *attr,
  char *buf)
 {
-   return fsg_show_nofua(dev, attr, buf);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_show_nofua(curlun, buf);
 }
 
 static ssize_t file_show(struct device *dev, struct device_attribute *attr,
 char *buf)
 {
-   return fsg_show_file(dev, attr, buf);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_show_file(curlun, filesem, buf);
 }
 
 static ssize_t ro_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
 {
-   return fsg_store_ro(dev, attr, buf, count);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_store_ro(curlun, filesem, buf, count);
 }
 
 static ssize_t nofua_store(struct device *dev, struct device_attribute *attr,
   const char *buf, size_t count)
 {
-   return fsg_store_nofua(dev, attr, buf, count);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+
+   return fsg_store_nofua(curlun, buf, count);
 }
 
 static ssize_t file_store(struct device *dev, struct device_attribute *attr,
  const char *buf, size_t count)
 {
-   return fsg_store_file(dev, attr, buf, count);
+   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
+   struct rw_semaphore *filesem = dev_get_drvdata(dev);
+
+   return fsg_store_file(curlun, filesem, buf, count);
 }
 
 static DEVICE_ATTR_RW(ro);
diff --git a/drivers/usb/gadget/storage_common.c 
b/drivers/usb/gadget/storage_common.c
index 3e2500f..969948d 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -31,11 +31,6 @@
 
 #include "storage_common.h"
 
-static inline struct fsg_lun *fsg_lun_from_dev(struct device *dev)
-{
-   return container_of(dev, struct fsg_lun, dev);
-}
-
 /* There is only one interface. */
 
 struct usb_interface_descriptor fsg_intf_desc = {
@@ -324,31 +319,23 @@ EXPORT_SYMBOL(store_cdrom_address);
 /*-*/
 
 
-ssize_t fsg_show_ro(struct device *dev, struct device_attribute *attr,
-   char *buf)
+ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf)
 {
-   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-
return sprintf(buf, "%d\n", fsg_lun_is_open(curlun)
  ? curlun->ro
  : curlun->initially_ro);
 }
 EXPORT_SYMBOL(fsg_show_ro);
 
-ssize_t fsg_show_nofua(struct device *dev, struct device_attribute *attr,
-  char *buf)
+ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf)
 {
-   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-
return sprintf(buf, "%u\n", curlun->nofua);
 }
 EXPORT_SYMBOL(fsg_show_nofua);
 
-ssize_t fsg_show_file(struct device *dev, struct device_attribute *attr,
+ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
  char *buf)
 {
-   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-   struct rw_semaphore *filesem = dev_get_drvdata(dev);
char*p;
ssize_t rc;
 
@@ -373,12 +360,10 @@ ssize_t fsg_show_file(struct device *dev, struct 
device_attribute *attr,
 EXPORT_SYMBOL(fsg_show_file);
 
 
-ssize_t fsg_store_ro(struct device *dev, struct device_attribute *attr,
+ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
 const char *buf, size_t count)
 {
ssize_t rc;
-   struct fsg_lun  *curlun = fsg_lun_from_dev(dev);
-   struct rw_semaphore *filesem = dev_get_drvdata(dev);
unsignedro

[PATCH v4 09/19] usb/gadget: f_mass_storage: use fsg_common_set_nluns in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   22 +-
 1 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 1234990..45b44d7 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3039,12 +3039,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
int nluns, i, rc;
char *pathbuf;
 
-   /* Find out how many LUNs there should be */
-   nluns = cfg->nluns;
-   if (nluns < 1 || nluns > FSG_MAX_LUNS) {
-   dev_err(&gadget->dev, "invalid number of LUNs: %u\n", nluns);
-   return ERR_PTR(-EINVAL);
-   }
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3074,17 +3068,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
 
-   /*
-* Create the LUNs, open their backing files, and register the
-* LUN devices in sysfs.
-*/
-   curlun_it = kcalloc(nluns, sizeof(*curlun_it), GFP_KERNEL);
-   if (unlikely(!curlun_it)) {
-   rc = -ENOMEM;
-   goto error_release;
-   }
-   common->luns = curlun_it;
 
+   rc = fsg_common_set_nluns(common, cfg->nluns);
+   if (rc)
+   goto error_release;
+   curlun_it = common->luns;
+   nluns = cfg->nluns;
for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
struct fsg_lun *curlun;
 
@@ -3148,7 +3137,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
goto error_luns;
}
}
-   common->nluns = nluns;
 
 
/* Prepare inquiryString */
-- 
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 v4 08/19] usb/gadget: f_mass_storage: use fsg_common_set_num_buffers in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   29 +++--
 1 files changed, 3 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index d94d9d6..1234990 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3033,17 +3033,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct fsg_config *cfg)
 {
struct usb_gadget *gadget = cdev->gadget;
-   struct fsg_buffhd *bh;
struct fsg_lun **curlun_it;
struct fsg_lun_config *lcfg;
struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
-   rc = fsg_num_buffers_validate(cfg->fsg_num_buffers);
-   if (rc != 0)
-   return ERR_PTR(rc);
-
/* Find out how many LUNs there should be */
nluns = cfg->nluns;
if (nluns < 1 || nluns > FSG_MAX_LUNS) {
@@ -3057,15 +3052,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
common->sysfs = true;
common->state = FSG_STATE_IDLE;
 
-   common->fsg_num_buffers = cfg->fsg_num_buffers;
-   common->buffhds = kcalloc(common->fsg_num_buffers,
- sizeof *(common->buffhds), GFP_KERNEL);
-   if (!common->buffhds) {
+   rc = fsg_common_set_num_buffers(common, cfg->fsg_num_buffers);
+   if (rc) {
if (common->free_storage_on_release)
kfree(common);
-   return ERR_PTR(-ENOMEM);
+   return ERR_PTR(rc);
}
-
common->ops = cfg->ops;
common->private_data = cfg->private_data;
 
@@ -3158,21 +3150,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
}
common->nluns = nluns;
 
-   /* Data buffers cyclic list */
-   bh = common->buffhds;
-   i = common->fsg_num_buffers;
-   goto buffhds_first_it;
-   do {
-   bh->next = bh + 1;
-   ++bh;
-buffhds_first_it:
-   bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
-   if (unlikely(!bh->buf)) {
-   rc = -ENOMEM;
-   goto error_release;
-   }
-   } while (--i);
-   bh->next = common->buffhds;
 
/* Prepare inquiryString */
i = get_default_bcdDevice();
-- 
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 v4 14/19] usb/gadget: f_mass_storage: use fsg_common_run_thread in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   14 +++---
 1 files changed, 3 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 2e73037..fe3be86 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3065,21 +3065,13 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 
fsg_common_set_inquiry_string(common, cfg->vendor_name,
  cfg->product_name);
-   /* Tell the thread to start working */
-   common->thread_task =
-   kthread_create(fsg_main_thread, common, "file-storage");
-   if (IS_ERR(common->thread_task)) {
-   rc = PTR_ERR(common->thread_task);
-   goto error_release;
-   }
 
/* Information */
INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
-   INFO(common, "Number of LUNs=%d\n", common->nluns);
 
-   DBG(common, "I/O thread pid: %d\n", task_pid_nr(common->thread_task));
-
-   wake_up_process(common->thread_task);
+   rc = fsg_common_run_thread(common);
+   if (rc)
+   goto error_release;
 
return common;
 
-- 
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 v4 15/19] usb/gadget: f_mass_storage: convert to new function interface with backward compatibility

2013-09-26 Thread Andrzej Pietrasiewicz
Converting mass storage to the new function interface requires converting
the USB mass storage's function code and its users.
This patch converts the f_mass_storage.c to the new function interface.
The file is now compiled into a separate usb_f_mass_storage.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/acm_ms.c |1 +
 drivers/usb/gadget/f_mass_storage.c |  217 +++---
 drivers/usb/gadget/f_mass_storage.h |7 +
 drivers/usb/gadget/mass_storage.c   |1 +
 drivers/usb/gadget/multi.c  |1 +
 7 files changed, 212 insertions(+), 20 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 98220dc..40adaf0 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -528,6 +528,9 @@ config USB_F_RNDIS
 config USB_U_MS
tristate
 
+config USB_F_MASS_STORAGE
+   tristate
+
 choice
tristate "USB Gadget Drivers"
default USB_ETH
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index d90a0b0..4a86b0c 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -62,6 +62,8 @@ usb_f_rndis-y := f_rndis.o
 obj-$(CONFIG_USB_F_RNDIS)  += usb_f_rndis.o
 u_ms-y := storage_common.o
 obj-$(CONFIG_USB_U_MS) += u_ms.o
+usb_f_mass_storage-y   := f_mass_storage.o
+obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 992ffb0..31aae8f 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -40,6 +40,7 @@
  * the runtime footprint, and giving us at least some parts of what
  * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  */
+#define USB_FMS_INCLUDED
 #include "f_mass_storage.c"
 
 /*-*/
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index fe3be86..b55b874 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -213,6 +213,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -2625,11 +2626,17 @@ void fsg_common_get(struct fsg_common *common)
 {
kref_get(&common->ref);
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_get);
+#endif
 
 void fsg_common_put(struct fsg_common *common)
 {
kref_put(&common->ref, fsg_common_release);
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_put);
+#endif
 
 /* check if fsg_num_buffers is within a valid range */
 static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
@@ -2667,6 +2674,9 @@ void fsg_common_set_sysfs(struct fsg_common *common, bool 
sysfs)
 {
common->sysfs = sysfs;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_sysfs);
+#endif
 
 static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
 {
@@ -2718,12 +2728,18 @@ error_release:
 
return -ENOMEM;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_num_buffers);
+#endif
 
 void fsg_common_free_buffers(struct fsg_common *common)
 {
_fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
common->buffhds = NULL;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_free_buffers);
+#endif
 
 int fsg_common_set_nluns(struct fsg_common *common, int nluns)
 {
@@ -2749,6 +2765,9 @@ int fsg_common_set_nluns(struct fsg_common *common, int 
nluns)
 
return 0;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_nluns);
+#endif
 
 void fsg_common_free_luns(struct fsg_common *common)
 {
@@ -2756,17 +2775,26 @@ void fsg_common_free_luns(struct fsg_common *common)
kfree(common->luns);
common->luns = NULL;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_free_luns);
+#endif
 
 void fsg_common_set_ops(struct fsg_common *common,
const struct fsg_operations *ops)
 {
common->ops = ops;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_ops);
+#endif
 
 void fsg_common_set_private_data(struct fsg_common *common, void *priv)
 {
common->private_data = priv;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_private_data);
+#endif
 
 int fsg_common_set_cdev(struct fsg_common *common,
 struct usb_composite_dev *cdev, bool can_stall)
@@ -2796,6 +2824,9 @@ int fsg_common_set_cdev(struct fsg_common *common,
 
return 0;
 }
+#ifndef USB_FMS_INCLUDED
+EXPORT_SYMBOL(fsg_common_set_cdev);
+#endif
 
 static inline int fsg_common_add_sysfs(struct fsg_common *common,

[PATCH v4 18/19] usb/gadget: storage_common: add methods to show/store 'cdrom' and 'removable'

2013-09-26 Thread Andrzej Pietrasiewicz
This will be required by configfs integration.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungin Park 
---
 drivers/usb/gadget/storage_common.c |   42 +++
 drivers/usb/gadget/storage_common.h |5 
 2 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/storage_common.c 
b/drivers/usb/gadget/storage_common.c
index 969948d..c7b78a1 100644
--- a/drivers/usb/gadget/storage_common.c
+++ b/drivers/usb/gadget/storage_common.c
@@ -359,6 +359,17 @@ ssize_t fsg_show_file(struct fsg_lun *curlun, struct 
rw_semaphore *filesem,
 }
 EXPORT_SYMBOL(fsg_show_file);
 
+ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf)
+{
+   return sprintf(buf, "%u\n", curlun->cdrom);
+}
+EXPORT_SYMBOL(fsg_show_cdrom);
+
+ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf)
+{
+   return sprintf(buf, "%u\n", curlun->removable);
+}
+EXPORT_SYMBOL(fsg_show_removable);
 
 ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
 const char *buf, size_t count)
@@ -439,4 +450,35 @@ ssize_t fsg_store_file(struct fsg_lun *curlun, struct 
rw_semaphore *filesem,
 }
 EXPORT_SYMBOL(fsg_store_file);
 
+ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count)
+{
+   unsignedcdrom;
+   int ret;
+
+   ret = kstrtouint(buf, 2, &cdrom);
+   if (ret)
+   return ret;
+
+   curlun->cdrom = cdrom;
+
+   return count;
+}
+EXPORT_SYMBOL(fsg_store_cdrom);
+
+ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
+   size_t count)
+{
+   unsignedremovable;
+   int ret;
+
+   ret = kstrtouint(buf, 2, &removable);
+   if (ret)
+   return ret;
+
+   curlun->removable = removable;
+
+   return count;
+}
+EXPORT_SYMBOL(fsg_store_removable);
+
 MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/storage_common.h 
b/drivers/usb/gadget/storage_common.h
index aa8bf94..ca7b479 100644
--- a/drivers/usb/gadget/storage_common.h
+++ b/drivers/usb/gadget/storage_common.h
@@ -214,10 +214,15 @@ ssize_t fsg_show_ro(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_show_nofua(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_show_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
  char *buf);
+ssize_t fsg_show_cdrom(struct fsg_lun *curlun, char *buf);
+ssize_t fsg_show_removable(struct fsg_lun *curlun, char *buf);
 ssize_t fsg_store_ro(struct fsg_lun *curlun, struct rw_semaphore *filesem,
 const char *buf, size_t count);
 ssize_t fsg_store_nofua(struct fsg_lun *curlun, const char *buf, size_t count);
 ssize_t fsg_store_file(struct fsg_lun *curlun, struct rw_semaphore *filesem,
   const char *buf, size_t count);
+ssize_t fsg_store_cdrom(struct fsg_lun *curlun, const char *buf, size_t count);
+ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
+   size_t count);
 
 #endif /* USB_STORAGE_COMMON_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 v4 12/19] usb/gadget: f_mass_storage: use fsg_common_create_luns in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |  101 ++-
 1 files changed, 4 insertions(+), 97 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 970213f..c55950f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3032,12 +3032,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct usb_composite_dev *cdev,
   struct fsg_config *cfg)
 {
-   struct usb_gadget *gadget = cdev->gadget;
-   struct fsg_lun **curlun_it;
-   struct fsg_lun_config *lcfg;
-   int nluns, i, rc;
-   char *pathbuf;
-
+   int i, rc;
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3062,72 +3057,10 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
rc = fsg_common_set_nluns(common, cfg->nluns);
if (rc)
goto error_release;
-   curlun_it = common->luns;
-   nluns = cfg->nluns;
-   for (i = 0, lcfg = cfg->luns; i < nluns; ++i, ++curlun_it, ++lcfg) {
-   struct fsg_lun *curlun;
-
-   curlun = kzalloc(sizeof(*curlun), GFP_KERNEL);
-   if (!curlun) {
-   rc = -ENOMEM;
-   common->nluns = i;
-   goto error_release;
-   }
-   *curlun_it = curlun;
-
-   curlun->name = kzalloc(MAX_LUN_NAME_LEN, GFP_KERNEL);
-   if (!curlun->name) {
-   rc = -ENOMEM;
-   common->nluns = i;
-   goto error_release;
-   }
-   curlun->cdrom = !!lcfg->cdrom;
-   curlun->ro = lcfg->cdrom || lcfg->ro;
-   curlun->initially_ro = curlun->ro;
-   curlun->removable = lcfg->removable;
-   curlun->dev.release = fsg_lun_release;
-   curlun->dev.parent = &gadget->dev;
-   /* curlun->dev.driver = &fsg_driver.driver; XXX */
-   dev_set_drvdata(&curlun->dev, &common->filesem);
-   dev_set_name(&curlun->dev, "lun%d", i);
-   strlcpy(curlun->name, dev_name(&curlun->dev), MAX_LUN_NAME_LEN);
-
-   rc = device_register(&curlun->dev);
-   if (rc) {
-   INFO(common, "failed to register LUN%d: %d\n", i, rc);
-   common->nluns = i;
-   put_device(&curlun->dev);
-   kfree(curlun);
-   goto error_release;
-   }
-
-   rc = device_create_file(&curlun->dev,
-   curlun->cdrom
- ? &dev_attr_ro_cdrom
- : &dev_attr_ro);
-   if (rc)
-   goto error_luns;
-   rc = device_create_file(&curlun->dev,
-   curlun->removable
- ? &dev_attr_file
- : &dev_attr_file_nonremovable);
-   if (rc)
-   goto error_luns;
-   rc = device_create_file(&curlun->dev, &dev_attr_nofua);
-   if (rc)
-   goto error_luns;
-
-   if (lcfg->filename) {
-   rc = fsg_lun_open(curlun, lcfg->filename);
-   if (rc)
-   goto error_luns;
-   } else if (!curlun->removable) {
-   ERROR(common, "no file given for LUN%d\n", i);
-   rc = -EINVAL;
-   goto error_luns;
-   }
-   }
 
+   rc = fsg_common_create_luns(common, cfg);
+   if (rc)
+   goto error_release;
 
/* Prepare inquiryString */
i = get_default_bcdDevice();
@@ -3139,7 +3072,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 : "File-Stor Gadget"),
 i);
 
-
/* Tell the thread to start working */
common->thread_task =
kthread_create(fsg_main_thread, common, "file-storage");
@@ -3152,37 +3084,12 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
INFO(common, FSG_DRIVER_DESC ", version: " FSG_DRIVER_VERSION "\n");
INFO(common, "Number of LUNs=%d\n", common->nluns);
 
-   pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
-   for (i = 0, nluns = common->nluns, curlun_it = common->luns;
-i < nluns;
-++curlun_it, ++i) {
-   struct fsg_lun *curlun = *curlun_it;
-   char *p = "(no medium)";
-   if (f

[PATCH v4 13/19] usb/gadget: f_mass_storage: use fsg_common_set_inquiry_string in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   13 +++--
 1 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index c55950f..2e73037 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3032,7 +3032,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
   struct usb_composite_dev *cdev,
   struct fsg_config *cfg)
 {
-   int i, rc;
+   int rc;
 
common = fsg_common_setup(common, !!common);
if (IS_ERR(common))
@@ -3062,16 +3062,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
if (rc)
goto error_release;
 
-   /* Prepare inquiryString */
-   i = get_default_bcdDevice();
-   snprintf(common->inquiry_string, sizeof common->inquiry_string,
-"%-8s%-16s%04x", cfg->vendor_name ?: "Linux",
-/* Assume product name dependent on the first LUN */
-cfg->product_name ?: ((*common->luns)->cdrom
-? "File-CD Gadget"
-: "File-Stor Gadget"),
-i);
 
+   fsg_common_set_inquiry_string(common, cfg->vendor_name,
+ cfg->product_name);
/* Tell the thread to start working */
common->thread_task =
kthread_create(fsg_main_thread, common, "file-storage");
-- 
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 v4 05/19] usb/gadget: f_mass_storage: use usb_gstrings_attach

2013-09-26 Thread Andrzej Pietrasiewicz
Prepare for handling with configfs.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |   25 -
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index bc512b1..e2598f4 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -242,6 +242,11 @@ static struct usb_gadget_strings   fsg_stringtab = {
.strings= fsg_strings,
 };
 
+static struct usb_gadget_strings *fsg_strings_array[] = {
+   &fsg_stringtab,
+   NULL,
+};
+
 /*-*/
 
 struct fsg_dev;
@@ -2643,6 +2648,7 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
struct fsg_buffhd *bh;
struct fsg_lun **curlun_it;
struct fsg_lun_config *lcfg;
+   struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
@@ -2685,14 +2691,13 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
common->ep0req = cdev->req;
common->cdev = cdev;
 
-   /* Maybe allocate device-global string IDs, and patch descriptors */
-   if (fsg_strings[FSG_STRING_INTERFACE].id == 0) {
-   rc = usb_string_id(cdev);
-   if (unlikely(rc < 0))
-   goto error_release;
-   fsg_strings[FSG_STRING_INTERFACE].id = rc;
-   fsg_intf_desc.iInterface = rc;
+   us = usb_gstrings_attach(cdev, fsg_strings_array,
+ARRAY_SIZE(fsg_strings));
+   if (IS_ERR(us)) {
+   rc = PTR_ERR(us);
+   goto error_release;
}
+   fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
 
/*
 * Create the LUNs, open their backing files, and register the
@@ -2986,11 +2991,6 @@ autoconf_fail:
 
 /** ADD FUNCTION **/
 
-static struct usb_gadget_strings *fsg_strings_array[] = {
-   &fsg_stringtab,
-   NULL,
-};
-
 static int fsg_bind_config(struct usb_composite_dev *cdev,
   struct usb_configuration *c,
   struct fsg_common *common)
@@ -3003,7 +3003,6 @@ static int fsg_bind_config(struct usb_composite_dev *cdev,
return -ENOMEM;
 
fsg->function.name= FSG_DRIVER_DESC;
-   fsg->function.strings = fsg_strings_array;
fsg->function.bind= fsg_bind;
fsg->function.unbind  = fsg_unbind;
fsg->function.setup   = fsg_setup;
-- 
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 v4 11/19] usb/gadget: f_mass_storage: use fsg_common_set_cdev in fsg_common_init

2013-09-26 Thread Andrzej Pietrasiewicz
fsg_common_init is a lengthy function. Now there are helper functions
which cover all parts of it. Use them.

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

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index ab1458b..970213f 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -3035,7 +3035,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
struct usb_gadget *gadget = cdev->gadget;
struct fsg_lun **curlun_it;
struct fsg_lun_config *lcfg;
-   struct usb_string *us;
int nluns, i, rc;
char *pathbuf;
 
@@ -3056,19 +3055,9 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
fsg_common_set_ops(common, cfg->ops);
fsg_common_set_private_data(common, cfg->private_data);
 
-   common->gadget = gadget;
-   common->ep0 = gadget->ep0;
-   common->ep0req = cdev->req;
-   common->cdev = cdev;
-
-   us = usb_gstrings_attach(cdev, fsg_strings_array,
-ARRAY_SIZE(fsg_strings));
-   if (IS_ERR(us)) {
-   rc = PTR_ERR(us);
+   rc = fsg_common_set_cdev(common, cdev, cfg->can_stall);
+   if (rc)
goto error_release;
-   }
-   fsg_intf_desc.iInterface = us[FSG_STRING_INTERFACE].id;
-
 
rc = fsg_common_set_nluns(common, cfg->nluns);
if (rc)
@@ -3150,14 +3139,6 @@ struct fsg_common *fsg_common_init(struct fsg_common 
*common,
 : "File-Stor Gadget"),
 i);
 
-   /*
-* Some peripheral controllers are known not to be able to
-* halt bulk endpoints correctly.  If one of them is present,
-* disable stalls.
-*/
-   common->can_stall = cfg->can_stall &&
-   !(gadget_is_at91(common->gadget));
-
 
/* Tell the thread to start working */
common->thread_task =
-- 
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 v4 06/19] usb/gadget: f_mass_storage: split fsg_common initialization into a number of functions

2013-09-26 Thread Andrzej Pietrasiewicz
When configfs is in place, the things related to intialization
of struct fsg_common will be split over a number of places.
This patch adds several functions which together cover the former
intialization routine fsg_common_init.

When configfs is in place, the luns will not be represented in sysfs,
so there will be no struct device associated with a lun.
To prepare for this some debug macros need to be adjusted. Two new
fields are added to struct fsg_lun: name and name_pfx.
The "name" is for storing a string which is presented to the user
instead of the dev_name. The "name_pfx", if non-NULL, is prepended
to the "name" at printing time.

The name_pfx is for a future lun.0, which will be a default group in
mass_storage.. By design at USB function configfs group's creation
time its name is not known (but instead set a bit later in
drivers/usb/gadget/configfs.c:function_make) and it is this name that
serves the purpose of the said name prefix. So instead of copying
a yet-unknown string a pointer to it is stored in struct fsg_lun.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |  424 +--
 drivers/usb/gadget/f_mass_storage.h |   33 +++
 drivers/usb/gadget/storage_common.h |   20 ++-
 3 files changed, 454 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index e2598f4..0bf7503 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -299,6 +299,7 @@ struct fsg_common {
unsigned intshort_packet_received:1;
unsigned intbad_lun_okay:1;
unsigned intrunning:1;
+   unsigned intsysfs:1;
 
int thread_wakeup_needed;
struct completion   thread_notifier;
@@ -2640,6 +2641,393 @@ static inline int fsg_num_buffers_validate(unsigned int 
fsg_num_buffers)
return -EINVAL;
 }
 
+static struct fsg_common *fsg_common_setup(struct fsg_common *common, bool 
zero)
+{
+   if (!common) {
+   common = kzalloc(sizeof(*common), GFP_KERNEL);
+   if (!common)
+   return ERR_PTR(-ENOMEM);
+   common->free_storage_on_release = 1;
+   } else {
+   if (zero)
+   memset(common, 0, sizeof(*common));
+   common->free_storage_on_release = 0;
+   }
+   init_rwsem(&common->filesem);
+   spin_lock_init(&common->lock);
+   kref_init(&common->ref);
+   init_completion(&common->thread_notifier);
+   init_waitqueue_head(&common->fsg_wait);
+   common->state = FSG_STATE_TERMINATED;
+
+   return common;
+}
+
+void fsg_common_set_sysfs(struct fsg_common *common, bool sysfs)
+{
+   common->sysfs = sysfs;
+}
+
+static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
+{
+   if (buffhds) {
+   struct fsg_buffhd *bh = buffhds;
+   while (n--) {
+   kfree(bh->buf);
+   ++bh;
+   }
+   kfree(buffhds);
+   }
+}
+
+int fsg_common_set_num_buffers(struct fsg_common *common, unsigned int n)
+{
+   struct fsg_buffhd *bh, *new_buffhds;
+   int i, rc;
+
+   rc = fsg_num_buffers_validate(n);
+   if (rc != 0)
+   return rc;
+
+   new_buffhds = kcalloc(n, sizeof *(new_buffhds), GFP_KERNEL);
+   if (!new_buffhds)
+   return -ENOMEM;
+
+   /* Data buffers cyclic list */
+   bh = new_buffhds;
+   i = n;
+   goto buffhds_first_it;
+   do {
+   bh->next = bh + 1;
+   ++bh;
+buffhds_first_it:
+   bh->buf = kmalloc(FSG_BUFLEN, GFP_KERNEL);
+   if (unlikely(!bh->buf))
+   goto error_release;
+   } while (--i);
+   bh->next = new_buffhds;
+
+   _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
+   common->fsg_num_buffers = n;
+   common->buffhds = new_buffhds;
+
+   return 0;
+
+error_release:
+   _fsg_common_free_buffers(new_buffhds, n - i);
+
+   return -ENOMEM;
+}
+
+void fsg_common_free_buffers(struct fsg_common *common)
+{
+   _fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
+   common->buffhds = NULL;
+}
+
+int fsg_common_set_nluns(struct fsg_common *common, int nluns)
+{
+   struct fsg_lun **curlun;
+
+   /* Find out how many LUNs there should be */
+   if (nluns < 1 || nluns > FSG_MAX_LUNS) {
+   pr_err("invalid number of LUNs: %u\n", nluns);
+   return -EINVAL;
+   }
+
+   curlun = kcalloc(nluns, sizeof(*curlun), GFP_KERNEL);
+   if (unlikely(!curlun))
+   return -ENOMEM;
+
+   if (common->luns)
+   fsg_common_free_luns(common);
+
+   common->luns = curlun;
+   common->nluns = nluns;
+
+   pr_info("Number of

[PATCH v4 19/19] usb/gadget: f_mass_storage: add configfs support

2013-09-26 Thread Andrzej Pietrasiewicz
>From this commit on f_mass_storage is available through configfs.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 .../ABI/testing/configfs-usb-gadget-mass-storage   |   31 ++
 drivers/usb/gadget/Kconfig |   11 +
 drivers/usb/gadget/f_mass_storage.c|  368 
 drivers/usb/gadget/f_mass_storage.h|   17 +
 4 files changed, 427 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-mass-storage

diff --git a/Documentation/ABI/testing/configfs-usb-gadget-mass-storage 
b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
new file mode 100644
index 000..e1e918e
--- /dev/null
+++ b/Documentation/ABI/testing/configfs-usb-gadget-mass-storage
@@ -0,0 +1,31 @@
+What:  /config/usb-gadget/gadget/functions/mass_storage.name
+Date:  Jul 2013
+KenelVersion:  3.12
+Description:
+   The attributes:
+
+   stall   - Set to permit function to halt bulk endpoints.
+   Disabled on some USB devices known not to work
+   correctly. You should set it to true.
+   num_buffers - Number of pipeline buffers. Valid numbers
+   are 2..4. Available only if
+   CONFIG_USB_GADGET_DEBUG_FILES is set.
+
+What:  /config/usb-gadget/gadget/functions/mass_storage.name/lun.name
+Date:  Jul 2013
+KenelVersion:  3.12
+Description:
+   The attributes:
+
+   file- The path to the backing file for the LUN.
+   Required if LUN is not marked as removable.
+   ro  - Flag specifying access to the LUN shall be
+   read-only. This is implied if CD-ROM emulation
+   is enabled as well as when it was impossible
+   to open "filename" in R/W mode.
+   removable   - Flag specifying that LUN shall be indicated as
+   being removable.
+   cdrom   - Flag specifying that LUN shall be reported as
+   being a CD-ROM.
+   nofua   - Flag specifying that FUA flag
+   in SCSI WRITE(10,12)
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 7d64e47..bc5dea2 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -668,6 +668,17 @@ config USB_CONFIGFS_PHONET
help
  The Phonet protocol implementation for USB device.
 
+config USB_CONFIGFS_MASS_STORAGE
+   boolean "Mass storage"
+   depends on USB_CONFIGFS
+   select USB_U_MS
+   select USB_F_MASS_STORAGE
+   help
+ The Mass Storage Gadget acts as a USB Mass Storage disk drive.
+ As its storage repository it can use a regular file or a block
+ device (in much the same way as the "loop" device driver),
+ specified as a module parameter or sysfs option.
+
 config USB_ZERO
tristate "Gadget Zero (DEVELOPMENT)"
select USB_LIBCOMPOSITE
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 50f7612..fb43a49 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -220,6 +220,7 @@
 #include 
 
 #include "gadget_chips.h"
+#include "configfs.h"
 
 
 /**/
@@ -3324,6 +3325,350 @@ static int fsg_bind_config(struct usb_composite_dev 
*cdev,
 
 #else
 
+static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct fsg_lun_opts, group);
+}
+
+static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
+{
+   return container_of(to_config_group(item), struct fsg_opts,
+   func_inst.group);
+}
+
+CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
+CONFIGFS_ATTR_OPS(fsg_lun_opts);
+
+static void fsg_lun_attr_release(struct config_item *item)
+{
+   struct fsg_lun_opts *lun_opts;
+
+   lun_opts = to_fsg_lun_opts(item);
+   kfree(lun_opts);
+}
+
+static struct configfs_item_operations fsg_lun_item_ops = {
+   .release= fsg_lun_attr_release,
+   .show_attribute = fsg_lun_opts_attr_show,
+   .store_attribute = fsg_lun_opts_attr_store,
+};
+
+static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page)
+{
+   struct fsg_opts *fsg_opts;
+
+   fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+
+   return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
+}
+
+static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts,
+  const char *page, size_t len)
+{
+   struct fsg_opts *fsg_opts;
+
+   fsg_opts = to_fsg_opts(opts->g

[PATCH v4 02/19] usb/gadget: create a utility module for mass_storage

2013-09-26 Thread Andrzej Pietrasiewicz
Converting to configfs requires making the f_mass_storage.c a module.
But first we need to get rid of "#include "storage_common.c".
This patch makes storage_common.c a separately compiled file, which is
built as a utility module named u_ms.ko. After all mass storage users are
converted to the new function interface this module can be eliminated
by merging it with the mass storage function's module.

USB descriptors are exported so that they can be accessed from
f_mass_storage.

FSG_VENDOR_ID and FSG_PRODUCT_ID are moved to their only user.

Handling of CONFIG_USB_GADGET_DEBUG_FILES is moved to f_mass_storage.c.
The fsg_num_buffers static is moved to FSG_MODULE_PARAMETER users, so
instead of using a global variable the f_mass_storage introduces
fsg_num_buffers member in fsg_common (and fsg_config).

fsg_strings and fsg_stringtab are moved to f_mass_storage.c.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig  |6 +
 drivers/usb/gadget/Makefile |2 +
 drivers/usb/gadget/acm_ms.c |   17 ++-
 drivers/usb/gadget/f_mass_storage.c |  106 ++--
 drivers/usb/gadget/mass_storage.c   |   25 +++-
 drivers/usb/gadget/multi.c  |   17 ++-
 drivers/usb/gadget/storage_common.c |  331 ++-
 drivers/usb/gadget/storage_common.h |  210 ++
 8 files changed, 423 insertions(+), 291 deletions(-)
 create mode 100644 drivers/usb/gadget/storage_common.h

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 48cddf3..98220dc 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -525,6 +525,9 @@ config USB_F_SUBSET
 config USB_F_RNDIS
tristate
 
+config USB_U_MS
+   tristate
+
 choice
tristate "USB Gadget Drivers"
default USB_ETH
@@ -878,6 +881,7 @@ config USB_MASS_STORAGE
tristate "Mass Storage Gadget"
depends on BLOCK
select USB_LIBCOMPOSITE
+   select USB_U_MS
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
  As its storage repository it can use a regular file or a block
@@ -1001,6 +1005,7 @@ config USB_G_ACM_MS
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_F_ACM
+   select USB_U_MS
help
  This driver provides two functions in one configuration:
  a mass storage, and a CDC ACM (serial port) link.
@@ -1017,6 +1022,7 @@ config USB_G_MULTI
select USB_U_ETHER
select USB_U_RNDIS
select USB_F_ACM
+   select USB_U_MS
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
  and/or CDC Ethernet), mass storage and ACM serial link
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 386db9d..d90a0b0 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -60,6 +60,8 @@ 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
+u_ms-y := storage_common.o
+obj-$(CONFIG_USB_U_MS) += u_ms.o
 
 #
 # USB gadget drivers
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 4b947bb..992ffb0 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -104,6 +104,20 @@ static struct usb_gadget_strings *dev_strings[] = {
 /** Configurations **/
 
 static struct fsg_module_parameters fsg_mod_data = { .stall = 1 };
+#ifdef CONFIG_USB_GADGET_DEBUG_FILES
+
+static unsigned int fsg_num_buffers = CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
+
+#else
+
+/*
+ * Number of buffers we will use.
+ * 2 is usually enough for good buffering pipeline
+ */
+#define fsg_num_buffersCONFIG_USB_GADGET_STORAGE_NUM_BUFFERS
+
+#endif /* CONFIG_USB_DEBUG */
+
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
 static struct fsg_common fsg_common;
@@ -167,7 +181,8 @@ static int __init acm_ms_bind(struct usb_composite_dev 
*cdev)
void*retp;
 
/* set up mass storage function */
-   retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data);
+   retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data,
+ fsg_num_buffers);
if (IS_ERR(retp)) {
status = PTR_ERR(retp);
return PTR_ERR(retp);
diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index 313b835..a7c33c0 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -228,8 +228,18 @@
 
 static const char fsg_string_interface[] = "Mass Storage";
 
-#include "storage_common.c"
+#include "storage_common.h"
 
+/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
+static struct usb_string  

[PATCH v3 0/1] Equivalent of g_acm_ms.ko with configfs

2013-09-26 Thread Andrzej Pietrasiewicz
Here I present the conversion of everything that is required to provide
the equivalent of g_acm_ms.ko with configfs.

In fact this series consists of just one patch; everything required to provide
the equivalent of g_acm_ms.ko with configfs has been done in the series related
to the g_mass_storage.ko. The current series just moves the g_acm_ms to the
new function interface of f_mass_storage.

v1..v2:

- removed the cause of Felipe returning -ENOLOG
- moved fsg_common_set_sysfs invocation after the lun number is set, so that
the latter operation does not try freeing nonexistent sysfs entries

v2..v3:

- rebased onto 3.12-rc1

A branch 'usb-gadget-configfs-for-3.12' is available at:
git://git.linaro.org/people/mszyprowski/linux-srpol.git

This series depends on the [PATCH v4 ] Equivalent of g_mass_storage with
configfs which has just been sent.

BACKWARD COMPATIBILITY
==

Please note that the old g_acm_ms.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 (*).

The g_acm_ms.ko provides 2 functions:

- acm (described in (*))
- mass storage (described in a series preceding the current one,
  I will reply to this post to send a link when spinics or gmane
  has indexed the series in question)


The procedure of setting up such a gadget with configfs is given
below with an example:

$ modprobe libcomposite

$ mount none cfg -t configfs

$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1

$ echo 0x0106 > idProduct
$ echo 0x04e8 > idVendor
$ mkdir strings/0x409
$ echo my-serial-number > strings/0x409/serialnumber
$ echo my-manufacturer > strings/0x409/manufacturer
$ echo "ACM/MS Gadget" > strings/0x409/product

$ mkdir configs/c.1
$ echo 120 > configs/c.1/MaxPower
$ mkdir configs/c.1/strings/0x409
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration

$ mkdir functions/mass_storage.0
$ echo /root/lun0.img > functions/mass_storage.0/lun.0/file
$ mkdir functions/mass_storage.0/lun.1
$ echo /root/lun1.img > functions/mass_storage.0/lun.1/file

$ mkdir functions/acm.usb0

$ ln -s functions/mass_storage.0 configs/c.1
$ ln -s functions/acm.usb0 configs/c.1

$ echo s3c-hsotg > UDC

After unbinding the gadget with echo "" > UDC
the symbolic links in the configuration directory can be removed,
the strings/* subdirectories in the configuration directory can
be removed, the strings/* subdirectories at the gadget level can
be removed and the configs/* subdirectories can be removed.
The functions/* subdirectories can be removed.
After that the gadget directory can be removed.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS


acm)

On the host:

cat > /dev/ttyACM0

On the device:

cat /dev/ttyGS0

and then the other way round:

cat > /dev/ttyGS0

cat /dev/ttyACM0

mass storage)

device: connect the gadget, enable it
host: dmesg, see the USB drives appear (if system configured to automatically
mount)


Andrzej Pietrasiewicz (1):
  usb/gadget: acm_ms: convert to new interface of f_mass_storage

 drivers/usb/gadget/Kconfig  |1 +
 drivers/usb/gadget/acm_ms.c |  113 ---
 2 files changed, 75 insertions(+), 39 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 v3 1/1] usb/gadget: acm_ms: convert to new interface of f_mass_storage

2013-09-26 Thread Andrzej Pietrasiewicz
Convert the legacy acm_ms gadget to use the new function interface
of f_mass_storage, so that later the compatibility layer in
f_mass_storage can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig  |1 +
 drivers/usb/gadget/acm_ms.c |  113 ---
 2 files changed, 75 insertions(+), 39 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index bc5dea2..886db6a 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -1021,6 +1021,7 @@ config USB_G_ACM_MS
select USB_U_SERIAL
select USB_F_ACM
select USB_U_MS
+   select USB_F_MASS_STORAGE
help
  This driver provides two functions in one configuration:
  a mass storage, and a CDC ACM (serial port) link.
diff --git a/drivers/usb/gadget/acm_ms.c b/drivers/usb/gadget/acm_ms.c
index 31aae8f..b405bc4 100644
--- a/drivers/usb/gadget/acm_ms.c
+++ b/drivers/usb/gadget/acm_ms.c
@@ -31,17 +31,7 @@
 #define ACM_MS_VENDOR_NUM  0x1d6b  /* Linux Foundation */
 #define ACM_MS_PRODUCT_NUM 0x0106  /* Composite Gadget: ACM + MS*/
 
-/*-*/
-
-/*
- * 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.
- */
-#define USB_FMS_INCLUDED
-#include "f_mass_storage.c"
+#include "f_mass_storage.h"
 
 /*-*/
 USB_GADGET_COMPOSITE_OPTIONS();
@@ -121,16 +111,19 @@ static unsigned int fsg_num_buffers = 
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
 
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
-static struct fsg_common fsg_common;
-
 /*-*/
 static struct usb_function *f_acm;
 static struct usb_function_instance *f_acm_inst;
+
+static struct usb_function_instance *fi_msg;
+static struct usb_function *f_msg;
+
 /*
  * We _always_ have both ACM and mass storage functions.
  */
 static int __init acm_ms_do_config(struct usb_configuration *c)
 {
+   struct fsg_opts *opts;
int status;
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -138,31 +131,37 @@ static int __init acm_ms_do_config(struct 
usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   f_acm_inst = usb_get_function_instance("acm");
-   if (IS_ERR(f_acm_inst))
-   return PTR_ERR(f_acm_inst);
+   opts = container_of(fi_msg, struct fsg_opts, func_inst);
 
f_acm = usb_get_function(f_acm_inst);
-   if (IS_ERR(f_acm)) {
-   status = PTR_ERR(f_acm);
-   goto err_func;
+   if (IS_ERR(f_acm))
+   return PTR_ERR(f_acm);
+
+   f_msg = usb_get_function(fi_msg);
+   if (IS_ERR(f_msg)) {
+   status = PTR_ERR(f_msg);
+   goto put_acm;
}
 
status = usb_add_function(c, f_acm);
if (status < 0)
-   goto err_conf;
+   goto put_msg;
 
-   status = fsg_bind_config(c->cdev, c, &fsg_common);
-   if (status < 0)
-   goto err_fsg;
+   status = fsg_common_run_thread(opts->common);
+   if (status)
+   goto remove_acm;
+
+   status = usb_add_function(c, f_msg);
+   if (status)
+   goto remove_acm;
 
return 0;
-err_fsg:
+remove_acm:
usb_remove_function(c, f_acm);
-err_conf:
+put_msg:
+   usb_put_function(f_msg);
+put_acm:
usb_put_function(f_acm);
-err_func:
-   usb_put_function_instance(f_acm_inst);
return status;
 }
 
@@ -178,46 +177,82 @@ static struct usb_configuration acm_ms_config_driver = {
 static int __init acm_ms_bind(struct usb_composite_dev *cdev)
 {
struct usb_gadget   *gadget = cdev->gadget;
+   struct fsg_opts *opts;
+   struct fsg_config   config;
int status;
-   void*retp;
 
-   /* set up mass storage function */
-   retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data,
- fsg_num_buffers);
-   if (IS_ERR(retp)) {
-   status = PTR_ERR(retp);
-   return PTR_ERR(retp);
+   f_acm_inst = usb_get_function_instance("acm");
+   if (IS_ERR(f_acm_inst))
+   return PTR_ERR(f_acm_inst);
+
+   fi_msg = usb_get_function_instance("mass_storage");
+   if (IS_ERR(fi_msg)) {
+   status = PTR_ERR(fi_msg);
+   goto fail_get_msg;
}
 
+   /* set up mass storage function */
+   fsg_config_from_params(&config, &fsg_mod_data,

[PATCH v3 0/5] Equivalent of g_multi.ko with configfs

2013-09-26 Thread Andrzej Pietrasiewicz
Here I present the conversion of everything that is required to provide
the equivalent of g_multi.ko with configfs.

v1..v2:

- removed the cause of Felipe returning -ENOLOG
- moved fsg_common_set_sysfs invocation after the lun number is set, so that
the latter operation does not try freeing nonexistent sysfs entries
- adapted to earlier changes in multi.c (*_do_config)

v2..v3:

- rebased onto 3.12-rc1

A branch 'usb-gadget-configfs-for-3.12' is available at:
git://git.linaro.org/people/mszyprowski/linux-srpol.git

This series depends on a [PATCH v3] Equivalent of g_acm_ms with configfs,
which has just been sent.

BACKWARD COMPATIBILITY
==

Please note that the old g_multi.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 (*).

The g_multi.ko provides 4 functions:

- acm (described in (*))
- ecm (http://www.spinics.net/lists/linux-usb/msg86561.html)
- rndis (http://www.spinics.net/lists/linux-usb/msg86561.html)
- mass storage (described in a series preceding the current one,
  I will reply to this post to send a link when spinics or gmane
  has indexed the series in question)

and using all of them with configfs has already been described.

The procedure of setting up a new "multi" gadget with configfs is given
below with an example:

$ modprobe libcomposite

$ mount none cfg -t configfs

$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1

$ echo 0x0106 > idProduct
$ echo 0x04e8 > idVendor
$ mkdir strings/0x409
$ echo my-serial-num > strings/0x409/serialnumber
$ echo my-manufacturer > strings/0x409/manufacturer
$ echo "Multi Gadget" > strings/0x409/product

$ mkdir configs/c.1
$ echo 120 > configs/c.1/MaxPower
$ mkdir configs/c.1/strings/0x409
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration

$ mkdir configs/c.2
$ echo 120 > configs/c.2/MaxPower
$ mkdir configs/c.2/strings/0x409
$ echo "Conf 2" > configs/c.2/strings/0x409/configuration

$ mkdir functions/mass_storage.0
$ echo /root/lun0.img > functions/mass_storage.0/lun.0/file
$ mkdir functions/mass_storage.0/lun.1
$ echo /root/lun1.img > functions/mass_storage.0/lun.1/file

$ mkdir functions/acm.0
$ mkdir functions/ecm.0
$ mkdir functions/rndis.0

$ ln -s functions/rndis.0 configs/c.1
$ ln -s functions/acm.0 configs/c.1
$ ln -s functions/mass_storage.0 configs/c.1

$ ln -s functions/ecm.0 configs/c.2
$ ln -s functions/acm.0 configs/c.2
$ ln -s functions/mass_storage.0 configs/c.2


After unbinding the gadget with echo "" > UDC
the symbolic links in the configuration directory can be removed,
the strings/* subdirectories in the configuration directory can
be removed, the strings/* subdirectories at the gadget level can
be removed and the configs/* subdirectories can be removed.
The functions/* subdirectories can be removed.
After that the gadget directory can be removed.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS


acm)

On the host:

cat > /dev/ttyACM0

On the device:

cat /dev/ttyGS0

and then the other way round:

cat > /dev/ttyGS0

cat /dev/ttyACM0

mass storage)

device: connect the gadget, enable it
host: dmesg, see the USB drives appear (if system configured to automatically
mount)

ecm, rndis)

On the device: ping 
On the host: ping 


Andrzej Pietrasiewicz (5):
  usb/gadget: multi: convert to new interface of f_ecm
  usb/gadget: multi: convert to new interface of f_rndis
  usb/gadget: multi: convert to new interface of f_mass_storage
  usb/gadget: f_mass_storage: remove compatibility layer
  usb/gadget: mass_storage: merge usb_f_mass_storage module with u_ms
module

 drivers/usb/gadget/Kconfig  |   12 +--
 drivers/usb/gadget/Makefile |4 +-
 drivers/usb/gadget/f_mass_storage.c |  154 +--
 drivers/usb/gadget/f_mass_storage.h |   21 ---
 drivers/usb/gadget/multi.c  |  237 +++
 5 files changed, 190 insertions(+), 238 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 v3 3/5] usb/gadget: multi: convert to new interface of f_mass_storage

2013-09-26 Thread Andrzej Pietrasiewicz
Convert the legacy multi gadget to the new interface of f_mass_storage,
so that later the compatibility layer in f_mass_storage can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/multi.c |  112 
 2 files changed, 83 insertions(+), 30 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index bbcc313..4b0c456 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -1038,6 +1038,7 @@ config USB_G_MULTI
select USB_U_ETHER
select USB_F_ACM
select USB_U_MS
+   select USB_F_MASS_STORAGE
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
  and/or CDC Ethernet), mass storage and ACM serial link
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index be62bea..7f84efa 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -33,17 +33,7 @@ MODULE_AUTHOR("Michal Nazarewicz");
 MODULE_LICENSE("GPL");
 
 
-/* All the files... */
-
-/*
- * 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.
- */
-#define USB_FMS_INCLUDED
-#include "f_mass_storage.c"
+#include "f_mass_storage.h"
 
 #include "u_ecm.h"
 #ifdef USB_ETH_RNDIS
@@ -148,9 +138,8 @@ static unsigned int fsg_num_buffers = 
CONFIG_USB_GADGET_STORAGE_NUM_BUFFERS;
 
 FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
-static struct fsg_common fsg_common;
-
 static struct usb_function_instance *fi_acm;
+static struct usb_function_instance *fi_msg;
 
 /** RNDIS **/
 
@@ -158,9 +147,11 @@ static struct usb_function_instance *fi_acm;
 static struct usb_function_instance *fi_rndis;
 static struct usb_function *f_acm_rndis;
 static struct usb_function *f_rndis;
+static struct usb_function *f_msg_rndis;
 
 static __init int rndis_do_config(struct usb_configuration *c)
 {
+   struct fsg_opts *fsg_opts;
int ret;
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -186,11 +177,24 @@ static __init int rndis_do_config(struct 
usb_configuration *c)
if (ret)
goto err_conf;
 
-   ret = fsg_bind_config(c->cdev, c, &fsg_common);
-   if (ret < 0)
+   f_msg_rndis = usb_get_function(fi_msg);
+   if (IS_ERR(f_msg_rndis)) {
+   ret = PTR_ERR(f_msg_rndis);
goto err_fsg;
+   }
+
+   fsg_opts = container_of(fi_msg, struct fsg_opts, func_inst);
+   ret = fsg_common_run_thread(fsg_opts->common);
+   if (ret)
+   goto err_run;
+
+   ret = usb_add_function(c, f_msg_rndis);
+   if (ret)
+   goto err_run;
 
return 0;
+err_run:
+   usb_put_function(f_msg_rndis);
 err_fsg:
usb_remove_function(c, f_acm_rndis);
 err_conf:
@@ -231,9 +235,11 @@ static int rndis_config_register(struct usb_composite_dev 
*cdev)
 static struct usb_function_instance *fi_ecm;
 static struct usb_function *f_acm_multi;
 static struct usb_function *f_ecm;
+static struct usb_function *f_msg_multi;
 
 static __init int cdc_do_config(struct usb_configuration *c)
 {
+   struct fsg_opts *fsg_opts;
int ret;
 
if (gadget_is_otg(c->cdev->gadget)) {
@@ -260,11 +266,24 @@ static __init int cdc_do_config(struct usb_configuration 
*c)
if (ret)
goto err_conf;
 
-   ret = fsg_bind_config(c->cdev, c, &fsg_common);
-   if (ret < 0)
+   f_msg_multi = usb_get_function(fi_msg);
+   if (IS_ERR(f_msg_multi)) {
+   ret = PTR_ERR(f_msg_multi);
goto err_fsg;
+   }
+
+   fsg_opts = container_of(fi_msg, struct fsg_opts, func_inst);
+   ret = fsg_common_run_thread(fsg_opts->common);
+   if (ret)
+   goto err_run;
+
+   ret = usb_add_function(c, f_msg_multi);
+   if (ret)
+   goto err_run;
 
return 0;
+err_run:
+   usb_put_function(f_msg_multi);
 err_fsg:
usb_remove_function(c, f_acm_multi);
 err_conf:
@@ -311,6 +330,8 @@ static int __ref multi_bind(struct usb_composite_dev *cdev)
 #ifdef USB_ETH_RNDIS
struct f_rndis_opts *rndis_opts;
 #endif
+   struct fsg_opts *fsg_opts;
+   struct fsg_config config;
int status;
 
if (!can_support_ecm(cdev->gadget)) {
@@ -373,41 +394,65 @@ static int __ref multi_bind(struct usb_composite_dev 
*cdev)
}
 
/* set up mass storage function */
-   {
-   void *retp;
-   retp = fsg_common_from_params(&fsg_common, cdev, &fsg_mod_data,
- fsg_num_buffers);
- 

[PATCH v3 5/5] usb/gadget: mass_storage: merge usb_f_mass_storage module with u_ms module

2013-09-26 Thread Andrzej Pietrasiewicz
u_ms.ko is needed only together with usb_f_mass_storage.ko. Merge them.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig  |7 ---
 drivers/usb/gadget/Makefile |4 +---
 2 files changed, 1 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 4b0c456..604f885 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -525,9 +525,6 @@ config USB_F_SUBSET
 config USB_F_RNDIS
tristate
 
-config USB_U_MS
-   tristate
-
 config USB_F_MASS_STORAGE
tristate
 
@@ -671,7 +668,6 @@ config USB_CONFIGFS_PHONET
 config USB_CONFIGFS_MASS_STORAGE
boolean "Mass storage"
depends on USB_CONFIGFS
-   select USB_U_MS
select USB_F_MASS_STORAGE
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
@@ -895,7 +891,6 @@ config USB_MASS_STORAGE
tristate "Mass Storage Gadget"
depends on BLOCK
select USB_LIBCOMPOSITE
-   select USB_U_MS
select USB_F_MASS_STORAGE
help
  The Mass Storage Gadget acts as a USB Mass Storage disk drive.
@@ -1020,7 +1015,6 @@ config USB_G_ACM_MS
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_F_ACM
-   select USB_U_MS
select USB_F_MASS_STORAGE
help
  This driver provides two functions in one configuration:
@@ -1037,7 +1031,6 @@ config USB_G_MULTI
select USB_U_SERIAL
select USB_U_ETHER
select USB_F_ACM
-   select USB_U_MS
select USB_F_MASS_STORAGE
help
  The Multifunction Composite Gadget provides Ethernet (RNDIS
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 4a86b0c..f1bd42a 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -60,9 +60,7 @@ 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
-u_ms-y := storage_common.o
-obj-$(CONFIG_USB_U_MS) += u_ms.o
-usb_f_mass_storage-y   := f_mass_storage.o
+usb_f_mass_storage-y   := f_mass_storage.o storage_common.o
 obj-$(CONFIG_USB_F_MASS_STORAGE)+= usb_f_mass_storage.o
 
 #
-- 
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 v3 1/5] usb/gadget: multi: convert to new interface of f_ecm

2013-09-26 Thread Andrzej Pietrasiewicz
Convert the legacy multi gadget to the new interface of f_ecm,
so that later the compatibility layer in f_ecm can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |1 +
 drivers/usb/gadget/multi.c |   68 ++-
 2 files changed, 61 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 886db6a..92a8966 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -1070,6 +1070,7 @@ config USB_G_MULTI_CDC
bool "CDC Ethernet + CDC Serial + Storage configuration"
depends on USB_G_MULTI
default n
+   select USB_F_ECM
help
  This option enables a configuration with CDC Ethernet (ECM), CDC
  Serial and Mass Storage functions available in the Multifunction
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index c232f76..0d1d132 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -15,6 +15,7 @@
 
 #include 
 #include 
+#include 
 
 #include "u_serial.h"
 #if defined USB_ETH_RNDIS
@@ -44,8 +45,7 @@ MODULE_LICENSE("GPL");
 #define USB_FMS_INCLUDED
 #include "f_mass_storage.c"
 
-#define USBF_ECM_INCLUDED
-#include "f_ecm.c"
+#include "u_ecm.h"
 #ifdef USB_ETH_RNDIS
 #  define USB_FRNDIS_INCLUDED
 #  include "f_rndis.c"
@@ -151,14 +151,14 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 
 static struct fsg_common fsg_common;
 
-static u8 host_mac[ETH_ALEN];
-
 static struct usb_function_instance *fi_acm;
 static struct eth_dev *the_dev;
 
 /** RNDIS **/
 
 #ifdef USB_ETH_RNDIS
+static u8 host_mac[ETH_ALEN];
+
 static struct usb_function *f_acm_rndis;
 
 static __init int rndis_do_config(struct usb_configuration *c)
@@ -220,7 +220,9 @@ static int rndis_config_register(struct usb_composite_dev 
*cdev)
 /** CDC ECM **/
 
 #ifdef CONFIG_USB_G_MULTI_CDC
+static struct usb_function_instance *fi_ecm;
 static struct usb_function *f_acm_multi;
+static struct usb_function *f_ecm;
 
 static __init int cdc_do_config(struct usb_configuration *c)
 {
@@ -231,14 +233,20 @@ static __init int cdc_do_config(struct usb_configuration 
*c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   ret = ecm_bind_config(c, host_mac, the_dev);
+   f_ecm = usb_get_function(fi_ecm);
+   if (IS_ERR(f_ecm))
+   return PTR_ERR(f_ecm);
+
+   ret = usb_add_function(c, f_ecm);
if (ret < 0)
-   return ret;
+   goto err_func_ecm;
 
/* implicit port_num is zero */
f_acm_multi = usb_get_function(fi_acm);
-   if (IS_ERR(f_acm_multi))
-   return PTR_ERR(f_acm_multi);
+   if (IS_ERR(f_acm_multi)) {
+   ret = PTR_ERR(f_acm_multi);
+   goto err_func_acm;
+   }
 
ret = usb_add_function(c, f_acm_multi);
if (ret)
@@ -253,6 +261,10 @@ err_fsg:
usb_remove_function(c, f_acm_multi);
 err_conf:
usb_put_function(f_acm_multi);
+err_func_acm:
+   usb_remove_function(c, f_ecm);
+err_func_ecm:
+   usb_put_function(f_ecm);
return ret;
 }
 
@@ -285,6 +297,9 @@ static int cdc_config_register(struct usb_composite_dev 
*cdev)
 static int __ref multi_bind(struct usb_composite_dev *cdev)
 {
struct usb_gadget *gadget = cdev->gadget;
+#ifdef CONFIG_USB_G_MULTI_CDC
+   struct f_ecm_opts *ecm_opts;
+#endif
int status;
 
if (!can_support_ecm(cdev->gadget)) {
@@ -293,11 +308,39 @@ static int __ref multi_bind(struct usb_composite_dev 
*cdev)
return -EINVAL;
}
 
+#ifdef CONFIG_USB_G_MULTI_CDC
+   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);
+
+#elif defined USB_ETH_RNDIS
+
/* 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);
+#endif
+
+#if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
+   gether_set_gadget(ecm_opts->net, cdev->gadget);
+   status = gether_register_netdev(ecm_opts->net);
+   if (status)
+   goto fail0;
+   ecm_opts->bound = true;
+
+   gether_get_host_addr_u8(ecm_opts->net, host_mac);
+#endif
 
/* set up serial link layer */
fi_acm = usb_get_function_instance("acm");
@@ -345,7 +388,11 @@ fail2:
 fail1:
usb_p

[PATCH v3 2/5] usb/gadget: multi: convert to new interface of f_rndis

2013-09-26 Thread Andrzej Pietrasiewicz
Convert the legacy multi gadget to the new interface of f_rndis,
so that later the compatibility layer in f_rndis can be removed.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/Kconfig |3 +-
 drivers/usb/gadget/multi.c |   73 ++--
 2 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 92a8966..bbcc313 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -1036,7 +1036,6 @@ config USB_G_MULTI
select USB_LIBCOMPOSITE
select USB_U_SERIAL
select USB_U_ETHER
-   select USB_U_RNDIS
select USB_F_ACM
select USB_U_MS
help
@@ -1057,6 +1056,8 @@ config USB_G_MULTI
 config USB_G_MULTI_RNDIS
bool "RNDIS + CDC Serial + Storage configuration"
depends on USB_G_MULTI
+   select USB_U_RNDIS
+   select USB_F_RNDIS
default y
help
  This option enables a configuration with RNDIS, CDC Serial and
diff --git a/drivers/usb/gadget/multi.c b/drivers/usb/gadget/multi.c
index 0d1d132..be62bea 100644
--- a/drivers/usb/gadget/multi.c
+++ b/drivers/usb/gadget/multi.c
@@ -47,8 +47,7 @@ MODULE_LICENSE("GPL");
 
 #include "u_ecm.h"
 #ifdef USB_ETH_RNDIS
-#  define USB_FRNDIS_INCLUDED
-#  include "f_rndis.c"
+#  include "u_rndis.h"
 #  include "rndis.h"
 #endif
 #include "u_ether.h"
@@ -152,14 +151,13 @@ FSG_MODULE_PARAMETERS(/* no prefix */, fsg_mod_data);
 static struct fsg_common fsg_common;
 
 static struct usb_function_instance *fi_acm;
-static struct eth_dev *the_dev;
 
 /** RNDIS **/
 
 #ifdef USB_ETH_RNDIS
-static u8 host_mac[ETH_ALEN];
-
+static struct usb_function_instance *fi_rndis;
 static struct usb_function *f_acm_rndis;
+static struct usb_function *f_rndis;
 
 static __init int rndis_do_config(struct usb_configuration *c)
 {
@@ -170,13 +168,19 @@ static __init int rndis_do_config(struct 
usb_configuration *c)
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
}
 
-   ret = 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);
+
+   ret = usb_add_function(c, f_rndis);
if (ret < 0)
-   return ret;
+   goto err_func_rndis;
 
f_acm_rndis = usb_get_function(fi_acm);
-   if (IS_ERR(f_acm_rndis))
-   return PTR_ERR(f_acm_rndis);
+   if (IS_ERR(f_acm_rndis)) {
+   ret = PTR_ERR(f_acm_rndis);
+   goto err_func_acm;
+   }
 
ret = usb_add_function(c, f_acm_rndis);
if (ret)
@@ -191,6 +195,10 @@ err_fsg:
usb_remove_function(c, f_acm_rndis);
 err_conf:
usb_put_function(f_acm_rndis);
+err_func_acm:
+   usb_remove_function(c, f_rndis);
+err_func_rndis:
+   usb_put_function(f_rndis);
return ret;
 }
 
@@ -300,11 +308,14 @@ static int __ref multi_bind(struct usb_composite_dev 
*cdev)
 #ifdef CONFIG_USB_G_MULTI_CDC
struct f_ecm_opts *ecm_opts;
 #endif
+#ifdef USB_ETH_RNDIS
+   struct f_rndis_opts *rndis_opts;
+#endif
int status;
 
if (!can_support_ecm(cdev->gadget)) {
dev_err(&gadget->dev, "controller '%s' not usable\n",
-   gadget->name);
+   gadget->name);
return -EINVAL;
}
 
@@ -320,26 +331,38 @@ static int __ref multi_bind(struct usb_composite_dev 
*cdev)
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);
+#endif
 
-   the_dev = netdev_priv(ecm_opts->net);
+#ifdef USB_ETH_RNDIS
+   fi_rndis = usb_get_function_instance("rndis");
+   if (IS_ERR(fi_rndis)) {
+   status = PTR_ERR(fi_rndis);
+   goto fail;
+   }
 
-#elif defined USB_ETH_RNDIS
+   rndis_opts = container_of(fi_rndis, struct f_rndis_opts, func_inst);
 
-   /* 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);
+   gether_set_qmult(rndis_opts->net, qmult);
+   if (!gether_set_host_addr(rndis_opts->net, host_addr))
+   pr_info("using host ethernet address: %s", host_addr);
+   if (!gether_set_dev_addr(rndis_opts->net, dev_addr))
+   pr_info("using self ethernet address: %s", dev_addr);
 #endif
 
 #if (defined CONFIG_USB_G_MULTI_CDC && defined USB_ETH_RNDIS)
+   /*
+* If both ecm and rndis are selected then:
+*  1) rndis borrows the net interface from ecm
+*  2) since the interface is shared it must not be bound
+*  twice - in ecm's _and_ rndis' binds, so do it here.
+*/
gether_

[PATCH v3 4/5] usb/gadget: f_mass_storage: remove compatibility layer

2013-09-26 Thread Andrzej Pietrasiewicz
There are no more old interface users left. Remove it.

Signed-off-by: Andrzej Pietrasiewicz 
Signed-off-by: Kyungmin Park 
---
 drivers/usb/gadget/f_mass_storage.c |  154 +--
 drivers/usb/gadget/f_mass_storage.h |   21 -
 2 files changed, 1 insertions(+), 174 deletions(-)

diff --git a/drivers/usb/gadget/f_mass_storage.c 
b/drivers/usb/gadget/f_mass_storage.c
index fb43a49..8700479 100644
--- a/drivers/usb/gadget/f_mass_storage.c
+++ b/drivers/usb/gadget/f_mass_storage.c
@@ -2642,17 +2642,13 @@ void fsg_common_get(struct fsg_common *common)
 {
kref_get(&common->ref);
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_get);
-#endif
 
 void fsg_common_put(struct fsg_common *common)
 {
kref_put(&common->ref, fsg_common_release);
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_put);
-#endif
 
 /* check if fsg_num_buffers is within a valid range */
 static inline int fsg_num_buffers_validate(unsigned int fsg_num_buffers)
@@ -2690,9 +2686,7 @@ void fsg_common_set_sysfs(struct fsg_common *common, bool 
sysfs)
 {
common->sysfs = sysfs;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_sysfs);
-#endif
 
 static void _fsg_common_free_buffers(struct fsg_buffhd *buffhds, unsigned n)
 {
@@ -2744,18 +2738,14 @@ error_release:
 
return -ENOMEM;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_num_buffers);
-#endif
 
 void fsg_common_free_buffers(struct fsg_common *common)
 {
_fsg_common_free_buffers(common->buffhds, common->fsg_num_buffers);
common->buffhds = NULL;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_free_buffers);
-#endif
 
 int fsg_common_set_nluns(struct fsg_common *common, int nluns)
 {
@@ -2781,9 +2771,7 @@ int fsg_common_set_nluns(struct fsg_common *common, int 
nluns)
 
return 0;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_nluns);
-#endif
 
 void fsg_common_free_luns(struct fsg_common *common)
 {
@@ -2791,26 +2779,20 @@ void fsg_common_free_luns(struct fsg_common *common)
kfree(common->luns);
common->luns = NULL;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_free_luns);
-#endif
 
 void fsg_common_set_ops(struct fsg_common *common,
const struct fsg_operations *ops)
 {
common->ops = ops;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_ops);
-#endif
 
 void fsg_common_set_private_data(struct fsg_common *common, void *priv)
 {
common->private_data = priv;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_private_data);
-#endif
 
 int fsg_common_set_cdev(struct fsg_common *common,
 struct usb_composite_dev *cdev, bool can_stall)
@@ -2840,9 +2822,7 @@ int fsg_common_set_cdev(struct fsg_common *common,
 
return 0;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_cdev);
-#endif
 
 static inline int fsg_common_add_sysfs(struct fsg_common *common,
   struct fsg_lun *lun)
@@ -2907,9 +2887,7 @@ void fsg_common_remove_lun(struct fsg_lun *lun, bool 
sysfs)
kfree(lun->name);
kfree(lun);
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_remove_lun);
-#endif
 
 void _fsg_common_remove_luns(struct fsg_common *common, int n)
 {
@@ -2926,9 +2904,7 @@ void fsg_common_remove_luns(struct fsg_common *common)
 {
_fsg_common_remove_luns(common, common->nluns);
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_remove_luns);
-#endif
 
 #define MAX_LUN_NAME_LEN 80
 
@@ -3025,9 +3001,7 @@ error_name:
kfree(lun);
return rc;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_create_lun);
-#endif
 
 int fsg_common_create_luns(struct fsg_common *common, struct fsg_config *cfg)
 {
@@ -3049,9 +3023,7 @@ fail:
_fsg_common_remove_luns(common, i);
return rc;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_create_luns);
-#endif
 
 void fsg_common_set_inquiry_string(struct fsg_common *common, const char *vn,
   const char *pn)
@@ -3068,9 +3040,7 @@ void fsg_common_set_inquiry_string(struct fsg_common 
*common, const char *vn,
 : "File-Stor Gadget"),
 i);
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_set_inquiry_string);
-#endif
 
 int fsg_common_run_thread(struct fsg_common *common)
 {
@@ -3089,66 +3059,7 @@ int fsg_common_run_thread(struct fsg_common *common)
 
return 0;
 }
-#ifndef USB_FMS_INCLUDED
 EXPORT_SYMBOL(fsg_common_run_thread);
-#endif
-
-struct fsg_common *fsg_common_init(struct fsg_common *common,
-  struct usb_composite_dev *cdev,
-  struct fsg_config *cfg)
-{
-   int rc;
-
-   common = fsg_common_setup(common, !!common);
-   if (IS_ERR(common))
-   return common;
-   common->sysfs = true;
-   common->state = FSG_STATE_IDLE;
-
-   rc = fsg_common_set_num_buffers(common,

[PATCH 3/4] usb: musb: conditionally restore and resume the context on resume

2013-09-26 Thread Daniel Mack
It appears not all platforms featuring a musb core need to save the musb
core registers at suspend time and restore them on resume.

The dsps platform does, however. So add a bit in struct
musb_hdrc_platform_data to let platforms specify their need of such
action being taken.

Signed-off-by: Daniel Mack 
---
 drivers/usb/musb/musb_core.c | 17 -
 include/linux/usb/musb.h |  1 +
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2b9f4b4..f17604e 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2152,6 +2152,7 @@ static int musb_suspend(struct device *dev)
 {
struct musb *musb = dev_to_musb(dev);
unsigned long   flags;
+   struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
 
spin_lock_irqsave(&musb->lock, flags);
 
@@ -2165,16 +2166,30 @@ static int musb_suspend(struct device *dev)
 */
}
 
+   if (plat->restore_after_suspend)
+   musb_save_context(musb);
+
spin_unlock_irqrestore(&musb->lock, flags);
return 0;
 }
 
 static int musb_resume_noirq(struct device *dev)
 {
-   /* for static cmos like DaVinci, register values were preserved
+   struct musb *musb = dev_to_musb(dev);
+   struct musb_hdrc_platform_data *plat = dev_get_platdata(dev);
+
+   /*
+* For static cmos like DaVinci, register values were preserved
 * unless for some reason the whole soc powered down or the USB
 * module got reset through the PSC (vs just being disabled).
+*
+* The plaform data tells us about the necessity of saving and
+* restoring the context across a suspend cycle.
 */
+
+   if (plat->restore_after_suspend)
+   musb_restore_context(musb);
+
return 0;
 }
 
diff --git a/include/linux/usb/musb.h b/include/linux/usb/musb.h
index 053c268..296be6c 100644
--- a/include/linux/usb/musb.h
+++ b/include/linux/usb/musb.h
@@ -100,6 +100,7 @@ struct musb_hdrc_platform_data {
u8  mode;
 
u8  has_mailbox:1;
+   u8  restore_after_suspend:1;
 
/* for clk_get() */
const char  *clock;
-- 
1.8.3.1

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


[PATCH 1/4] usb: musb: move port reset to worker

2013-09-26 Thread Daniel Mack
musb_port_reset() sleeps, so we can't call it from atomic context. It
is, however, called from places inside musb_hub_control() while
&musb->lock is held, which leads to a "scheduling while atomic" warning.

Fix this by moving the logic into a worker, and call it where the
function was previously called directly.

Signed-off-by: Daniel Mack 
---
 drivers/usb/musb/musb_core.c|  7 +++
 drivers/usb/musb/musb_core.h|  3 +++
 drivers/usb/musb/musb_host.h|  2 ++
 drivers/usb/musb/musb_virthub.c | 13 -
 4 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 18e877f..2b9f4b4 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1699,6 +1699,12 @@ static void musb_irq_work(struct work_struct *data)
}
 }
 
+static void musb_port_reset_work(struct work_struct *data)
+{
+   struct musb *musb = container_of(data, struct musb, port_reset_work);
+   musb_port_reset(musb);
+}
+
 /* --
  * Init support
  */
@@ -1857,6 +1863,7 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
 
/* Init IRQ workqueue before request_irq */
INIT_WORK(&musb->irq_work, musb_irq_work);
+   INIT_WORK(&musb->port_reset_work, musb_port_reset_work);
 
/* attach to the IRQ */
if (request_irq(nIrq, musb->isr, 0, dev_name(dev), musb)) {
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 65f3917..9529512 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -294,6 +294,9 @@ struct musb {
 
irqreturn_t (*isr)(int, void *);
struct work_struct  irq_work;
+   struct work_struct  port_reset_work;
+   boolport_reset_state;
+
u16 hwvers;
 
u16 intrrxe;
diff --git a/drivers/usb/musb/musb_host.h b/drivers/usb/musb/musb_host.h
index 960d735..843f48e 100644
--- a/drivers/usb/musb/musb_host.h
+++ b/drivers/usb/musb/musb_host.h
@@ -92,6 +92,7 @@ extern void musb_host_rx(struct musb *, u8);
 extern void musb_root_disconnect(struct musb *musb);
 extern void musb_host_resume_root_hub(struct musb *musb);
 extern void musb_host_poke_root_hub(struct musb *musb);
+extern void musb_port_reset(struct musb *musb);
 #else
 static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
 {
@@ -121,6 +122,7 @@ static inline void musb_root_disconnect(struct musb *musb)  
{}
 static inline void musb_host_resume_root_hub(struct musb *musb){}
 static inline void musb_host_poll_rh_status(struct musb *musb) {}
 static inline void musb_host_poke_root_hub(struct musb *musb)  {}
+static inline void musb_port_reset(struct musb *musb)  {}
 #endif
 
 struct usb_hcd;
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index a523950..30b43a1 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -155,7 +155,7 @@ static void musb_port_suspend(struct musb *musb, bool 
do_suspend)
}
 }
 
-static void musb_port_reset(struct musb *musb, bool do_reset)
+void musb_port_reset(struct musb *musb)
 {
u8  power;
void __iomem*mbase = musb->mregs;
@@ -173,7 +173,7 @@ static void musb_port_reset(struct musb *musb, bool 
do_reset)
 * the appropriate amount of time has passed
 */
power = musb_readb(mbase, MUSB_POWER);
-   if (do_reset) {
+   if (musb->port_reset_state) {
 
/*
 * If RESUME is set, we must make sure it stays minimum 20 ms.
@@ -356,8 +356,10 @@ int musb_hub_control(
 
/* finish RESET signaling? */
if ((musb->port1_status & USB_PORT_STAT_RESET)
-   && time_after_eq(jiffies, musb->rh_timer))
-   musb_port_reset(musb, false);
+   && time_after_eq(jiffies, musb->rh_timer)) {
+   musb->port_reset_state = false;
+   schedule_work(&musb->port_reset_work);
+   }
 
/* finish RESUME signaling? */
if ((musb->port1_status & MUSB_PORT_STAT_RESUME)
@@ -412,7 +414,8 @@ int musb_hub_control(
musb_start(musb);
break;
case USB_PORT_FEAT_RESET:
-   musb_port_reset(musb, true);
+   musb->port_reset_state = true;
+   schedule_work(&musb->port_reset_work);
break;
case USB_PORT_FEAT_SUSPEND:
musb_port_suspend(musb, true);
-- 
1.8.3.1

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

[PATCH 4/4] usb: musb: dsps: add support for suspend and resume

2013-09-26 Thread Daniel Mack
The dsps platform needs to save save some registers at suspend time and
restore them after resume. This patch adds a struct for these registers,
and also lets the musb core know that the core registers need to be
saved as well.

Signed-off-by: Daniel Mack 
---
 drivers/usb/musb/musb_dsps.c | 54 
 1 file changed, 54 insertions(+)

diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 4047cbb..c93c365 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -110,6 +110,17 @@ struct dsps_musb_wrapper {
u8  poll_seconds;
 };
 
+/*
+ * register shadow for suspend
+ */
+struct dsps_context {
+   u32 control;
+   u32 epintr;
+   u32 coreintr;
+   u32 phy_utmi;
+   u32 mode;
+};
+
 /**
  * DSPS glue structure.
  */
@@ -119,6 +130,8 @@ struct dsps_glue {
const struct dsps_musb_wrapper *wrp; /* wrapper register offsets */
struct timer_list timer;/* otg_workaround timer */
unsigned long last_timer;/* last timer data for each instance */
+
+   struct dsps_context context;
 };
 
 /**
@@ -502,6 +515,7 @@ static int dsps_create_musb_pdev(struct dsps_glue *glue,
}
pdata.config = config;
pdata.platform_ops = &dsps_ops;
+   pdata.restore_after_suspend = 1;
 
config->num_eps = get_int_prop(dn, "mentor,num-eps");
config->ram_bits = get_int_prop(dn, "mentor,ram-bits");
@@ -623,11 +637,51 @@ static const struct of_device_id musb_dsps_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, musb_dsps_of_match);
 
+#ifdef CONFIG_PM
+static int dsps_suspend(struct device *dev)
+{
+   struct dsps_glue *glue = dev_get_drvdata(dev);
+   const struct dsps_musb_wrapper *wrp = glue->wrp;
+   struct musb *musb = platform_get_drvdata(glue->musb);
+   void __iomem *mbase = musb->ctrl_base;
+
+   glue->context.control = dsps_readl(mbase, wrp->control);
+   glue->context.epintr = dsps_readl(mbase, wrp->epintr_set);
+   glue->context.coreintr = dsps_readl(mbase, wrp->coreintr_set);
+   glue->context.phy_utmi = dsps_readl(mbase, wrp->phy_utmi);
+   glue->context.mode = dsps_readl(mbase, wrp->mode);
+
+   return 0;
+}
+
+static int dsps_resume(struct device *dev)
+{
+   struct dsps_glue *glue = dev_get_drvdata(dev);
+   const struct dsps_musb_wrapper *wrp = glue->wrp;
+   struct musb *musb = platform_get_drvdata(glue->musb);
+   void __iomem *mbase = musb->ctrl_base;
+
+   dsps_writel(mbase, wrp->control, glue->context.control);
+   dsps_writel(mbase, wrp->epintr_set, glue->context.epintr);
+   dsps_writel(mbase, wrp->coreintr_set, glue->context.coreintr);
+   dsps_writel(mbase, wrp->phy_utmi, glue->context.phy_utmi);
+   dsps_writel(mbase, wrp->mode, glue->context.mode);
+
+   musb->port_reset_state = false;
+   schedule_work(&musb->port_reset_work);
+
+   return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(dsps_pm_ops, dsps_suspend, dsps_resume);
+
 static struct platform_driver dsps_usbss_driver = {
.probe  = dsps_probe,
.remove = dsps_remove,
.driver = {
.name   = "musb-dsps",
+   .pm = &dsps_pm_ops,
.of_match_table = of_match_ptr(musb_dsps_of_match),
},
 };
-- 
1.8.3.1

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


[PATCH 0/4] usb: musb: support for suspend and resume

2013-09-26 Thread Daniel Mack
I've been working on some patches that allow suspending and resuming
the musb-dsps platform. This was tested for host mode only.

With these patches applied, I can successfully bring an AM335x board
to suspend with a USB media connected, and access it again after
resume. Note that this currently only works with CONFIG_MUSB_PIO_ONLY
set. The cppi41 driver needs some more love to make this work. I'll
work on that next.

Thanks,
Daniel


Daniel Mack (4):
  usb: musb: move port reset to worker
  usb: musb: call musb_port_suspend from musb_bus_suspend
  usb: musb: conditionally restore and resume the context on resume
  usb: musb: dsps: add support for suspend and resume

 drivers/usb/musb/musb_core.c| 24 +-
 drivers/usb/musb/musb_core.h|  3 +++
 drivers/usb/musb/musb_dsps.c| 54 +
 drivers/usb/musb/musb_host.c|  2 ++
 drivers/usb/musb/musb_host.h|  4 +++
 drivers/usb/musb/musb_virthub.c | 15 +++-
 include/linux/usb/musb.h|  1 +
 7 files changed, 96 insertions(+), 7 deletions(-)

-- 
1.8.3.1

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


[PATCH 2/4] usb: musb: call musb_port_suspend from musb_bus_suspend

2013-09-26 Thread Daniel Mack
Make musb_port_suspend() externally available, and call it when to host
goes into suspend. This allows the core to go into suspend while a
device is connected.

Signed-off-by: Daniel Mack 
---
 drivers/usb/musb/musb_host.c| 2 ++
 drivers/usb/musb/musb_host.h| 2 ++
 drivers/usb/musb/musb_virthub.c | 2 +-
 3 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 9a2b8c8..2b60596 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2433,6 +2433,8 @@ static int musb_bus_suspend(struct usb_hcd *hcd)
struct musb *musb = hcd_to_musb(hcd);
u8  devctl;
 
+   musb_port_suspend(musb, true);
+
if (!is_host_active(musb))
return 0;
 
diff --git a/drivers/usb/musb/musb_host.h b/drivers/usb/musb/musb_host.h
index 843f48e..dcffea7 100644
--- a/drivers/usb/musb/musb_host.h
+++ b/drivers/usb/musb/musb_host.h
@@ -93,6 +93,7 @@ extern void musb_root_disconnect(struct musb *musb);
 extern void musb_host_resume_root_hub(struct musb *musb);
 extern void musb_host_poke_root_hub(struct musb *musb);
 extern void musb_port_reset(struct musb *musb);
+extern void musb_port_suspend(struct musb *musb, bool do_suspend);
 #else
 static inline struct musb *hcd_to_musb(struct usb_hcd *hcd)
 {
@@ -123,6 +124,7 @@ static inline void musb_host_resume_root_hub(struct musb 
*musb) {}
 static inline void musb_host_poll_rh_status(struct musb *musb) {}
 static inline void musb_host_poke_root_hub(struct musb *musb)  {}
 static inline void musb_port_reset(struct musb *musb)  {}
+static inline void musb_port_suspend(struct musb *musb, bool do_suspend) {}
 #endif
 
 struct usb_hcd;
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index 30b43a1..9f3a0f3 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -90,7 +90,7 @@ static void musb_start(struct musb *musb)
musb_writeb(regs, MUSB_DEVCTL, devctl);
 }
 
-static void musb_port_suspend(struct musb *musb, bool do_suspend)
+void musb_port_suspend(struct musb *musb, bool do_suspend)
 {
struct usb_otg  *otg = musb->xceiv->otg;
u8  power;
-- 
1.8.3.1

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


Re: problematic device

2013-09-26 Thread folkert
> > In this logging I plugged-in the device and waited for it to disconnect
> > and reconnect again.
> > I googled but did not find something that translates this logging into
> > human readable format. Are there any that you know of?
> 
> No.  But I can interpret it for you.

thanks!

> Almost 7 seconds later, this shows the device disconnecting itself from 
> the bus.  There's no obvious reason.
> The rest of the trace is just the same thing repeated.

Ok thank you.
I contacted my contact at Cleware and he told me it is a workaround for
windows 8. He's going to see if he can find a different solution.

Thanks for your help!


Folkert van Heusden

-- 
MultiTail er et flexible tool for å kontrolere Logfiles og commandoer.
Med filtrer, farger, sammenføringer, forskeliger ansikter etc.
http://www.vanheusden.com/multitail/
--
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
--
To unsubscribe from this list: send the line "unsubscribe 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] net: qmi_wwan: fix Cinterion PLXX product ID

2013-09-26 Thread Schmiedl Christian
Aleksander Morgado  writes:

> Cinterion PLXX LTE devices have a 0x0060 product ID, not 0x12d1.
>
> The blacklisting in the serial/option driver does actually use the
> correct PID, as per commit 8ff10bdb14a52e3f25d4ce09e0582a8684c1a6db
> ('USB: Blacklisted Cinterion's PLxx WWAN Interface').

Thanks for patching

Acked-by: Christian Schmiedl 

Chris



This message and any attachments are intended solely for the addressees and may 
contain confidential information. Any unauthorized use or disclosure, either 
whole or partial, is prohibited.
E-mails are susceptible to alteration. Our company shall not be liable for the 
message if altered, changed or falsified. If you are not the intended recipient 
of this message, please delete it and notify the sender.
Although all reasonable efforts have been made to keep this transmission free 
from viruses, the sender will not be liable for damages caused by a transmitted 
virus
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/27] mmc: vub300: Remove redundant suspend and resume callbacks

2013-09-26 Thread Ulf Hansson
Suspend and resume of cards are handled by the protocol layer and
consequently the mmc_suspend|resume_host APIs are marked as deprecated.

While moving away from using the deprecated APIs, there are nothing
left to be done for the suspend and resume callbacks, so remove them.

Cc: Tony Olech 
Cc: linux-usb@vger.kernel.org
Signed-off-by: Ulf Hansson 
---
 drivers/mmc/host/vub300.c |   30 --
 1 file changed, 30 deletions(-)

diff --git a/drivers/mmc/host/vub300.c b/drivers/mmc/host/vub300.c
index e9028ad..db99edc 100644
--- a/drivers/mmc/host/vub300.c
+++ b/drivers/mmc/host/vub300.c
@@ -2389,34 +2389,6 @@ static void vub300_disconnect(struct usb_interface 
*interface)
}
 }
 
-#ifdef CONFIG_PM
-static int vub300_suspend(struct usb_interface *intf, pm_message_t message)
-{
-   struct vub300_mmc_host *vub300 = usb_get_intfdata(intf);
-   if (!vub300 || !vub300->mmc) {
-   return 0;
-   } else {
-   struct mmc_host *mmc = vub300->mmc;
-   mmc_suspend_host(mmc);
-   return 0;
-   }
-}
-
-static int vub300_resume(struct usb_interface *intf)
-{
-   struct vub300_mmc_host *vub300 = usb_get_intfdata(intf);
-   if (!vub300 || !vub300->mmc) {
-   return 0;
-   } else {
-   struct mmc_host *mmc = vub300->mmc;
-   mmc_resume_host(mmc);
-   return 0;
-   }
-}
-#else
-#define vub300_suspend NULL
-#define vub300_resume NULL
-#endif
 static int vub300_pre_reset(struct usb_interface *intf)
 {  /* NOT irq */
struct vub300_mmc_host *vub300 = usb_get_intfdata(intf);
@@ -2437,8 +2409,6 @@ static struct usb_driver vub300_driver = {
.name = "vub300",
.probe = vub300_probe,
.disconnect = vub300_disconnect,
-   .suspend = vub300_suspend,
-   .resume = vub300_resume,
.pre_reset = vub300_pre_reset,
.post_reset = vub300_post_reset,
.id_table = vub300_table,
-- 
1.7.9.5

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


Re: driver request

2013-09-26 Thread Greg KH
On Tue, Sep 24, 2013 at 03:19:24PM -0400, Alex MacPherson wrote:
> Hello,
> 
> Can you add the startech.com usb to serial adapter to a proper
> driver. I am using the command
> 
> sudo modprobe usbserial vendor=0x14b0 product=0x3410
> 
> It works on my ubuntu 12.04 AMD 64 desktop system but my linux mint
> 15 netbook AOD270 will not get me to console into my Cisco hardware.

By doing the same thing, both kernels do not work the same?  What kernel
versions are in each of those releases?

What is the name and type of device you are using here?

thanks,

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


Re: [help] imx27 - isp1504 : unable to init transceiver, probably missing

2013-09-26 Thread Christoph Fritz
On Wed, 2013-09-25 at 16:00 +0200, Eric Bénard wrote:
> Le Wed, 25 Sep 2013 12:17:40 +0200,
> Christoph Fritz  a écrit :
> 
> > On Tue, 2013-04-09 at 14:28 -0300, Fabio Estevam wrote:
> > > On Mon, Apr 8, 2013 at 9:09 PM, Fabio Estevam  wrote:
> > > 
> > > >> I know that I have to use the driver ULPI but with my configuration, I
> > > >> get these errors :
> > > >> "
> > > >> ehci-mxc: Freescale On-Chip EHCI Host driver
> > > >> mxc-ehci mxc-ehci.0: initializing i.MX USB Controller
> > > >> timeout polling for ULPI device
> > > >> mxc-ehci mxc-ehci.0: unable to init transceiver, probably missing
> > > 
> > > Just tested mx31pdk on a 3.8.6 kernel and I got:
> > > 
> > > ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
> > > ehci-mxc: Freescale On-Chip EHCI Host driver
> > > mxc-ehci mxc-ehci.0: initializing i.MX USB Controller
> > > ULPI transceiver vendor/product ID 0x04cc/0x1504
> > > Found NXP ISP1504 ULPI transceiver.
> > > ULPI integrity check: passed.
> > > mxc-ehci mxc-ehci.0: EHCI Host Controller
> > > mxc-ehci mxc-ehci.0: new USB bus registered, assigned bus number 1
> > > mxc-ehci mxc-ehci.0: irq 53, io mem 0x43f88000
> > > mxc-ehci mxc-ehci.0: USB 2.0 started, EHCI 1.00
> > > hub 1-0:1.0: USB hub found
> > > hub 1-0:1.0: 1 port detected
> > > mxc-ehci mxc-ehci.2: initializing i.MX USB Controller
> > > timeout polling for ULPI device
> > > mxc-ehci mxc-ehci.2: unable to init transceiver, probably missing
> > 
> > Any updates on this?
> > 
> > I'm facing the same kind of issue with an SMSC3340 phy connected to an
> > imx.27: After some minutes in power-off state, the first boot fails to
> > detect the ULPI device connected to USBOTG-Pins, no matter if host- or
> > device-mode is configured.
> > But the strange thing is that then, after a reboot or reset the phy gets
> > detected.
> > 
> are you sure some pins on the ULPI interface don't change their level
> between the time where you release the PHY's reset and when the ULPI
> access occurs ?

I'm pretty sure that there are, but not intended by software I could
control (bootloader+kernel).

I got a pdf entitled "Using ISP1504 with i.MX27" which is a
Freescale-"Hardware-Bug-Tech-Note" from 2008. It's about the same
problem we are facing here in this thread. To quote their conclusion:

- i.MX27 HS OTG core is software configurable for ULPI or Serial
  transceiver interface
- Default setup at power-up is for Serial transceiver
- This has been found to cause problems with ISP1504 ULPI High-
  Speed USB OTG transceiver
  - Problems appear rarely and randomly during system power-up
  - Final result is that sometimes ISP1504 enters suspend mode during
startup preventing proper initialization via ULPI bus

Their software fix:
   "As first attemp at fixing this issue, one may try to switch LINK to
   ULPI mode before configuring MUX and pads for USB operation. Fear is
   that this could cause unexpected transfer from PHY to LINK, somehow
   preventing proper initialization"

I'll try that here with the smsc3340-phy.

Please drop me a private mail if you want me to send the pdf to you.

Thanks
 -- Christoph

--
To unsubscribe from this list: send the line "unsubscribe 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/2] usb: wusbcore: rename data fields

2013-09-26 Thread Thomas Pugliese
Hi, 
This set of patches renames various data fields in wa_seg and wahc 
to more clearly specify their purpose.  I plan to add isochronous 
support to wusbcore soon and these changes will make that patch easier 
to comprehend.


Thomas Pugliese (2):
  usb: wusbcore: rename urb to tr_urb in struct wa_seg
  usb: wusbcore: rename xfer_result to dti_buf and xfer_result_size to 
dti_buf_size in struct wahc.

 drivers/usb/wusbcore/wa-hc.c   |   14 ++--
 drivers/usb/wusbcore/wa-hc.h   |4 ++--
 drivers/usb/wusbcore/wa-xfer.c |   48 +---
 3 files changed, 34 insertions(+), 32 deletions(-)

-- 
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 1/2] usb: wusbcore: rename urb to tr_urb in struct wa_seg

2013-09-26 Thread Thomas Pugliese
Rename urb to tr_urb in struct wa_seg to make it clear that the urb is 
used for the transfer request.

Signed-off-by: Thomas Pugliese 

---
 drivers/usb/wusbcore/wa-xfer.c |   30 --
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 6ad02f5..3718847 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -114,8 +114,8 @@ static void wa_xfer_delayed_run(struct wa_rpipe *);
  * struct).
  */
 struct wa_seg {
-   struct urb urb;
-   struct urb *dto_urb;/* for data output? */
+   struct urb tr_urb;  /* transfer request urb. */
+   struct urb *dto_urb;/* for data output. */
struct list_head list_node; /* for rpipe->req_list */
struct wa_xfer *xfer;   /* out xfer */
u8 index;   /* which segment we are */
@@ -127,11 +127,11 @@ struct wa_seg {
 
 static inline void wa_seg_init(struct wa_seg *seg)
 {
-   usb_init_urb(&seg->urb);
+   usb_init_urb(&seg->tr_urb);
 
/* set the remaining memory to 0. */
-   memset(((void *)seg) + sizeof(seg->urb), 0,
-   sizeof(*seg) - sizeof(seg->urb));
+   memset(((void *)seg) + sizeof(seg->tr_urb), 0,
+   sizeof(*seg) - sizeof(seg->tr_urb));
 }
 
 /*
@@ -179,7 +179,7 @@ static void wa_xfer_destroy(struct kref *_xfer)
unsigned cnt;
for (cnt = 0; cnt < xfer->segs; cnt++) {
usb_free_urb(xfer->seg[cnt]->dto_urb);
-   usb_free_urb(&xfer->seg[cnt]->urb);
+   usb_free_urb(&xfer->seg[cnt]->tr_urb);
}
}
kfree(xfer);
@@ -494,12 +494,12 @@ static void __wa_xfer_setup_hdr0(struct wa_xfer *xfer,
 /*
  * Callback for the OUT data phase of the segment request
  *
- * Check wa_seg_cb(); most comments also apply here because this
+ * Check wa_seg_tr_cb(); most comments also apply here because this
  * function does almost the same thing and they work closely
  * together.
  *
  * If the seg request has failed but this DTO phase has succeeded,
- * wa_seg_cb() has already failed the segment and moved the
+ * wa_seg_tr_cb() has already failed the segment and moved the
  * status to WA_SEG_ERROR, so this will go through 'case 0' and
  * effectively do nothing.
  */
@@ -576,7 +576,7 @@ static void wa_seg_dto_cb(struct urb *urb)
  * as in that case, wa_seg_dto_cb will do it when the OUT data phase
  * finishes.
  */
-static void wa_seg_cb(struct urb *urb)
+static void wa_seg_tr_cb(struct urb *urb)
 {
struct wa_seg *seg = urb->context;
struct wa_xfer *xfer = seg->xfer;
@@ -740,11 +740,11 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, 
size_t xfer_hdr_size)
wa_seg_init(seg);
seg->xfer = xfer;
seg->index = cnt;
-   usb_fill_bulk_urb(&seg->urb, usb_dev,
+   usb_fill_bulk_urb(&seg->tr_urb, usb_dev,
  usb_sndbulkpipe(usb_dev,
  dto_epd->bEndpointAddress),
  &seg->xfer_hdr, xfer_hdr_size,
- wa_seg_cb, seg);
+ wa_seg_tr_cb, seg);
buf_itr_size = min(buf_size, xfer->seg_size);
if (xfer->is_inbound == 0 && buf_size > 0) {
/* outbound data. */
@@ -888,12 +888,14 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct 
wa_xfer *xfer,
   struct wa_seg *seg)
 {
int result;
-   result = usb_submit_urb(&seg->urb, GFP_ATOMIC);
+   /* submit the transfer request. */
+   result = usb_submit_urb(&seg->tr_urb, GFP_ATOMIC);
if (result < 0) {
printk(KERN_ERR "xfer %p#%u: REQ submit failed: %d\n",
   xfer, seg->index, result);
goto error_seg_submit;
}
+   /* submit the out data if this is an out request. */
if (seg->dto_urb) {
result = usb_submit_urb(seg->dto_urb, GFP_ATOMIC);
if (result < 0) {
@@ -907,7 +909,7 @@ static int __wa_seg_submit(struct wa_rpipe *rpipe, struct 
wa_xfer *xfer,
return 0;
 
 error_dto_submit:
-   usb_unlink_urb(&seg->urb);
+   usb_unlink_urb(&seg->tr_urb);
 error_seg_submit:
seg->status = WA_SEG_ERROR;
seg->result = result;
@@ -1313,7 +1315,7 @@ int wa_urb_dequeue(struct wahc *wa, struct urb *urb)
break;
case WA_SEG_SUBMITTED:
seg->status = WA_SEG_ABORTED;
-   usb_unlink_urb(&seg->urb);
+   usb_unlink_urb(&seg->tr_urb);
if (xfer->is_inbound == 0)
usb_unlink_urb(seg->dto_urb);
xfer->segs_done++;
-

[PATCH 2/2] usb: wusbcore: rename fields in struct wahc

2013-09-26 Thread Thomas Pugliese
Rename xfer_result to dti_buf and xfer_result_size to dti_buf_size in 
struct wahc.  The dti buffer will also be used for isochronous status 
packets once isochronous transfers are supported.

Signed-off-by: Thomas Pugliese 

---
 drivers/usb/wusbcore/wa-hc.c   |   14 +++---
 drivers/usb/wusbcore/wa-hc.h   |4 ++--
 drivers/usb/wusbcore/wa-xfer.c |   18 +-
 3 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index a09b65e..6c09b0e 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -44,11 +44,11 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
/* Fill up Data Transfer EP pointers */
wa->dti_epd = &iface->cur_altsetting->endpoint[1].desc;
wa->dto_epd = &iface->cur_altsetting->endpoint[2].desc;
-   wa->xfer_result_size = usb_endpoint_maxp(wa->dti_epd);
-   wa->xfer_result = kmalloc(wa->xfer_result_size, GFP_KERNEL);
-   if (wa->xfer_result == NULL) {
+   wa->dti_buf_size = usb_endpoint_maxp(wa->dti_epd);
+   wa->dti_buf = kmalloc(wa->dti_buf_size, GFP_KERNEL);
+   if (wa->dti_buf == NULL) {
result = -ENOMEM;
-   goto error_xfer_result_alloc;
+   goto error_dti_buf_alloc;
}
result = wa_nep_create(wa, iface);
if (result < 0) {
@@ -59,8 +59,8 @@ int wa_create(struct wahc *wa, struct usb_interface *iface)
return 0;
 
 error_nep_create:
-   kfree(wa->xfer_result);
-error_xfer_result_alloc:
+   kfree(wa->dti_buf);
+error_dti_buf_alloc:
wa_rpipes_destroy(wa);
 error_rpipes_create:
return result;
@@ -76,7 +76,7 @@ void __wa_destroy(struct wahc *wa)
usb_kill_urb(wa->buf_in_urb);
usb_put_urb(wa->buf_in_urb);
}
-   kfree(wa->xfer_result);
+   kfree(wa->dti_buf);
wa_nep_destroy(wa);
wa_rpipes_destroy(wa);
 }
diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
index cf250c2..ab39934 100644
--- a/drivers/usb/wusbcore/wa-hc.h
+++ b/drivers/usb/wusbcore/wa-hc.h
@@ -184,8 +184,8 @@ struct wahc {
struct urb *dti_urb;/* URB for reading xfer results */
struct urb *buf_in_urb; /* URB for reading data in */
struct edc dti_edc; /* DTI error density counter */
-   struct wa_xfer_result *xfer_result; /* real size = dti_ep maxpktsize */
-   size_t xfer_result_size;
+   void *dti_buf;
+   size_t dti_buf_size;
 
s32 status; /* For reading status */
 
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 3718847..11d684c 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -1418,7 +1418,8 @@ static int wa_xfer_status_to_errno(u8 status)
  *
  * FIXME: this function needs to be broken up in parts
  */
-static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer)
+static void wa_xfer_result_chew(struct wahc *wa, struct wa_xfer *xfer,
+   struct wa_xfer_result *xfer_result)
 {
int result;
struct device *dev = &wa->usb_iface->dev;
@@ -1426,8 +1427,7 @@ static void wa_xfer_result_chew(struct wahc *wa, struct 
wa_xfer *xfer)
u8 seg_idx;
struct wa_seg *seg;
struct wa_rpipe *rpipe;
-   struct wa_xfer_result *xfer_result = wa->xfer_result;
-   u8 done = 0;
+   unsigned done = 0;
u8 usb_status;
unsigned rpipe_ready = 0;
 
@@ -1689,7 +1689,7 @@ static void wa_buf_in_cb(struct urb *urb)
  * We go back to OFF when we detect a ENOENT or ESHUTDOWN (or too many
  * errors) in the URBs.
  */
-static void wa_xfer_result_cb(struct urb *urb)
+static void wa_dti_cb(struct urb *urb)
 {
int result;
struct wahc *wa = urb->context;
@@ -1711,7 +1711,7 @@ static void wa_xfer_result_cb(struct urb *urb)
urb->actual_length, sizeof(*xfer_result));
break;
}
-   xfer_result = wa->xfer_result;
+   xfer_result = (struct wa_xfer_result *)(wa->dti_buf);
if (xfer_result->hdr.bLength != sizeof(*xfer_result)) {
dev_err(dev, "DTI Error: xfer result--"
"bad header length %u\n",
@@ -1737,7 +1737,7 @@ static void wa_xfer_result_cb(struct urb *urb)
xfer_id, usb_status);
break;
}
-   wa_xfer_result_chew(wa, xfer);
+   wa_xfer_result_chew(wa, xfer, xfer_result);
wa_xfer_put(xfer);
break;
case -ENOENT:   /* (we killed the URB)...so, no broadcast */
@@ -1779,7 +1779,7 @@ out:
  * don't really set it up and start it until the first xfer complete
  * notification arrives, which is what we do here.
  *
- * Follow up in wa_xfer_result_cb(), as that's where t

Re: [help] imx27 - isp1504 : unable to init transceiver, probably missing

2013-09-26 Thread Eric Bénard
Hi,

Le Thu, 26 Sep 2013 17:59:39 +0200,
Christoph Fritz  a écrit :

> On Wed, 2013-09-25 at 16:00 +0200, Eric Bénard wrote:
> > Le Wed, 25 Sep 2013 12:17:40 +0200,
> > Christoph Fritz  a écrit :
> > 
> > > On Tue, 2013-04-09 at 14:28 -0300, Fabio Estevam wrote:
> > > > On Mon, Apr 8, 2013 at 9:09 PM, Fabio Estevam  
> > > > wrote:
> > > > 
> > > > >> I know that I have to use the driver ULPI but with my configuration, 
> > > > >> I
> > > > >> get these errors :
> > > > >> "
> > > > >> ehci-mxc: Freescale On-Chip EHCI Host driver
> > > > >> mxc-ehci mxc-ehci.0: initializing i.MX USB Controller
> > > > >> timeout polling for ULPI device
> > > > >> mxc-ehci mxc-ehci.0: unable to init transceiver, probably missing
> > > > 
> > > > Just tested mx31pdk on a 3.8.6 kernel and I got:
> > > > 
> > > > ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
> > > > ehci-mxc: Freescale On-Chip EHCI Host driver
> > > > mxc-ehci mxc-ehci.0: initializing i.MX USB Controller
> > > > ULPI transceiver vendor/product ID 0x04cc/0x1504
> > > > Found NXP ISP1504 ULPI transceiver.
> > > > ULPI integrity check: passed.
> > > > mxc-ehci mxc-ehci.0: EHCI Host Controller
> > > > mxc-ehci mxc-ehci.0: new USB bus registered, assigned bus number 1
> > > > mxc-ehci mxc-ehci.0: irq 53, io mem 0x43f88000
> > > > mxc-ehci mxc-ehci.0: USB 2.0 started, EHCI 1.00
> > > > hub 1-0:1.0: USB hub found
> > > > hub 1-0:1.0: 1 port detected
> > > > mxc-ehci mxc-ehci.2: initializing i.MX USB Controller
> > > > timeout polling for ULPI device
> > > > mxc-ehci mxc-ehci.2: unable to init transceiver, probably missing
> > > 
> > > Any updates on this?
> > > 
> > > I'm facing the same kind of issue with an SMSC3340 phy connected to an
> > > imx.27: After some minutes in power-off state, the first boot fails to
> > > detect the ULPI device connected to USBOTG-Pins, no matter if host- or
> > > device-mode is configured.
> > > But the strange thing is that then, after a reboot or reset the phy gets
> > > detected.
> > > 
> > are you sure some pins on the ULPI interface don't change their level
> > between the time where you release the PHY's reset and when the ULPI
> > access occurs ?
> 
> I'm pretty sure that there are, but not intended by software I could
> control (bootloader+kernel).
> 
from memory we had this problem with ISP1504 a few years ago and this
only real fix was to switch to an other PHY with a reset to unlock it
when bad things happen.

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: [PATCH v2 2/2] USB: unexport usb_bus_list_lock and update comments

2013-09-26 Thread Greg Kroah-Hartman
On Fri, Sep 13, 2013 at 01:57:42PM -0600, Bjorn Helgaas wrote:
> usb_bus_list_lock is used by usbfs, but that's in the same module as
> hcd.c, so there's no need to export it.  Update the comment to show
> that it protects the set of root hubs as well as the list of buses.

usbmon also uses this, so this patch breaks the build:

ERROR: "usb_bus_list_lock" [drivers/usb/mon/usbmon.ko] undefined!

So I can't take this patch, sorry.

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 V5 1/9] USB: OHCI: make ohci-exynos a separate driver

2013-09-26 Thread Greg KH
On Sat, Sep 21, 2013 at 04:38:38PM +0530, Manjunath Goudar wrote:
> Separate the  Samsung OHCI EXYNOS host controller driver from ohci-hcd
> host code so that it can be built as a separate driver module.
> This work is part of enabling multi-platform kernels on ARM.
> 
> Signed-off-by: Manjunath Goudar 
> Signed-off-by: Deepak Saxena 
> Acked-by: Alan Stern 
> Acked-by: Jingoo Han 
> Cc: Vivek Gautam 
> Cc: Arnd Bergmann 
> Cc: Kukjin Kim 
> Cc: Greg KH 
> Cc: linux-usb@vger.kernel.org
> 
> V2->V3:
>  -No major changes only "exynos" written in capital letters
>   in "OHCI exynos driver".
> 
> V1->V2:
>  -exynos_ohci_hcd structure assignment error fixed.
>  -Removed multiple usb_create_hcd() from prob funtion.
>  -platform_set_drvdata() called before exynos_ohci_phy_enable().
>  -ohci_setup() removed because it is called in .reset member
>   of the ohci_hc_driver structure
> ---

In the future, these "version" lines need to go below the cut ("---"),
not above it, as I need to edit these patches by hand to remove them now
:(

thanks,

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


Re: [PATCH v2 2/2] USB: unexport usb_bus_list_lock and update comments

2013-09-26 Thread Bjorn Helgaas
On Thu, Sep 26, 2013 at 10:45 AM, Greg Kroah-Hartman
 wrote:
> On Fri, Sep 13, 2013 at 01:57:42PM -0600, Bjorn Helgaas wrote:
>> usb_bus_list_lock is used by usbfs, but that's in the same module as
>> hcd.c, so there's no need to export it.  Update the comment to show
>> that it protects the set of root hubs as well as the list of buses.
>
> usbmon also uses this, so this patch breaks the build:
>
> ERROR: "usb_bus_list_lock" [drivers/usb/mon/usbmon.ko] undefined!

Oops, sorry, I should have noticed that, sorry.

Bjorn
--
To unsubscribe from this list: send the line "unsubscribe 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 v11 2/8] usb: phy: omap-usb2: use the new generic PHY framework

2013-09-26 Thread Greg KH
On Wed, Aug 21, 2013 at 11:16:07AM +0530, Kishon Vijay Abraham I wrote:
> Used the generic PHY framework API to create the PHY. Now the power off and
> power on are done in omap_usb_power_off and omap_usb_power_on respectively.
> The omap-usb2 driver is also moved to driver/phy.
> 
> However using the old USB PHY library cannot be completely removed
> because OTG is intertwined with PHY and moving to the new framework
> will break OTG. Once we have a separate OTG state machine, we
> can get rid of the USB PHY library.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> Reviewed-by: Sylwester Nawrocki 
> Acked-by: Felipe Balbi 
> ---
>  drivers/phy/Kconfig   |   12 +
>  drivers/phy/Makefile  |1 +
>  drivers/{usb => }/phy/phy-omap-usb2.c |   45 
> ++---
>  drivers/usb/phy/Kconfig   |   10 
>  drivers/usb/phy/Makefile  |1 -
>  5 files changed, 54 insertions(+), 15 deletions(-)
>  rename drivers/{usb => }/phy/phy-omap-usb2.c (88%)

I tried to apply this to my USB branch, but it fails.

Kishon, you were going to refresh this patch series, right?  Please do,
because as-is, I can't take it.

thanks,

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


[PATCH 0/4] usb: wusbcore: resource cleanup fixes

2013-09-26 Thread Thomas Pugliese
This set of patches fixes a few cases where objects were being 
incompletely cleaned up by error handlers which could cause double free 
conditions or NULL dereferences in those cases.  There is also a memory 
leak fix for out transfers on the HWA.

These should be applied after the struct field rename patches I sent 
earlier since this set references some of those renamed objects.

Thomas Pugliese (4):
  usb: wusbcore: allow wa_xfer_destroy to clean up partially
constructed xfers
  usb: wusbcore: resource cleanup fix in __wa_xfer_setup_segs
  usb: wusbcore: clean up the sg list that was created for out
transfers
  usb: wusbcore: set pointers to NULL after freeing in error cases

 drivers/usb/wusbcore/wa-xfer.c |  137 
 1 file changed, 81 insertions(+), 56 deletions(-)

-- 
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 1/4] usb: wusbcore: allow wa_xfer_destroy to clean up partially constructed xfers

2013-09-26 Thread Thomas Pugliese
If __wa_xfer_setup fails, it can leave a partially constructed wa_xfer
object.  The error handling code eventually calls wa_xfer_destroy which
does not check for NULL before dereferencing xfer->seg which could cause
a kernel panic.  This change also makes sure to free xfer->seg which was
being leaked for all transfers before this change.

Signed-off-by: Thomas Pugliese 
---
 drivers/usb/wusbcore/wa-xfer.c |   10 --
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 11d684c..dfb11bf 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -178,9 +178,15 @@ static void wa_xfer_destroy(struct kref *_xfer)
if (xfer->seg) {
unsigned cnt;
for (cnt = 0; cnt < xfer->segs; cnt++) {
-   usb_free_urb(xfer->seg[cnt]->dto_urb);
-   usb_free_urb(&xfer->seg[cnt]->tr_urb);
+   if (xfer->seg[cnt]) {
+   if (xfer->seg[cnt]->dto_urb) {
+   kfree(xfer->seg[cnt]->dto_urb->sg);
+   usb_free_urb(xfer->seg[cnt]->dto_urb);
+   }
+   usb_free_urb(&xfer->seg[cnt]->tr_urb);
+   }
}
+   kfree(xfer->seg);
}
kfree(xfer);
 }
-- 
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 4/4] usb: wusbcore: set pointers to NULL after freeing in error cases

2013-09-26 Thread Thomas Pugliese
This patch fixes two cases where error handling code was freeing memory
but not setting the pointer to NULL.  This could lead to a double free
in the HWA shutdown code.

Signed-off-by: Thomas Pugliese 
---
 drivers/usb/wusbcore/wa-xfer.c |2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 78b7ae0..08bf21d 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -1560,6 +1560,7 @@ error_submit_buf_in:
xfer, seg_idx, result);
seg->result = result;
kfree(wa->buf_in_urb->sg);
+   wa->buf_in_urb->sg = NULL;
 error_sg_alloc:
__wa_xfer_abort(xfer);
 error_complete:
@@ -1861,6 +1862,7 @@ out:
 
 error_dti_urb_submit:
usb_put_urb(wa->buf_in_urb);
+   wa->buf_in_urb = NULL;
 error_buf_in_urb_alloc:
usb_put_urb(wa->dti_urb);
wa->dti_urb = NULL;
-- 
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 3/4] usb: wusbcore: clean up the sg list that was created for out transfers

2013-09-26 Thread Thomas Pugliese
Clean up the SG list after transfer completetion for out transfers if one
was created by the HWA.

Signed-off-by: Thomas Pugliese 
---
 drivers/usb/wusbcore/wa-xfer.c |4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 4531752..78b7ae0 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -520,6 +520,10 @@ static void wa_seg_dto_cb(struct urb *urb)
unsigned rpipe_ready = 0;
u8 done = 0;
 
+   /* free the sg if it was used. */
+   kfree(urb->sg);
+   urb->sg = NULL;
+
switch (urb->status) {
case 0:
spin_lock_irqsave(&xfer->lock, flags);
-- 
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 2/4] usb: wusbcore: resource cleanup fix in __wa_xfer_setup_segs

2013-09-26 Thread Thomas Pugliese
This patch updates __wa_xfer_setup_segs error path to only clean up the
xfer->seg entry that it failed to create and then set that entry to
NULL.  wa_xfer_destroy will clean up the remaining xfer->segs that were
fully created.  It also moves the code to create the dto sg list to an
out of line function to make __wa_xfer_setup_segs easier to read.  Prior
to this change, __wa_xfer_setup_segs would clean up all entries in the
xfer->seg array in case of an error but it did not set them to NULL.
This resulted in a double free when wa_xfer_destroy was eventually
called by the higher level error handler.

Signed-off-by: Thomas Pugliese 
---
 drivers/usb/wusbcore/wa-xfer.c |  121 ++--
 1 file changed, 67 insertions(+), 54 deletions(-)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index dfb11bf..4531752 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -635,9 +635,11 @@ static void wa_seg_tr_cb(struct urb *urb)
}
 }
 
-/* allocate an SG list to store bytes_to_transfer bytes and copy the
+/*
+ * Allocate an SG list to store bytes_to_transfer bytes and copy the
  * subset of the in_sg that matches the buffer subset
- * we are about to transfer. */
+ * we are about to transfer.
+ */
 static struct scatterlist *wa_xfer_create_subset_sg(struct scatterlist *in_sg,
const unsigned int bytes_transferred,
const unsigned int bytes_to_transfer, unsigned int *out_num_sgs)
@@ -716,6 +718,55 @@ static struct scatterlist *wa_xfer_create_subset_sg(struct 
scatterlist *in_sg,
 }
 
 /*
+ * Populate buffer ptr and size, DMA buffer or SG list for the dto urb.
+ */
+static int __wa_populate_dto_urb(struct wa_xfer *xfer,
+   struct wa_seg *seg, size_t buf_itr_offset, size_t buf_itr_size)
+{
+   int result = 0;
+
+   if (xfer->is_dma) {
+   seg->dto_urb->transfer_dma =
+   xfer->urb->transfer_dma + buf_itr_offset;
+   seg->dto_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+   seg->dto_urb->sg = NULL;
+   seg->dto_urb->num_sgs = 0;
+   } else {
+   /* do buffer or SG processing. */
+   seg->dto_urb->transfer_flags &=
+   ~URB_NO_TRANSFER_DMA_MAP;
+   /* this should always be 0 before a resubmit. */
+   seg->dto_urb->num_mapped_sgs = 0;
+
+   if (xfer->urb->transfer_buffer) {
+   seg->dto_urb->transfer_buffer =
+   xfer->urb->transfer_buffer +
+   buf_itr_offset;
+   seg->dto_urb->sg = NULL;
+   seg->dto_urb->num_sgs = 0;
+   } else {
+   seg->dto_urb->transfer_buffer = NULL;
+
+   /*
+* allocate an SG list to store seg_size bytes
+* and copy the subset of the xfer->urb->sg that
+* matches the buffer subset we are about to
+* read.
+*/
+   seg->dto_urb->sg = wa_xfer_create_subset_sg(
+   xfer->urb->sg,
+   buf_itr_offset, buf_itr_size,
+   &(seg->dto_urb->num_sgs));
+   if (!(seg->dto_urb->sg))
+   result = -ENOMEM;
+   }
+   }
+   seg->dto_urb->transfer_buffer_length = buf_itr_size;
+
+   return result;
+}
+
+/*
  * Allocate the segs array and initialize each of them
  *
  * The segments are freed by wa_xfer_destroy() when the xfer use count
@@ -762,48 +813,13 @@ static int __wa_xfer_setup_segs(struct wa_xfer *xfer, 
size_t xfer_hdr_size)
usb_sndbulkpipe(usb_dev,
dto_epd->bEndpointAddress),
NULL, 0, wa_seg_dto_cb, seg);
-   if (xfer->is_dma) {
-   seg->dto_urb->transfer_dma =
-   xfer->urb->transfer_dma + buf_itr;
-   seg->dto_urb->transfer_flags |=
-   URB_NO_TRANSFER_DMA_MAP;
-   seg->dto_urb->transfer_buffer = NULL;
-   seg->dto_urb->sg = NULL;
-   seg->dto_urb->num_sgs = 0;
-   } else {
-   /* do buffer or SG processing. */
-   seg->dto_urb->transfer_flags &=
-   ~URB_NO_TRANSFER_DMA_MAP;
-   /* this should always be 0 before a resubmit. */
-   seg->dto_urb->num_mapped_sgs = 0;
-
-   if (xfer->urb->transfer_buffer) {
-   seg->dto

[PATCH] usb: dwc3: add support for Merrifield

2013-09-26 Thread David Cohen
Add PCI id for Intel Merrifield

Signed-off-by: David Cohen 
---
 drivers/usb/dwc3/dwc3-pci.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index 997ebe4..2e252aa 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -29,6 +29,7 @@
 #define PCI_VENDOR_ID_SYNOPSYS 0x16c3
 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB30xabcd
 #define PCI_DEVICE_ID_INTEL_BYT0x0f37
+#define PCI_DEVICE_ID_INTEL_MRFLD  0x119e
 
 struct dwc3_pci {
struct device   *dev;
@@ -189,6 +190,7 @@ static DEFINE_PCI_DEVICE_TABLE(dwc3_pci_id_table) = {
PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3),
},
{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_BYT), },
+   { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MRFLD), },
{  }/* Terminating Entry */
 };
 MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table);
-- 
1.8.4.rc3

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


Re: [PATCH] usb: dwc3: add support for Merrifield

2013-09-26 Thread Greg KH
On Thu, Sep 26, 2013 at 01:01:44PM -0700, David Cohen wrote:
> Add PCI id for Intel Merrifield
> 
> Signed-off-by: David Cohen 
> ---
>  drivers/usb/dwc3/dwc3-pci.c | 2 ++
>  1 file changed, 2 insertions(+)

Nice, Felipe, mind if I just pick this up now, as I'm applying USB
patches at the moment...

David, this should go to older kernels as well, right?

thanks,

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


Re: [PATCH 00/51] DMA mask changes

2013-09-26 Thread Rafał Miłecki
2013/9/19 Russell King - ARM Linux :
> This email is only being sent to the mailing lists in question, not to
> anyone personally.  The list of individuals is far to great to do that.
> I'm hoping no mailing lists reject the patches based on the number of
> recipients.

Huh, I think it was enough to send only 3 patches to the b43-dev@. Like:
[PATCH 01/51] DMA-API: provide a helper to set both DMA and coherent DMA masks
[PATCH 14/51] DMA-API: net: b43: (...)
[PATCH 15/51] DMA-API: net: b43legacy: (...)
;)

I believe Joe has some nice script for doing it that way. When fixing
some coding style / formatting, he sends only related patches to the
given ML.

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


Re: [PATCH] usb: dwc3: add support for Merrifield

2013-09-26 Thread David Cohen

Hi Greg,

On 09/26/2013 01:14 PM, Greg KH wrote:

On Thu, Sep 26, 2013 at 01:01:44PM -0700, David Cohen wrote:

Add PCI id for Intel Merrifield

Signed-off-by: David Cohen 
---
  drivers/usb/dwc3/dwc3-pci.c | 2 ++
  1 file changed, 2 insertions(+)


Nice, Felipe, mind if I just pick this up now, as I'm applying USB
patches at the moment...

David, this should go to older kernels as well, right?


This was first tested on kernel 3.10. So I can't ack any older kernel at 
this moment.


Br, David Cohen



thanks,

greg k-h



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


Re: [PATCH] usb: dwc3: add support for Merrifield

2013-09-26 Thread Greg KH
On Thu, Sep 26, 2013 at 01:39:04PM -0700, David Cohen wrote:
> Hi Greg,
> 
> On 09/26/2013 01:14 PM, Greg KH wrote:
> >On Thu, Sep 26, 2013 at 01:01:44PM -0700, David Cohen wrote:
> >>Add PCI id for Intel Merrifield
> >>
> >>Signed-off-by: David Cohen 
> >>---
> >>  drivers/usb/dwc3/dwc3-pci.c | 2 ++
> >>  1 file changed, 2 insertions(+)
> >
> >Nice, Felipe, mind if I just pick this up now, as I'm applying USB
> >patches at the moment...
> >
> >David, this should go to older kernels as well, right?
> 
> This was first tested on kernel 3.10. So I can't ack any older
> kernel at this moment.

3.10+ is good enough for me, that's all that really has dwc3 support
anyway that I care about :)

thanks,

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


Re: [PATCH v2 2/2] USB: unexport usb_bus_list_lock and update comments

2013-09-26 Thread Alan Stern
On Thu, 26 Sep 2013, Bjorn Helgaas wrote:

> On Thu, Sep 26, 2013 at 10:45 AM, Greg Kroah-Hartman
>  wrote:
> > On Fri, Sep 13, 2013 at 01:57:42PM -0600, Bjorn Helgaas wrote:
> >> usb_bus_list_lock is used by usbfs, but that's in the same module as
> >> hcd.c, so there's no need to export it.  Update the comment to show
> >> that it protects the set of root hubs as well as the list of buses.
> >
> > usbmon also uses this, so this patch breaks the build:
> >
> > ERROR: "usb_bus_list_lock" [drivers/usb/mon/usbmon.ko] undefined!
> 
> Oops, sorry, I should have noticed that, sorry.

Me too.  :-(

I guess the comment in the definition needs to be changed.  It should 
say that usb_bus_list_lock is exported for usbmon, not usbfs.

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: EHCI bus glue driver works for storage, fails for a WiFi module

2013-09-26 Thread Arokux X
Dear Alan,

thank you very much for your reply. It was very encouraging. I am
totally new to kernel development and it took me quite some time to
gather all the bits needed for this simple glue driver.

On Tue, Sep 24, 2013 at 5:22 PM, Alan Stern  wrote:
> On Mon, 23 Sep 2013, Arokux X wrote:
>
>> Hi,
>>
>> recently I was working on porting EHCI HCD bus glue driver from the
>> vendors kernel tree to the mainline [1]. I've got the storage (USB
>> stick and USB external hard drive) working and was happy. However it
>> does not work completely. Specifically something goes wrong if WiFi
>> module is talked to. This WiFi module is on-board and connected
>> through USB. The WiFi module is correctly identified and the rtl8192cu
>> driver manages to output something, but issuing
>>
>> ip link set wlan0 up
>>
>> will cause an error, see the output of the dmesg [2].
>>
>> Note, the same hardware works with vendor's tree EHCI bus glue driver
>> and rtl8192cu, so hardware is ok.
>>
>> Maybe using a fact that my driver works for the storage but fails for
>> the WiFi module you could help me identify the problem in it?
>
> Nope.  Not without comparing it to the vendor's driver.

I have done something simple, but reliable now. I have stripped the
vendors driver, so that it had only ~230 LOC. This driver was still
fully functional and wifi module worked. Then I carefully implanted it
into the mainline kernel, making only minimal changes to it.
Afterwards I tried to

ip link set wlan0 up

and saw exactly same errors in kernel log as with my driver (lots of
detected XactErr len 0/0 retry). This suggest the problem might be
elsewhere, for example in the wifi driver. To eliminate this unknown
I've used the wifi driver from 3.10 backports (not the latest
mainline) in the vendors tree (it is based on 3.4). The wifi module
still worked. So again - the problem is elsewhere. This time however I
do not know what to look for. I hope you can help.

The ARM SoC I am working on is Allwinner A10 aka sun4i. It belongs to
sunxi family. Not very much was mainlined so far. Some people have
suggested the missing DMA bits can be what causes the problem. I have
discovered the usb stack uses DMA too, since I assign dma_mask. The
vendors DMA driver that is used for my SoC is here [0].

Do you think the absence of the DMA support is what causing the
problem? Can I somehow check it? If not, what else could be?

Additionally I have gathered logs with usbmon. The working.mon.out [1]
is from the legacy 3.4 vendor's kernel. The not-working.mon.out [2] is
the output I get with my driver. Maybe these logs can give some clue
too.

>> By the way, the output of the lsusb - looks identical in both
>> cases (with my driver and vendor's) [3].
>
> One problem is the part of the patch that changes ehci-hcd.c.  That
> hunk should be removed (it caused the "Error: Driver 'sunxi-ehci' is
> already registered, aborting..." message at timestamp 0.781332 in your
> log).
>
> If usb_add_hcd() fails, you don't call sunxi_ehci_disable().
>
> There's another problem in sunxi_ehci_remove().  The routine accesses
> sunxi_ehci after it has been deallocated by the call to usb_put_hcd().

Yes, thank you.

> The line where sunxi_ehci_init_module() assigns a string to
> sunxi_ehci_hc_driver.product_desc should be removed.

I have found some discussion about this and now I understand why it
should be removed. Originally I was confused because OHCI overrides
allow you to specify product_desc. Now I assume it is a historical
leftover. Perhaps you want to unify this with EHCI drivers? If so, I
could submit a patch.

> What is the meaning of the "FIXME: Should there be two of those?"
> comment on line 215?  Two of what?

Two instances of the structure hc_driver. So rephrasing, is one
instance of the hc_driver enough to manage two EHCI controllers?

The new code with applied corrections can be found at [3], the whole
branch with dt bindings at [4]. Once the wifi problem is solved and
enough usb devices are tested I'll submit patches.

Best regards,
Arokux

[0] 
https://github.com/linux-sunxi/linux-sunxi/blob/sunxi-3.4/arch/arm/plat-sunxi/dma.c
[1] https://www.dropbox.com/s/lpvp4jhsm4ki2tv/working.mon.out
[2] https://www.dropbox.com/s/hdu0dfdowofx737/not-working.mon.out
[3] 
https://github.com/arokux/linux/commit/c86e622367769173f8cf0e1af132d7ae9b3ee727
[4] https://github.com/arokux/linux
--
To unsubscribe from this list: send the line "unsubscribe 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 0/2] USB 2.0 Link PM is broken

2013-09-26 Thread Sarah Sharp
On Tue, Sep 24, 2013 at 08:22:31PM -0700, Julius Werner wrote:
> > My hypothesis is that the Synopsys host doesn't go into L1 if the device
> > NAKs a transfer, only when the bus is idle.  That way, it doesn't have
> > to depend on L1 remote wakeup, which is broken for these devices.  I
> > don't have a way to confirm that though.  Paul, is the Synopsys host
> > working around these broken devices?
> 
> I think the device actually NAKs the IN transfer of the MSC command in
> my test, the same way it does on Haswell. It does go into L1, but then
> there is a resume just a few dozen microseconds later. Unfortunately
> its very hard to differentiate between device and host-initiated
> resume in USB 2.0... but maybe the Synopsys controller just wakes
> stuff up on its own in some circumstances? There doesn't seem to be a
> clear guideline in the spec for when to trigger a host-initiated
> resume, so maybe they just do it whenever there are transfers queued
> up for a slot or something.
> 
> Also, I only know that the device doesn't fail, I'm not that convinced
> that the LPM really works as it should. I see a lot of L1-suspends
> that only last for a few dozen microseconds (and the resume signalling
> after that takes more than a millisecond), which probably doesn't
> really save power. In some of those cases the host waits a few frames
> before scheduling a new command after resume, which suggests that the
> wakeup was earlier than necessary.

That behavior was seen on the Synopsys host, not the Intel host,
correct?

> > I do want to allow the Synopsys host to have USB 2.0 Link PM enabled if
> > the host has a way to work around these broken devices.  Paul and
> > Julius, let's work out a solution to do this on top of these patches.
> > I suspect that the solution may be to add an update_device method to
> > xhci-plat that sets udev->usb2_hw_lpm_allowed, calls xhci_update_device,
> > and then calls usb_set_usb2_hardware_lpm().  We'll have to wait for the
> > updated patches from Mathias though.
> 
> I'm not sure if it's necessary to make this decision in the kernel,
> since this seems to be very specific to a particular controller (we
> maybe should try out some external PCI controllers if anyone has one).
> I would be fine with just turning this on from user-space as we
> already do with autosuspend, where we can implement arbitrary policies
> for any particular HC/device combination.

Ok.  Mathias has a patch to enable it for internal devices and BESL
devices.  I'll send out the updated patchset shortly.  Can you run lsusb
on your Intel system, and see if the webcam supports Link PM?  If so, it
would be great if you could add the patches, disable auto-suspend, and
double check that the latest version of lsusb shows that the device goes
into L1.  I don't have access to a system today or tomorrow, but I can
check next week if necessary.

The lsusb you use to check L1 status should have this commit, which was
recently added:

commit 781622ddaf99b5071eace2850b4359cba6ccb299
Author: Alexandra Yates 
Date:   Wed Aug 7 16:45:50 2013 -0700

lsusb: Reports if USB2.0 port is on L1 state

This patch reports the low power state L1 for ports with attahced USB2
devices.  The output will be part of the roothub port status as follows:

 ayates@magd:~$ sudo lsusb -v -s 001:001
 Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
 ...
 Hub Descriptor:
   bLength  11
   bDescriptorType  41
   nNbrPorts 9
   wHubCharacteristic 0x000a
 No power switching (usb 1.0)
 Per-port overcurrent protection
 TT think time 8 FS bits
   bPwrOn2PwrGood   10 * 2 milli seconds
   bHubContrCurrent  0 milli Ampere
   DeviceRemovable0x68 0x02
   PortPwrCtrlMask0xff 0xff
  Hub Port Status:
Port 1: .0103 power enable
Port 2: .0523 highspeed power L1 enable
Port 3: .0100 power
Port 4: .0100 power
Port 5: .0503 highspeed power enable
Port 6: .0100 power
Port 7: .0100 power
Port 8: .0100 power
Port 9: .0100 power
 Device Status: 0x0001
  
In this example port id: .0523 is in L1 status.
This output is collected from testing the change on a HSWULT platform.

Signed-off-by: Alexandra Yates 
Signed-off-by: Greg Kroah-Hartman 

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 0/2] USB 2.0 Link PM is broken

2013-09-26 Thread Julius Werner
> That behavior was seen on the Synopsys host, not the Intel host,
> correct?

Yes. Looks like the L1 transitions that are not fatal on the Intel
host are much longer in my trace, usually above 100ms. This would be
another indication that in the Synopsys case the L1 resume is
host-triggered.

> Ok.  Mathias has a patch to enable it for internal devices and BESL
> devices.  I'll send out the updated patchset shortly.  Can you run lsusb
> on your Intel system, and see if the webcam supports Link PM?  If so, it
> would be great if you could add the patches, disable auto-suspend, and
> double check that the latest version of lsusb shows that the device goes
> into L1.  I don't have access to a system today or tomorrow, but I can
> check next week if necessary.

Unfortunately, none of the internal devices on our current Haswell
system support LPM. Our firmware also doesn't set the right ACPI table
entries to mark ports as removable. I think the easiest way to verify
your patch would be a small kernel hack that would force an inserted
device to look non-removable.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


rndis_host: rndis device enumeration

2013-09-26 Thread Bin Liu
Hi,

Sorry if I missed any previous discussion on this topic.

The msdn link [1] says that

The host does not continuously poll the USB Control endpoint for input
control messages. Upon placing a control message on its Control
endpoint, the device must return a notification on the Communication
Class interface's Interrupt IN endpoint, which is polled by the host
whenever the device can return control messages.

Which means the following transfer sequence from the host:

- SETUP xfer: SET_ENCAPSULATED_COMMAND
- INT xfer
- SETUP xfer: GET_ENCAPSULATED_RESPONSE

But in rndis_command() in rndis_host.c, the INT xfer between
SET_ENCAPSULATED_COMMAND and GET_ENCAPSULATED_RESPONSE has a if
condition check, so the INT xfer is not sent for some (most) rndis
devices.

Is there any reason why the INT xfer has this if condition?

Thanks,
-Bin.

[1]: http://msdn.microsoft.com/en-us/library/aa447434.aspx
--
To unsubscribe from this list: send the line "unsubscribe 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 31/51] DMA-API: media: omap3isp: use dma_coerce_mask_and_coherent()

2013-09-26 Thread Laurent Pinchart
Hi Russell,

Thank you for the patch.

On Thursday 19 September 2013 22:56:02 Russell King wrote:
> The code sequence:
>   isp->raw_dmamask = DMA_BIT_MASK(32);
>   isp->dev->dma_mask = &isp->raw_dmamask;
>   isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
> bypasses the architectures check on the DMA mask.  It can be replaced
> with dma_coerce_mask_and_coherent(), avoiding the direct initialization
> of this mask.
> 
> Signed-off-by: Russell King 

Acked-by: Laurent Pinchart 

> ---
>  drivers/media/platform/omap3isp/isp.c |6 +++---
>  drivers/media/platform/omap3isp/isp.h |3 ---
>  2 files changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/media/platform/omap3isp/isp.c
> b/drivers/media/platform/omap3isp/isp.c index df3a0ec..1c36080 100644
> --- a/drivers/media/platform/omap3isp/isp.c
> +++ b/drivers/media/platform/omap3isp/isp.c
> @@ -2182,9 +2182,9 @@ static int isp_probe(struct platform_device *pdev)
>   isp->pdata = pdata;
>   isp->ref_count = 0;
> 
> - isp->raw_dmamask = DMA_BIT_MASK(32);
> - isp->dev->dma_mask = &isp->raw_dmamask;
> - isp->dev->coherent_dma_mask = DMA_BIT_MASK(32);
> + ret = dma_coerce_mask_and_coherent(isp->dev, DMA_BIT_MASK(32));
> + if (ret)
> + return ret;
> 
>   platform_set_drvdata(pdev, isp);
> 
> diff --git a/drivers/media/platform/omap3isp/isp.h
> b/drivers/media/platform/omap3isp/isp.h index cd3eff4..ce65d3a 100644
> --- a/drivers/media/platform/omap3isp/isp.h
> +++ b/drivers/media/platform/omap3isp/isp.h
> @@ -152,7 +152,6 @@ struct isp_xclk {
>   * @mmio_base_phys: Array with physical L4 bus addresses for ISP register
>   *  regions.
>   * @mmio_size: Array with ISP register regions size in bytes.
> - * @raw_dmamask: Raw DMA mask
>   * @stat_lock: Spinlock for handling statistics
>   * @isp_mutex: Mutex for serializing requests to ISP.
>   * @crashed: Bitmask of crashed entities (indexed by entity ID)
> @@ -190,8 +189,6 @@ struct isp_device {
>   unsigned long mmio_base_phys[OMAP3_ISP_IOMEM_LAST];
>   resource_size_t mmio_size[OMAP3_ISP_IOMEM_LAST];
> 
> - u64 raw_dmamask;
> -
>   /* ISP Obj */
>   spinlock_t stat_lock;   /* common lock for statistic drivers */
>   struct mutex isp_mutex; /* For handling ref_count field */
-- 
Regards,

Laurent Pinchart

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


[PATCH v12 1/7] drivers: phy: add generic PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
The PHY framework provides a set of APIs for the PHY drivers to
create/destroy a PHY and APIs for the PHY users to obtain a reference to the
PHY with or without using phandle. For dt-boot, the PHY drivers should
also register *PHY provider* with the framework.

PHY drivers should create the PHY by passing id and ops like init, exit,
power_on and power_off. This framework is also pm runtime enabled.

The documentation for the generic PHY framework is added in
Documentation/phy.txt and the documentation for dt binding can be found at
Documentation/devicetree/bindings/phy/phy-bindings.txt

Cc: Tomasz Figa 
Cc: Greg Kroah-Hartman 
Signed-off-by: Kishon Vijay Abraham I 
Acked-by: Felipe Balbi 
Tested-by: Sylwester Nawrocki 
---
 .../devicetree/bindings/phy/phy-bindings.txt   |   66 ++
 Documentation/phy.txt  |  166 +
 MAINTAINERS|8 +
 drivers/Kconfig|2 +
 drivers/Makefile   |2 +
 drivers/phy/Kconfig|   18 +
 drivers/phy/Makefile   |5 +
 drivers/phy/phy-core.c |  698 
 include/linux/phy/phy.h|  270 
 9 files changed, 1235 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-bindings.txt
 create mode 100644 Documentation/phy.txt
 create mode 100644 drivers/phy/Kconfig
 create mode 100644 drivers/phy/Makefile
 create mode 100644 drivers/phy/phy-core.c
 create mode 100644 include/linux/phy/phy.h

diff --git a/Documentation/devicetree/bindings/phy/phy-bindings.txt 
b/Documentation/devicetree/bindings/phy/phy-bindings.txt
new file mode 100644
index 000..8ae844f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-bindings.txt
@@ -0,0 +1,66 @@
+This document explains only the device tree data binding. For general
+information about PHY subsystem refer to Documentation/phy.txt
+
+PHY device node
+===
+
+Required Properties:
+#phy-cells:Number of cells in a PHY specifier;  The meaning of all those
+   cells is defined by the binding for the phy node. The PHY
+   provider can use the values in cells to find the appropriate
+   PHY.
+
+For example:
+
+phys: phy {
+compatible = "xxx";
+reg = <...>;
+.
+.
+#phy-cells = <1>;
+.
+.
+};
+
+That node describes an IP block (PHY provider) that implements 2 different 
PHYs.
+In order to differentiate between these 2 PHYs, an additonal specifier should 
be
+given while trying to get a reference to it.
+
+PHY user node
+=
+
+Required Properties:
+phys : the phandle for the PHY device (used by the PHY subsystem)
+phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phys* phandle
+
+Example 1:
+usb1: usb_otg_ss@xxx {
+compatible = "xxx";
+reg = ;
+.
+.
+phys = <&usb2_phy>, <&usb3_phy>;
+phy-names = "usb2phy", "usb3phy";
+.
+.
+};
+
+This node represents a controller that uses two PHYs, one for usb2 and one for
+usb3.
+
+Example 2:
+usb2: usb_otg_ss@xxx {
+compatible = "xxx";
+reg = ;
+.
+.
+phys = <&phys 1>;
+phy-names = "usbphy";
+.
+.
+};
+
+This node represents a controller that uses one of the PHYs of the PHY provider
+device defined previously. Note that the phy handle has an additional specifier
+"1" to differentiate between the two PHYs.
diff --git a/Documentation/phy.txt b/Documentation/phy.txt
new file mode 100644
index 000..0103e4b
--- /dev/null
+++ b/Documentation/phy.txt
@@ -0,0 +1,166 @@
+   PHY SUBSYSTEM
+ Kishon Vijay Abraham I 
+
+This document explains the Generic PHY Framework along with the APIs provided,
+and how-to-use.
+
+1. Introduction
+
+*PHY* is the abbreviation for physical layer. It is used to connect a device
+to the physical medium e.g., the USB controller has a PHY to provide functions
+such as serialization, de-serialization, encoding, decoding and is responsible
+for obtaining the required data transmission rate. Note that some USB
+controllers have PHY functionality embedded into it and others use an external
+PHY. Other peripherals that use PHY include Wireless LAN, Ethernet,
+SATA etc.
+
+The intention of creating this framework is to bring the PHY drivers spread
+all over the Linux kernel to drivers/phy to increase code re-use and for
+better code maintainability.
+
+This framework will be of use only to devices that use external PHY (PHY
+functionality is not embedded within the controller).
+
+2. Registering/Unregistering the PHY provider
+
+PHY provider refers to an entity that implements one or more PHY instances.
+For the simple case where the PHY provider implements only a single instance of
+the PHY, the framework provides its own implementation of of_xlate in
+of_phy_simple_xla

[PATCH v12 5/7] ARM: dts: omap: update usb_otg_hs data

2013-09-26 Thread Kishon Vijay Abraham I
Updated the usb_otg_hs dt data to include the *phy* and *phy-names*
binding in order for the driver to use the new generic PHY framework.
Also updated the Documentation to include the binding information.
The PHY binding information can be found at
Documentation/devicetree/bindings/phy/phy-bindings.txt

Signed-off-by: Kishon Vijay Abraham I 
Acked-by: Felipe Balbi 
Acked-by: Tony Lindgren 
Reviewed-by: Sylwester Nawrocki 
---
 Documentation/devicetree/bindings/usb/omap-usb.txt |5 +
 Documentation/devicetree/bindings/usb/usb-phy.txt  |6 ++
 arch/arm/boot/dts/omap3-beagle-xm.dts  |2 ++
 arch/arm/boot/dts/omap3-evm.dts|2 ++
 arch/arm/boot/dts/omap3-overo.dtsi |2 ++
 arch/arm/boot/dts/omap4.dtsi   |3 +++
 arch/arm/boot/dts/twl4030.dtsi |1 +
 7 files changed, 21 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/omap-usb.txt 
b/Documentation/devicetree/bindings/usb/omap-usb.txt
index 9088ab0..661cb06 100644
--- a/Documentation/devicetree/bindings/usb/omap-usb.txt
+++ b/Documentation/devicetree/bindings/usb/omap-usb.txt
@@ -19,6 +19,9 @@ OMAP MUSB GLUE
  - power : Should be "50". This signifies the controller can supply up to
100mA when operating in host mode.
  - usb-phy : the phandle for the PHY device
+ - phys : the phandle for the PHY device (used by generic PHY framework)
+ - phy-names : the names of the PHY corresponding to the PHYs present in the
+   *phy* phandle.
 
 Optional properties:
  - ctrl-module : phandle of the control module this glue uses to write to
@@ -33,6 +36,8 @@ usb_otg_hs: usb_otg_hs@4a0ab000 {
num-eps = <16>;
ram-bits = <12>;
ctrl-module = <&omap_control_usb>;
+   phys = <&usb2_phy>;
+   phy-names = "usb2-phy";
 };
 
 Board specific device node entry
diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt 
b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 61496f5..c0245c8 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -5,6 +5,8 @@ OMAP USB2 PHY
 Required properties:
  - compatible: Should be "ti,omap-usb2"
  - reg : Address and length of the register set for the device.
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -16,6 +18,7 @@ usb2phy@4a0ad080 {
compatible = "ti,omap-usb2";
reg = <0x4a0ad080 0x58>;
ctrl-module = <&omap_control_usb>;
+   #phy-cells = <0>;
 };
 
 OMAP USB3 PHY
@@ -25,6 +28,8 @@ Required properties:
  - reg : Address and length of the register set for the device.
  - reg-names: The names of the register addresses corresponding to the 
registers
filled in "reg".
+ - #phy-cells: determine the number of cells that should be given in the
+   phandle while referencing this phy.
 
 Optional properties:
  - ctrl-module : phandle of the control module used by PHY driver to power on
@@ -39,4 +44,5 @@ usb3phy@4a084400 {
  <0x4a084c00 0x40>;
reg-names = "phy_rx", "phy_tx", "pll_ctrl";
ctrl-module = <&omap_control_usb>;
+   #phy-cells = <0>;
 };
diff --git a/arch/arm/boot/dts/omap3-beagle-xm.dts 
b/arch/arm/boot/dts/omap3-beagle-xm.dts
index 0c514dc..8483846 100644
--- a/arch/arm/boot/dts/omap3-beagle-xm.dts
+++ b/arch/arm/boot/dts/omap3-beagle-xm.dts
@@ -144,6 +144,8 @@
 &usb_otg_hs {
interface-type = <0>;
usb-phy = <&usb2_phy>;
+   phys = <&usb2_phy>;
+   phy-names = "usb2-phy";
mode = <3>;
power = <50>;
 };
diff --git a/arch/arm/boot/dts/omap3-evm.dts b/arch/arm/boot/dts/omap3-evm.dts
index 7d4329d..4134dd0 100644
--- a/arch/arm/boot/dts/omap3-evm.dts
+++ b/arch/arm/boot/dts/omap3-evm.dts
@@ -70,6 +70,8 @@
 &usb_otg_hs {
interface-type = <0>;
usb-phy = <&usb2_phy>;
+   phys = <&usb2_phy>;
+   phy-names = "usb2-phy";
mode = <3>;
power = <50>;
 };
diff --git a/arch/arm/boot/dts/omap3-overo.dtsi 
b/arch/arm/boot/dts/omap3-overo.dtsi
index 8f1abec..a461d2f 100644
--- a/arch/arm/boot/dts/omap3-overo.dtsi
+++ b/arch/arm/boot/dts/omap3-overo.dtsi
@@ -76,6 +76,8 @@
 &usb_otg_hs {
interface-type = <0>;
usb-phy = <&usb2_phy>;
+   phys = <&usb2_phy>;
+   phy-names = "usb2-phy";
mode = <3>;
power = <50>;
 };
diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 22d9f2b..1e8e2fe 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -520,6 +520,7 @@
compatible = "ti,omap-usb2";
reg = <0x4a0ad080 0x58>;
ctrl-module = <&omap_control_usb>;
+   #phy-cells = <0>;
};
};
 
@@ 

[PATCH v12 0/7] PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
Added a generic PHY framework that provides a set of APIs for the PHY drivers
to create/destroy a PHY and APIs for the PHY users to obtain a reference to
the PHY with or without using phandle.

This framework will be of use only to devices that uses external PHY (PHY
functionality is not embedded within the controller).

The intention of creating this framework is to bring the phy drivers spread
all over the Linux kernel to drivers/phy to increase code re-use and to
increase code maintainability.

Comments to make PHY as bus wasn't done because PHY devices can be part of
other bus and making a same device attached to multiple bus leads to bad
design.

If the PHY driver has to send notification on connect/disconnect, the PHY
driver should make use of the extcon framework. Using this susbsystem
to use extcon framwork will have to be analysed.

You can find this patch series @
git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git testing

I'll create a new branch *next* once this patch series is finalized. All the
PHY driver development that depends on PHY framework can be based on this
branch.

Did USB enumeration testing in panda and beagle after applying [1] (needed for
non-dt)

Changes from v11:
* rebased to 3.12-rc2
* dropped "usb: phy: omap-usb2: remove *set_suspend* callback from omap-usb2"
patch. It will be added in the patch series that adapts dwc3 to generic phy
framework.
* Fixed checkpatch warning that shows up newly for having extern in header file.

Changes from v10:
* fixed a mistake in devm_of_phy_provider_register macro which was carried over
from earlier version.
* used ida_simple_get for obtaining the id.

Changes from v9:
* Fixed Greg's concern on having *find PHY by string* and changed it to Tomasz
  pseudo code.
* move omap-usb2 phy and twl4030-usb phy to drivers/phy
* made all the dependent drivers select GENERIC_PHY instead of having depends
  on
* Made PHY core to assign the id's (so changed the phy_create API).
* Adapted twl4030-usb to the new design.

Changes from v8:
* Added phy_set_drvdata and phy_get_drvdata in phy.h.
* Changed phy_create API not to take void *priv. private data should now be set
  using phy_set_drvdata now.
Changes from v7:
* Fixed Documentation
* Added to_phy, of_phy_provider_register and devm_of_phy_provider_register
* modified runtime_pm usage in phy_init, phy_exit, phy_power_on and
  phy_power_off. Now phy_power_on will enable the clocks and phy_power_off will
  disable the clocks.
* pm_runtime_no_callbacks() is added so that pm_runtime_get_sync doesn't fail
* modified other patches to adhere to the changes in the PHY framework
* removed usb: phy: twl4030: twl4030 shouldn't be subsys_initcall as it will
  be merged separately.
* reference counting has been added to protect phy ops when the PHY is shared
  by multiple consumers.

Changes from v6
* corrected few typos in Documentation
* Changed PHY Subsystem to *bool* in Kconfig (to avoid compilation errors when
  PHY Subsystem is kept as module and the dependent modules are built-in)
* Added if pm_runtime_enabled check before runtime pm calls.

Changes from v5:
* removed the new sysfs entries as it dint have any new information other than
  what is already there in /sys/devices/...
* removed a bunch of APIs added to get the PHY and now only phy_get and
  devm_phy_get are used.
* Added new APIs to register/unregister the PHY provider. This is needed for
  dt boot case.
* Enabled pm runtime and incorporated the comments given by Alan Stern in a
  different patch series by Gautam.
* Removed the *phy_bind* API. Now the phy binding information should be passed
  using the platform data to the controller devices.
* Fixed a few typos.

Changes from v4:
* removed of_phy_get_with_args/devm_of_phy_get_with_args. Now the *phy 
providers*
  should use their custom implementation of of_xlate or use of_phy_xlate to get
  *phy instance* from *phy providers*.
* Added of_phy_xlate to be used by *phy providers* if it provides only one PHY.
* changed phy_core from having subsys_initcall to module_init.
* other minor fixes.

Changes from v3:
* Changed the return value of PHY APIs to ENOSYS
* Added APIs of_phy_get_with_args/devm_of_phy_get_with_args to support getting
  PHYs if the same IP implements multiple PHYs.
* modified phy_bind API so that the binding information can now be _updated_.
  In effect of this removed the binding information added in board files and
  added only in usb-musb.c. If a particular board uses a different phy binding,
  it can update it in board file after usb_musb_init().
* Added Documentation/devicetree/bindings/phy/phy-bindings.txt for dt binding
  information.

Changes from v2:
* removed phy_descriptor structure completely so changed the APIs which were
  taking phy_descriptor as parameters
* Added 2 more APIs *of_phy_get_byname* and *devm_of_phy_get_byname* to be used
  by PHY user drivers which has *phy* and *phy-names* binding in the dt data
* Fixed a few typos
* Removed phy_list an

[PATCH v12 3/7] usb: phy: twl4030: use the new generic PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
Used the generic PHY framework API to create the PHY. For powering on
and powering off the PHY, power_on and power_off ops are used. Once the
MUSB OMAP glue is adapted to the new framework, the suspend and resume
ops of usb phy library will be removed. Also twl4030-usb driver is moved
to drivers/phy/.

However using the old usb phy library cannot be completely removed
because otg is intertwined with phy and moving to the new
framework completely will break otg. Once we have a separate otg state machine,
we can get rid of the usb phy library.

Signed-off-by: Kishon Vijay Abraham I 
Acked-by: Felipe Balbi 
Reviewed-by: Sylwester Nawrocki 
---
 drivers/phy/Kconfig |   11 ++
 drivers/phy/Makefile|1 +
 drivers/{usb => }/phy/phy-twl4030-usb.c |   56 +--
 drivers/usb/phy/Kconfig |   10 --
 drivers/usb/phy/Makefile|1 -
 include/linux/i2c/twl.h |2 ++
 6 files changed, 67 insertions(+), 14 deletions(-)
 rename drivers/{usb => }/phy/phy-twl4030-usb.c (95%)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 38c3477..ac239ac 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -27,4 +27,15 @@ config OMAP_USB2
  The USB OTG controller communicates with the comparator using this
  driver.
 
+config TWL4030_USB
+   tristate "TWL4030 USB Transceiver Driver"
+   depends on TWL4030_CORE && REGULATOR_TWL4030 && USB_MUSB_OMAP2PLUS
+   select GENERIC_PHY
+   select USB_PHY
+   help
+ Enable this to support the USB OTG transceiver on TWL4030
+ family chips (including the TWL5030 and TPS659x0 devices).
+ This transceiver supports high and full speed devices plus,
+ in host mode, low speed.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index ed5b088..0dd8a98 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -4,3 +4,4 @@
 
 obj-$(CONFIG_GENERIC_PHY)  += phy-core.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
+obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
diff --git a/drivers/usb/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
similarity index 95%
rename from drivers/usb/phy/phy-twl4030-usb.c
rename to drivers/phy/phy-twl4030-usb.c
index 90730c8..d02913f 100644
--- a/drivers/usb/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -431,6 +432,14 @@ static void twl4030_phy_suspend(struct twl4030_usb *twl, 
int controller_off)
dev_dbg(twl->dev, "%s\n", __func__);
 }
 
+static int twl4030_phy_power_off(struct phy *phy)
+{
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
+
+   twl4030_phy_suspend(twl, 0);
+   return 0;
+}
+
 static void __twl4030_phy_resume(struct twl4030_usb *twl)
 {
twl4030_phy_power(twl, 1);
@@ -459,6 +468,14 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
}
 }
 
+static int twl4030_phy_power_on(struct phy *phy)
+{
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
+
+   twl4030_phy_resume(twl);
+   return 0;
+}
+
 static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
 {
/* Enable writing to power configuration registers */
@@ -602,13 +619,22 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
status = twl4030_usb_linkstat(twl);
twl->linkstat = status;
 
-   if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID)
+   if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
omap_musb_mailbox(twl->linkstat);
+   twl4030_phy_resume(twl);
+   }
 
sysfs_notify(&twl->dev->kobj, NULL, "vbus");
return 0;
 }
 
+static int twl4030_phy_init(struct phy *phy)
+{
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
+
+   return twl4030_usb_phy_init(&twl->phy);
+}
+
 static int twl4030_set_suspend(struct usb_phy *x, int suspend)
 {
struct twl4030_usb *twl = phy_to_twl(x);
@@ -646,13 +672,23 @@ static int twl4030_set_host(struct usb_otg *otg, struct 
usb_bus *host)
return 0;
 }
 
+static const struct phy_ops ops = {
+   .init   = twl4030_phy_init,
+   .power_on   = twl4030_phy_power_on,
+   .power_off  = twl4030_phy_power_off,
+   .owner  = THIS_MODULE,
+};
+
 static int twl4030_usb_probe(struct platform_device *pdev)
 {
struct twl4030_usb_data *pdata = dev_get_platdata(&pdev->dev);
struct twl4030_usb  *twl;
+   struct phy  *phy;
int status, err;
struct usb_otg  *otg;
struct device_node  *np = pdev->dev.of_node;
+   struct phy_provider *phy_provider;
+   struct phy_init_data*init_data = NULL;
 
twl = devm_kzalloc(&pdev->dev, sizeof *twl, GFP_KERNEL);
if (!twl)
@@ -661,9 +697,10 @@ static in

[PATCH v12 4/7] arm: omap3: twl: add phy consumer data in twl4030_usb_data

2013-09-26 Thread Kishon Vijay Abraham I
The PHY framework uses the phy consumer data populated in platform data in the
case of non-dt boot to return the reference to the PHY when the controller
(PHY consumer) requests for it. So populated the phy consumer data in the 
platform
data of twl usb.

Signed-off-by: Kishon Vijay Abraham I 
---
 arch/arm/mach-omap2/twl-common.c |   11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/mach-omap2/twl-common.c b/arch/arm/mach-omap2/twl-common.c
index c05898f..b0d54da 100644
--- a/arch/arm/mach-omap2/twl-common.c
+++ b/arch/arm/mach-omap2/twl-common.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -90,8 +91,18 @@ void __init omap_pmic_late_init(void)
 }
 
 #if defined(CONFIG_ARCH_OMAP3)
+struct phy_consumer consumers[] = {
+   PHY_CONSUMER("musb-hdrc.0", "usb"),
+};
+
+struct phy_init_data init_data = {
+   .consumers = consumers,
+   .num_consumers = ARRAY_SIZE(consumers),
+};
+
 static struct twl4030_usb_data omap3_usb_pdata = {
.usb_mode   = T2_USB_MODE_ULPI,
+   .init_data  = &init_data,
 };
 
 static int omap3_batt_table[] = {
-- 
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 v12 7/7] usb: phy: twl4030-usb: remove *set_suspend* and *phy_init* ops

2013-09-26 Thread Kishon Vijay Abraham I
Now that twl4030-usb is adapted to the new generic PHY framework,
*set_suspend* and *phy_init* ops can be removed from twl4030-usb driver.

Signed-off-by: Kishon Vijay Abraham I 
Acked-by: Felipe Balbi 
Reviewed-by: Sylwester Nawrocki 
---
 drivers/phy/phy-twl4030-usb.c |   57 ++---
 1 file changed, 13 insertions(+), 44 deletions(-)

diff --git a/drivers/phy/phy-twl4030-usb.c b/drivers/phy/phy-twl4030-usb.c
index d02913f..e0212d8 100644
--- a/drivers/phy/phy-twl4030-usb.c
+++ b/drivers/phy/phy-twl4030-usb.c
@@ -422,25 +422,20 @@ static void twl4030_phy_power(struct twl4030_usb *twl, 
int on)
}
 }
 
-static void twl4030_phy_suspend(struct twl4030_usb *twl, int controller_off)
+static int twl4030_phy_power_off(struct phy *phy)
 {
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
+
if (twl->asleep)
-   return;
+   return 0;
 
twl4030_phy_power(twl, 0);
twl->asleep = 1;
dev_dbg(twl->dev, "%s\n", __func__);
-}
-
-static int twl4030_phy_power_off(struct phy *phy)
-{
-   struct twl4030_usb *twl = phy_get_drvdata(phy);
-
-   twl4030_phy_suspend(twl, 0);
return 0;
 }
 
-static void __twl4030_phy_resume(struct twl4030_usb *twl)
+static void __twl4030_phy_power_on(struct twl4030_usb *twl)
 {
twl4030_phy_power(twl, 1);
twl4030_i2c_access(twl, 1);
@@ -449,11 +444,13 @@ static void __twl4030_phy_resume(struct twl4030_usb *twl)
twl4030_i2c_access(twl, 0);
 }
 
-static void twl4030_phy_resume(struct twl4030_usb *twl)
+static int twl4030_phy_power_on(struct phy *phy)
 {
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
+
if (!twl->asleep)
-   return;
-   __twl4030_phy_resume(twl);
+   return 0;
+   __twl4030_phy_power_on(twl);
twl->asleep = 0;
dev_dbg(twl->dev, "%s\n", __func__);
 
@@ -466,13 +463,6 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
cancel_delayed_work(&twl->id_workaround_work);
schedule_delayed_work(&twl->id_workaround_work, HZ);
}
-}
-
-static int twl4030_phy_power_on(struct phy *phy)
-{
-   struct twl4030_usb *twl = phy_get_drvdata(phy);
-
-   twl4030_phy_resume(twl);
return 0;
 }
 
@@ -604,9 +594,9 @@ static void twl4030_id_workaround_work(struct work_struct 
*work)
}
 }
 
-static int twl4030_usb_phy_init(struct usb_phy *phy)
+static int twl4030_phy_init(struct phy *phy)
 {
-   struct twl4030_usb *twl = phy_to_twl(phy);
+   struct twl4030_usb *twl = phy_get_drvdata(phy);
enum omap_musb_vbus_id_status status;
 
/*
@@ -621,32 +611,13 @@ static int twl4030_usb_phy_init(struct usb_phy *phy)
 
if (status == OMAP_MUSB_ID_GROUND || status == OMAP_MUSB_VBUS_VALID) {
omap_musb_mailbox(twl->linkstat);
-   twl4030_phy_resume(twl);
+   twl4030_phy_power_on(phy);
}
 
sysfs_notify(&twl->dev->kobj, NULL, "vbus");
return 0;
 }
 
-static int twl4030_phy_init(struct phy *phy)
-{
-   struct twl4030_usb *twl = phy_get_drvdata(phy);
-
-   return twl4030_usb_phy_init(&twl->phy);
-}
-
-static int twl4030_set_suspend(struct usb_phy *x, int suspend)
-{
-   struct twl4030_usb *twl = phy_to_twl(x);
-
-   if (suspend)
-   twl4030_phy_suspend(twl, 1);
-   else
-   twl4030_phy_resume(twl);
-
-   return 0;
-}
-
 static int twl4030_set_peripheral(struct usb_otg *otg,
struct usb_gadget *gadget)
 {
@@ -719,8 +690,6 @@ static int twl4030_usb_probe(struct platform_device *pdev)
twl->phy.label  = "twl4030";
twl->phy.otg= otg;
twl->phy.type   = USB_PHY_TYPE_USB2;
-   twl->phy.set_suspend= twl4030_set_suspend;
-   twl->phy.init   = twl4030_usb_phy_init;
 
otg->phy= &twl->phy;
otg->set_host   = twl4030_set_host;
-- 
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 v12 6/7] usb: musb: omap2430: use the new generic PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
Use the generic PHY framework API to get the PHY. The usb_phy_set_resume
and usb_phy_set_suspend is replaced with power_on and
power_off to align with the new PHY framework.

musb->xceiv can't be removed as of now because musb core uses xceiv.state and
xceiv.otg. Once there is a separate state machine to handle otg, these can be
moved out of xceiv and then we can start using the generic PHY framework.

Signed-off-by: Kishon Vijay Abraham I 
Reviewed-by: Sylwester Nawrocki 
Acked-by: Felipe Balbi 
---
 drivers/usb/musb/Kconfig |1 +
 drivers/usb/musb/musb_core.h |2 ++
 drivers/usb/musb/omap2430.c  |   26 --
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index c258a97..0440e28 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -75,6 +75,7 @@ config USB_MUSB_TUSB6010
 config USB_MUSB_OMAP2PLUS
tristate "OMAP2430 and onwards"
depends on ARCH_OMAP2PLUS
+   select GENERIC_PHY
 
 config USB_MUSB_AM35X
tristate "AM35x"
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 65f3917..d408a99 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -46,6 +46,7 @@
 #include 
 #include 
 #include 
+#include 
 
 struct musb;
 struct musb_hw_ep;
@@ -341,6 +342,7 @@ struct musb {
u16 int_tx;
 
struct usb_phy  *xceiv;
+   struct phy  *phy;
 
int nIrq;
unsignedirq_wake:1;
diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
index 59d2245..d0fc4d9 100644
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -348,11 +348,21 @@ static int omap2430_musb_init(struct musb *musb)
 * up through ULPI.  TWL4030-family PMICs include one,
 * which needs a driver, drivers aren't always needed.
 */
-   if (dev->parent->of_node)
+   if (dev->parent->of_node) {
+   musb->phy = devm_phy_get(dev->parent, "usb2-phy");
+
+   /* We can't totally remove musb->xceiv as of now because
+* musb core uses xceiv.state and xceiv.otg. Once we have
+* a separate state machine to handle otg, these can be moved
+* out of xceiv and then we can start using the generic PHY
+* framework
+*/
musb->xceiv = devm_usb_get_phy_by_phandle(dev->parent,
"usb-phy", 0);
-   else
+   } else {
musb->xceiv = devm_usb_get_phy_dev(dev, 0);
+   musb->phy = devm_phy_get(dev, "usb");
+   }
 
if (IS_ERR(musb->xceiv)) {
status = PTR_ERR(musb->xceiv);
@@ -364,6 +374,10 @@ static int omap2430_musb_init(struct musb *musb)
return -EPROBE_DEFER;
}
 
+   if (IS_ERR(musb->phy)) {
+   pr_err("HS USB OTG: no PHY configured\n");
+   return PTR_ERR(musb->phy);
+   }
musb->isr = omap2430_musb_interrupt;
 
status = pm_runtime_get_sync(dev);
@@ -397,7 +411,7 @@ static int omap2430_musb_init(struct musb *musb)
if (glue->status != OMAP_MUSB_UNKNOWN)
omap_musb_set_mailbox(glue);
 
-   usb_phy_init(musb->xceiv);
+   phy_init(musb->phy);
 
pm_runtime_put_noidle(musb->controller);
return 0;
@@ -460,6 +474,7 @@ static int omap2430_musb_exit(struct musb *musb)
del_timer_sync(&musb_idle_timer);
 
omap2430_low_level_exit(musb);
+   phy_exit(musb->phy);
 
return 0;
 }
@@ -638,7 +653,7 @@ static int omap2430_runtime_suspend(struct device *dev)
OTG_INTERFSEL);
 
omap2430_low_level_exit(musb);
-   usb_phy_set_suspend(musb->xceiv, 1);
+   phy_power_off(musb->phy);
}
 
return 0;
@@ -653,8 +668,7 @@ static int omap2430_runtime_resume(struct device *dev)
omap2430_low_level_init(musb);
musb_writel(musb->mregs, OTG_INTERFSEL,
musb->context.otg_interfsel);
-
-   usb_phy_set_suspend(musb->xceiv, 0);
+   phy_power_on(musb->phy);
}
 
return 0;
-- 
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 v12 2/7] usb: phy: omap-usb2: use the new generic PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
Used the generic PHY framework API to create the PHY. Now the power off and
power on are done in omap_usb_power_off and omap_usb_power_on respectively.
The omap-usb2 driver is also moved to driver/phy.

However using the old USB PHY library cannot be completely removed
because OTG is intertwined with PHY and moving to the new framework
will break OTG. Once we have a separate OTG state machine, we
can get rid of the USB PHY library.

Signed-off-by: Kishon Vijay Abraham I 
Reviewed-by: Sylwester Nawrocki 
Acked-by: Felipe Balbi 
---
 drivers/phy/Kconfig   |   12 +
 drivers/phy/Makefile  |1 +
 drivers/{usb => }/phy/phy-omap-usb2.c |   45 ++---
 drivers/usb/phy/Kconfig   |   11 
 drivers/usb/phy/Makefile  |1 -
 5 files changed, 54 insertions(+), 16 deletions(-)
 rename drivers/{usb => }/phy/phy-omap-usb2.c (88%)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 349bef2..38c3477 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -15,4 +15,16 @@ config GENERIC_PHY
  phy users can obtain reference to the PHY. All the users of this
  framework should select this config.
 
+config OMAP_USB2
+   tristate "OMAP USB2 PHY Driver"
+   depends on ARCH_OMAP2PLUS
+   select GENERIC_PHY
+   select USB_PHY
+   select OMAP_CONTROL_USB
+   help
+ Enable this to support the transceiver that is part of SOC. This
+ driver takes care of all the PHY functionality apart from comparator.
+ The USB OTG controller communicates with the comparator using this
+ driver.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 9e9560f..ed5b088 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_GENERIC_PHY)  += phy-core.o
+obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
diff --git a/drivers/usb/phy/phy-omap-usb2.c b/drivers/phy/phy-omap-usb2.c
similarity index 88%
rename from drivers/usb/phy/phy-omap-usb2.c
rename to drivers/phy/phy-omap-usb2.c
index d266861..4d7b4e5 100644
--- a/drivers/usb/phy/phy-omap-usb2.c
+++ b/drivers/phy/phy-omap-usb2.c
@@ -28,6 +28,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /**
  * omap_usb2_set_comparator - links the comparator present in the sytem with
@@ -118,10 +119,36 @@ static int omap_usb2_suspend(struct usb_phy *x, int 
suspend)
return 0;
 }
 
+static int omap_usb_power_off(struct phy *x)
+{
+   struct omap_usb *phy = phy_get_drvdata(x);
+
+   omap_control_usb_phy_power(phy->control_dev, 0);
+
+   return 0;
+}
+
+static int omap_usb_power_on(struct phy *x)
+{
+   struct omap_usb *phy = phy_get_drvdata(x);
+
+   omap_control_usb_phy_power(phy->control_dev, 1);
+
+   return 0;
+}
+
+static struct phy_ops ops = {
+   .power_on   = omap_usb_power_on,
+   .power_off  = omap_usb_power_off,
+   .owner  = THIS_MODULE,
+};
+
 static int omap_usb2_probe(struct platform_device *pdev)
 {
struct omap_usb *phy;
+   struct phy  *generic_phy;
struct usb_otg  *otg;
+   struct phy_provider *phy_provider;
 
phy = devm_kzalloc(&pdev->dev, sizeof(*phy), GFP_KERNEL);
if (!phy) {
@@ -143,6 +170,11 @@ static int omap_usb2_probe(struct platform_device *pdev)
phy->phy.otg= otg;
phy->phy.type   = USB_PHY_TYPE_USB2;
 
+   phy_provider = devm_of_phy_provider_register(phy->dev,
+   of_phy_simple_xlate);
+   if (IS_ERR(phy_provider))
+   return PTR_ERR(phy_provider);
+
phy->control_dev = omap_get_control_dev();
if (IS_ERR(phy->control_dev)) {
dev_dbg(&pdev->dev, "Failed to get control device\n");
@@ -158,6 +190,15 @@ static int omap_usb2_probe(struct platform_device *pdev)
otg->start_srp  = omap_usb_start_srp;
otg->phy= &phy->phy;
 
+   platform_set_drvdata(pdev, phy);
+   pm_runtime_enable(phy->dev);
+
+   generic_phy = devm_phy_create(phy->dev, &ops, NULL);
+   if (IS_ERR(generic_phy))
+   return PTR_ERR(generic_phy);
+
+   phy_set_drvdata(generic_phy, phy);
+
phy->wkupclk = devm_clk_get(phy->dev, "usb_phy_cm_clk32k");
if (IS_ERR(phy->wkupclk)) {
dev_err(&pdev->dev, "unable to get usb_phy_cm_clk32k\n");
@@ -173,10 +214,6 @@ static int omap_usb2_probe(struct platform_device *pdev)
 
usb_add_phy_dev(&phy->phy);
 
-   platform_set_drvdata(pdev, phy);
-
-   pm_runtime_enable(phy->dev);
-
return 0;
 }
 
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index d5589f9..508e915 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -66,17 +66,6 @@ config OMAP_CONTROL_USB
  power on the USB2 PHY is present in OMAP4 and OMAP5. OMAP5 ha

Re: [PATCH v11 2/8] usb: phy: omap-usb2: use the new generic PHY framework

2013-09-26 Thread Kishon Vijay Abraham I
Hi Greg,

On Friday 27 September 2013 12:21 AM, Greg KH wrote:
> On Wed, Aug 21, 2013 at 11:16:07AM +0530, Kishon Vijay Abraham I wrote:
>> Used the generic PHY framework API to create the PHY. Now the power off and
>> power on are done in omap_usb_power_off and omap_usb_power_on respectively.
>> The omap-usb2 driver is also moved to driver/phy.
>>
>> However using the old USB PHY library cannot be completely removed
>> because OTG is intertwined with PHY and moving to the new framework
>> will break OTG. Once we have a separate OTG state machine, we
>> can get rid of the USB PHY library.
>>
>> Signed-off-by: Kishon Vijay Abraham I 
>> Reviewed-by: Sylwester Nawrocki 
>> Acked-by: Felipe Balbi 
>> ---
>>  drivers/phy/Kconfig   |   12 +
>>  drivers/phy/Makefile  |1 +
>>  drivers/{usb => }/phy/phy-omap-usb2.c |   45 
>> ++---
>>  drivers/usb/phy/Kconfig   |   10 
>>  drivers/usb/phy/Makefile  |1 -
>>  5 files changed, 54 insertions(+), 15 deletions(-)
>>  rename drivers/{usb => }/phy/phy-omap-usb2.c (88%)
> 
> I tried to apply this to my USB branch, but it fails.
> 
> Kishon, you were going to refresh this patch series, right?  Please do,
> because as-is, I can't take it.

Just sent.

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