Re: [PATCH 2/9] ARM: dts: i.MX51: Add a second usbphy.

2014-03-10 Thread Alexander Shiyan
Понедельник, 10 марта 2014, 5:50 UTC от Peter Chen peter.c...@freescale.com:
  
   
diff --git a/arch/arm/boot/dts/imx51.dtsi
b/arch/arm/boot/dts/imx51.dtsi index e508e6f..917b6ed 100644
--- a/arch/arm/boot/dts/imx51.dtsi
+++ b/arch/arm/boot/dts/imx51.dtsi
@@ -100,6 +100,13 @@
clocks = clks IMX5_CLK_USB_PHY_GATE;
clock-names = main_clk;
};
+
+   usbphy1: usbphy@1 {
+   compatible = usb-nop-xceiv;
+   reg = 1;
+   clocks = clks IMX5_CLK_USB_PHY_GATE;
+   clock-names = main_clk;
+   };
  
   Is this the ulpi phy for host1 controller? Why the clock is the same
   with utmi phy clock for otg controller.
  
  As far as I know, for i.MX51 this is as it should be.
  
 
 Are you sure? From clock file, they are different ccm clock gate.

clk-imx51-imx53.c ? I think you confuse with i.MX50/53.

---


RE: [PATCH 2/9] ARM: dts: i.MX51: Add a second usbphy.

2014-03-10 Thread Peter Chen
 
 

 diff --git a/arch/arm/boot/dts/imx51.dtsi
 b/arch/arm/boot/dts/imx51.dtsi index e508e6f..917b6ed 100644
 --- a/arch/arm/boot/dts/imx51.dtsi
 +++ b/arch/arm/boot/dts/imx51.dtsi
 @@ -100,6 +100,13 @@
   clocks = clks IMX5_CLK_USB_PHY_GATE;
   clock-names = main_clk;
   };
 +
 + usbphy1: usbphy@1 {
 + compatible = usb-nop-xceiv;
 + reg = 1;
 + clocks = clks IMX5_CLK_USB_PHY_GATE;
 + clock-names = main_clk;
 + };
   
Is this the ulpi phy for host1 controller? Why the clock is the
same with utmi phy clock for otg controller.
  
   As far as I know, for i.MX51 this is as it should be.
  
 
  Are you sure? From clock file, they are different ccm clock gate.
 
 clk-imx51-imx53.c ? I think you confuse with i.MX50/53.
 

Yes

341 clk[IMX5_CLK_USB_PHY1_GATE] = imx_clk_gate2(usb_phy1_gate, 
usb_phy_sel, MXC_CCM_CCGR4, 10);
342 clk[IMX5_CLK_USB_PHY2_GATE] = imx_clk_gate2(usb_phy2_gate, 
usb_phy_sel, MXC_CCM_CCGR4, 12);


Re: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Emmanuel Grumbach
Hi,

On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
How do you disable WiFi? Rfkill or removing iwlwifi?


 lspci -vnn output:
 ..
 sniped
 ..
 00:1d.0 USB controller: Intel Corporation Lynx Point-LP USB EHCI #1
 (rev 04) (prog-if 20 [EHCI])
 Subsystem: Lenovo Device 2218
 Flags: bus master, medium devsel, latency 0, IRQ 23
 Memory at f052d000 (32-bit, non-prefetchable) [size=1K]
 Capabilities: [50] Power Management version 3
 Capabilities: [58] Debug port: BAR=1 offset=00a0
 Capabilities: [98] PCI Advanced Features
 Kernel driver in use: ehci-pci
 ..
 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83)
 Subsystem: Intel Corporation Dual Band Wireless-AC 7260
 Flags: bus master, fast devsel, latency 0, IRQ 59
 Memory at f040 (64-bit, non-prefetchable) [size=8K]
 Capabilities: [c8] Power Management version 3
 Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+
 Capabilities: [40] Express Endpoint, MSI 00
 Capabilities: [100] Advanced Error Reporting
 Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-5e-4c-cd
 Capabilities: [14c] Latency Tolerance Reporting
 Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014 ?
 Kernel driver in use: iwlwifi
 Kernel modules: iwlwifi
 --
 To unsubscribe from this list: send the line unsubscribe linux-wireless in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH net-next] r8152: add skb_cow_head

2014-03-10 Thread Hayes Wang
Call skb_cow_head() before editing the tx packet header. The header
would be reallocated if it is shared.

Signed-off-by: Hayes Wang hayesw...@realtek.com
---
 drivers/net/usb/r8152.c | 13 +++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index c7ef30d..faad39b 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1376,6 +1376,11 @@ static int msdn_giant_send_check(struct sk_buff *skb)
 {
const struct ipv6hdr *ipv6h;
struct tcphdr *th;
+   int ret;
+
+   ret = skb_cow_head(skb, 0);
+   if (ret)
+   goto out1;
 
ipv6h = ipv6_hdr(skb);
th = tcp_hdr(skb);
@@ -1383,7 +1388,8 @@ static int msdn_giant_send_check(struct sk_buff *skb)
th-check = 0;
th-check = ~tcp_v6_check(0, ipv6h-saddr, ipv6h-daddr, 0);
 
-   return 0;
+out1:
+   return ret;
 }
 
 static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
@@ -1412,8 +1418,11 @@ static int r8152_tx_csum(struct r8152 *tp, struct 
tx_desc *desc,
break;
 
case htons(ETH_P_IPV6):
+   if (msdn_giant_send_check(skb)) {
+   ret = TX_CSUM_TSO;
+   goto unavailable;
+   }
opts1 |= GTSENDV6;
-   msdn_giant_send_check(skb);
break;
 
default:
-- 
1.8.4.2

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


[PATCH] xhci: fix wrong port number reported when setting USB2.0 hardware LPM.

2014-03-10 Thread Lin Wang
This patch fix wrong port number reported when trying to enable/disable
USB2.0 hardware LPM.

Signed-off-by: Lin Wang lin.x.w...@intel.com
---
 drivers/usb/host/xhci.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 6fe577d..972f00d 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4064,7 +4064,7 @@ int xhci_set_usb2_hardware_lpm(struct usb_hcd *hcd,
field = le32_to_cpu(udev-bos-ext_cap-bmAttributes);
 
xhci_dbg(xhci, %s port %d USB2 hardware LPM\n,
-   enable ? enable : disable, port_num);
+   enable ? enable : disable, port_num + 1);
 
if (enable) {
/* Host supports BESL timeout instead of HIRD */
-- 
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: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Shuduo Sang
On Mon, Mar 10, 2014 at 2:11 PM, Emmanuel Grumbach egrumb...@gmail.com wrote:
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


I have disabled WIFI device in BIOS, then its suspend/resume works.


 lspci -vnn output:
 ..
 sniped
 ..
 00:1d.0 USB controller: Intel Corporation Lynx Point-LP USB EHCI #1
 (rev 04) (prog-if 20 [EHCI])
 Subsystem: Lenovo Device 2218
 Flags: bus master, medium devsel, latency 0, IRQ 23
 Memory at f052d000 (32-bit, non-prefetchable) [size=1K]
 Capabilities: [50] Power Management version 3
 Capabilities: [58] Debug port: BAR=1 offset=00a0
 Capabilities: [98] PCI Advanced Features
 Kernel driver in use: ehci-pci
 ..
 03:00.0 Network controller: Intel Corporation Wireless 7260 (rev 83)
 Subsystem: Intel Corporation Dual Band Wireless-AC 7260
 Flags: bus master, fast devsel, latency 0, IRQ 59
 Memory at f040 (64-bit, non-prefetchable) [size=8K]
 Capabilities: [c8] Power Management version 3
 Capabilities: [d0] MSI: Enable+ Count=1/1 Maskable- 64bit+
 Capabilities: [40] Express Endpoint, MSI 00
 Capabilities: [100] Advanced Error Reporting
 Capabilities: [140] Device Serial Number 7c-7a-91-ff-ff-5e-4c-cd
 Capabilities: [14c] Latency Tolerance Reporting
 Capabilities: [154] Vendor Specific Information: ID=cafe Rev=1 Len=014 ?
 Kernel driver in use: iwlwifi
 Kernel modules: iwlwifi
 --
 To unsubscribe from this list: send the line unsubscribe linux-wireless in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: musb for davinci

2014-03-10 Thread Christian Riesch

Hi Alexander,

--On March 09, 2014 20:58 +0100 Alexander Holler hol...@ahsoftware.de 
wrote:



Hello,

may I ask what's the deal with drivers/usb/musb/davinci.c and why it
depends on BROKEN?

I've just enabled it here and it compiles and seems to work.


I noticed the same for drivers/usb/musb/da8xx.c which was marked BROKEN by 
the same patch. It works for me, so I think the BROKEN should be removed.


I posted a patch for this, see [1].

Regards, Christian

[1] http://marc.info/?t=1394061r=1w=2



I haven't tested it thoroughly, but when I compare it with other (still
broken) drivers, I don't really see a reason to hide it by letting it
depend on BROKEN.

And at least the comment of the commit which has hidden it (787f56),
isn't completely true anymore. The driver doesn't include mach/*, at
least I don't see such an include.

Regards,

Alexander Holler





--
To unsubscribe from this list: send the line unsubscribe 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: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Emmanuel Grumbach
On Mon, Mar 10, 2014 at 8:49 AM, Shuduo Sang sangshu...@gmail.com wrote:
 On Mon, Mar 10, 2014 at 2:11 PM, Emmanuel Grumbach egrumb...@gmail.com 
 wrote:
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


 I have disabled WIFI device in BIOS, then its suspend/resume works.


Do you have any logs to share?
I supposed you tested 3.13.6 right?
--
To unsubscribe from this list: send the line unsubscribe 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 08/23] libusbg: Fix wrong binding parsing.

2014-03-10 Thread Krzysztof Opasiak
 -Original Message-
 From: Sergei Shtylyov [mailto:sergei.shtyl...@cogentembedded.com]
 Sent: Wednesday, March 05, 2014 7:58 PM
 To: Krzysztof Opasiak; mpor...@linaro.org; linux-
 u...@vger.kernel.org
 Cc: Andrzej Pietrasiewicz; Karol Lewandowski; Stanislaw Wadas;
 ty317@samsung.org; Marek Szyprowski; Robert Baldyga
 Subject: Re: [PATCH 08/23] libusbg: Fix wrong binding parsing.
 
 Hello.
 
 On 03/05/2014 05:14 PM, Krzysztof Opasiak wrote:
 
  usbg_parse_bindings() function has done parsing incorrectly
  and in inefficent way. Changes made in this function provide
  better performance and fix wrong linking issue when having
  two instances of the same function.
 
  Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
  ---
src/usbg.c |   34 --
1 file changed, 20 insertions(+), 14 deletions(-)
 
  diff --git a/src/usbg.c b/src/usbg.c
  index 198fc7a..255074f 100644
  --- a/src/usbg.c
  +++ b/src/usbg.c
 [...]
  @@ -420,19 +423,22 @@ static void
 usbg_parse_config_bindings(usbg_config *c)
  TAILQ_INIT(c-bindings);
 
  n = scandir(bpath, dent, bindings_select, alphasort);
 [...]
  +   for (i = 0; i  n; i++) {
  +   sprintf(file_name, %s/%s, bpath, dent[i]-d_name);
  +   nmb = readlink(file_name, target,
 USBG_MAX_PATH_LENGTH);
  +   if (nmb  0)
  +   ERRORNO(bytes %d contents %s\n, n, target);
  +
  +   /* readlink() don't add this, so we have to do it
 manually */
  +   target[nmb] = '\0';
  +   /* Target contains a full path
  +*  but we need only function dir name */
  +   target_name = strrchr(target, '/') + 1;
 
 Why the indentation jumped suddenly to the right? I know I'm
 asking this
 question for the 2nd time already. :-)
 
Ohhh stupid mergetool. I was rebasing my patches to change their
order and I have used kdiff to solve conflicts but unexpectedly that
tool has done some wrong automerge like this. As you recommended earlier
I have used a checkpatch.pl script but it didn't found it as error or
warning. I will fix it for v2.

Thank you for your remarks,

BR's
Krzysiek


--
To unsubscribe from this list: send the line unsubscribe 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: f_fs: add missing spinlock and mutex unlock

2014-03-10 Thread Robert Baldyga
This patch adds missing spin_unlock and mutex_unlock calls in
error handling code.

Signed-off-by: Robert Baldyga r.bald...@samsung.com
---
 drivers/usb/gadget/f_fs.c |8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index b7d273a..d6bd0a3 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -802,7 +802,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
ffs_io_data *io_data)
if (io_data-aio) {
req = usb_ep_alloc_request(ep-ep, GFP_KERNEL);
if (unlikely(!req))
-   goto error;
+   goto error_lock;
 
req-buf  = data;
req-length   = io_data-len;
@@ -817,7 +817,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
ffs_io_data *io_data)
ret = usb_ep_queue(ep-ep, req, GFP_ATOMIC);
if (unlikely(ret)) {
usb_ep_free_request(ep-ep, req);
-   goto error;
+   goto error_lock;
}
ret = -EIOCBQUEUED;
 
@@ -863,6 +863,10 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
ffs_io_data *io_data)
 
mutex_unlock(epfile-mutex);
return ret;
+
+error_lock:
+   spin_unlock_irq(epfile-ffs-eps_lock);
+   mutex_unlock(epfile-mutex);
 error:
kfree(data);
return ret;
-- 
1.7.9.5

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


[PATCH 0/2] Rename struct dev_state to struct usb_dev_state

2014-03-10 Thread Valentina Manea
Since it is needed outside usbcore and exposed in include/linux/usb.h,
it conflicts with enum dev_state in rt2x00 wireless driver and breaks
the build.

Mark it as usb specific to avoid conflicts in the future and update
USB/IP to use the new name.

Valentina Manea (2):
  usbcore: rename struct dev_state to struct usb_dev_state
  staging: usbip: rename struct dev_state to usb_dev_state

 drivers/staging/usbip/stub_dev.c |   4 +-
 drivers/usb/core/devio.c | 112 +++
 drivers/usb/core/hub.c   |  12 ++---
 drivers/usb/core/hub.h   |   2 +-
 drivers/usb/core/usb.h   |   4 +-
 include/linux/usb.h  |   6 +--
 6 files changed, 70 insertions(+), 70 deletions(-)

-- 
1.8.1.2

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


[PATCH 1/2] usbcore: rename struct dev_state to struct usb_dev_state

2014-03-10 Thread Valentina Manea
Since it is needed outside usbcore and exposed in include/linux/usb.h,
it conflicts with enum dev_state in rt2x00 wireless driver.

Mark it as usb specific to avoid conflicts in the future.

Signed-off-by: Valentina Manea valentina.mane...@gmail.com
---
 drivers/usb/core/devio.c | 112 +++
 drivers/usb/core/hub.c   |  12 ++---
 drivers/usb/core/hub.h   |   2 +-
 drivers/usb/core/usb.h   |   4 +-
 include/linux/usb.h  |   6 +--
 5 files changed, 68 insertions(+), 68 deletions(-)

diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 90e18f6..2a8afe6 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -62,7 +62,7 @@
 /* Mutual exclusion for removal, open, and release */
 DEFINE_MUTEX(usbfs_mutex);
 
-struct dev_state {
+struct usb_dev_state {
struct list_head list;  /* state list */
struct usb_device *dev;
struct file *file;
@@ -81,7 +81,7 @@ struct dev_state {
 
 struct async {
struct list_head asynclist;
-   struct dev_state *ps;
+   struct usb_dev_state *ps;
struct pid *pid;
const struct cred *cred;
unsigned int signr;
@@ -151,7 +151,7 @@ static void usbfs_decrease_memory_usage(unsigned amount)
atomic_sub(amount, usbfs_memory_usage);
 }
 
-static int connected(struct dev_state *ps)
+static int connected(struct usb_dev_state *ps)
 {
return (!list_empty(ps-list) 
ps-dev-state != USB_STATE_NOTATTACHED);
@@ -184,7 +184,7 @@ static loff_t usbdev_lseek(struct file *file, loff_t 
offset, int orig)
 static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
   loff_t *ppos)
 {
-   struct dev_state *ps = file-private_data;
+   struct usb_dev_state *ps = file-private_data;
struct usb_device *dev = ps-dev;
ssize_t ret = 0;
unsigned len;
@@ -307,7 +307,7 @@ static void free_async(struct async *as)
 
 static void async_newpending(struct async *as)
 {
-   struct dev_state *ps = as-ps;
+   struct usb_dev_state *ps = as-ps;
unsigned long flags;
 
spin_lock_irqsave(ps-lock, flags);
@@ -317,7 +317,7 @@ static void async_newpending(struct async *as)
 
 static void async_removepending(struct async *as)
 {
-   struct dev_state *ps = as-ps;
+   struct usb_dev_state *ps = as-ps;
unsigned long flags;
 
spin_lock_irqsave(ps-lock, flags);
@@ -325,7 +325,7 @@ static void async_removepending(struct async *as)
spin_unlock_irqrestore(ps-lock, flags);
 }
 
-static struct async *async_getcompleted(struct dev_state *ps)
+static struct async *async_getcompleted(struct usb_dev_state *ps)
 {
unsigned long flags;
struct async *as = NULL;
@@ -340,7 +340,7 @@ static struct async *async_getcompleted(struct dev_state 
*ps)
return as;
 }
 
-static struct async *async_getpending(struct dev_state *ps,
+static struct async *async_getpending(struct usb_dev_state *ps,
 void __user *userurb)
 {
struct async *as;
@@ -448,7 +448,7 @@ static int copy_urb_data_to_user(u8 __user *userbuffer, 
struct urb *urb)
 #define AS_CONTINUATION1
 #define AS_UNLINK  2
 
-static void cancel_bulk_urbs(struct dev_state *ps, unsigned bulk_addr)
+static void cancel_bulk_urbs(struct usb_dev_state *ps, unsigned bulk_addr)
 __releases(ps-lock)
 __acquires(ps-lock)
 {
@@ -489,7 +489,7 @@ __acquires(ps-lock)
 static void async_completed(struct urb *urb)
 {
struct async *as = urb-context;
-   struct dev_state *ps = as-ps;
+   struct usb_dev_state *ps = as-ps;
struct siginfo sinfo;
struct pid *pid = NULL;
u32 secid = 0;
@@ -529,7 +529,7 @@ static void async_completed(struct urb *urb)
wake_up(ps-wait);
 }
 
-static void destroy_async(struct dev_state *ps, struct list_head *list)
+static void destroy_async(struct usb_dev_state *ps, struct list_head *list)
 {
struct urb *urb;
struct async *as;
@@ -551,7 +551,7 @@ static void destroy_async(struct dev_state *ps, struct 
list_head *list)
spin_unlock_irqrestore(ps-lock, flags);
 }
 
-static void destroy_async_on_interface(struct dev_state *ps,
+static void destroy_async_on_interface(struct usb_dev_state *ps,
   unsigned int ifnum)
 {
struct list_head *p, *q, hitlist;
@@ -566,7 +566,7 @@ static void destroy_async_on_interface(struct dev_state *ps,
destroy_async(ps, hitlist);
 }
 
-static void destroy_all_async(struct dev_state *ps)
+static void destroy_all_async(struct usb_dev_state *ps)
 {
destroy_async(ps, ps-async_pending);
 }
@@ -585,7 +585,7 @@ static int driver_probe(struct usb_interface *intf,
 
 static void driver_disconnect(struct usb_interface *intf)
 {
-   struct dev_state *ps = usb_get_intfdata(intf);
+   struct usb_dev_state *ps = usb_get_intfdata(intf);
unsigned int ifnum = 

[PATCH 2/2] staging: usbip: rename struct dev_state to usb_dev_state

2014-03-10 Thread Valentina Manea
struct dev_state definition in usbcore conflicted with
enum dev_state definition in rt2x00 driver so it was
renamed to usb_dev_state.

Update usbip for this change.

Signed-off-by: Valentina Manea valentina.mane...@gmail.com
---
 drivers/staging/usbip/stub_dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/usbip/stub_dev.c b/drivers/staging/usbip/stub_dev.c
index 952743c..773d8ca 100644
--- a/drivers/staging/usbip/stub_dev.c
+++ b/drivers/staging/usbip/stub_dev.c
@@ -395,7 +395,7 @@ static int stub_probe(struct usb_device *udev)
 * (struct dev_state) as long as it is unique.
 */
rc = usb_hub_claim_port(udev-parent, udev-portnum,
-   (struct dev_state *) udev);
+   (struct usb_dev_state *) udev);
if (rc) {
dev_dbg(udev-dev, unable to claim port\n);
return rc;
@@ -464,7 +464,7 @@ static void stub_disconnect(struct usb_device *udev)
 
/* release port */
rc = usb_hub_release_port(udev-parent, udev-portnum,
- (struct dev_state *) udev);
+ (struct usb_dev_state *) udev);
if (rc) {
dev_dbg(udev-dev, unable to release port\n);
return;
-- 
1.8.1.2

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


[PATCH v2 04/23] libusbg: Refresh config attributes while each get.

2014-03-10 Thread Krzysztof Opasiak
Config attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 4a69b9c..e11f44e 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -63,7 +63,6 @@ struct usbg_config
 
char name[USBG_MAX_NAME_LENGTH];
char path[USBG_MAX_PATH_LENGTH];
-   usbg_config_attrs attrs;
usbg_config_strs strs;
 };
 
@@ -408,7 +407,6 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
c-parent = g;
strcpy(c-name, dent[i]-d_name);
strcpy(c-path, cpath);
-   usbg_parse_config_attrs(cpath, c-name, c-attrs);
usbg_parse_config_strs(cpath, c-name, c-strs);
usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(g-configs, c, cnode);
@@ -948,8 +946,6 @@ usbg_config *usbg_create_config(usbg_gadget *g, char *name,
 
if (c_attrs)
usbg_set_config_attrs(c, c_attrs);
-   else
-   usbg_parse_config_attrs(c-path, c-name, c-attrs);
 
if (c_strs)
usbg_set_config_string(c, LANG_US_ENG, c_strs-configuration);
@@ -986,8 +982,6 @@ void usbg_set_config_attrs(usbg_config *c, 
usbg_config_attrs *c_attrs)
if (!c || !c_attrs)
return;
 
-   c-attrs = *c_attrs;
-
usbg_write_dec(c-path, c-name, MaxPower, c_attrs-bMaxPower);
usbg_write_hex8(c-path, c-name, bmAttributes, 
c_attrs-bmAttributes);
 }
@@ -996,7 +990,7 @@ usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs)
 {
if (c  c_attrs)
-   *c_attrs = c-attrs;
+   usbg_parse_config_attrs(c-path, c-name, c_attrs);
else
c_attrs = NULL;
 
@@ -1005,13 +999,11 @@ usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
 
 void usbg_set_config_max_power(usbg_config *c, int bMaxPower)
 {
-   c-attrs.bMaxPower = bMaxPower;
usbg_write_dec(c-path, c-name, MaxPower, bMaxPower);
 }
 
 void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
 {
-   c-attrs.bmAttributes = bmAttributes;
usbg_write_hex8(c-path, c-name, bmAttributes, bmAttributes);
 }
 
-- 
1.7.9.5

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


[PATCH v2 07/23] libusbg: Add internal free functions for each library structure.

2014-03-10 Thread Krzysztof Opasiak
Library should have internal API for freing structures instead of
copy pasting same code in different places.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   77 +++-
 1 file changed, 50 insertions(+), 27 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index d7284bb..198fc7a 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -266,6 +266,55 @@ static inline void usbg_write_string(char *path, char 
*name, char *file, char *b
usbg_write_buf(path, name, file, buf);
 }
 
+static inline void usbg_free_binding(usbg_binding *b)
+{
+   free(b);
+}
+
+static inline void usbg_free_function(usbg_function *f)
+{
+   free(f);
+}
+
+static void usbg_free_config(usbg_config *c)
+{
+   usbg_binding *b;
+   while (!TAILQ_EMPTY(c-bindings)) {
+   b = TAILQ_FIRST(c-bindings);
+   TAILQ_REMOVE(c-bindings, b, bnode);
+   usbg_free_binding(b);
+   }
+   free(c);
+}
+
+static void usbg_free_gadget(usbg_gadget *g)
+{
+   usbg_config *c;
+   usbg_function *f;
+   while (!TAILQ_EMPTY(g-configs)) {
+   c = TAILQ_FIRST(g-configs);
+   TAILQ_REMOVE(g-configs, c, cnode);
+   usbg_free_config(c);
+   }
+   while (!TAILQ_EMPTY(g-functions)) {
+   f = TAILQ_FIRST(g-functions);
+   TAILQ_REMOVE(g-functions, f, fnode);
+   usbg_free_function(f);
+   }
+   free(g);
+}
+
+static void usbg_free_state(usbg_state *s)
+{
+   usbg_gadget *g;
+   while (!TAILQ_EMPTY(s-gadgets)) {
+   g = TAILQ_FIRST(s-gadgets);
+   TAILQ_REMOVE(s-gadgets, g, gnode);
+   usbg_free_gadget(g);
+   }
+   free(s);
+}
+
 static void usbg_parse_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
@@ -532,33 +581,7 @@ out:
 
 void usbg_cleanup(usbg_state *s)
 {
-   usbg_gadget *g;
-   usbg_config *c;
-   usbg_binding *b;
-   usbg_function *f;
-
-   while (!TAILQ_EMPTY(s-gadgets)) {
-   g = TAILQ_FIRST(s-gadgets);
-   while (!TAILQ_EMPTY(g-configs)) {
-   c = TAILQ_FIRST(g-configs);
-   while(!TAILQ_EMPTY(c-bindings)) {
-   b = TAILQ_FIRST(c-bindings);
-   TAILQ_REMOVE(c-bindings, b, bnode);
-   free(b);
-   }
-   TAILQ_REMOVE(g-configs, c, cnode);
-   free(c);
-   }
-   while (!TAILQ_EMPTY(g-functions)) {
-   f = TAILQ_FIRST(g-functions);
-   TAILQ_REMOVE(g-functions, f, fnode);
-   free(f);
-   }
-   TAILQ_REMOVE(s-gadgets, g, gnode);
-   free(g);
-   }
-
-   free(s);
+   usbg_free_state(s);
 }
 
 size_t usbg_get_configfs_path_len(usbg_state *s)
-- 
1.7.9.5

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


[PATCH v2 14/23] libusbg: Add return value to usbg_set_gadget_*() functions.

2014-03-10 Thread Krzysztof Opasiak
Setting each of attribute may fail due to a lot of reasons
so those functions should report this failure to a user.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   33 +---
 src/usbg.c  |   85 +--
 2 files changed, 77 insertions(+), 41 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index f6f7a2e..17084bb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -314,62 +314,70 @@ extern int usbg_get_gadget_name(usbg_gadget *g, char 
*buf, size_t len);
  * @brief Set the USB gadget vendor id
  * @param g Pointer to gadget
  * @param idVendor USB device vendor id
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
+extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
 
 /**
  * @brief Set the USB gadget product id
  * @param g Pointer to gadget
  * @param idProduct USB device product id
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
+extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
 
 /**
  * @brief Set the USB gadget device class code
  * @param g Pointer to gadget
  * @param bDeviceClass USB device class code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_class(usbg_gadget *g,
+extern int usbg_set_gadget_device_class(usbg_gadget *g,
uint8_t bDeviceClass);
 
 /**
  * @brief Set the USB gadget protocol code
  * @param g Pointer to gadget
  * @param bDeviceProtocol USB protocol code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_protocol(usbg_gadget *g,
+extern int usbg_set_gadget_device_protocol(usbg_gadget *g,
uint8_t bDeviceProtocol);
 
 /**
  * @brief Set the USB gadget device subclass code
  * @param g Pointer to gadget
  * @param bDeviceSubClass USB device subclass code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_subclass(usbg_gadget *g,
+extern int usbg_set_gadget_device_subclass(usbg_gadget *g,
uint8_t bDeviceSubClass);
 
 /**
  * @brief Set the maximum packet size for a gadget
  * @param g Pointer to gadget
  * @param bMaxPacketSize0 Maximum packet size
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_max_packet(usbg_gadget *g,
+extern int usbg_set_gadget_device_max_packet(usbg_gadget *g,
uint8_t bMaxPacketSize0);
 
 /**
  * @brief Set the gadget device BCD release number
  * @param g Pointer to gadget
  * @param bcdDevice BCD release number
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_bcd_device(usbg_gadget *g,
+extern int usbg_set_gadget_device_bcd_device(usbg_gadget *g,
uint16_t bcdDevice);
 
 /**
  * @brief Set the gadget device BCD USB version
  * @param g Pointer to gadget
  * @param bcdUSB BCD USB version
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
+extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
 
 /**
  * @brief Get the USB gadget strings
@@ -397,24 +405,27 @@ extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param ser Serial number
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
+extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
 
 /**
  * @brief Set the manufacturer name for a gadget
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param mnf Manufacturer
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
+extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
 
 /**
  * @brief Set the product name for a gadget
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param prd Product
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
+extern int usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
 
 /* USB function allocation and configuration */
 
diff --git a/src/usbg.c b/src/usbg.c
index ed8070d..5a4202c 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1012,44 +1012,52 @@ out:
return ret;
 }
 
-void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
+int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
 {
-   usbg_write_hex16(g-path, g-name, idVendor, idVendor);
+   return g ? usbg_write_hex16(g-path, g-name, idVendor, idVendor)
+ 

[PATCH v2 00/23] libusbg: Add error code propagation and attributes refreshing.

2014-03-10 Thread Krzysztof Opasiak
Dear Matt,

I have prepared next series of patches. This time I have added error
code propagation which you have palced at todo list.

In this series I have also removed caching gadget/function/config
attributes in internal structures. Those attributes may be changed
by kernel when enabling gadget, so user should get actual attributes
each time he use usbg_get_*() function.

There was also some bug in matching between binding and function.
Previously library took only function type and ignore instance name.
Now while lookup both function type and instance name is considered.

This series depends on my previous series you can easily find them
on a list or in github pull request. 

--
BR's
Krzysztof Opasiak
Samsung RD Institute Poland
Samsung Electronics

---
Changes since v1:
- remove conflicts description from commit messages
- fix additional whitespace

Krzysztof Opasiak (23):
  libusbg: Remove unused variables to make compiler happy.
  libusbg: Refresh gadget attributes while each get.
  libusbg: Refresh gadget strings while each get.
  libusbg: Refresh config attributes while each get.
  libusbg: Refresh config strings while each get.
  libusbg: Refresh function attributes while each get.
  libusbg: Add internal free functions for each library structure.
  libusbg: Fix wrong binding parsing.
  libusbg: Add error handling to usbg_init() and related functions.
  libusbg: Return usbg_error instead of -1 in usbg_*_len().
  libusbg: Return usbg_error instead of char* in usbg_get_*_name().
  libusbg: Add parenthesis to INSERT_TAILQ_STRING_ORDER macro.
  libusbg: Add return value to gadget creation functions.
  libusbg: Add return value to usbg_set_gadget_*() functions.
  libusbg: Add return value to usb function related functions.
  libusbg: Add return value to config related functions.
  libusbg: Add return value to usbg_enable/disable_gadget().
  libusbg: Return error code instead of NULL pointer.
  libusbg: Return error code instead of NULL pointer - config.
  libusbg: Change usbg_get_function_attrs() to return error code.
  libusbg: Return error code instead of -1.
  libusbg: Add functions for getting error strings.
  libusbg: Update examples to use returned error codes.

 examples/gadget-acm-ecm.c |   73 ++-
 examples/show-gadgets.c   |   48 +-
 include/usbg/usbg.h   |  205 --
 src/usbg.c| 1554 +
 4 files changed, 1247 insertions(+), 633 deletions(-)

-- 
1.7.9.5

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


[PATCH v2 03/23] libusbg: Refresh gadget strings while each get.

2014-03-10 Thread Krzysztof Opasiak
Gadget strings should not be cached in library.
Removing internal strings structure allowed to add
full support for multilingual strings.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/show-gadgets.c |2 +-
 include/usbg/usbg.h |6 --
 src/usbg.c  |   48 +--
 3 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 7ba9687..7d9909a 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -51,7 +51,7 @@ void show_gadget(usbg_gadget *g)
fprintf(stdout,   idVendor\t\t0x%04x\n, g_attrs.idVendor);
fprintf(stdout,   idProduct\t\t0x%04x\n, g_attrs.idProduct);
 
-   usbg_get_gadget_strs(g, g_strs);
+   usbg_get_gadget_strs(g, LANG_US_ENG, g_strs);
fprintf(stdout,   Serial Number\t\t%s\n, g_strs.str_ser);
fprintf(stdout,   Manufacturer\t\t%s\n, g_strs.str_mnf);
fprintf(stdout,   Product\t\t%s\n, g_strs.str_prd);
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 71845cd..e1a0b5c 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -355,10 +355,12 @@ extern void usbg_set_gadget_device_bcd_usb(usbg_gadget 
*g, uint16_t bcdUSB);
 /**
  * @brief Get the USB gadget strings
  * @param g Pointer to gadget
+ * @param lang Language of strings
  * @param g_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @retur Pointer to filled structure or NULL if error occurred or
+ * if no strings for given language.
  */
-extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index ae26434..4a69b9c 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -49,8 +49,6 @@ struct usbg_gadget
char path[USBG_MAX_PATH_LENGTH];
char udc[USBG_MAX_STR_LENGTH];
 
-   usbg_gadget_strs strs;
-
TAILQ_ENTRY(usbg_gadget) gnode;
TAILQ_HEAD(chead, usbg_config) configs;
TAILQ_HEAD(fhead, usbg_function) functions;
@@ -435,17 +433,26 @@ static void usbg_parse_gadget_attrs(char *path, char 
*name,
g_attrs-bcdDevice = (uint16_t)usbg_read_hex(path, name, bcdDevice);
 }
 
-static void usbg_parse_strings(char *path, char *name, usbg_gadget_strs 
*g_strs)
+static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
+   usbg_gadget_strs *g_strs)
 {
-   /* Strings - hardcoded to U.S. English only for now */
-   int lang = LANG_US_ENG;
+   DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, %s/%s/%s/0x%x, path, name, STRINGS_DIR, lang);
 
-   usbg_read_string(spath, , serialnumber, g_strs-str_ser);
-   usbg_read_string(spath, , manufacturer, g_strs-str_mnf);
-   usbg_read_string(spath, , product, g_strs-str_prd);
+   /* Check if directory exist */
+   dir = opendir(spath);
+   if (dir) {
+   closedir(dir);
+   usbg_read_string(spath, , serialnumber, g_strs-str_ser);
+   usbg_read_string(spath, , manufacturer, g_strs-str_mnf);
+   usbg_read_string(spath, , product, g_strs-str_prd);
+   } else {
+   g_strs = NULL;
+   }
+
+   return g_strs;
 }
 
 static int usbg_parse_gadgets(char *path, usbg_state *s)
@@ -464,7 +471,6 @@ static int usbg_parse_gadgets(char *path, usbg_state *s)
g-parent = s;
/* UDC bound to, if any */
usbg_read_string(path, g-name, UDC, g-udc);
-   usbg_parse_strings(path, g-name, g-strs);
usbg_parse_functions(path, g);
usbg_parse_configs(path, g);
TAILQ_INSERT_TAIL(s-gadgets, g, gnode);
@@ -672,8 +678,6 @@ usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char 
*name,
usbg_write_hex16(s-path, name, idVendor, idVendor);
usbg_write_hex16(s-path, name, idProduct, idProduct);
 
-   usbg_parse_strings(s-path, name, g-strs);
-
INSERT_TAILQ_STRING_ORDER(s-gadgets, ghead, name, g, gnode);
}
 
@@ -703,8 +707,6 @@ usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
 
if (g_strs)
usbg_set_gadget_strs(g, LANG_US_ENG, g_strs);
-   else
-   usbg_parse_strings(s-path, name, g-strs);
 
INSERT_TAILQ_STRING_ORDER(s-gadgets, ghead, name, g, gnode);
}
@@ -798,11 +800,11 @@ void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB)
usbg_write_hex16(g-path, g-name, bcdUSB, bcdUSB);
 }
 
-usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs)
 {
if (g  g_strs)
-   *g_strs = g-strs;
+   g_strs = 

[PATCH v2 09/23] libusbg: Add error handling to usbg_init() and related functions.

2014-03-10 Thread Krzysztof Opasiak
Assumption that all malloc() and read()/write() finish correctly
is too bold. Errors should be handled and propagated to upper
layers of library and returned to user.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |5 +-
 examples/show-gadgets.c   |5 +-
 include/usbg/usbg.h   |   19 ++-
 src/usbg.c|  393 +++--
 4 files changed, 292 insertions(+), 130 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 5b027b6..5ab42cf 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -34,6 +34,7 @@ int main(void)
usbg_config *c;
usbg_function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL;
+   int usbg_ret;
 
usbg_gadget_attrs g_attrs = {
0x0200, /* bcdUSB */
@@ -56,8 +57,8 @@ int main(void)
CDC 2xACM+ECM
};
 
-   s = usbg_init(/sys/kernel/config);
-   if (!s) {
+   usbg_ret = usbg_init(/sys/kernel/config, s);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error on USB gadget init\n);
goto out1;
}
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 2665262..4d79a09 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -125,9 +125,10 @@ int main(void)
usbg_gadget *g;
usbg_function *f;
usbg_config *c;
+   int usbg_ret;
 
-   s = usbg_init(/sys/kernel/config);
-   if (!s) {
+   usbg_ret = usbg_init(/sys/kernel/config, s);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error on USB gadget init\n);
return -EINVAL;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 562fdc5..ffef084 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -175,14 +175,29 @@ typedef union {
usbg_f_phonet_attrs phonet;
 } usbg_function_attrs;
 
+/**
+ * @typedef usbg_error
+ * @brief Errors which could be returned by library functions
+ */
+typedef enum  {
+   USBG_SUCCESS = 0,
+   USBG_ERROR_NO_MEM = -1,
+   USBG_ERROR_NO_ACCESS = -2,
+   USBG_ERROR_INVALID_PARAM = -3,
+   USBG_ERROR_NOT_FOUND = -4,
+   USBG_ERROR_IO = -5,
+   USBG_ERROR_OTHER_ERROR = -99
+} usbg_error;
+
 /* Library init and cleanup */
 
 /**
  * @brief Initialize the libusbg library state
  * @param configfs_path Path to the mounted configfs filesystem
- * @return Pointer to a state structure
+ * @param Pointer to be filled with pointer to usbg_state
+ * @return 0 on success, usbg_error on error
  */
-extern usbg_state *usbg_init(char *configfs_path);
+extern int usbg_init(char *configfs_path, usbg_state **state);
 
 /**
  * @brief Clean up the libusbg library state
diff --git a/src/usbg.c b/src/usbg.c
index 8fb61ee..d6b3192 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -133,6 +133,35 @@ const char *function_names[] =
} \
} while (0)
 
+static int usbg_translate_error(int error)
+{
+   int ret;
+
+   switch (error) {
+   case ENOMEM:
+   ret = USBG_ERROR_NO_MEM;
+   break;
+   case EACCES:
+   ret = USBG_ERROR_NO_ACCESS;
+   break;
+   case ENOENT:
+   case ENOTDIR:
+   ret = USBG_ERROR_NOT_FOUND;
+   break;
+   case EINVAL:
+   case USBG_ERROR_INVALID_PARAM:
+   ret = USBG_ERROR_INVALID_PARAM;
+   break;
+   case EIO:
+   ret = USBG_ERROR_IO;
+   break;
+   default:
+   ret = USBG_ERROR_OTHER_ERROR;
+   }
+
+   return ret;
+}
+
 static int usbg_lookup_function_type(char *name)
 {
int i = 0;
@@ -169,52 +198,59 @@ static int file_select(const struct dirent *dent)
return 1;
 }
 
-static char *usbg_read_buf(char *path, char *name, char *file, char *buf)
+static int usbg_read_buf(char *path, char *name, char *file, char *buf)
 {
char p[USBG_MAX_STR_LENGTH];
FILE *fp;
-   char *ret = NULL;
+   int ret = USBG_SUCCESS;
 
sprintf(p, %s/%s/%s, path, name, file);
 
fp = fopen(p, r);
-   if (!fp)
-   goto out;
+   if (fp) {
+   /* Successfully opened */
+   if (!fgets(buf, USBG_MAX_STR_LENGTH, fp)) {
+   ERROR(read error);
+   ret = USBG_ERROR_IO;
+   }
 
-   ret = fgets(buf, USBG_MAX_STR_LENGTH, fp);
-   if (ret == NULL) {
-   ERROR(read error);
fclose(fp);
-   return ret;
+   } else {
+   /* Set error correctly */
+   ret = usbg_translate_error(errno);
}
 
-   fclose(fp);
-
-out:
return ret;
 }
 
-static int usbg_read_int(char *path, char *name, char *file, int base)
+static int usbg_read_int(char *path, char *name, char *file, int base,
+   

[PATCH v2 08/23] libusbg: Fix wrong binding parsing.

2014-03-10 Thread Krzysztof Opasiak
usbg_parse_bindings() function has done parsing incorrectly
and in inefficent way. Changes made in this function provide
better performance and fix wrong linking issue when having
two instances of the same function.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   35 +--
 1 file changed, 21 insertions(+), 14 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 198fc7a..8fb61ee 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -408,9 +408,12 @@ static usbg_config_strs *usbg_parse_config_strs(char 
*path, char *name,
 
 static void usbg_parse_config_bindings(usbg_config *c)
 {
-   int i, n;
+   int i, n, nmb;
struct dirent **dent;
char bpath[USBG_MAX_PATH_LENGTH];
+   char file_name[USBG_MAX_PATH_LENGTH];
+   char target[USBG_MAX_STR_LENGTH];
+   char *target_name;
usbg_gadget *g = c-parent;
usbg_binding *b;
usbg_function *f;
@@ -420,23 +423,27 @@ static void usbg_parse_config_bindings(usbg_config *c)
TAILQ_INIT(c-bindings);
 
n = scandir(bpath, dent, bindings_select, alphasort);
-   for (i=0; i  n; i++) {
-   TAILQ_FOREACH(f, g-functions, fnode) {
-   int n;
-   char contents[USBG_MAX_STR_LENGTH];
-   char cpath[USBG_MAX_PATH_LENGTH];
-   char fname[40];
-
-   sprintf(cpath, %s/%s, bpath, dent[i]-d_name);
-   n = readlink(cpath, contents, USBG_MAX_PATH_LENGTH);
-   if (n0)
-   ERRORNO(bytes %d contents %s\n, n, contents);
-   strcpy(fname, f-name);
-   if (strstr(contents, strtok(fname, .))) {
+   for (i = 0; i  n; i++) {
+   sprintf(file_name, %s/%s, bpath, dent[i]-d_name);
+   nmb = readlink(file_name, target, USBG_MAX_PATH_LENGTH);
+   if (nmb  0)
+   ERRORNO(bytes %d contents %s\n, n, target);
+
+   /* readlink() don't add this, so we have to do it manually */
+   target[nmb] = '\0';
+   /* Target contains a full path
+*  but we need only function dir name */
+   target_name = strrchr(target, '/') + 1;
+
+   TAILQ_FOREACH(f, g-functions, fnode)
+   {
+   /* Check if this is our target function */
+   if (strcmp(f-name, target_name) == 0) {
b = malloc(sizeof(usbg_binding));
strcpy(b-name, dent[i]-d_name);
strcpy(b-path, bpath);
b-target = f;
+   b-parent = c;
TAILQ_INSERT_TAIL(c-bindings, b, bnode);
break;
}
-- 
1.7.9.5

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


[PATCH v2 12/23] libusbg: Add parenthesis to INSERT_TAILQ_STRING_ORDER macro.

2014-03-10 Thread Krzysztof Opasiak
Surround each pointer in macro with parenthesis to avid
errors related to operator precedence.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 55e44c2..b6aa80d 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -118,17 +118,17 @@ const char *function_names[] =
 /* Insert in string order */
 #define INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, 
NodeField) \
do { \
-   if (TAILQ_EMPTY(HeadPtr) || \
-   (strcmp(ToInsert-NameField, 
TAILQ_FIRST(HeadPtr)-NameField)  0)) \
-   TAILQ_INSERT_HEAD(HeadPtr, ToInsert, NodeField); \
-   else if (strcmp(ToInsert-NameField, TAILQ_LAST(HeadPtr, 
HeadType)-NameField)  0) \
-   TAILQ_INSERT_TAIL(HeadPtr, ToInsert, NodeField); \
+   if (TAILQ_EMPTY((HeadPtr)) || \
+   (strcmp((ToInsert)-NameField, 
TAILQ_FIRST((HeadPtr))-NameField)  0)) \
+   TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
+   else if (strcmp((ToInsert)-NameField, TAILQ_LAST((HeadPtr), 
HeadType)-NameField)  0) \
+   TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
else { \
typeof(ToInsert) _cur; \
-   TAILQ_FOREACH(_cur, HeadPtr, NodeField) { \
-   if (strcmp(ToInsert-NameField, 
_cur-NameField)  0) \
+   TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
+   if (strcmp((ToInsert)-NameField, 
_cur-NameField)  0) \
continue; \
-   TAILQ_INSERT_BEFORE(_cur, ToInsert, NodeField); 
\
+   TAILQ_INSERT_BEFORE(_cur, (ToInsert), 
NodeField); \
} \
} \
} while (0)
-- 
1.7.9.5

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


[PATCH v2 01/23] libusbg: Remove unused variables to make compiler happy.

2014-03-10 Thread Krzysztof Opasiak
Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |1 -
 examples/show-gadgets.c   |1 -
 src/usbg.c|2 --
 3 files changed, 4 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index b3c776d..5b027b6 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -31,7 +31,6 @@ int main(void)
 {
usbg_state *s;
usbg_gadget *g;
-   usbg_function *f;
usbg_config *c;
usbg_function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL;
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 9814039..7ba9687 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -125,7 +125,6 @@ int main(void)
usbg_gadget *g;
usbg_function *f;
usbg_config *c;
-   usbg_binding *b;
 
s = usbg_init(/sys/kernel/config);
if (!s) {
diff --git a/src/usbg.c b/src/usbg.c
index 5e803f1..91165b8 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -110,14 +110,12 @@ const char *function_names[] =
 };
 
 #define ERROR(msg, ...) do {\
-char *str;\
 fprintf(stderr, %s()  msg \n, \
 __func__, ##__VA_ARGS__);\
 fflush(stderr);\
 } while (0)
 
 #define ERRORNO(msg, ...) do {\
-char *str;\
 fprintf(stderr, %s()  %s: msg \n, \
 __func__, strerror(errno), ##__VA_ARGS__);\
 fflush(stderr);\
-- 
1.7.9.5

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


[PATCH v2 10/23] libusbg: Return usbg_error instead of -1 in usbg_*_len().

2014-03-10 Thread Krzysztof Opasiak
Functions which provides user length of some internal
strings should return usbg_error instead of -1.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   12 ++--
 src/usbg.c  |   12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ffef084..ad52a5f 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -208,7 +208,7 @@ extern void usbg_cleanup(usbg_state *s);
 /**
  * @brief Get ConfigFS path length
  * @param s Pointer to state
- * @return Length of path or -1 if error occurred.
+ * @return Length of path or usbg_error if error occurred.
  */
 extern size_t usbg_get_configfs_path_len(usbg_state *s);
 
@@ -293,7 +293,7 @@ extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget 
*g,
 /**
  * @brief Get gadget name length
  * @param g Gadget which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_gadget_name_len(usbg_gadget *g);
 
@@ -427,7 +427,7 @@ extern usbg_function *usbg_create_function(usbg_gadget *g, 
usbg_function_type ty
 /**
  * @brief Get function name length
  * @param f Config which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_function_name_len(usbg_function *f);
 
@@ -456,7 +456,7 @@ extern usbg_config *usbg_create_config(usbg_gadget *g, char 
*name,
 /**
  * @brief Get config name length
  * @param c Config which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_config_name_len(usbg_config *c);
 
@@ -546,7 +546,7 @@ extern usbg_function *usbg_get_binding_target(usbg_binding 
*b);
 /**
  * @brief Get binding name length
  * @param b Binding which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_binding_name_len(usbg_binding *b);
 
@@ -584,7 +584,7 @@ extern void usbg_disable_gadget(usbg_gadget *g);
 /**
  * @brief Get gadget name length
  * @param g Gadget which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  * @note If gadget isn't enabled on any udc returned size is 0.
  */
 extern size_t usbg_get_gadget_udc_len(usbg_gadget *g);
diff --git a/src/usbg.c b/src/usbg.c
index d6b3192..1098872 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -738,7 +738,7 @@ void usbg_cleanup(usbg_state *s)
 
 size_t usbg_get_configfs_path_len(usbg_state *s)
 {
-   return s ? strlen(s-path) : -1;
+   return s ? strlen(s-path) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
@@ -906,7 +906,7 @@ usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
 
 size_t usbg_get_gadget_name_len(usbg_gadget *g)
 {
-   return g ? strlen(g-name) : -1;
+   return g ? strlen(g-name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
@@ -916,7 +916,7 @@ char *usbg_get_gadget_name(usbg_gadget *g, char *buf, 
size_t len)
 
 size_t usbg_get_gadget_udc_len(usbg_gadget *g)
 {
-   return g ? strlen(g-udc) : -1;
+   return g ? strlen(g-udc) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len)
@@ -1136,7 +1136,7 @@ usbg_config *usbg_create_config(usbg_gadget *g, char 
*name,
 
 size_t usbg_get_config_name_len(usbg_config *c)
 {
-   return c ? strlen(c-name) : -1;
+   return c ? strlen(c-name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_config_name(usbg_config *c, char *buf, size_t len)
@@ -1146,7 +1146,7 @@ char *usbg_get_config_name(usbg_config *c, char *buf, 
size_t len)
 
 size_t usbg_get_function_name_len(usbg_function *f)
 {
-   return f ? strlen(f-name) : -1;
+   return f ? strlen(f-name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_function_name(usbg_function *f, char *buf, size_t len)
@@ -1266,7 +1266,7 @@ usbg_function *usbg_get_binding_target(usbg_binding *b)
 
 size_t usbg_get_binding_name_len(usbg_binding *b)
 {
-   return b ? strlen(b-name) : -1;
+   return b ? strlen(b-name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len)
-- 
1.7.9.5

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


[PATCH v2 02/23] libusbg: Refresh gadget attributes while each get.

2014-03-10 Thread Krzysztof Opasiak
Gadget attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   16 +---
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 91165b8..ae26434 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -49,7 +49,6 @@ struct usbg_gadget
char path[USBG_MAX_PATH_LENGTH];
char udc[USBG_MAX_STR_LENGTH];
 
-   usbg_gadget_attrs attrs;
usbg_gadget_strs strs;
 
TAILQ_ENTRY(usbg_gadget) gnode;
@@ -465,7 +464,6 @@ static int usbg_parse_gadgets(char *path, usbg_state *s)
g-parent = s;
/* UDC bound to, if any */
usbg_read_string(path, g-name, UDC, g-udc);
-   usbg_parse_gadget_attrs(path, g-name, g-attrs);
usbg_parse_strings(path, g-name, g-strs);
usbg_parse_functions(path, g);
usbg_parse_configs(path, g);
@@ -674,7 +672,6 @@ usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char 
*name,
usbg_write_hex16(s-path, name, idVendor, idVendor);
usbg_write_hex16(s-path, name, idProduct, idProduct);
 
-   usbg_parse_gadget_attrs(s-path, name, g-attrs);
usbg_parse_strings(s-path, name, g-strs);
 
INSERT_TAILQ_STRING_ORDER(s-gadgets, ghead, name, g, gnode);
@@ -703,8 +700,6 @@ usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
if (g) {
if (g_attrs)
usbg_set_gadget_attrs(g, g_attrs);
-   else
-   usbg_parse_gadget_attrs(s-path, name, g-attrs);
 
if (g_strs)
usbg_set_gadget_strs(g, LANG_US_ENG, g_strs);
@@ -721,7 +716,7 @@ usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
usbg_gadget_attrs *g_attrs)
 {
if (g  g_attrs)
-   *g_attrs = g-attrs;
+   usbg_parse_gadget_attrs(g-path, g-name, g_attrs);
else
g_attrs = NULL;
 
@@ -753,7 +748,6 @@ void usbg_set_gadget_attrs(usbg_gadget *g, 
usbg_gadget_attrs *g_attrs)
if (!g || !g_attrs)
return;
 
-   g-attrs = *g_attrs;
usbg_write_hex16(g-path, g-name, bcdUSB, g_attrs-bcdUSB);
usbg_write_hex8(g-path, g-name, bDeviceClass, 
g_attrs-bDeviceClass);
usbg_write_hex8(g-path, g-name, bDeviceSubClass, 
g_attrs-bDeviceSubClass);
@@ -766,49 +760,41 @@ void usbg_set_gadget_attrs(usbg_gadget *g, 
usbg_gadget_attrs *g_attrs)
 
 void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
 {
-   g-attrs.idVendor = idVendor;
usbg_write_hex16(g-path, g-name, idVendor, idVendor);
 }
 
 void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
 {
-   g-attrs.idProduct = idProduct;
usbg_write_hex16(g-path, g-name, idProduct, idProduct);
 }
 
 void usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
 {
-   g-attrs.bDeviceClass = bDeviceClass;
usbg_write_hex8(g-path, g-name, bDeviceClass, bDeviceClass);
 }
 
 void usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
 {
-   g-attrs.bDeviceProtocol = bDeviceProtocol;
usbg_write_hex8(g-path, g-name, bDeviceProtocol, bDeviceProtocol);
 }
 
 void usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
 {
-   g-attrs.bDeviceSubClass = bDeviceSubClass;
usbg_write_hex8(g-path, g-name, bDeviceSubClass, bDeviceSubClass);
 }
 
 void usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
 {
-   g-attrs.bMaxPacketSize0 = bMaxPacketSize0;
usbg_write_hex8(g-path, g-name, bMaxPacketSize0, bMaxPacketSize0);
 }
 
 void usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
 {
-   g-attrs.bcdDevice = bcdDevice;
usbg_write_hex16(g-path, g-name, bcdDevice, bcdDevice);
 }
 
 void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
 {
-   g-attrs.bcdUSB = bcdUSB;
usbg_write_hex16(g-path, g-name, bcdUSB, bcdUSB);
 }
 
-- 
1.7.9.5

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


[PATCH v2 11/23] libusbg: Return usbg_error instead of char* in usbg_get_*_name().

2014-03-10 Thread Krzysztof Opasiak
API should be consistent and use error codes to determine what
type of error occurred instead of returning NULL only.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   24 ++---
 src/usbg.c  |   60 ---
 2 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ad52a5f..0d76010 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -217,9 +217,9 @@ extern size_t usbg_get_configfs_path_len(usbg_state *s);
  * @param s Pointer to state
  * @param buf Buffer where path should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len);
+extern int usbg_get_configfs_path(usbg_state *s, char *buf, size_t len);
 
 /* USB gadget queries */
 
@@ -302,9 +302,9 @@ extern size_t usbg_get_gadget_name_len(usbg_gadget *g);
  * @param b Pointer to gadget
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len);
+extern int usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len);
 
 /**
  * @brief Set the USB gadget vendor id
@@ -436,9 +436,9 @@ extern size_t usbg_get_function_name_len(usbg_function *f);
  * @param f Pointer to function
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_function_name(usbg_function *f, char *buf, size_t len);
+extern int usbg_get_function_name(usbg_function *f, char *buf, size_t len);
 
 /* USB configurations allocation and configuration */
 
@@ -465,9 +465,9 @@ extern size_t usbg_get_config_name_len(usbg_config *c);
  * @param c Pointer to config
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_config_name(usbg_config *c, char *buf, size_t len);
+extern int usbg_get_config_name(usbg_config *c, char *buf, size_t len);
 
 /**
  * @brief Set the USB configuration attributes
@@ -555,9 +555,9 @@ extern size_t usbg_get_binding_name_len(usbg_binding *b);
  * @param b Pointer to binding
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len);
+extern int usbg_get_binding_name(usbg_binding *b, char *buf, size_t len);
 
 /* USB gadget setup and teardown */
 
@@ -594,10 +594,10 @@ extern size_t usbg_get_gadget_udc_len(usbg_gadget *g);
  * @param b Pointer to gadget
  * @param buf Buffer where udc name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  * @note If gadget isn't enabled on any udc returned string is empty.
  */
-extern char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len);
+extern int usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len);
 
 /*
  * USB function-specific attribute configuration
diff --git a/src/usbg.c b/src/usbg.c
index 1098872..55e44c2 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -741,9 +741,15 @@ size_t usbg_get_configfs_path_len(usbg_state *s)
return s ? strlen(s-path) : USBG_ERROR_INVALID_PARAM;
 }
 
-char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
+int usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
 {
-   return s ? strncpy(buf, s-path, len) : NULL;
+   int ret = USBG_SUCCESS;
+   if (s  buf)
+   strncpy(buf, s-path, len);
+   else
+   ret = USBG_ERROR_INVALID_PARAM;
+
+   return ret;
 }
 
 usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name)
@@ -909,9 +915,15 @@ size_t usbg_get_gadget_name_len(usbg_gadget *g)
return g ? strlen(g-name) : USBG_ERROR_INVALID_PARAM;
 }
 
-char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
+int usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
 {
-   return g ? strncpy(buf, g-name, len) : NULL;
+   int ret = USBG_SUCCESS;
+   if (g  buf)
+   strncpy(buf, g-name, len);
+   else
+   ret = USBG_ERROR_INVALID_PARAM;
+
+   return ret;
 }
 
 size_t usbg_get_gadget_udc_len(usbg_gadget *g)
@@ -919,9 +931,15 @@ size_t usbg_get_gadget_udc_len(usbg_gadget *g)

[PATCH v2 13/23] libusbg: Add return value to gadget creation functions.

2014-03-10 Thread Krzysztof Opasiak
Functions related to gadget creation should return error codes
instead of pointer.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |4 +-
 include/usbg/usbg.h   |   21 ++--
 src/usbg.c|  258 +
 3 files changed, 185 insertions(+), 98 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 5ab42cf..b1131b4 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -63,8 +63,8 @@ int main(void)
goto out1;
}
 
-   g = usbg_create_gadget(s, g1, g_attrs, g_strs);
-   if (!g) {
+   usbg_ret = usbg_create_gadget(s, g1, g_attrs, g_strs, g);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error on create gadget\n);
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 0d76010..f6f7a2e 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -186,6 +186,7 @@ typedef enum  {
USBG_ERROR_INVALID_PARAM = -3,
USBG_ERROR_NOT_FOUND = -4,
USBG_ERROR_IO = -5,
+   USBG_ERROR_EXIST = -6,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -255,10 +256,11 @@ extern usbg_config *usbg_get_config(usbg_gadget *g, const 
char *name);
  * @param name Name of the gadget
  * @param idVendor Gadget vendor ID
  * @param idProduct Gadget product ID
- * @return Pointer to gadget or NULL if the gadget cannot be created
+ * @param g Pointer to be filled with pointer to gadget
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name,
-   uint16_t idVendor, uint16_t idProduct);
+extern int usbg_create_gadget_vid_pid(usbg_state *s, char *name,
+   uint16_t idVendor, uint16_t idProduct, usbg_gadget **g);
 
 /**
  * @brief Create a new USB gadget device and set given attributes
@@ -267,18 +269,20 @@ extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state 
*s, char *name,
  * @param name Name of the gadget
  * @param g_attrs Gadget attributes to be set. If NULL setting is omitted.
  * @param g_strs Gadget strings to be set. If NULL setting is omitted.
+ * @param g Pointer to be filled with pointer to gadget
  * @note Given strings are assumed to be in US English
- * @return Pointer to gadget or NULL if the gadget cannot be created
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
-   usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs);
+extern int usbg_create_gadget(usbg_state *s, char *name,
+   usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs, 
usbg_gadget **g);
 
 /**
  * @brief Set the USB gadget attributes
  * @param g Pointer to gadget
  * @param g_attrs Gadget attributes
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_attrs(usbg_gadget *g,
+extern int usbg_set_gadget_attrs(usbg_gadget *g,
usbg_gadget_attrs *g_attrs);
 
 /**
@@ -383,8 +387,9 @@ extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget 
*g, int lang,
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param g_sttrs Gadget attributes
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_strs(usbg_gadget *g, int lang,
+extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index b6aa80d..ed8070d 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
ret = USBG_ERROR_NO_MEM;
break;
case EACCES:
+   case EROFS:
ret = USBG_ERROR_NO_ACCESS;
break;
case ENOENT:
@@ -155,6 +156,9 @@ static int usbg_translate_error(int error)
case EIO:
ret = USBG_ERROR_IO;
break;
+   case EEXIST:
+   ret = USBG_ERROR_EXIST;
+   break;
default:
ret = USBG_ERROR_OTHER_ERROR;
}
@@ -261,46 +265,49 @@ static int usbg_read_string(char *path, char *name, char 
*file, char *buf)
return ret;
 }
 
-static void usbg_write_buf(char *path, char *name, char *file, char *buf)
+static int usbg_write_buf(char *path, char *name, char *file, char *buf)
 {
char p[USBG_MAX_STR_LENGTH];
FILE *fp;
-   int err;
+   int ret = USBG_SUCCESS;
 
sprintf(p, %s/%s/%s, path, name, file);
 
fp = fopen(p, w);
-   if (!fp) {
-   ERRORNO(%s\n, p);
-   return;
-   }
+   if (fp) {
+   fputs(buf, fp);
+   fflush(fp);
 
-   fputs(buf, fp);
-   fflush(fp);
-   err = ferror(fp);
-   fclose(fp);
-   
-   if (err){
-   ERROR(write error);
-   return;
+   ret = 

[PATCH v2 05/23] libusbg: Refresh config strings while each get.

2014-03-10 Thread Krzysztof Opasiak
Config strings should not be cached in library.
Removing internal strings structure allowed to add
full support for multilingual strings.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/show-gadgets.c |2 +-
 include/usbg/usbg.h |3 ++-
 src/usbg.c  |   31 ---
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 7d9909a..2665262 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -108,7 +108,7 @@ void show_config(usbg_config *c)
fprintf(stdout, MaxPower\t\t%d\n, c_attrs.bMaxPower);
fprintf(stdout, bmAttributes\t0x%02x\n, c_attrs.bmAttributes);
 
-   usbg_get_config_strs(c, c_strs);
+   usbg_get_config_strs(c, LANG_US_ENG, c_strs);
fprintf(stdout, configuration\t%s\n, c_strs.configuration);
 
usbg_for_each_binding(b, c) {
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index e1a0b5c..562fdc5 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -488,10 +488,11 @@ extern void usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes);
 /**
  * @brief Get the USB configuration strings
  * @param c Pointer to configuration
+ * @param lang Language of strings
  * @param c_sttrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+extern usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index e11f44e..63b8a32 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -63,7 +63,6 @@ struct usbg_config
 
char name[USBG_MAX_NAME_LENGTH];
char path[USBG_MAX_PATH_LENGTH];
-   usbg_config_strs strs;
 };
 
 struct usbg_function
@@ -339,15 +338,24 @@ static void usbg_parse_config_attrs(char *path, char 
*name,
c_attrs-bmAttributes = usbg_read_hex(path, name, bmAttributes);
 }
 
-static void usbg_parse_config_strs(char *path, char *name,
-   usbg_config_strs *c_attrs)
+static usbg_config_strs *usbg_parse_config_strs(char *path, char *name,
+   int lang, usbg_config_strs *c_strs)
 {
-   /* Hardcoded to US English right now*/
-   int lang = LANG_US_ENG;
+   DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, %s/%s/%s/0x%x, path, name, STRINGS_DIR, lang);
-   usbg_read_string(spath, , configuration, c_attrs-configuration);
+
+   /* Check if directory exist */
+   dir = opendir(spath);
+   if (dir) {
+   closedir(dir);
+   usbg_read_string(spath, , configuration, 
c_strs-configuration);
+   } else {
+   c_strs = NULL;
+   }
+
+   return c_strs;
 }
 
 static void usbg_parse_config_bindings(usbg_config *c)
@@ -407,7 +415,6 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
c-parent = g;
strcpy(c-name, dent[i]-d_name);
strcpy(c-path, cpath);
-   usbg_parse_config_strs(cpath, c-name, c-strs);
usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(g-configs, c, cnode);
free(dent[i]);
@@ -949,8 +956,6 @@ usbg_config *usbg_create_config(usbg_gadget *g, char *name,
 
if (c_strs)
usbg_set_config_string(c, LANG_US_ENG, c_strs-configuration);
-   else
-   usbg_parse_config_strs(c-path, c-name, c-strs);
 
INSERT_TAILQ_STRING_ORDER(g-configs, chead, name, c, cnode);
 
@@ -1007,11 +1012,11 @@ void usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes)
usbg_write_hex8(c-path, c-name, bmAttributes, bmAttributes);
 }
 
-usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs)
 {
if (c  c_strs)
-   *c_strs = c-strs;
+   c_strs = usbg_parse_config_strs(c-path, c-name, lang, c_strs);
else
c_strs = NULL;
 
@@ -1032,10 +1037,6 @@ void usbg_set_config_string(usbg_config *c, int lang, 
char *str)
 
mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
-   /* strings in library are hardcoded to US English for now */
-   if (lang == LANG_US_ENG)
-   strcpy(c-strs.configuration, str);
-
usbg_write_string(path, , configuration, str);
 }
 
-- 
1.7.9.5

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


[PATCH v2 06/23] libusbg: Refresh function attributes while each get.

2014-03-10 Thread Krzysztof Opasiak
Function attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 src/usbg.c |   31 +++
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 63b8a32..d7284bb 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -74,7 +74,6 @@ struct usbg_function
char path[USBG_MAX_PATH_LENGTH];
 
usbg_function_type type;
-   usbg_function_attrs attr;
 };
 
 struct usbg_binding
@@ -267,7 +266,8 @@ static inline void usbg_write_string(char *path, char 
*name, char *file, char *b
usbg_write_buf(path, name, file, buf);
 }
 
-static void usbg_parse_function_attrs(usbg_function *f)
+static void usbg_parse_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
 {
struct ether_addr *addr;
char str_addr[40];
@@ -276,7 +276,7 @@ static void usbg_parse_function_attrs(usbg_function *f)
case F_SERIAL:
case F_ACM:
case F_OBEX:
-   f-attr.serial.port_num = usbg_read_dec(f-path, f-name, 
port_num);
+   f_attrs-serial.port_num = usbg_read_dec(f-path, f-name, 
port_num);
break;
case F_ECM:
case F_SUBSET:
@@ -286,18 +286,18 @@ static void usbg_parse_function_attrs(usbg_function *f)
usbg_read_string(f-path, f-name, dev_addr, str_addr);
addr = ether_aton(str_addr);
if (addr)
-   f-attr.net.dev_addr = *addr;
+   f_attrs-net.dev_addr = *addr;
 
usbg_read_string(f-path, f-name, host_addr, str_addr);
addr = ether_aton(str_addr);
if(addr)
-   f-attr.net.host_addr = *addr;
+   f_attrs-net.host_addr = *addr;
 
-   usbg_read_string(f-path, f-name, ifname, 
f-attr.net.ifname);
-   f-attr.net.qmult = usbg_read_dec(f-path, f-name, qmult);
+   usbg_read_string(f-path, f-name, ifname, 
f_attrs-net.ifname);
+   f_attrs-net.qmult = usbg_read_dec(f-path, f-name, qmult);
break;
case F_PHONET:
-   usbg_read_string(f-path, f-name, ifname, 
f-attr.phonet.ifname);
+   usbg_read_string(f-path, f-name, ifname, 
f_attrs-phonet.ifname);
break;
default:
ERROR(Unsupported function type\n);
@@ -322,7 +322,6 @@ static int usbg_parse_functions(char *path, usbg_gadget *g)
strcpy(f-name, dent[i]-d_name);
strcpy(f-path, fpath);
f-type = usbg_lookup_function_type(strtok(dent[i]-d_name, 
.));
-   usbg_parse_function_attrs(f);
TAILQ_INSERT_TAIL(g-functions, f, fnode);
free(dent[i]);
}
@@ -905,8 +904,6 @@ usbg_function *usbg_create_function(usbg_gadget *g, 
usbg_function_type type,
 
if (f_attrs)
usbg_set_function_attrs(f, f_attrs);
-   else
-   usbg_parse_function_attrs(f);
 
INSERT_TAILQ_STRING_ORDER(g-functions, fhead, name, f, fnode);
 
@@ -1143,10 +1140,11 @@ usbg_function_type usbg_get_function_type(usbg_function 
*f)
return f-type;
 }
 
-usbg_function_attrs *usbg_get_function_attrs(usbg_function *f, 
usbg_function_attrs *f_attrs)
+usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
 {
if (f  f_attrs)
-   *f_attrs = f-attr;
+   usbg_parse_function_attrs(f, f_attrs);
else
f_attrs = NULL;
 
@@ -1160,8 +1158,6 @@ void usbg_set_function_attrs(usbg_function *f, 
usbg_function_attrs *f_attrs)
if (!f || !f_attrs)
return;
 
-   f-attr = *f_attrs;
-
switch (f-type) {
case F_SERIAL:
case F_ACM:
@@ -1195,8 +1191,6 @@ void usbg_set_net_dev_addr(usbg_function *f, struct 
ether_addr *dev_addr)
 {
char *str_addr;
 
-   f-attr.net.dev_addr = *dev_addr;
-
str_addr = ether_ntoa(dev_addr);
usbg_write_string(f-path, f-name, dev_addr, str_addr);
 }
@@ -1205,15 +1199,12 @@ void usbg_set_net_host_addr(usbg_function *f, struct 
ether_addr *host_addr)
 {
char *str_addr;
 
-   f-attr.net.host_addr = *host_addr;
-
str_addr = ether_ntoa(host_addr);
usbg_write_string(f-path, f-name, host_addr, str_addr);
 }
 
 void usbg_set_net_qmult(usbg_function *f, int qmult)
 {
-   f-attr.net.qmult = qmult;
usbg_write_dec(f-path, f-name, qmult, qmult);
 }
 
-- 
1.7.9.5

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


[PATCH v2 16/23] libusbg: Add return value to config related functions.

2014-03-10 Thread Krzysztof Opasiak
Each usbg_set_config_*() may fail so it should have
a return value to notify user about reason of failure.

To be consistent with rest of API usbg_create_config()
should also return error code to notify user about reasons
of failure instead of binary information (NULL or not).

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |4 +-
 include/usbg/usbg.h   |   23 ++
 src/usbg.c|  110 ++---
 3 files changed, 81 insertions(+), 56 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 678514c..cda3808 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -87,8 +87,8 @@ int main(void)
goto out2;
}
 
-   c = usbg_create_config(g, c.1, NULL /* use defaults */, c_strs);
-   if (!c) {
+   usbg_ret = usbg_create_config(g, c.1, NULL /* use defaults */, 
c_strs, c);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating config\n);
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 005f9eb..1fa9d22 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -466,10 +466,12 @@ extern int usbg_get_function_name(usbg_function *f, char 
*buf, size_t len);
  * @param name Name of configuration
  * @param c_attrs Configuration attributes to be set
  * @param c_strs Configuration strings to be set
- * @return Pointer to configuration or NULL if it cannot be created
+ * @param c Pointer to be filled with pointer to configuration
+ * @note Given strings are assumed to be in US English
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs);
+extern int usbg_create_config(usbg_gadget *g, char *name,
+   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs, 
usbg_config **c);
 
 /**
  * @brief Get config name length
@@ -491,8 +493,9 @@ extern int usbg_get_config_name(usbg_config *c, char *buf, 
size_t len);
  * @brief Set the USB configuration attributes
  * @param c Pointer to configuration
  * @param c_attrs Configuration attributes
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_attrs(usbg_config *c,
+extern int usbg_set_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs);
 
 /**
@@ -508,15 +511,17 @@ extern usbg_config_attrs 
*usbg_get_config_attrs(usbg_config *c,
  * @brief Set the configuration maximum power
  * @param c Pointer to config
  * @param bMaxPower Maximum power (in 2 mA units)
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_max_power(usbg_config *c, int bMaxPower);
+extern int usbg_set_config_max_power(usbg_config *c, int bMaxPower);
 
 /**
  * @brief Set the configuration bitmap attributes
  * @param c Pointer to config
  * @param bmAttributes Configuration characteristics
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
+extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
 
 /**
  * @brief Get the USB configuration strings
@@ -533,8 +538,9 @@ extern usbg_config_strs *usbg_get_config_strs(usbg_config 
*c, int lang,
  * @param c Pointer to configuration
  * @param lang USB language ID
  * @param c_sttrs Configuration strings
+ * @return 0 on success, usbg_error on failure.
  */
-extern void usbg_set_config_strs(usbg_config *c, int lang,
+extern int usbg_set_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
@@ -542,8 +548,9 @@ extern void usbg_set_config_strs(usbg_config *c, int lang,
  * @param c Pointer to config
  * @param lang USB language ID
  * @param string Configuration description
+ * @return 0 on success, usbg_error on failure.
  */
-extern void usbg_set_config_string(usbg_config *c, int lang, char *string);
+extern int usbg_set_config_string(usbg_config *c, int lang, char *string);
 
 /**
  * @brief Add a function to a configuration
diff --git a/src/usbg.c b/src/usbg.c
index 08cd397..24e5466 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1216,53 +1216,58 @@ int usbg_create_function(usbg_gadget *g, 
usbg_function_type type,
return ret;
 }
 
-usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs)
+int usbg_create_config(usbg_gadget *g, char *name,
+   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs, 
usbg_config **c)
 {
char cpath[USBG_MAX_PATH_LENGTH];
-   usbg_config *c;
-   int ret;
+   usbg_config *conf;
+   int ret = USBG_ERROR_INVALID_PARAM;
 
-   if (!g)
-   return NULL;
+   if (!g || !c)
+   return ret;
 
/**
 * @todo Check for legal configuration name
   

[PATCH v2 23/23] libusbg: Update examples to use returned error codes.

2014-03-10 Thread Krzysztof Opasiak
Examples provided with the library should use returned
error codes and provide information to user.

Remove todo baceuse it has been already done.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |   51 +++--
 examples/show-gadgets.c   |   40 +++
 src/usbg.c|1 -
 3 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index cda3808..8eb4aeb 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -60,44 +60,83 @@ int main(void)
usbg_ret = usbg_init(/sys/kernel/config, s);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error on USB gadget init\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out1;
}
 
usbg_ret = usbg_create_gadget(s, g1, g_attrs, g_strs, g);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error on create gadget\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
usbg_ret = usbg_create_function(g, F_ACM, usb0, NULL, f_acm0);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating acm0 function\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
usbg_ret = usbg_create_function(g, F_ACM, usb1, NULL, f_acm1);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating acm1 function\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_ret = usbg_create_function(g, F_ECM, usb0, NULL, f_acm1);
+   usbg_ret = usbg_create_function(g, F_ECM, usb0, NULL, f_ecm);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating ecm function\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_ret = usbg_create_config(g, c.1, NULL /* use defaults */, 
c_strs, c);
+   usbg_ret = usbg_create_config(g, c.1, NULL /* use defaults */, 
c_strs,
+   c);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating config\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_add_config_function(c, acm.GS0, f_acm0);
-   usbg_add_config_function(c, acm.GS1, f_acm1);
-   usbg_add_config_function(c, ecm.usb0, f_ecm);
+   usbg_ret = usbg_add_config_function(c, acm.GS0, f_acm0);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error adding acm.GS0\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
+
+   usbg_ret = usbg_add_config_function(c, acm.GS1, f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error adding acm.GS1\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
 
-   usbg_enable_gadget(g, DEFAULT_UDC);
+   usbg_ret = usbg_add_config_function(c, ecm.usb0, f_ecm);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error adding ecm.usb0\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
+
+   usbg_ret = usbg_enable_gadget(g, DEFAULT_UDC);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error enabling gadget\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
 
ret = 0;
 
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 4d79a09..df86cb9 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -30,11 +30,17 @@
 void show_gadget(usbg_gadget *g)
 {
char buf[USBG_MAX_STR_LENGTH];
+   int usbg_ret;
usbg_gadget_attrs g_attrs;
usbg_gadget_strs g_strs;
 
usbg_get_gadget_name(g, buf, USBG_MAX_STR_LENGTH);
-   usbg_get_gadget_attrs(g, g_attrs);
+   usbg_ret = usbg_get_gadget_attrs(g, g_attrs);
+   if (usbg_ret != USBG_SUCCESS) {
+

[PATCH v2 19/23] libusbg: Return error code instead of NULL pointer - config.

2014-03-10 Thread Krzysztof Opasiak
Change usbg_get_config_strs() and usbg_get_config_attrs()
to return usbg_error instead of NULL pointer.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |9 -
 src/usbg.c  |   50 +-
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 6855833..1bb652e 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -502,10 +502,9 @@ extern int usbg_set_config_attrs(usbg_config *c,
  * @brief Get the USB configuration strings
  * @param c Pointer to configuration
  * @param c_attrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
-   usbg_config_attrs *c_attrs);
+extern int usbg_get_config_attrs(usbg_config *c, usbg_config_attrs *c_attrs);
 
 /**
  * @brief Set the configuration maximum power
@@ -528,9 +527,9 @@ extern int usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes);
  * @param c Pointer to configuration
  * @param lang Language of strings
  * @param c_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
+extern int usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 2d67bd6..f97ad1d 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -441,20 +441,28 @@ static int usbg_parse_functions(char *path, usbg_gadget 
*g)
return ret;
 }
 
-static void usbg_parse_config_attrs(char *path, char *name,
+static int usbg_parse_config_attrs(char *path, char *name,
usbg_config_attrs *c_attrs)
 {
-   int buf;
-   usbg_read_dec(path, name, MaxPower, buf);
-   c_attrs-bMaxPower = (uint8_t)buf;
-   usbg_read_hex(path, name, bmAttributes, buf);
-   c_attrs-bmAttributes = (uint8_t)buf;
+   int buf, ret;
+
+   ret = usbg_read_dec(path, name, MaxPower, buf);
+   if (ret == USBG_SUCCESS) {
+   c_attrs-bMaxPower = (uint8_t)buf;
+
+   ret = usbg_read_hex(path, name, bmAttributes, buf);
+   if (ret == USBG_SUCCESS)
+   c_attrs-bmAttributes = (uint8_t)buf;
+   }
+
+   return ret;
 }
 
-static usbg_config_strs *usbg_parse_config_strs(char *path, char *name,
+static int usbg_parse_config_strs(char *path, char *name,
int lang, usbg_config_strs *c_strs)
 {
DIR *dir;
+   int ret;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, %s/%s/%s/0x%x, path, name, STRINGS_DIR, lang);
@@ -463,12 +471,13 @@ static usbg_config_strs *usbg_parse_config_strs(char 
*path, char *name,
dir = opendir(spath);
if (dir) {
closedir(dir);
-   usbg_read_string(spath, , configuration, 
c_strs-configuration);
+   ret = usbg_read_string(spath, , configuration,
+   c_strs-configuration);
} else {
-   c_strs = NULL;
+   ret = usbg_translate_error(errno);
}
 
-   return c_strs;
+   return ret;
 }
 
 static int usbg_parse_config_bindings(usbg_config *c)
@@ -1323,15 +1332,11 @@ int usbg_set_config_attrs(usbg_config *c, 
usbg_config_attrs *c_attrs)
return ret;
 }
 
-usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
+int usbg_get_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs)
 {
-   if (c  c_attrs)
-   usbg_parse_config_attrs(c-path, c-name, c_attrs);
-   else
-   c_attrs = NULL;
-
-   return c_attrs;
+   return c  c_attrs ? usbg_parse_config_attrs(c-path, c-name, c_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_config_max_power(usbg_config *c, int bMaxPower)
@@ -1346,15 +1351,10 @@ int usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes)
: USBG_ERROR_INVALID_PARAM;
 }
 
-usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
-   usbg_config_strs *c_strs)
+int usbg_get_config_strs(usbg_config *c, int lang, usbg_config_strs *c_strs)
 {
-   if (c  c_strs)
-   c_strs = usbg_parse_config_strs(c-path, c-name, lang, c_strs);
-   else
-   c_strs = NULL;
-
-   return c_strs;
+   return c  c_strs ? usbg_parse_config_strs(c-path, c-name, lang, 
c_strs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_config_strs(usbg_config *c, int lang,
-- 
1.7.9.5

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


[PATCH v2 18/23] libusbg: Return error code instead of NULL pointer.

2014-03-10 Thread Krzysztof Opasiak
Change usbg_get_gadget_strs() and usbg_get_gadget_attrs()
to return usbg_error instead of NULL pointer.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   10 --
 src/usbg.c  |   43 ++-
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 3ad98b6..6855833 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -291,10 +291,9 @@ extern int usbg_set_gadget_attrs(usbg_gadget *g,
  * @brief Get the USB gadget strings
  * @param g Pointer to gadget
  * @param g_attrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-   usbg_gadget_attrs *g_attrs);
+extern int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs);
 
 /**
  * @brief Get gadget name length
@@ -386,10 +385,9 @@ extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB);
  * @param g Pointer to gadget
  * @param lang Language of strings
  * @param g_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred or
- * if no strings for given language.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index f9f5ec8..2d67bd6 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -617,9 +617,10 @@ out:
return ret;
 }
 
-static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
+static int usbg_parse_gadget_strs(char *path, char *name, int lang,
usbg_gadget_strs *g_strs)
 {
+   int ret;
DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
@@ -629,14 +630,23 @@ static usbg_gadget_strs *usbg_parse_strings(char *path, 
char *name, int lang,
dir = opendir(spath);
if (dir) {
closedir(dir);
-   usbg_read_string(spath, , serialnumber, g_strs-str_ser);
-   usbg_read_string(spath, , manufacturer, g_strs-str_mnf);
-   usbg_read_string(spath, , product, g_strs-str_prd);
+   ret = usbg_read_string(spath, , serialnumber, 
g_strs-str_ser);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_string(spath, , manufacturer, 
g_strs-str_mnf);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_string(spath, , product, g_strs-str_prd);
+   if (ret != USBG_SUCCESS)
+   goto out;
} else {
-   g_strs = NULL;
+   ret = usbg_translate_error(errno);
}
 
-   return g_strs;
+out:
+   return ret;
 }
 
 static inline int usbg_parse_gadget(char *path, char *name, usbg_state *parent,
@@ -928,15 +938,10 @@ int usbg_create_gadget(usbg_state *s, char *name,
return ret;
 }
 
-usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-   usbg_gadget_attrs *g_attrs)
+int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs)
 {
-   if (g  g_attrs)
-   usbg_parse_gadget_attrs(g-path, g-name, g_attrs);
-   else
-   g_attrs = NULL;
-
-   return g_attrs;
+   return g  g_attrs ? usbg_parse_gadget_attrs(g-path, g-name, g_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 size_t usbg_get_gadget_name_len(usbg_gadget *g)
@@ -1066,15 +1071,11 @@ int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB)
: USBG_ERROR_INVALID_PARAM;
 }
 
-usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+int usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs)
 {
-   if (g  g_strs)
-   g_strs = usbg_parse_strings(g-path, g-name, lang, g_strs);
-   else
-   g_strs = NULL;
-
-   return g_strs;
+   return g  g_strs ? usbg_parse_gadget_strs(g-path, g-name, lang,
+   g_strs) : USBG_ERROR_INVALID_PARAM;
 }
 
 static int usbg_check_dir(char *path)
-- 
1.7.9.5

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


[PATCH v2 15/23] libusbg: Add return value to usb function related functions.

2014-03-10 Thread Krzysztof Opasiak
Each usbg_set_*() may fail so it should have a return value
to notify user about reason of failure.

To be consistent with rest of API usbg_create_function()
should also return error code to notify user about reasons
of failure instead of binary information (NULL or not).

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/gadget-acm-ecm.c |   12 ++--
 include/usbg/usbg.h   |   20 ---
 src/usbg.c|  140 -
 3 files changed, 108 insertions(+), 64 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index b1131b4..678514c 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -69,20 +69,20 @@ int main(void)
goto out2;
}
 
-   f_acm0 = usbg_create_function(g, F_ACM, usb0, NULL);
-   if (!f_acm0) {
+   usbg_ret = usbg_create_function(g, F_ACM, usb0, NULL, f_acm0);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating acm0 function\n);
goto out2;
}
 
-   f_acm1 = usbg_create_function(g, F_ACM, usb1, NULL);
-   if (!f_acm1) {
+   usbg_ret = usbg_create_function(g, F_ACM, usb1, NULL, f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating acm1 function\n);
goto out2;
}
 
-   f_ecm = usbg_create_function(g, F_ECM, usb0, NULL);
-   if (!f_ecm) {
+   usbg_ret = usbg_create_function(g, F_ECM, usb0, NULL, f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, Error creating ecm function\n);
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 17084bb..005f9eb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -435,10 +435,12 @@ extern int usbg_set_gadget_product(usbg_gadget *g, int 
lang, char *prd);
  * @param type Type of function
  * @param instance Function instance name
  * @param f_attrs Function attributes to be set. If NULL setting is omitted.
- * @return Pointer to function or NULL if it cannot be created
+ * @param f Pointer to be filled with pointer to function
+ * @note Given strings are assumed to be in US English
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type 
type,
-   char *instance, usbg_function_attrs *f_attrs);
+extern int usbg_create_function(usbg_gadget *g, usbg_function_type type,
+   char *instance, usbg_function_attrs *f_attrs, usbg_function 
**f);
 
 /**
  * @brief Get function name length
@@ -640,29 +642,33 @@ extern usbg_function_attrs 
*usbg_get_function_attrs(usbg_function *f,
  * @brief Set attributes of given function
  * @param f Pointer to function
  * @param f_attrs Attributes to be set
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_function_attrs(usbg_function *f, usbg_function_attrs 
*f_attrs);
+extern int usbg_set_function_attrs(usbg_function *f, usbg_function_attrs 
*f_attrs);
 
 /**
  * @brief Set USB function network device address
  * @param f Pointer to function
  * @param addr Pointer to Ethernet address
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *addr);
+extern int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *addr);
 
 /**
  * @brief Set USB function network host address
  * @param f Pointer to function
  * @param addr Pointer to Ethernet address
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_host_addr(usbg_function *f, struct ether_addr *addr);
+extern int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *addr);
 
 /**
  * @brief Set USB function network qmult
  * @param f Pointer to function
  * @param qmult Queue length multiplier
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_qmult(usbg_function *f, int qmult);
+extern int usbg_set_net_qmult(usbg_function *f, int qmult);
 
 /**
  * @def usbg_for_each_gadget(g, s)
diff --git a/src/usbg.c b/src/usbg.c
index 5a4202c..08cd397 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1162,52 +1162,58 @@ int usbg_set_gadget_product(usbg_gadget *g, int lang, 
char *prd)
return ret;
 }
 
-usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type type,
-   char *instance, usbg_function_attrs *f_attrs)
+int usbg_create_function(usbg_gadget *g, usbg_function_type type,
+   char *instance, usbg_function_attrs *f_attrs, usbg_function **f)
 {
char fpath[USBG_MAX_PATH_LENGTH];
char name[USBG_MAX_STR_LENGTH];
-   usbg_function *f;
-   int ret;
+   usbg_function *func;
+   int ret = USBG_ERROR_INVALID_PARAM;
 
-   if (!g)
-   return NULL;
+   if (!g || !f)
+   return ret;
 
/**
 * @todo Check for legal 

[PATCH v2 21/23] libusbg: Return error code instead of -1.

2014-03-10 Thread Krzysztof Opasiak
Change usbg_add_config_function() to return usbg_error
instead of returning 0 or -1.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |2 +-
 src/usbg.c  |   14 --
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ae53d22..249b40f 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -557,7 +557,7 @@ extern int usbg_set_config_string(usbg_config *c, int lang, 
char *string);
  * @param c Pointer to config
  * @param name Name of configuration function binding
  * @param f Pointer to function
- * @return 0 on success, -1 on failure.
+ * @return 0 on success, usbg_error on failure.
  */
 extern int usbg_add_config_function(usbg_config *c, char *name, usbg_function 
*f);
 
diff --git a/src/usbg.c b/src/usbg.c
index 3589dd0..944dd10 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1418,21 +1418,21 @@ int usbg_add_config_function(usbg_config *c, char 
*name, usbg_function *f)
char bpath[USBG_MAX_PATH_LENGTH];
char fpath[USBG_MAX_PATH_LENGTH];
usbg_binding *b;
-   int ret = -1;
+   int ret = USBG_SUCCESS;
 
if (!c || !f)
-   return ret;
+   return USBG_ERROR_INVALID_PARAM;
 
b = usbg_get_binding(c, name);
if (b) {
ERROR(duplicate binding name\n);
-   return ret;
+   return USBG_ERROR_EXIST;
}
 
b = usbg_get_link_binding(c, f);
if (b) {
ERROR(duplicate binding link\n);
-   return ret;
+   return USBG_ERROR_EXIST;
}
 
sprintf(bpath, %s/%s/%s, c-path, c-name, name);
@@ -1441,13 +1441,15 @@ int usbg_add_config_function(usbg_config *c, char 
*name, usbg_function *f)
b = malloc(sizeof(usbg_binding));
if (!b) {
ERRORNO(allocating binding\n);
-   return -1;
+   return USBG_ERROR_NO_MEM;
}
 
ret = symlink(fpath, bpath);
if (ret  0) {
ERRORNO(%s - %s\n, bpath, fpath);
return ret;
+   } else {
+   ret = USBG_SUCCESS;
}
 
strcpy(b-name, name);
@@ -1457,7 +1459,7 @@ int usbg_add_config_function(usbg_config *c, char *name, 
usbg_function *f)
 
INSERT_TAILQ_STRING_ORDER(c-bindings, bhead, name, b, bnode);
 
-   return 0;
+   return ret;
 }
 
 usbg_function *usbg_get_binding_target(usbg_binding *b)
-- 
1.7.9.5

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


[PATCH v2 20/23] libusbg: Change usbg_get_function_attrs() to return error code.

2014-03-10 Thread Krzysztof Opasiak
usbg_get_function_attrs() may fail due to many reasons
so it should notify the user about exact reason of failure
instead of returning only NULL pointer.

Add also USBG_ERROR_NOT_SUPPORTED to usbg_set_function_attrs().

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |5 ++--
 src/usbg.c  |   77 +++
 2 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1bb652e..ae53d22 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -189,6 +189,7 @@ typedef enum  {
USBG_ERROR_EXIST = -6,
USBG_ERROR_NO_DEV = -7,
USBG_ERROR_BUSY = -8,
+   USBG_ERROR_NOT_SUPPORTED = -9,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -641,9 +642,9 @@ extern usbg_function_type 
usbg_get_function_type(usbg_function *f);
  * @brief Get attributes of given function
  * @param f Pointer to function
  * @param f_attrs Union to be filled
- * @return Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred.
  */
-extern usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+extern int usbg_get_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index f97ad1d..3589dd0 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -365,43 +365,76 @@ static void usbg_free_state(usbg_state *s)
free(s);
 }
 
-
-static void usbg_parse_function_attrs(usbg_function *f,
+static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
struct ether_addr *addr;
char str_addr[40];
+   int ret;
+
+   ret = usbg_read_string(f-path, f-name, dev_addr, str_addr);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   addr = ether_aton(str_addr);
+   if (addr) {
+   f_attrs-net.dev_addr = *addr;
+   } else {
+   ret = USBG_ERROR_IO;
+   goto out;
+   }
+
+   ret = usbg_read_string(f-path, f-name, host_addr, str_addr);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   addr = ether_aton(str_addr);
+   if (addr) {
+   f_attrs-net.host_addr = *addr;
+   } else {
+   ret = USBG_ERROR_IO;
+   goto out;
+   }
+
+   ret = usbg_read_string(f-path, f-name, ifname, f_attrs-net.ifname);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_dec(f-path, f-name, qmult, (f_attrs-net.qmult));
+
+out:
+   return ret;
+}
+
+static int usbg_parse_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
+{
+   int ret;
 
switch (f-type) {
case F_SERIAL:
case F_ACM:
case F_OBEX:
-   usbg_read_dec(f-path, f-name, port_num, 
(f_attrs-serial.port_num));
+   ret = usbg_read_dec(f-path, f-name, port_num,
+   (f_attrs-serial.port_num));
break;
case F_ECM:
case F_SUBSET:
case F_NCM:
case F_EEM:
case F_RNDIS:
-   usbg_read_string(f-path, f-name, dev_addr, str_addr);
-   addr = ether_aton(str_addr);
-   if (addr)
-   f_attrs-net.dev_addr = *addr;
-
-   usbg_read_string(f-path, f-name, host_addr, str_addr);
-   addr = ether_aton(str_addr);
-   if(addr)
-   f_attrs-net.host_addr = *addr;
-
-   usbg_read_string(f-path, f-name, ifname, 
f_attrs-net.ifname);
-   usbg_read_dec(f-path, f-name, qmult, (f_attrs-net.qmult));
+   ret = usbg_parse_function_net_attrs(f, f_attrs);
break;
case F_PHONET:
-   usbg_read_string(f-path, f-name, ifname, 
f_attrs-phonet.ifname);
+   ret = usbg_read_string(f-path, f-name, ifname,
+   f_attrs-phonet.ifname);
break;
default:
ERROR(Unsupported function type\n);
+   ret = USBG_ERROR_NOT_SUPPORTED;
}
+
+   return ret;
 }
 
 static int usbg_parse_functions(char *path, usbg_gadget *g)
@@ -1516,15 +1549,10 @@ usbg_function_type usbg_get_function_type(usbg_function 
*f)
return f-type;
 }
 
-usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
-   usbg_function_attrs *f_attrs)
+int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
 {
-   if (f  f_attrs)
-   usbg_parse_function_attrs(f, f_attrs);
-   else
-   f_attrs = NULL;
-
-   return f_attrs;
+   return f  f_attrs ? usbg_parse_function_attrs(f, f_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_function_net_attrs(usbg_function *f, usbg_f_net_attrs *attrs)
@@ -1577,6 +1605,7 @@ int  

[PATCH v2 17/23] libusbg: Add return value to usbg_enable/disable_gadget().

2014-03-10 Thread Krzysztof Opasiak
Enabling and disabling gadget may fail due to many reasons
so those functions should notify user about it.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   10 +---
 src/usbg.c  |   67 ++-
 2 files changed, 57 insertions(+), 20 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1fa9d22..3ad98b6 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -187,6 +187,8 @@ typedef enum  {
USBG_ERROR_NOT_FOUND = -4,
USBG_ERROR_IO = -5,
USBG_ERROR_EXIST = -6,
+   USBG_ERROR_NO_DEV = -7,
+   USBG_ERROR_BUSY = -8,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -589,7 +591,7 @@ extern int usbg_get_binding_name(usbg_binding *b, char 
*buf, size_t len);
 /**
  * @brief Get a list of UDC devices on the system
  * @param udc_list Pointer to pointer to dirent pointer
- * @return Number of UDC devices on success, -1 on failure
+ * @return Number of UDC devices on success, usbg_error on failure
  */
 extern int usbg_get_udcs(struct dirent ***udc_list);
 
@@ -597,14 +599,16 @@ extern int usbg_get_udcs(struct dirent ***udc_list);
  * @brief Enable a USB gadget device
  * @param g Pointer to gadget
  * @param udc Name of UDC to enable gadget
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_enable_gadget(usbg_gadget *g, char *udc);
+extern int usbg_enable_gadget(usbg_gadget *g, char *udc);
 
 /**
  * @brief Disable a USB gadget device
  * @param g Pointer to gadget
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_disable_gadget(usbg_gadget *g);
+extern int usbg_disable_gadget(usbg_gadget *g);
 
 /**
  * @brief Get gadget name length
diff --git a/src/usbg.c b/src/usbg.c
index 24e5466..f9f5ec8 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -159,6 +159,12 @@ static int usbg_translate_error(int error)
case EEXIST:
ret = USBG_ERROR_EXIST;
break;
+   case ENODEV:
+   ret = USBG_ERROR_NO_DEV;
+   break;
+   case EBUSY:
+   ret = USBG_ERROR_BUSY;
+   break;
default:
ret = USBG_ERROR_OTHER_ERROR;
}
@@ -1443,34 +1449,61 @@ int usbg_get_binding_name(usbg_binding *b, char *buf, 
size_t len)
 
 int usbg_get_udcs(struct dirent ***udc_list)
 {
-   return scandir(/sys/class/udc, udc_list, file_select, alphasort);
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (udc_list) {
+   ret = scandir(/sys/class/udc, udc_list, file_select, 
alphasort);
+   if (ret  0)
+   ret = usbg_translate_error(errno);
+   }
+
+   return ret;
 }
 
-void usbg_enable_gadget(usbg_gadget *g, char *udc)
+int usbg_enable_gadget(usbg_gadget *g, char *udc)
 {
char gudc[USBG_MAX_STR_LENGTH];
struct dirent **udc_list;
-   int n;
+   int i;
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (!g)
+   return ret;
 
if (!udc) {
-   n = usbg_get_udcs(udc_list);
-   if (!n)
-   return;
-   strcpy(gudc, udc_list[0]-d_name);
-   while (n--)
-   free(udc_list[n]);
-   free(udc_list);
-   } else
-   strcpy (gudc, udc);
+   ret = usbg_get_udcs(udc_list);
+   if (ret = 0) {
+   /* Look for default one - first in string order */
+   strcpy(gudc, udc_list[0]-d_name);
+   udc = gudc;
+
+   /** Free the memory */
+   for (i = 0; i  ret; ++i)
+   free(udc_list[i]);
+   free(udc_list);
+   } else {
+   return ret;
+   }
+   }
+
+   ret = usbg_write_string(g-path, g-name, UDC, udc);
 
-   strcpy(g-udc, gudc);
-   usbg_write_string(g-path, g-name, UDC, gudc);
+   if (ret == USBG_SUCCESS)
+   strcpy(g-udc, udc);
+
+   return ret;
 }
 
-void usbg_disable_gadget(usbg_gadget *g)
+int usbg_disable_gadget(usbg_gadget *g)
 {
-   strcpy(g-udc, );
-   usbg_write_string(g-path, g-name, UDC, );
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (g) {
+   strcpy(g-udc, );
+   ret = usbg_write_string(g-path, g-name, UDC, );
+   }
+
+   return ret;
 }
 
 /*
-- 
1.7.9.5

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


[PATCH 1/6] libusbg: Add remove binding functionality.

2014-03-10 Thread Krzysztof Opasiak
Add function which allow to remove binding between function
and configuration. This functions also remove binding from
internal library structures wht means that after this
operation all pointers to removed binding are invalid.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   10 ++
 src/usbg.c  |   36 
 2 files changed, 46 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 354ba38..aa8ebc9 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -267,6 +267,16 @@ extern usbg_function *usbg_get_function(usbg_gadget *g, 
const char *name);
  */
 extern usbg_config *usbg_get_config(usbg_gadget *g, const char *name);
 
+/* USB gadget/config/function/binding removal */
+
+/**
+ * @brief Remove binding between configuration and function
+ * @details This function frees also the memory allocated for binding
+ * @param b Binding to be removed
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_binding(usbg_binding *b);
+
 /* USB gadget allocation and configuration */
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index f655675..e82658c 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
break;
case EACCES:
case EROFS:
+   case EPERM:
ret = USBG_ERROR_NO_ACCESS;
break;
case ENOENT:
@@ -450,6 +451,22 @@ static void usbg_free_state(usbg_state *s)
free(s);
 }
 
+static int usbg_remove_file(char *path, char *name)
+{
+   int ret;
+   char buf[USBG_MAX_PATH_LENGTH];
+
+   sprintf(buf, %s/%s, path, name);
+
+   ret = unlink(buf);
+   if (ret != 0)
+   ret = usbg_translate_error(errno);
+   else
+   ret = USBG_SUCCESS;
+
+   return ret;
+}
+
 static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
@@ -957,6 +974,25 @@ usbg_binding *usbg_get_link_binding(usbg_config *c, 
usbg_function *f)
return NULL;
 }
 
+int usbg_remove_binding(usbg_binding *b)
+{
+   int ret = USBG_SUCCESS;
+   usbg_config *c;
+
+   if (!b)
+   return USBG_ERROR_INVALID_PARAM;
+
+   c = b-parent;
+
+   ret = usbg_remove_file(b-path, b-name);
+   if (ret == USBG_SUCCESS) {
+   TAILQ_REMOVE((c-bindings), b, bnode);
+   usbg_free_binding(b);
+   }
+
+   return ret;
+}
+
 static int usbg_create_empty_gadget(usbg_state *s, char *name, usbg_gadget **g)
 {
char gpath[USBG_MAX_PATH_LENGTH];
-- 
1.7.9.5

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


[PATCH 0/6] libusbg: Add remove gadget/config/func/binding functionality.

2014-03-10 Thread Krzysztof Opasiak
Dear Matt,

In this series of patch I have added remove gadget, config, function,
binding functionality which was missing since introduction of library.
I have also added remove strings functionality which allow to remove
gadget and configuration strings in given language.

To show how to use new part of API I have also added example
gadget-vid-pid-remove which removes gadget created by
gadget-acm-ecm (identified using VID and PID).

This series of patch depends on all my previous series whcih you can
find on a list or in github pull request.

--
BR's
Krzysztof Opasiak
Samsung RD Institute Poland
Samsung Electronics

---
Krzysztof Opasiak (6):
  libusbg: Add remove binding functionality.
  libusbg: Add remove gadget/config strings functionality.
  libusbg: Add remove configuration functionality.
  libusbg: Add remove function functionality.
  libusbg: Add remove gadget functionality.
  libusbg: Update examples to new API functionality.

 examples/Makefile.am |3 +-
 examples/gadget-vid-pid-remove.c |  113 ++
 include/usbg/usbg.h  |   57 +-
 src/usbg.c   |  234 ++
 4 files changed, 405 insertions(+), 2 deletions(-)
 create mode 100644 examples/gadget-vid-pid-remove.c

-- 
1.7.9.5

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


[PATCH 4/6] libusbg: Add remove function functionality.

2014-03-10 Thread Krzysztof Opasiak
Add function which allow to remove USB function.
This functions also remove function from internal
library structures what means that after this
operation all pointers to removed function are invalid.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   10 ++
 src/usbg.c  |   42 ++
 2 files changed, 52 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ef5aba2..f65d443 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -288,6 +288,16 @@ extern int usbg_remove_binding(usbg_binding *b);
 extern int usbg_remove_config(usbg_config *c, int recursive);
 
 /**
+ * @brief Remove existing USB function
+ * @details This function frees also the memory allocated for function
+ * @param f Function to be removed
+ * @param recursive If different than 0 all bindings pointing
+ *  to this function will be also removed before removing function
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_function(usbg_function *f, int recursive);
+
+/**
  * @brief Remove configuration strings for given language
  * @param c Pointer to configuration
  * @param lang Language of strings which should be deleted
diff --git a/src/usbg.c b/src/usbg.c
index 55530bb..1ea05d1 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1071,6 +1071,48 @@ int usbg_remove_config(usbg_config *c, int recursive)
return ret;
 }
 
+int usbg_remove_function(usbg_function *f, int recursive)
+{
+   int ret = USBG_ERROR_INVALID_PARAM;
+   usbg_gadget *g;
+
+   if (!f)
+   return ret;
+
+   g = f-parent;
+
+   if (recursive) {
+   /* Recursive flag was given
+* so remove all bindings to this function */
+   usbg_config *c;
+   usbg_binding *b;
+
+   TAILQ_FOREACH(c, g-configs, cnode) {
+   b = TAILQ_FIRST(c-bindings);
+   while (b != NULL) {
+   if (b-target == f) {
+   usbg_binding *b_next = TAILQ_NEXT(b, 
bnode);
+   ret = usbg_remove_binding(b);
+   if (ret != USBG_SUCCESS)
+   return ret;
+
+   b = b_next;
+   } else {
+   b = TAILQ_NEXT(b, bnode);
+   }
+   }
+   }
+   }
+
+   ret = usbg_remove_dir(f-path, f-name);
+   if (ret == USBG_SUCCESS) {
+   TAILQ_REMOVE((g-functions), f, fnode);
+   usbg_free_function(f);
+   }
+
+   return ret;
+}
+
 int usbg_remove_config_strs(usbg_config *c, int lang)
 {
int ret = USBG_SUCCESS;
-- 
1.7.9.5

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


[PATCH 5/6] libusbg: Add remove gadget functionality.

2014-03-10 Thread Krzysztof Opasiak
Add function which allow to remove USB gadget.
This functions also remove gadget from internal
library structures what means that after this
operation all pointers to removed gadget are invalid.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   10 ++
 src/usbg.c  |   47 +++
 2 files changed, 57 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index f65d443..d0abd80 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -298,6 +298,16 @@ extern int usbg_remove_config(usbg_config *c, int 
recursive);
 extern int usbg_remove_function(usbg_function *f, int recursive);
 
 /**
+ * @brief Remove existing USB gadget
+ * @details This function frees also the memory allocated for gadget
+ * @param g Gadget to be removed
+ * @param recursive If different than 0 all configs, functions
+ * and strings will be also removed before removing gadget
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_gadget(usbg_gadget *g, int recursive);
+
+/**
  * @brief Remove configuration strings for given language
  * @param c Pointer to configuration
  * @param lang Language of strings which should be deleted
diff --git a/src/usbg.c b/src/usbg.c
index 1ea05d1..8f613a4 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1113,6 +1113,53 @@ int usbg_remove_function(usbg_function *f, int recursive)
return ret;
 }
 
+int usbg_remove_gadget(usbg_gadget *g, int recursive)
+{
+   int ret = USBG_ERROR_INVALID_PARAM;
+   usbg_state *s;
+   if (!g)
+   return ret;
+
+   s = g-parent;
+
+   if (recursive) {
+   /* Recursive flag was given
+* so remove all configs and functions
+* using recursive flags */
+   usbg_config *c;
+   usbg_function *f;
+   char spath[USBG_MAX_PATH_LENGTH];
+
+   while (!TAILQ_EMPTY(g-configs)) {
+   c = TAILQ_FIRST(g-configs);
+   ret = usbg_remove_config(c, 1);
+   if (ret != USBG_SUCCESS)
+   return ret;
+   }
+
+   while (!TAILQ_EMPTY(g-functions)) {
+   f = TAILQ_FIRST(g-functions);
+   ret = usbg_remove_function(f, 1);
+   if (ret != USBG_SUCCESS)
+   return ret;
+   }
+
+   sprintf(spath, %s/%s/%s, g-path, g-name, STRINGS_DIR);
+
+   ret = usbg_remove_all_dirs(spath);
+   if (ret != USBG_SUCCESS)
+   return ret;
+   }
+
+   ret = usbg_remove_dir(g-path, g-name);
+   if (ret == USBG_SUCCESS) {
+   TAILQ_REMOVE((s-gadgets), g, gnode);
+   usbg_free_gadget(g);
+   }
+
+   return ret;
+}
+
 int usbg_remove_config_strs(usbg_config *c, int lang)
 {
int ret = USBG_SUCCESS;
-- 
1.7.9.5

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


[PATCH 2/6] libusbg: Add remove gadget/config strings functionality.

2014-03-10 Thread Krzysztof Opasiak
Add functions which allow to remove strings in gadget
and configuration.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 include/usbg/usbg.h |   16 
 src/usbg.c  |   47 +++
 2 files changed, 63 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index aa8ebc9..6c14cbc 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -277,6 +277,22 @@ extern usbg_config *usbg_get_config(usbg_gadget *g, const 
char *name);
  */
 extern int usbg_remove_binding(usbg_binding *b);
 
+/**
+ * @brief Remove configuration strings for given language
+ * @param c Pointer to configuration
+ * @param lang Language of strings which should be deleted
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_config_strs(usbg_config *c, int lang);
+
+/**
+ * @brief Remove gadget strings for given language
+ * @param g Pointer to gadget
+ * @param lang Language of strings which should be deleted
+ * @return 0 on success, usbg_error if error occurred
+ */
+extern int usbg_remove_gadget_strs(usbg_gadget *g, int lang);
+
 /* USB gadget allocation and configuration */
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index e82658c..8f18047 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -467,6 +467,22 @@ static int usbg_remove_file(char *path, char *name)
return ret;
 }
 
+static int usbg_remove_dir(char *path, char *name)
+{
+   int ret;
+   char buf[USBG_MAX_PATH_LENGTH];
+
+   sprintf(buf, %s/%s, path, name);
+
+   ret = rmdir(buf);
+   if (ret != 0)
+   ret = usbg_translate_error(errno);
+   else
+   ret = USBG_SUCCESS;
+
+   return ret;
+}
+
 static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
@@ -993,6 +1009,37 @@ int usbg_remove_binding(usbg_binding *b)
return ret;
 }
 
+int usbg_remove_config_strs(usbg_config *c, int lang)
+{
+   int ret = USBG_SUCCESS;
+   char path[USBG_MAX_PATH_LENGTH];
+
+   if (!c)
+   return USBG_ERROR_INVALID_PARAM;
+
+   sprintf(path, %s/%s/%s/0x%x, c-path, c-name, STRINGS_DIR, lang);
+
+   ret = usbg_remove_dir(path, );
+
+   return ret;
+}
+
+int usbg_remove_gadget_strs(usbg_gadget *g, int lang)
+{
+   int ret = USBG_SUCCESS;
+   char path[USBG_MAX_PATH_LENGTH];
+
+   if (!g)
+   return USBG_ERROR_INVALID_PARAM;
+
+   sprintf(path, %s/%s/%s/0x%x, g-path, g-name, STRINGS_DIR, lang);
+
+   ret = usbg_remove_dir(path, );
+
+   return ret;
+}
+
+
 static int usbg_create_empty_gadget(usbg_state *s, char *name, usbg_gadget **g)
 {
char gpath[USBG_MAX_PATH_LENGTH];
-- 
1.7.9.5

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


[PATCH 6/6] libusbg: Update examples to new API functionality.

2014-03-10 Thread Krzysztof Opasiak
Removing gadget/config/function/binding functionality
has been added to API so add example of how to use it.

Signed-off-by: Krzysztof Opasiak k.opas...@samsung.com
---
 examples/Makefile.am |3 +-
 examples/gadget-vid-pid-remove.c |  113 ++
 include/usbg/usbg.h  |1 -
 3 files changed, 115 insertions(+), 2 deletions(-)
 create mode 100644 examples/gadget-vid-pid-remove.c

diff --git a/examples/Makefile.am b/examples/Makefile.am
index f9f9407..9fc235a 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,5 +1,6 @@
-bin_PROGRAMS = show-gadgets gadget-acm-ecm 
+bin_PROGRAMS = show-gadgets gadget-acm-ecm gadget-vid-pid-remove
 gadget_acm_ecm_SOURCES = gadget-acm-ecm.c
 show_gadgets_SOURCES = show-gadgets.c
+gadget_vid_pid_remove_SOURCES = gadget-vid-pid-remove.c
 AM_CPPFLAGS=-I../include/
 AM_LDFLAGS=-L../src/ -lusbg
diff --git a/examples/gadget-vid-pid-remove.c b/examples/gadget-vid-pid-remove.c
new file mode 100644
index 000..55e8364
--- /dev/null
+++ b/examples/gadget-vid-pid-remove.c
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2014 Samsung Electronics
+ *
+ * Krzysztof Opasiak k.opas...@samsung.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+/**
+ * @file gadget-vid-pid-remove.c
+ * @example gadget-vid-pid-remove.c
+ * This is an example of how to find and remove an gadget device with given
+ * Vendor ID and product ID.
+ */
+
+#include errno.h
+#include stdio.h
+#include usbg/usbg.h
+
+#define VENDOR 0x1d6b
+#define PRODUCT0x0104
+
+int remove_gadget(usbg_gadget *g)
+{
+   int usbg_ret;
+   char udc[USBG_MAX_PATH_LENGTH];
+
+   /* Check if gadget is enabled */
+   usbg_ret = usbg_get_gadget_udc(g, udc, USBG_MAX_PATH_LENGTH);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error on USB get gadget udc\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out;
+   }
+
+   /* If gadget is enable we have to disable it first */
+   if (udc[0] != '\0') {
+   usbg_ret = usbg_disable_gadget(g);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error on USB disable gadget udc\n);
+   fprintf(stderr, Error: %s : %s\n, 
usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out;
+   }
+   }
+
+   /* Remove gadget */
+   usbg_ret = usbg_remove_gadget(g, 1 /* Remove also content */);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error on USB gadget remove\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   }
+
+out:
+   return usbg_ret;
+}
+
+int main(void)
+{
+   int usbg_ret;
+   int ret = -EINVAL;
+   usbg_state *s;
+   usbg_gadget *g;
+   usbg_gadget_attrs g_attrs;
+
+   usbg_ret = usbg_init(/sys/kernel/config, s);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error on USB state init\n);
+   fprintf(stderr, Error: %s : %s\n, usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out1;
+   }
+
+   g = usbg_get_first_gadget(s);
+   while (g != NULL) {
+   /* Get current gadget attrs to be compared */
+   usbg_ret = usbg_get_gadget_attrs(g, g_attrs);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, Error on USB get gadget attrs\n);
+   fprintf(stderr, Error: %s : %s\n, 
usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
+
+   /* Compare attrs with given values and remove if suitable */
+   if (g_attrs.idVendor == VENDOR  g_attrs.idProduct == PRODUCT) 
{
+   usbg_gadget *g_next = usbg_get_next_gadget(g);
+
+   usbg_ret = remove_gadget(g);
+   if (usbg_ret != USBG_SUCCESS)
+   goto out2;
+
+   g = g_next;
+   } else {
+   g = usbg_get_next_gadget(g);
+   }
+   }
+
+out2:
+   usbg_cleanup(s);
+out1:
+   return ret;
+}
diff --git 

Re: [PATCH 1/6] libusbg: Add remove binding functionality.

2014-03-10 Thread Robert Baldyga
Hi,

 diff --git a/src/usbg.c b/src/usbg.c
 index f655675..e82658c 100644
 --- a/src/usbg.c
 +++ b/src/usbg.c
 @@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
   break;
   case EACCES:
   case EROFS:
 + case EPERM:
   ret = USBG_ERROR_NO_ACCESS;
   break;
   case ENOENT:
 @@ -450,6 +451,22 @@ static void usbg_free_state(usbg_state *s)
   free(s);
  }
  
 +static int usbg_remove_file(char *path, char *name)
 +{
 + int ret;
 + char buf[USBG_MAX_PATH_LENGTH];
 +
 + sprintf(buf, %s/%s, path, name);

Maybe snprintf would be better?

 + ret = unlink(buf);
 + if (ret != 0)
 + ret = usbg_translate_error(errno);
 + else
 + ret = USBG_SUCCESS;
 +
 + return ret;
 +}
 +
  static int usbg_parse_function_net_attrs(usbg_function *f,
   usbg_function_attrs *f_attrs)
  {

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


RE: [PATCH 1/6] libusbg: Add remove binding functionality.

2014-03-10 Thread Krzysztof Opasiak
Hi,

 -Original Message-
 From: Robert Baldyga [mailto:r.bald...@samsung.com]
 Sent: Monday, March 10, 2014 10:43 AM
 To: Krzysztof Opasiak; mpor...@linaro.org; linux-
 u...@vger.kernel.org
 Cc: Andrzej Pietrasiewicz; Karol Lewandowski; Stanislaw Wadas;
 ty317@samsung.org; Marek Szyprowski
 Subject: Re: [PATCH 1/6] libusbg: Add remove binding functionality.
 
 Hi,
 
  diff --git a/src/usbg.c b/src/usbg.c
  index f655675..e82658c 100644
  --- a/src/usbg.c
  +++ b/src/usbg.c
  @@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
  break;
  case EACCES:
  case EROFS:
  +   case EPERM:
  ret = USBG_ERROR_NO_ACCESS;
  break;
  case ENOENT:
  @@ -450,6 +451,22 @@ static void usbg_free_state(usbg_state *s)
  free(s);
   }
 
  +static int usbg_remove_file(char *path, char *name)
  +{
  +   int ret;
  +   char buf[USBG_MAX_PATH_LENGTH];
  +
  +   sprintf(buf, %s/%s, path, name);
 
 Maybe snprintf would be better?

There is much more sprintf in library. All those functions will be
replaced with snprintf when removing satic buffers and handling
overflows. So it is future work in whole library

 
  +   ret = unlink(buf);
  +   if (ret != 0)
  +   ret = usbg_translate_error(errno);
  +   else
  +   ret = USBG_SUCCESS;
  +
  +   return ret;
  +}
  +
   static int usbg_parse_function_net_attrs(usbg_function *f,
  usbg_function_attrs *f_attrs)
   {
 

Krzysiek


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


Re: [PATCH 1/6] libusbg: Add remove binding functionality.

2014-03-10 Thread Robert Baldyga
On 03/10/2014 11:28 AM, Krzysztof Opasiak wrote:
 Hi,
 
 -Original Message-
 From: Robert Baldyga [mailto:r.bald...@samsung.com]
 Sent: Monday, March 10, 2014 10:43 AM
 To: Krzysztof Opasiak; mpor...@linaro.org; linux-
 u...@vger.kernel.org
 Cc: Andrzej Pietrasiewicz; Karol Lewandowski; Stanislaw Wadas;
 ty317@samsung.org; Marek Szyprowski
 Subject: Re: [PATCH 1/6] libusbg: Add remove binding functionality.

 Hi,

 diff --git a/src/usbg.c b/src/usbg.c
 index f655675..e82658c 100644
 --- a/src/usbg.c
 +++ b/src/usbg.c
 @@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
 break;
 case EACCES:
 case EROFS:
 +   case EPERM:
 ret = USBG_ERROR_NO_ACCESS;
 break;
 case ENOENT:
 @@ -450,6 +451,22 @@ static void usbg_free_state(usbg_state *s)
 free(s);
  }

 +static int usbg_remove_file(char *path, char *name)
 +{
 +   int ret;
 +   char buf[USBG_MAX_PATH_LENGTH];
 +
 +   sprintf(buf, %s/%s, path, name);

 Maybe snprintf would be better?
 
 There is much more sprintf in library. All those functions will be
 replaced with snprintf when removing satic buffers and handling
 overflows. So it is future work in whole library
 

Function snprintf should be used particularly with static buffers. When
you use dynamically allocated buffer you can adjust its size, and then
snprintf is not needed.


 +   ret = unlink(buf);
 +   if (ret != 0)
 +   ret = usbg_translate_error(errno);
 +   else
 +   ret = USBG_SUCCESS;
 +
 +   return ret;
 +}
 +
  static int usbg_parse_function_net_attrs(usbg_function *f,
 usbg_function_attrs *f_attrs)
  {


Robert.

--
To unsubscribe from this list: send the line unsubscribe 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: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Shuduo Sang
On Mon, Mar 10, 2014 at 3:27 PM, Emmanuel Grumbach egrumb...@gmail.com wrote:
 On Mon, Mar 10, 2014 at 8:49 AM, Shuduo Sang sangshu...@gmail.com wrote:
 On Mon, Mar 10, 2014 at 2:11 PM, Emmanuel Grumbach egrumb...@gmail.com 
 wrote:
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


 I have disabled WIFI device in BIOS, then its suspend/resume works.


 Do you have any logs to share?
 I supposed you tested 3.13.6 right?

Attach dmesg output. If any other log you need, I can capture too.
Actually I tried 3.14-rc6, 3.13.6 and 3.11.10.
[0.349516] pci :00:1f.2: reg 0x10: [io  0x30a8-0x30af]
[0.350512] pci :00:1f.2: reg 0x14: [io  0x30bc-0x30bf]
[0.351510] pci :00:1f.2: reg 0x18: [io  0x30a0-0x30a7]
[0.352511] pci :00:1f.2: reg 0x1c: [io  0x30b8-0x30bb]
[0.353512] pci :00:1f.2: reg 0x20: [io  0x3060-0x307f]
[0.354514] pci :00:1f.2: reg 0x24: [mem 0xf053c000-0xf053c7ff]
[0.355668] pci :00:1f.2: PME# supported from D3hot
[0.356692] pci :00:1f.3: [8086:9c22] type 00 class 0x0c0500
[0.357774] pci :00:1f.3: reg 0x10: [mem 0xf0538000-0xf05380ff 64bit]
[0.359033] pci :00:1f.3: reg 0x20: [io  0xefa0-0xefbf]
[0.360132] pci :00:1c.0: PCI bridge to [bus 02]
[0.361361] pci :03:00.0: [8086:08b2] type 00 class 0x028000
[0.362683] pci :03:00.0: reg 0x10: [mem 0xf040-0xf0401fff 64bit]
[0.364196] pci :03:00.0: PME# supported from D0 D3hot D3cold
[0.372088] pci :00:1c.1: PCI bridge to [bus 03]
[0.373037] pci :00:1c.1:   bridge window [mem 0xf040-0xf04f]
[0.375466] ACPI: Enabled 4 GPEs in block 00 to 7F
[0.376419] ACPI: \_SB_.PCI0: notify handler is installed
[0.377460] Found 1 acpi root devices
[0.378251] ACPI: EC: GPE = 0x25, I/O: command/status = 0x66, data = 0x62
[0.379631] vgaarb: device added: PCI::00:02.0,decodes=io+mem,owns=io+mem,locks=none
[0.381167] vgaarb: loaded
[0.381662] vgaarb: bridge control possible :00:02.0
[0.382825] SCSI subsystem initialized
[0.383539] ACPI: bus type ATA registered
[0.384335] libata version 3.00 loaded.
[0.385054] ACPI: bus type USB registered
[0.385811] usbcore: registered new interface driver usbfs
[0.386798] usbcore: registered new interface driver hub
[0.387816] usbcore: registered new device driver usb
[0.388899] PCI: Using ACPI for IRQ routing
[0.391052] PCI: pci_cache_line_size set to 64 bytes
[0.392361] e820: reserve RAM buffer [mem 0x0009d000-0x0009]
[0.393425] e820: reserve RAM buffer [mem 0xce23-0xcfff]
[0.394553] e820: reserve RAM buffer [mem 0x11e60-0x11fff]
[0.395759] NetLabel: Initializing
[0.396427] NetLabel:  domain hash size = 128
[0.397303] NetLabel:  protocols = UNLABELED CIPSOv4
[0.398312] NetLabel:  unlabeled traffic allowed by default
[0.399375] hpet0: at MMIO 0xfed0, IRQs 2, 8, 0, 0, 0, 0, 0, 0
[0.401184] hpet0: 8 comparators, 64-bit 14.318180 MHz counter
[0.404335] Switched to clocksource hpet
[0.409978] AppArmor: AppArmor Filesystem Enabled
[0.410839] pnp: PnP ACPI init
[0.411457] ACPI: bus type PNP registered
[0.412629] system 00:00: [mem 0x-0x0009] could not be reserved
[0.413824] system 00:00: [mem 0x000c-0x000c3fff] could not be reserved
[0.415074] system 00:00: [mem 0x000c4000-0x000c7fff] could not be reserved
[0.416326] system 00:00: [mem 0x000c8000-0x000cbfff] could not be reserved
[0.417582] system 00:00: [mem 0x000cc000-0x000c] could not be reserved
[0.418829] system 00:00: [mem 0x000d-0x000d3fff] has been reserved
[0.420080] system 00:00: [mem 0x000d4000-0x000d7fff] has been reserved
[0.421335] system 00:00: [mem 0x000d8000-0x000dbfff] has been reserved
[0.422582] system 00:00: [mem 0x000dc000-0x000d] has been reserved
[0.423833] system 00:00: [mem 0x000e-0x000e3fff] could not be reserved
[0.425088] system 00:00: [mem 0x000e4000-0x000e7fff] could not be reserved
[0.426336] system 00:00: [mem 0x000e8000-0x000ebfff] could not be reserved
[0.427587] system 00:00: [mem 0x000ec000-0x000e] could not be reserved
[0.428843] system 00:00: [mem 0x000f-0x000f] could not be reserved
[0.430090] system 00:00: [mem 0x0010-0xdf9f] could not 

Re: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Emmanuel Grumbach
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


 I have disabled WIFI device in BIOS, then its suspend/resume works.


 Do you have any logs to share?
 I supposed you tested 3.13.6 right?

 Attach dmesg output. If any other log you need, I can capture too.
 Actually I tried 3.14-rc6, 3.13.6 and 3.11.10.

This looks healthy.

Suspending console(s) (use no_console_suspend to debug)

can you use no_console_suspend?
--
To unsubscribe from this list: send the line unsubscribe 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] phy-rcar-gen2-usb: add device tree support

2014-03-10 Thread Magnus Damm
Hi Sergei,

On Sat, Mar 8, 2014 at 8:57 AM, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 Hello.


 On 03/07/2014 05:27 PM, Sergei Shtylyov wrote:

 Add support of the device tree probing for the Renesas R-Car generation
 2 SoCs
 documenting the device tree binding as necessary.


 Signed-off-by: Sergei Shtylyov sergei.shtyl...@cogentembedded.com


 ---
 This patch is against the 'next' branch of Felipe Balbi's 'usb.git'
 repo.


 Changes in version 2:
 - restored devm_clk_get() call and the error handling logic in the
 probe()
method, removed clk_put() call in the remove() method.


   Documentation/devicetree/bindings/usb/rcar-gen2-phy.txt |   29
 +++
   drivers/usb/phy/phy-rcar-gen2-usb.c |   42
 ++--
   2 files changed, 68 insertions(+), 3 deletions(-)


 Index: usb/Documentation/devicetree/bindings/usb/rcar-gen2-phy.txt
 ===
 --- /dev/null
 +++ usb/Documentation/devicetree/bindings/usb/rcar-gen2-phy.txt
 @@ -0,0 +1,29 @@
 +* Renesas R-Car generation 2 USB PHY
 +
 +This file provides information on what the device node for the R-Car
 generation
 +2 USB PHY contains.
 +
 +Required properties:
 +- compatible: renesas,usb-phy-r8a7790 if the device is a part of
 R8A7790
 SoC.
 + renesas,usb-phy-r8a7791 if the device is a part of
 R8A7791
 SoC.
 +- reg: offset and length of the register block.
 +- clocks: clock phandle and specifier pair.
 +- clock-names: string, clock input name, must be usbhs.
 +
 +Optional properties:
 +- renesas,channel0-pci: boolean, specify when USB channel 0 should be
 connected
 +   to PCI EHCI/OHCI; otherwise, it will be
 connected
 to the
 +   USBHS controller.
 +- renesas,channel2-pci: boolean, specify when USB channel 2 should be
 connected
 +   to PCI EHCI/OHCI; otherwise, it will be
 connected
 to the
 +   USBSS controller (xHCI).


 Thanks for your efforts here, but this DT binding looks like a mix of
 software configuration and hardware description.


 I disagree. I have already explained to Mark Rutland how selecting a
 particular controller for a particular USB port should depend on the kind
 of
 the USB connector used, i.e. the board hardware.

Just to clarify, I'm talking about the selection of USB IP that is
happening inside the SoC. You are right that there are also board
specific dependencies, but that's a different issue. As an example, on
Lager it is possible to use either USB 2.0 Host device functionality
or USB 3.0 Host functionality using the same USB 3.0-compatible
connector that is being exposed by the Lager board. In this case the
board needs to describe that it has a USB3.0-compatbile connector on
r8a7790 USB2, while the r8a7790 PHY driver and USB Host controller
glue needs to represent which internal devices that are mapped to
USB2.

I imagine that there are board-specific DT bits for Lager that
describe USB2 as USB3.0 compatible. Then there are r8a7790 specific
bits that show how the USB2.0 host controller and the USB3.0 host
controller both point to the USB2 channel included in the USB PHY. The
last portion is not modified by the board-level integrator, only the
board specific bits.

 +Example (Lager board):
 +
 +   usb-phy@e6590100 {
 +   compatible = renesas,usb-phy-r8a7790;
 +   reg = 0 0xe6590100 0 0x100;
 +   clocks = mstp7_clks R8A7790_CLK_HSUSB;
 +   clock-names = usbhs;
 +   renesas,channel2-pci;
 +   };


 As an example, instead of relying on renesas,channel0-pci or
 renesas,channel2-pci to specify which hard coded software
 configuration you want please rework this to expose 3 separate
 channels and use DT to point each host controller to the right
 channel.


 So you want to expose the channels as virtual devices? Or what do
 you
 want?

I'm not sure what virtual devices would be, but channel sub nodes
sounds like one possibility.

OK, let's assume you want either virtual PHYs or channel subnodes in
 the PHY node we have now. Now what the PHY driver should do with all these
 phandles pointing from the controller nodes to the PHY nodes or the channel
 subnodes? Scan all device tree in search of the nodes having certain prop
 and get info from such nodes on how to program the channel MUXing register
 using their compatible props? Sorry, that doesn't appeal to me at all.

I can't say that I'm 100% sure what is the best solution for this, but
I'm quite OK with basically anything that describes the hardware
mapping between PHY ports and host controllers in a sane way.

Exactly how to represent this in a sane way is however not trivial.
But how fun would that be? =)

One example from my side (which may be bad, not sure) is to point from
each USB Host controller to a subnode in the USB PHY device. But then
you will have to scan all though devices to find the link 

Re: [PATCH 2/8] ARM: dts: dra7-clock: Add l3init_960m_gfclk clock gate

2014-03-10 Thread Roger Quadros
On 03/07/2014 03:59 PM, Tero Kristo wrote:
 On 03/07/2014 03:09 PM, Roger Quadros wrote:
 This clock gate description was missing in older Reference manuals.
 It is present on the SoC to provide 960MHz reference clock to the
 internal USB PHYs.
 
 Can you provide a document reference here?
 

Unfortunately it hasn't yet been included in the TRM.
I have the internal defect ID but I don't think it makes any sense here.

DRA7xx-TRMINC00203

cheers,
-roger

 

 Use l3init_960m_gfclk as parent of usb_otg_ss1_refclk960m and
 usb_otg_ss2_refclk960m.

 CC: Tero Kristo t-kri...@ti.com
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
   arch/arm/boot/dts/dra7xx-clocks.dtsi | 12 ++--
   1 file changed, 10 insertions(+), 2 deletions(-)

 diff --git a/arch/arm/boot/dts/dra7xx-clocks.dtsi 
 b/arch/arm/boot/dts/dra7xx-clocks.dtsi
 index e96da9a..b8d3a9d 100644
 --- a/arch/arm/boot/dts/dra7xx-clocks.dtsi
 +++ b/arch/arm/boot/dts/dra7xx-clocks.dtsi
 @@ -1386,6 +1386,14 @@
   ti,dividers = 1, 8;
   };

 +l3init_960m_gfclk: l3init_960m_gfclk {
 +#clock-cells = 0;
 +compatible = ti,gate-clock;
 +clocks = dpll_usb_clkdcoldo;
 +ti,bit-shift = 8;
 +reg = 0x06c0;
 +};
 +
   dss_32khz_clk: dss_32khz_clk {
   #clock-cells = 0;
   compatible = ti,gate-clock;
 @@ -1533,7 +1541,7 @@
   usb_otg_ss1_refclk960m: usb_otg_ss1_refclk960m {
   #clock-cells = 0;
   compatible = ti,gate-clock;
 -clocks = dpll_usb_clkdcoldo;
 +clocks = l3init_960m_gfclk;
   ti,bit-shift = 8;
   reg = 0x13f0;
   };
 @@ -1541,7 +1549,7 @@
   usb_otg_ss2_refclk960m: usb_otg_ss2_refclk960m {
   #clock-cells = 0;
   compatible = ti,gate-clock;
 -clocks = dpll_usb_clkdcoldo;
 +clocks = l3init_960m_gfclk;
   ti,bit-shift = 8;
   reg = 0x1340;
   };

 

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


Re: [PATCH 1/6] libusbg: Add remove binding functionality.

2014-03-10 Thread Karol Lewandowski
On 03/10/2014 11:28 AM, Krzysztof Opasiak wrote:
 From: Robert Baldyga [mailto:r.bald...@samsung.com]

 +static int usbg_remove_file(char *path, char *name)
 +{
 +   int ret;
 +   char buf[USBG_MAX_PATH_LENGTH];
 +
 +   sprintf(buf, %s/%s, path, name);

 Maybe snprintf would be better?
 
 There is much more sprintf in library. All those functions will be
 replaced with snprintf when removing satic buffers and handling
 overflows. So it is future work in whole library

static buffer usage just begs for snprintf()-like function.  It's
an error to use sprintf in this case unless you control length of
supplied variables (path and name).

Cheers,
-- 
Karol Lewandowski, Samsung RD Institute Poland
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/9] usb: chipidea: usbmisc: Add USB Host support for i.MX25/i.MX35 CPUs

2014-03-10 Thread Fabio Estevam
Hi Alexander,

On Mon, Mar 10, 2014 at 1:58 AM, Alexander Shiyan shc_w...@mail.ru wrote:

 Fabio, start with to make work USB port on your board in the bootloader.
 Then with the previous driver (ehci-mxc).
 Most likely problem is a wrong (or missing) clock.
 As I mentioned earlier, DTS has incorrect clock nodes.

Yes, you are right, thanks.

If I change the usb host clocks as:

-   clocks = clks 9, clks 70, clks 8;
-   clock-names = ipg, ahb, per;
+   clocks = clks 70;

Then USB host1 works fine on my mx25pdk board.

Denis,

Could you please resend 4/9 by changing the clocks nodes in the OTG
and Host1 ports as shown above?

Thanks,

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


Re: [PATCH 1/9] usb: chipidea: usbmisc: Add USB Host support for i.MX25/i.MX35 CPUs

2014-03-10 Thread Fabio Estevam
Hi Eric,

On Mon, Mar 10, 2014 at 2:55 AM, Eric Bénard e...@eukrea.com wrote:
 Hi Fabio,

 (Not sure why it says full-speed device. When I connect the same
 device to a PC it says high-speed)

 because i.MX25 and i.MX35 only have a full speed phy on the host port.

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


Re: musb for davinci

2014-03-10 Thread Alexander Holler

Am 10.03.2014 08:21, schrieb Christian Riesch:

Hi Alexander,

--On March 09, 2014 20:58 +0100 Alexander Holler hol...@ahsoftware.de
wrote:


Hello,

may I ask what's the deal with drivers/usb/musb/davinci.c and why it
depends on BROKEN?

I've just enabled it here and it compiles and seems to work.


I noticed the same for drivers/usb/musb/da8xx.c which was marked BROKEN
by the same patch. It works for me, so I think the BROKEN should be
removed.

I posted a patch for this, see [1].

Regards, Christian

[1] http://marc.info/?t=1394061r=1w=2


The answer to that is just what I've expected and why I haven't posted a 
patch.






I haven't tested it thoroughly, but when I compare it with other (still
broken) drivers, I don't really see a reason to hide it by letting it
depend on BROKEN.

And at least the comment of the commit which has hidden it (787f56),
isn't completely true anymore. The driver doesn't include mach/*, at
least I don't see such an include.

Regards,

Alexander Holler







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


[PATCH v2 1/8] ARM: dts: dra7: Initialize USB_DPLL

2014-03-10 Thread Roger Quadros
USB_DPLL must be initialized and locked at boot so that
USB modules can work.

Program USB_DLL_M2 output to half rate as well.

Patch depends on
https://www.mail-archive.com/linux-omap@vger.kernel.org/msg101300.html

CC: Mike Turquette mturque...@linaro.org
CC: Tero Kristo t-kri...@ti.com
Signed-off-by: Roger Quadros rog...@ti.com
---
 arch/arm/boot/dts/dra7.dtsi | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index 597979b..f376923 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -815,3 +815,11 @@
 };
 
 /include/ dra7xx-clocks.dtsi
+
+dpll_usb_ck {
+default-rate = 96000;
+};
+
+dpll_usb_m2_ck {
+   default-rate = 48000;
+};
-- 
1.8.3.2

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


[PATCHv4 4/4] usb: dwc2: Edit the Kconfig and Makefile to build dwc2_gadget driver

2014-03-10 Thread Dinh Nguyen
From: Dinh Nguyen dingu...@altera.com

Modify the dwc2 Kconfig and Makefile so that it will build the dwc2_gadget
driver when peripheral only mode is selected. The dwc_platform.ko and dwc2.ko
will get built then dynamic linked modules are selected for Host mode. For
peripheral mode only dwc2_gadget.ko will get built.

Signed-off-by: Dinh Nguyen dingu...@altera.com
Tested-by: Jingoo Han jg1@samsung.com
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
Cc: Paul Zimmerman pa...@synopsys.com
Cc: Felipe Balbi ba...@ti.com
Cc: Ben Dooks ben-li...@fluff.org
Cc: Matt Porter mpor...@linaro.org
Cc: Kukjin Kim kgene@samsung.com
Cc: Stephen Warren swar...@wwwdotorg.org
Cc: Matthijs Kooijman matth...@stdin.nl
Cc: Sachin Kamat sachin.ka...@linaro.org
Cc: Robert Baldyga r.bald...@samsung.com
---
v4: Remove PCI dependency for USB_DWC2_PLATFORM
v3: Created
v2: none
---
 drivers/usb/dwc2/Kconfig| 36 +---
 drivers/usb/dwc2/Makefile   | 27 +++
 drivers/usb/gadget/Kconfig  |  7 ---
 drivers/usb/gadget/Makefile |  1 -
 4 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig
index be947d6..e85e6e1 100644
--- a/drivers/usb/dwc2/Kconfig
+++ b/drivers/usb/dwc2/Kconfig
@@ -5,21 +5,43 @@ config USB_DWC2
  Say Y or M here if your system has a Dual Role HighSpeed
  USB controller based on the DesignWare HSOTG IP Core.
 
- If you choose to build this driver as dynamically linked
- modules, the core module will be called dwc2.ko, the
+ For host mode, if you choose to build this driver as dynamically
+ linked modules, the core module will be called dwc2.ko, the
  PCI bus interface module (if you have a PCI bus system)
  will be called dwc2_pci.ko and the platform interface module
  (for controllers directly connected to the CPU) will be called
- dwc2_platform.ko.
+ dwc2_platform.ko. For gadget, it will be only be dwc2_gadget.ko.
 
- NOTE: This driver at present only implements the Host mode
- of the controller. The existing s3c-hsotg driver supports
- Peripheral mode, but only for the Samsung S3C platforms.
- There are plans to merge the s3c-hsotg driver with this
+ NOTE: The s3c-hsotg is now renamed as dwc2_gadget. The host
+ and gadget driver are still currently separate drivers. There
+ are plans to merge the dwc2_gadget driver with the dwc2 host
  driver in the near future to create a dual-role driver.
 
 if USB_DWC2
 
+config USB_DWC2_HOST
+   bool Host only mode
+   depends on USB=y || USB=USB_DWC2
+   default y
+   help
+ Select this when you want to use DWC2 in host mode only,
+ thereby the gadget feature will be regressed.
+
+config USB_DWC2_PERIPHERAL
+   depends on (ARM || USB_GADGET=y)  !USB_DWC2_HOST
+   tristate Gadget only mode
+   help
+ The Designware USB2.0 high-speed gadget controller
+ integrated into many SoCs.
+
+config USB_DWC2_PLATFORM
+   depends on USB_DWC2_HOST
+   tristate DWC2 Platform
+   default y
+   help
+ The Designware USB2.0 platform interface module for controllers
+ directly connected to the CPU. This is only used for Host mode.
+
 config USB_DWC2_DEBUG
bool Enable Debugging Messages
help
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
index 11529d3..1509032 100644
--- a/drivers/usb/dwc2/Makefile
+++ b/drivers/usb/dwc2/Makefile
@@ -1,25 +1,28 @@
 ccflags-$(CONFIG_USB_DWC2_DEBUG)   += -DDEBUG
 ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG
 
+ifeq ($(CONFIG_USB_DWC2_HOST),y)
 obj-$(CONFIG_USB_DWC2) += dwc2.o
-
 dwc2-y += core.o core_intr.o
-
-# NOTE: This driver at present only implements the Host mode
-# of the controller. The existing s3c-hsotg driver supports
-# Peripheral mode, but only for the Samsung S3C platforms.
-# There are plans to merge the s3c-hsotg driver with this
-# driver in the near future to create a dual-role driver. Once
-# that is done, Host mode will become an optional feature that
-# is selected with a config option.
-
 dwc2-y += hcd.o hcd_intr.o
 dwc2-y += hcd_queue.o hcd_ddma.o
+endif
+obj-$(CONFIG_USB_DWC2_PERIPHERAL)  += dwc2_gadget.o
+dwc2_gadget-objs   += gadget.o
+
+# NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to
+# this location and renamed gadget.c. When building for dynamically linked
+# modules, dwc2_gadget.ko will get built for peripheral mode. For host mode,
+# the core module will be dwc2.ko, the PCI bus interface module will called
+# dwc2_pci.ko and the platform interface module will be called 
dwc2_platform.ko.
+# At present the host and gadget driver will be separate drivers, but 

[PATCHv4 2/4] usb: s3c-hsotg: Move s3c-hsotg into dwc2 folder

2014-03-10 Thread Dinh Nguyen
From: Dinh Nguyen dingu...@altera.com

Moves the s3c-hsotg driver into the dwc2 folder and use the dwc2 defines in
hw.h. Renamed the s3c-hsotg.c to gadget.c.

Signed-off-by: Dinh Nguyen dingu...@altera.com
Tested-by: Jingoo Han jg1@samsung.com
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
Cc: Paul Zimmerman pa...@synopsys.com
Cc: Felipe Balbi ba...@ti.com
Cc: Ben Dooks ben-li...@fluff.org
Cc: Matt Porter mpor...@linaro.org
Cc: Kukjin Kim kgene@samsung.com
Cc: Stephen Warren swar...@wwwdotorg.org
Cc: Matthijs Kooijman matth...@stdin.nl
Cc: Sachin Kamat sachin.ka...@linaro.org
Cc: Robert Baldyga r.bald...@samsung.com
---
v4: none
v3:
- Renamed s3c-hsotg to dwc2/gadget
- Remove the edits to the Kconfig and Makefile as that will be in a separate
patch for v4.

v2:
- Fix whitespace damage
- Redo s3c_hsotg_handle_rx() to use dwc2 definitions
- Use FIFOSIZE_DEPTH_GET
---
 drivers/usb/{gadget/s3c-hsotg.c = dwc2/gadget.c} | 415 +++---
 drivers/usb/gadget/s3c-hsotg.h| 378 
 2 files changed, 206 insertions(+), 587 deletions(-)
 rename drivers/usb/{gadget/s3c-hsotg.c = dwc2/gadget.c} (91%)
 delete mode 100644 drivers/usb/gadget/s3c-hsotg.h

diff --git a/drivers/usb/gadget/s3c-hsotg.c b/drivers/usb/dwc2/gadget.c
similarity index 91%
rename from drivers/usb/gadget/s3c-hsotg.c
rename to drivers/usb/dwc2/gadget.c
index 1172eae..9bb1ed7 100644
--- a/drivers/usb/gadget/s3c-hsotg.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -37,7 +37,7 @@
 #include linux/usb/phy.h
 #include linux/platform_data/s3c-hsotg.h
 
-#include s3c-hsotg.h
+#include hw.h
 
 static const char * const s3c_hsotg_supply_names[] = {
vusb_d,   /* digital USB supply, 1.2V */
@@ -340,9 +340,8 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
/* set FIFO sizes to 2048/1024 */
 
writel(2048, hsotg-regs + GRXFSIZ);
-   writel(GNPTXFSIZ_NPTxFStAddr(2048) |
-  GNPTXFSIZ_NPTxFDep(1024),
-  hsotg-regs + GNPTXFSIZ);
+   writel((2048  FIFOSIZE_STARTADDR_SHIFT) |
+   (1024  FIFOSIZE_DEPTH_SHIFT), hsotg-regs + GNPTXFSIZ);
 
/*
 * arange all the rest of the TX FIFOs, as some versions of this
@@ -362,10 +361,10 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
 
for (ep = 1; ep = 15; ep++) {
val = addr;
-   val |= size  DPTXFSIZn_DPTxFSize_SHIFT;
+   val |= size  FIFOSIZE_DEPTH_SHIFT;
addr += size;
 
-   writel(val, hsotg-regs + DPTXFSIZn(ep));
+   writel(val, hsotg-regs + DPTXFSIZN(ep));
}
 
/*
@@ -373,15 +372,15 @@ static void s3c_hsotg_init_fifo(struct s3c_hsotg *hsotg)
 * all fifos are flushed before continuing
 */
 
-   writel(GRSTCTL_TxFNum(0x10) | GRSTCTL_TxFFlsh |
-  GRSTCTL_RxFFlsh, hsotg-regs + GRSTCTL);
+   writel(GRSTCTL_TXFNUM(0x10) | GRSTCTL_TXFFLSH |
+  GRSTCTL_RXFFLSH, hsotg-regs + GRSTCTL);
 
/* wait until the fifos are both flushed */
timeout = 100;
while (1) {
val = readl(hsotg-regs + GRSTCTL);
 
-   if ((val  (GRSTCTL_TxFFlsh | GRSTCTL_RxFFlsh)) == 0)
+   if ((val  (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH)) == 0)
break;
 
if (--timeout == 0) {
@@ -495,14 +494,14 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
 * how much data is left in the fifo.
 */
 
-   size_left = DxEPTSIZ_XferSize_GET(epsize);
+   size_left = DXEPTSIZ_XFERSIZE_GET(epsize);
 
/*
 * if shared fifo, we cannot write anything until the
 * previous data has been completely sent.
 */
if (hs_ep-fifo_load != 0) {
-   s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp);
+   s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP);
return -ENOSPC;
}
 
@@ -523,7 +522,7 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
__func__, can_write);
 
if (can_write = 0) {
-   s3c_hsotg_en_gsint(hsotg, GINTSTS_PTxFEmp);
+   s3c_hsotg_en_gsint(hsotg, GINTSTS_PTXFEMP);
return -ENOSPC;
}
} else if (hsotg-dedicated_fifos  hs_ep-index != 0) {
@@ -532,16 +531,16 @@ static int s3c_hsotg_write_fifo(struct s3c_hsotg *hsotg,
can_write = 0x;
can_write *= 4;
} else {
-   if (GNPTXSTS_NPTxQSpcAvail_GET(gnptxsts) == 0) {
+   if (GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(gnptxsts) == 0) {
dev_dbg(hsotg-dev,
%s: no queue slots available (0x%08x)\n,
__func__, gnptxsts);
 
-   s3c_hsotg_en_gsint(hsotg, 

[PATCHv4 3/4] usb: s3c-hsotg: Move s3c-hsotg data structures

2014-03-10 Thread Dinh Nguyen
From: Dinh Nguyen dingu...@altera.com

This patch moves the data structures that are in the s3c-hsotg source into
core.h. This is a necessary step towards unifying the s3c-hsotg and dwc2 into
a single DRD.

Signed-off-by: Dinh Nguyen dingu...@altera.com
Tested-by: Jingoo Han jg1@samsung.com
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
Cc: Paul Zimmerman pa...@synopsys.com
Cc: Felipe Balbi ba...@ti.com
Cc: Ben Dooks ben-li...@fluff.org
Cc: Matt Porter mpor...@linaro.org
Cc: Kukjin Kim kgene@samsung.com
Cc: Stephen Warren swar...@wwwdotorg.org
Cc: Matthijs Kooijman matth...@stdin.nl
Cc: Sachin Kamat sachin.ka...@linaro.org
Cc: Robert Baldyga r.bald...@samsung.com
---
v4: none
v3: none
v2: none
---
 drivers/usb/dwc2/core.h   | 182 ++
 drivers/usb/dwc2/gadget.c | 180 +
 2 files changed, 183 insertions(+), 179 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 648519c..1efd10c 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -37,6 +37,10 @@
 #ifndef __DWC2_CORE_H__
 #define __DWC2_CORE_H__
 
+#include linux/phy/phy.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
 #include linux/usb/phy.h
 #include hw.h
 
@@ -54,6 +58,184 @@ static inline void do_write(u32 value, void *addr)
 /* Maximum number of Endpoints/HostChannels */
 #define MAX_EPS_CHANNELS   16
 
+/* s3c-hsotg declarations */
+static const char * const s3c_hsotg_supply_names[] = {
+   vusb_d,   /* digital USB supply, 1.2V */
+   vusb_a,   /* analog USB supply, 1.1V */
+};
+
+/*
+ * EP0_MPS_LIMIT
+ *
+ * Unfortunately there seems to be a limit of the amount of data that can
+ * be transferred by IN transactions on EP0. This is either 127 bytes or 3
+ * packets (which practically means 1 packet and 63 bytes of data) when the
+ * MPS is set to 64.
+ *
+ * This means if we are wanting to move 127 bytes of data, we need to
+ * split the transactions up, but just doing one packet at a time does
+ * not work (this may be an implicit DATA0 PID on first packet of the
+ * transaction) and doing 2 packets is outside the controller's limits.
+ *
+ * If we try to lower the MPS size for EP0, then no transfers work properly
+ * for EP0, and the system will fail basic enumeration. As no cause for this
+ * has currently been found, we cannot support any large IN transfers for
+ * EP0.
+ */
+#define EP0_MPS_LIMIT   64
+
+struct s3c_hsotg;
+struct s3c_hsotg_req;
+
+/**
+ * struct s3c_hsotg_ep - driver endpoint definition.
+ * @ep: The gadget layer representation of the endpoint.
+ * @name: The driver generated name for the endpoint.
+ * @queue: Queue of requests for this endpoint.
+ * @parent: Reference back to the parent device structure.
+ * @req: The current request that the endpoint is processing. This is
+ *   used to indicate an request has been loaded onto the endpoint
+ *   and has yet to be completed (maybe due to data move, or simply
+ *   awaiting an ack from the core all the data has been completed).
+ * @debugfs: File entry for debugfs file for this endpoint.
+ * @lock: State lock to protect contents of endpoint.
+ * @dir_in: Set to true if this endpoint is of the IN direction, which
+ *  means that it is sending data to the Host.
+ * @index: The index for the endpoint registers.
+ * @mc: Multi Count - number of transactions per microframe
+ * @interval - Interval for periodic endpoints
+ * @name: The name array passed to the USB core.
+ * @halted: Set if the endpoint has been halted.
+ * @periodic: Set if this is a periodic ep, such as Interrupt
+ * @isochronous: Set if this is a isochronous ep
+ * @sent_zlp: Set if we've sent a zero-length packet.
+ * @total_data: The total number of data bytes done.
+ * @fifo_size: The size of the FIFO (for periodic IN endpoints)
+ * @fifo_load: The amount of data loaded into the FIFO (periodic IN)
+ * @last_load: The offset of data for the last start of request.
+ * @size_loaded: The last loaded size for DxEPTSIZE for periodic IN
+ *
+ * This is the driver's state for each registered enpoint, allowing it
+ * to keep track of transactions that need doing. Each endpoint has a
+ * lock to protect the state, to try and avoid using an overall lock
+ * for the host controller as much as possible.
+ *
+ * For periodic IN endpoints, we have fifo_size and fifo_load to try
+ * and keep track of the amount of data in the periodic FIFO for each
+ * of these as we don't have a status register that tells us how much
+ * is in each of them. (note, this may actually be useless information
+ * as in shared-fifo mode periodic in acts like a single-frame packet
+ * buffer than a fifo)
+ */
+struct s3c_hsotg_ep {
+   struct usb_ep   ep;
+   struct list_headqueue;
+   struct s3c_hsotg*parent;
+   struct s3c_hsotg_req*req;
+   struct dentry  

[PATCHv4 1/4] usb: dwc2: Add defines to support the s3c-hsotg driver

2014-03-10 Thread Dinh Nguyen
From: Dinh Nguyen dingu...@altera.com

In preparation of combining the dwc2/s3c-hsotg driver in a single DRD driver,
the defines in dwc2/hw.h needs to get updated so that the s3c-hsotg driver can
use them.

Signed-off-by: Dinh Nguyen dingu...@altera.com
Tested-by: Jingoo Han jg1@samsung.com
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
Cc: Paul Zimmerman pa...@synopsys.com
Cc: Felipe Balbi ba...@ti.com
Cc: Ben Dooks ben-li...@fluff.org
Cc: Matt Porter mpor...@linaro.org
Cc: Kukjin Kim kgene@samsung.com
Cc: Stephen Warren swar...@wwwdotorg.org
Cc: Matthijs Kooijman matth...@stdin.nl
Cc: Sachin Kamat sachin.ka...@linaro.org
Cc: Robert Baldyga r.bald...@samsung.com
---
v4: none
v3:
- Remove unused DXEPCTL_EPTYPE_SHIFT define

v2:
- No need to redo the GRXSTS_PKTSTS defines
- Add a FIFOSIZE_DEPTH_GET macro
---
 drivers/usb/dwc2/hw.h | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/hw.h b/drivers/usb/dwc2/hw.h
index 9c92a3c..51248b9 100644
--- a/drivers/usb/dwc2/hw.h
+++ b/drivers/usb/dwc2/hw.h
@@ -109,6 +109,7 @@
 #define GUSBCFG_FSINTF (1  5)
 #define GUSBCFG_ULPI_UTMI_SEL  (1  4)
 #define GUSBCFG_PHYIF16(1  3)
+#define GUSBCFG_PHYIF8 (0  3)
 #define GUSBCFG_TOUTCAL_MASK   (0x7  0)
 #define GUSBCFG_TOUTCAL_SHIFT  0
 #define GUSBCFG_TOUTCAL_LIMIT  0x7
@@ -403,6 +404,7 @@
 #define FIFOSIZE_DEPTH_SHIFT   16
 #define FIFOSIZE_STARTADDR_MASK(0x  0)
 #define FIFOSIZE_STARTADDR_SHIFT   0
+#define FIFOSIZE_DEPTH_GET(_x) (((_x)  16)  0x)
 
 /* Device mode registers */
 
@@ -519,11 +521,11 @@
 #define DXEPCTL_STALL  (1  21)
 #define DXEPCTL_SNP(1  20)
 #define DXEPCTL_EPTYPE_MASK(0x3  18)
-#define DXEPCTL_EPTYPE_SHIFT   18
-#define DXEPCTL_EPTYPE_CONTROL 0
-#define DXEPCTL_EPTYPE_ISO 1
-#define DXEPCTL_EPTYPE_BULK2
-#define DXEPCTL_EPTYPE_INTTERUPT   3
+#define DXEPCTL_EPTYPE_CONTROL (0x0  18)
+#define DXEPCTL_EPTYPE_ISO (0x1  18)
+#define DXEPCTL_EPTYPE_BULK(0x2  18)
+#define DXEPCTL_EPTYPE_INTERRUPT   (0x3  18)
+
 #define DXEPCTL_NAKSTS (1  17)
 #define DXEPCTL_DPID   (1  16)
 #define DXEPCTL_EOFRNUM(1  16)
-- 
1.8.3.2

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


Re: [PATCH] xhci: extend quirk for Renesas cards

2014-03-10 Thread Mathias Nyman

On 03/09/2014 04:20 PM, Igor Gnatenko wrote:

After suspend another Renesas PCI-X USB 3.0 card doesn't work.
03:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720202 USB 3.0 Host 
Controller [1912:0015] (rev 02) (prog-if 30 [XHCI])

Reported-and-tested-by: Anatoly K. rfr-b...@yandex.ru
Reference: http://redmine.russianfedora.pro/issues/1315
Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com
---
  drivers/usb/host/xhci-pci.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 04f986d..13d4add 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -143,9 +143,7 @@ static void xhci_pci_quirks(struct device *dev, struct 
xhci_hcd *xhci)
xhci-quirks |= XHCI_TRUST_TX_LENGTH;
}
if (pdev-vendor == PCI_VENDOR_ID_RENESAS 
-   pdev-device == 0x0015 
-   pdev-subsystem_vendor == PCI_VENDOR_ID_SAMSUNG 
-   pdev-subsystem_device == 0xc0cd)
+   pdev-device == 0x0015)
xhci-quirks |= XHCI_RESET_ON_RESUME;
if (pdev-vendor == PCI_VENDOR_ID_VIA)
xhci-quirks |= XHCI_RESET_ON_RESUME;



This will set the resume quirk for all devices with a Renesas  uPD720202 
host.


Do they all need this quirk, or should just this card manufacturer be 
added to the quirk? (subsystem vendor/device)


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


Re: [PATCH] usb: gadget: f_fs: add missing spinlock and mutex unlock

2014-03-10 Thread Michal Nazarewicz
On Mon, Mar 10 2014, Robert Baldyga r.bald...@samsung.com wrote:
 This patch adds missing spin_unlock and mutex_unlock calls in
 error handling code.

 Signed-off-by: Robert Baldyga r.bald...@samsung.com

Acked-by: Michal Nazarewicz min...@mina86.com

 ---
  drivers/usb/gadget/f_fs.c |8 ++--
  1 file changed, 6 insertions(+), 2 deletions(-)

 diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
 index b7d273a..d6bd0a3 100644
 --- a/drivers/usb/gadget/f_fs.c
 +++ b/drivers/usb/gadget/f_fs.c
 @@ -802,7 +802,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
 ffs_io_data *io_data)
   if (io_data-aio) {
   req = usb_ep_alloc_request(ep-ep, GFP_KERNEL);
   if (unlikely(!req))
 - goto error;
 + goto error_lock;
  
   req-buf  = data;
   req-length   = io_data-len;
 @@ -817,7 +817,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
 ffs_io_data *io_data)
   ret = usb_ep_queue(ep-ep, req, GFP_ATOMIC);
   if (unlikely(ret)) {
   usb_ep_free_request(ep-ep, req);
 - goto error;
 + goto error_lock;
   }
   ret = -EIOCBQUEUED;
  
 @@ -863,6 +863,10 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
 ffs_io_data *io_data)
  
   mutex_unlock(epfile-mutex);
   return ret;
 +
 +error_lock:
 + spin_unlock_irq(epfile-ffs-eps_lock);
 + mutex_unlock(epfile-mutex);
  error:
   kfree(data);
   return ret;
 -- 
 1.7.9.5


-- 
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of  o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz(o o)
ooo +--m...@google.com--xmpp:min...@jabber.org--ooO--(_)--Ooo--


signature.asc
Description: PGP signature


Re: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Shuduo Sang
On Mon, Mar 10, 2014 at 6:50 PM, Emmanuel Grumbach egrumb...@gmail.com wrote:
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


 I have disabled WIFI device in BIOS, then its suspend/resume works.


 Do you have any logs to share?
 I supposed you tested 3.13.6 right?

 Attach dmesg output. If any other log you need, I can capture too.
 Actually I tried 3.14-rc6, 3.13.6 and 3.11.10.

 This looks healthy.

 Suspending console(s) (use no_console_suspend to debug)

 can you use no_console_suspend?

Yes, this log is already output from the kernel I compile with
no_console_suspend.
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/8] ARM: dts: dra7: Initialize USB_DPLL

2014-03-10 Thread Tero Kristo

On 03/10/2014 02:49 PM, Roger Quadros wrote:

USB_DPLL must be initialized and locked at boot so that
USB modules can work.

Program USB_DLL_M2 output to half rate as well.

Patch depends on
https://www.mail-archive.com/linux-omap@vger.kernel.org/msg101300.html

CC: Mike Turquette mturque...@linaro.org
CC: Tero Kristo t-kri...@ti.com
Signed-off-by: Roger Quadros rog...@ti.com
---
  arch/arm/boot/dts/dra7.dtsi | 8 
  1 file changed, 8 insertions(+)

diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
index 597979b..f376923 100644
--- a/arch/arm/boot/dts/dra7.dtsi
+++ b/arch/arm/boot/dts/dra7.dtsi
@@ -815,3 +815,11 @@
  };

  /include/ dra7xx-clocks.dtsi
+
+dpll_usb_ck {
+default-rate = 96000;
+};
+
+dpll_usb_m2_ck {
+   default-rate = 48000;
+};



You can add these directly under the dra7xx-clocks.dtsi file as well, as 
I don't think anybody needs to modify these. And the properties can be 
added directly under the nodes themselves.


However, this patch can't be acked yet as we have no feedback from Mike 
for the default-rate proposal.


-Tero

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


Re: [PATCH v2 1/8] ARM: dts: dra7: Initialize USB_DPLL

2014-03-10 Thread Roger Quadros
On 03/10/2014 03:28 PM, Tero Kristo wrote:
 On 03/10/2014 02:49 PM, Roger Quadros wrote:
 USB_DPLL must be initialized and locked at boot so that
 USB modules can work.

 Program USB_DLL_M2 output to half rate as well.

 Patch depends on
 https://www.mail-archive.com/linux-omap@vger.kernel.org/msg101300.html

 CC: Mike Turquette mturque...@linaro.org
 CC: Tero Kristo t-kri...@ti.com
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
   arch/arm/boot/dts/dra7.dtsi | 8 
   1 file changed, 8 insertions(+)

 diff --git a/arch/arm/boot/dts/dra7.dtsi b/arch/arm/boot/dts/dra7.dtsi
 index 597979b..f376923 100644
 --- a/arch/arm/boot/dts/dra7.dtsi
 +++ b/arch/arm/boot/dts/dra7.dtsi
 @@ -815,3 +815,11 @@
   };

   /include/ dra7xx-clocks.dtsi
 +
 +dpll_usb_ck {
 +default-rate = 96000;
 +};
 +
 +dpll_usb_m2_ck {
 +default-rate = 48000;
 +};

 
 You can add these directly under the dra7xx-clocks.dtsi file as well, as I 
 don't think anybody needs to modify these. And the properties can be added 
 directly under the nodes themselves.
 
 However, this patch can't be acked yet as we have no feedback from Mike for 
 the default-rate proposal.

OK. I'll wait for the default-rate patch to be approved first and then revise 
this patch based on your
suggestion. Thanks for the review.

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


Re: [PATCH RFC] usb: gadget: Add xilinx axi usb2 device support

2014-03-10 Thread sundeep subbaraya
On Fri, Feb 21, 2014 at 9:09 PM, Felipe Balbi ba...@ti.com wrote:
 Hi,

 On Fri, Feb 21, 2014 at 11:27:07AM +, Subbaraya Sundeep Bhatta wrote:
  From the looks of it, I doubt this was actually tested, you need a lot
  of work on this driver.
 Tested on both ARM and Microblaze architectures with Mass storage gadget.
 Will send a v2 after addressing all your comments.

 clearly you didn't try to remove and reinsert the module or you would
 see a whole bunch of errors.


Yes you are correct. My console hung up as soon as i rmmod my driver.
Could you please point me where am wrong.

 This email and any attachments are intended for the sole use of the
 named recipient(s) and contain(s) confidential information that may be
 proprietary, privileged or copyrighted under applicable law. If you
 are not the intended recipient, do not read, copy, or forward this
 email message or any attachments. Delete this email message and any
 attachments immediately.

 remove this footer message, btw, when sending emails to public mailing
 lists.

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


Re: wifi driver or USB might leads suspend/resume failure on thinkpad X1 carbon

2014-03-10 Thread Emmanuel Grumbach
On Mon, Mar 10, 2014 at 3:20 PM, Shuduo Sang sangshu...@gmail.com wrote:
 On Mon, Mar 10, 2014 at 6:50 PM, Emmanuel Grumbach egrumb...@gmail.com 
 wrote:
 Hi,

 On Mon, Mar 10, 2014 at 7:05 AM, Shuduo Sang sangshu...@gmail.com 
 wrote:
 Hi,

 Sorry for cross posting. I'm suffering an issue my Thinkpad X1 Carbon
 can't resume after suspend recently. I tried many ways including
 latest vanilla kernel, latest stable 3.13 and 3.11 kernel but it still
 happens. I found it will not happen when I turn off WIFI device or USB
 3.0 in BIOS. So I suspect something need fix in either wifi driver or
 USB side. Since Windows 7 works good so I suppose no hardware issue.
 Anyone has some ideas to fix it or debug it?

 Thanks,
 Shuduo


 If you disable WiFi only (without touching USB 3.0 in BIOS), it works?
 How do you disable WiFi? Rfkill or removing iwlwifi?


 I have disabled WIFI device in BIOS, then its suspend/resume works.


 Do you have any logs to share?
 I supposed you tested 3.13.6 right?

 Attach dmesg output. If any other log you need, I can capture too.
 Actually I tried 3.14-rc6, 3.13.6 and 3.11.10.

 This looks healthy.

 Suspending console(s) (use no_console_suspend to debug)

 can you use no_console_suspend?

 Yes, this log is already output from the kernel I compile with
 no_console_suspend.

Hmm... weird...
Don't know how we can debug this further then...
--
To unsubscribe from this list: send the line unsubscribe 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 v9 1/9] mfd: omap-usb-host: Get clocks based on hardware revision

2014-03-10 Thread Lee Jones
 Not all revisions have all the clocks so get the necessary clocks
 based on hardware revision.
 
 This should avoid un-necessary clk_get failure messages that were
 observed earlier.
 
 Also remove the dummy USB host clocks from the OMAP3 clock data.
 These are no longer expected by the driver.
 
 CC: Lee Jones lee.jo...@linaro.org
 CC: Samuel Ortiz sa...@linux.intel.com
 CC: Tero Kristo t-kri...@ti.com
 Acked-by: Mike Turquette mturque...@linaro.org [OMAP3 CLK data]
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
  arch/arm/mach-omap2/cclock3xxx_data.c |  4 
  drivers/clk/ti/clk-3xxx.c |  4 
  drivers/mfd/omap-usb-host.c   | 43 
 ++-
  3 files changed, 32 insertions(+), 19 deletions(-)

Patches starting to take shape. I know that I've reviewed this patch
before, so if you've fixed-up all my previous comments you can have my
Ack for the MFD changes:
  Acked-by: Lee Jones lee.jo...@linaro.org

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line unsubscribe 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 v9 2/9] mfd: omap-usb-host: Always fail on clk_get() error

2014-03-10 Thread Lee Jones
 Be more strict and always fail on clk_get() error.
 
 CC: Lee Jones lee.jo...@linaro.org
 CC: Samuel Ortiz sa...@linux.intel.com
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
  drivers/mfd/omap-usb-host.c | 62 
 +
  1 file changed, 40 insertions(+), 22 deletions(-)

I like to principle of the patch assuming that the devices would be
useless without their clocks.

Acked-by: Lee Jones lee.jo...@linaro.org

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line unsubscribe 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 v9 4/9] mfd: omap-usb-host: Use clock names as per function for reference clocks

2014-03-10 Thread Lee Jones
 Use a meaningful name for the reference clocks so that it indicates the 
 function.
 
 Update the OMAP4+ USB Host node as well to be in sync with the changes.
 
 CC: Benoît Cousson bcous...@baylibre.com
 CC: Lee Jones lee.jo...@linaro.org
 CC: Samuel Ortiz sa...@linux.intel.com
 Signed-off-by: Roger Quadros rog...@ti.com
 ---
  arch/arm/boot/dts/omap4.dtsi |  6 ++
  arch/arm/boot/dts/omap5.dtsi |  6 ++
  drivers/mfd/omap-usb-host.c  | 12 ++--
  3 files changed, 18 insertions(+), 6 deletions(-)

The code looks fine and I queried the name change semantics before and
was satisfied with your answer, so as long as this patch has been
tested and nothing is broken:
  Acked-by: Lee Jones lee.jo...@linaro.org

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog
--
To unsubscribe from this list: send the line unsubscribe linux-usb in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/9] usb: chipidea: usbmisc: Add USB Host support for i.MX25/i.MX35 CPUs

2014-03-10 Thread Fabio Estevam
Hi Denis,

On Mon, Mar 10, 2014 at 8:16 AM, Fabio Estevam feste...@gmail.com wrote:

 Denis,

 Could you please resend 4/9 by changing the clocks nodes in the OTG
 and Host1 ports as shown above?

Thinking more about it, it would be better to send the USB clock
change as a separate patch.

I can submit the dts changes to the linux-arm-kernel list later today.

Regards,

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


Re: [PATCH 1/2] usbcore: rename struct dev_state to struct usb_dev_state

2014-03-10 Thread Greg KH
On Mon, Mar 10, 2014 at 10:36:40AM +0200, Valentina Manea wrote:
 Since it is needed outside usbcore and exposed in include/linux/usb.h,
 it conflicts with enum dev_state in rt2x00 wireless driver.
 
 Mark it as usb specific to avoid conflicts in the future.
 
 Signed-off-by: Valentina Manea valentina.mane...@gmail.com

With this patch, you break the usbip code, you can never have a patch
that breaks the build :(

I'll merge both of these together to prevent this from happening.

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] rebind: Add rebind mechanism for runtime-resume

2014-03-10 Thread Poulain, Loic
Despite the needs_rebind flag, the interface rebind was never
done for the PM runtime resume. This patch fixes this issue
by triggering the rebind in usb runtime resume.

The rebind procedure needs to be called with the device lock.
However, depending the call path (remote wakeup, local resume),
the device lock may or may not already be held in usb runtime
resume. So, use a work queue to take the lock unconditionally.
Protect this work against any deadlock in the same way as
reset_device.

Signed-off-by: lpoulain loic.poul...@intel.com
---
 drivers/usb/core/driver.c  | 30 +
 drivers/usb/core/message.c | 47 ++
 include/linux/usb.h|  6 ++
 3 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 47aade2..5a6692a 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -259,6 +259,18 @@ static void usb_cancel_queued_reset(struct usb_interface 
*iface)
cancel_work_sync(iface-reset_ws);
 }
 
+/*
+ * Cancel any pending scheduled rebind
+ *
+ * See comments in __usb_queue_rebind_device() regarding
+ * udev-rebind_running.
+ */
+static void usb_cancel_queued_rebind(struct usb_interface *iface)
+{
+   if (iface-rebind_running == 0)
+   cancel_work_sync(iface-rebind_ws);
+}
+
 /* called from driver core with dev locked */
 static int usb_probe_interface(struct device *dev)
 {
@@ -350,6 +362,7 @@ static int usb_probe_interface(struct device *dev)
intf-needs_remote_wakeup = 0;
intf-condition = USB_INTERFACE_UNBOUND;
usb_cancel_queued_reset(intf);
+   usb_cancel_queued_rebind(intf);
 
/* If the LPM disable succeeded, balance the ref counts. */
if (!lpm_disable_error)
@@ -418,6 +431,8 @@ static int usb_unbind_interface(struct device *dev)
intf-condition = USB_INTERFACE_UNBOUND;
intf-needs_remote_wakeup = 0;
 
+   usb_cancel_queued_rebind(intf);
+
/* Attempt to re-enable USB3 LPM, if the disable succeeded. */
if (!lpm_disable_error)
usb_unlocked_enable_lpm(udev);
@@ -1049,7 +1064,7 @@ static void 
unbind_no_reset_resume_drivers_interfaces(struct usb_device *udev)
}
 }
 
-static void do_rebind_interfaces(struct usb_device *udev)
+static void do_rebind_interfaces(struct usb_device *udev, int use_workqueue)
 {
struct usb_host_config  *config;
int i;
@@ -1059,8 +1074,12 @@ static void do_rebind_interfaces(struct usb_device *udev)
if (config) {
for (i = 0; i  config-desc.bNumInterfaces; ++i) {
intf = config-interface[i];
-   if (intf-needs_binding)
-   usb_rebind_intf(intf);
+   if (intf-needs_binding) {
+   if (use_workqueue)
+   schedule_work(intf-rebind_ws);
+   else
+   usb_rebind_intf(intf);
+   }
}
}
 }
@@ -1389,7 +1408,7 @@ int usb_resume_complete(struct device *dev)
 * whose needs_binding flag is set
 */
if (udev-state != USB_STATE_NOTATTACHED)
-   do_rebind_interfaces(udev);
+   do_rebind_interfaces(udev, 0);
return 0;
 }
 
@@ -1769,6 +1788,9 @@ int usb_runtime_resume(struct device *dev)
 * and all its interfaces.
 */
status = usb_resume_both(udev, PMSG_AUTO_RESUME);
+
+   do_rebind_interfaces(udev, 1);
+
return status;
 }
 
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index bb31597..bc46fc6 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1662,6 +1662,52 @@ static void __usb_queue_reset_device(struct work_struct 
*ws)
}
 }
 
+/*
+ * Internal function to queue an interface rebind
+ *
+ * This is initialized into the workstruct in 'struct
+ * usb_device-rebind_ws' that is launched by
+ * message.c:usb_set_configuration() when initializing each 'struct
+ * usb_interface'.
+ *
+ * It is safe to get the USB device without reference counts because
+ * the life cycle of @iface is bound to the life cycle of @udev. Then,
+ * this function will be ran only if @iface is alive (and before
+ * freeing it any scheduled instances of it will have been cancelled).
+ *
+ * We need to set a flag (usb_dev-rebind_running) because when we call
+ * the rebind, the interfaces will be unbound. The current interface
+ * cannot try to remove the queued work as it would cause a deadlock
+ * (you cannot remove your work from within your executing workqueue).
+ * This flag lets it know, so that usb_cancel_queued_rebind() doesn't
+ * try to do it.
+ */
+static void __usb_queue_rebind_intf(struct work_struct *ws)
+{
+   unsigned long jiffies_expire = jiffies + HZ;
+   

[PATCH 4/4] usb: gadget: composite: switch over to ERR_CAST()

2014-03-10 Thread Felipe Balbi
This patch fixes the following Coccinelle warning:

drivers/usb/gadget/composite.c:1142:9-16: WARNING: \
ERR_CAST can be used with uc

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

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index d742bed..fab9064 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1139,7 +1139,7 @@ struct usb_string *usb_gstrings_attach(struct 
usb_composite_dev *cdev,
 
uc = copy_gadget_strings(sp, n_gstrings, n_strings);
if (IS_ERR(uc))
-   return ERR_PTR(PTR_ERR(uc));
+   return ERR_CAST(uc);
 
n_gs = get_containers_gs(uc);
ret = usb_string_ids_tab(cdev, n_gs[0]-strings);
-- 
1.9.0

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


[PATCH 0/4] fix coccicenelle issues

2014-03-10 Thread Felipe Balbi
Hi,

I plan on sending these 4 patches after v3.15-rc1 is tagged.

Felipe Balbi (4):
  usb: gadget: lpc32xx_udc: fix wrong clk_put() sequence
  usb: gadget: f_subset: switch over to PTR_RET
  usb: gadget: inode: switch over to memdup_user()
  usb: gadget: composite: switch over to ERR_CAST()

 drivers/usb/gadget/composite.c   | 2 +-
 drivers/usb/gadget/f_subset.c| 2 +-
 drivers/usb/gadget/inode.c   | 9 +++--
 drivers/usb/gadget/lpc32xx_udc.c | 4 ++--
 4 files changed, 7 insertions(+), 10 deletions(-)

-- 
1.9.0

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


[PATCH 2/4] usb: gadget: f_subset: switch over to PTR_RET

2014-03-10 Thread Felipe Balbi
this patch fixes the following Coccinelle warning:

drivers/usb/gadget/f_subset.c:279:8-14: WARNING: \
PTR_RET can be used

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

diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index f1a5919..df4a0dcb 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -276,7 +276,7 @@ static int geth_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
}
 
net = gether_connect(geth-port);
-   return IS_ERR(net) ? PTR_ERR(net) : 0;
+   return PTR_RET(net);
 }
 
 static void geth_disable(struct usb_function *f)
-- 
1.9.0

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


[PATCH 1/4] usb: gadget: lpc32xx_udc: fix wrong clk_put() sequence

2014-03-10 Thread Felipe Balbi
This patch fixes the following Coccinelle error:

drivers/usb/gadget/lpc32xx_udc.c:3313:1-7: ERROR: \
missing clk_put; clk_get on line 3139 and \
execution via conditional on line 3146

Signed-off-by: Felipe Balbi ba...@ti.com
---
 drivers/usb/gadget/lpc32xx_udc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/lpc32xx_udc.c b/drivers/usb/gadget/lpc32xx_udc.c
index 049ebab..a139894 100644
--- a/drivers/usb/gadget/lpc32xx_udc.c
+++ b/drivers/usb/gadget/lpc32xx_udc.c
@@ -3295,9 +3295,9 @@ usb_clk_enable_fail:
 pll_set_fail:
clk_disable(udc-usb_pll_clk);
 pll_enable_fail:
-   clk_put(udc-usb_slv_clk);
-usb_otg_clk_get_fail:
clk_put(udc-usb_otg_clk);
+usb_otg_clk_get_fail:
+   clk_put(udc-usb_slv_clk);
 usb_clk_get_fail:
clk_put(udc-usb_pll_clk);
 pll_get_fail:
-- 
1.9.0

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


[PATCH 3/4] usb: gadget: inode: switch over to memdup_user()

2014-03-10 Thread Felipe Balbi
This patch fixes the following Coccinelle warning:

drivers/usb/gadget/inode.c:442:8-15: WARNING \
opportunity for memdup_user

Signed-off-by: Felipe Balbi ba...@ti.com
---
 drivers/usb/gadget/inode.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index b94c049..b5be6f03 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -439,11 +439,9 @@ ep_write (struct file *fd, const char __user *buf, size_t 
len, loff_t *ptr)
/* FIXME writebehind for O_NONBLOCK and poll(), qlen = 1 */
 
value = -ENOMEM;
-   kbuf = kmalloc (len, GFP_KERNEL);
-   if (!kbuf)
-   goto free1;
-   if (copy_from_user (kbuf, buf, len)) {
-   value = -EFAULT;
+   kbuf = memdup_user(buf, len);
+   if (!kbuf) {
+   value = PTR_ERR(kbuf);
goto free1;
}
 
@@ -452,7 +450,6 @@ ep_write (struct file *fd, const char __user *buf, size_t 
len, loff_t *ptr)
data-name, len, (int) value);
 free1:
mutex_unlock(data-lock);
-   kfree (kbuf);
return value;
 }
 
-- 
1.9.0

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


usbnet: driver_info-stop required to stop USB interrupts?

2014-03-10 Thread Grant Grundler
I've trying to unravel a page fault panic I've run into a few times
while testing load/unload of asix driver with ChromeOS 3.8.11 based
kernel.  I'm running into this crash on both ARM and X86. Panic output
below is from Exynos 5422 system. Test script attached.

My _guess_ is usbnet_stop() is racing with a USB interrupt from the
device and loses. First glance at the stack trace implies the
interrupt handler is trying to access something that has previously
been released.

usbnet_stop() calls driver_info-stop() if provided by the driver.  If
my guess above is correct, does that mean stop() call is expected
(required?) to stop interrupts coming from that USB device?
Or is something else supposed to stop RX (or other USB) traffic?

ax88179_178a.c appears to be the only usbnet driver that provides a
.stop call and was able to complete 10K iterations. asix driver
completes 200-5000 iterations before failing for different causes.

thanks,
grant

invoke the reload_asix script and monitor test ---
scp reload_asix $T:/tmp
for i in `seq 1`; do echo -n RELOAD $i   ; ssh $T .
/tmp/reload_asix eth0 100_full ; J=$? ; if [ $J -eq 255 ] ; then echo
 SSH timeout ; break ; fi ; ssh $T cat /var/log/reload-asix.out ;
if [ $J -ne 0 ] ; then echo   ERROR $J ; fi ; sleep 3 ; done | tee
~/reload-AX88772-$IP-04.out

 tombstone from Exynos 5422 on asix driver unload 
...
[28488.367522] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[28488.380574] asix 1-1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
[28493.308354] usbcore: deregistering interface driver asix
[28493.310775] asix 1-1:1.0 eth0: unregister 'asix'
usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet
[28494.369787] usbcore: registered new interface driver asix
[28494.725186] asix 1-1:1.0 eth0: register 'asix' at
usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet,
c8:d7:19:d8:0b:d3
[28494.725262] usb 1-1: authorized to connect
[28495.545485] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[28497.455518] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
[28497.466586] asix 1-1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
[28502.302851] usbcore: deregistering interface driver asix
[28502.308652] asix 1-1:1.0 eth0: unregister 'asix'
usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet
[28502.308717] Unable to handle kernel paging request at virtual
address e24cb004
[28502.308739] pgd = ea514000
[28502.308753] [e24cb004] *pgd=4241141e(bad)
[28502.308782] Internal error: Oops: 800d [#1] SMP ARM
[28502.308795] Modules linked in: asix(-) uvcvideo videobuf2_vmalloc
i2c_dev uinput exynos_gsc v4l2_mem2mem btmrvl_sdio sbs_9018(C)
mwifiex_sdio mwifiex btmrvl s5p_mfc videobuf2_core zram(C) bluetooth
videobuf2_dma_contig videobuf2_memops rtc_s3c zuse cfg80211
nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables usbnet
joydev [last unloaded: asix]
[28502.308998] CPU: 0Tainted: G C(3.8.11 #6)
[28502.309016] PC is at 0xe24cb004
[28502.309039] LR is at __wake_up_common+0x5c/0x88
[28502.309058] pc : [e24cb004]lr : [c014f848]psr: 8093
[28502.309058] sp : ef10be10  ip : e24cb004  fp : ef10be3c
[28502.309076] r10: e1a0c00d  r9 :   r8 : 0003
[28502.309091] r7 :   r6 : 0001  r5 : e92d3ff4  r4 : ea409d14
[28502.309106] r3 :   r2 :   r1 : 0003  r0 : c060ced4
[28502.309122] Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32  ISA ARM
Segment kernel
[28502.309138] Control: 10c5387d  Table: 4a51406a  DAC: 0015
[28502.309153] Process ksoftirqd/0 (pid: 3, stack limit = 0xef10a240)
[28502.309168] Stack: (0xef10be10 to 0xef10c000)
[28502.309186] be00: 
ea409d04 4013 0001
[28502.309209] be20: 0003  0100 3f6fdf7c ef10be6c
ef10be40 c0151c08 c014f7f8
[28502.309231] be40:  ef10be50 c0529a44 ea5ac540 
ea5ac64c  
[28502.309254] be60: ef10be8c ef10be70 bf00a0e4 c0151bcc bf009fa4
ea5ac6bc ea5ac6c0 c084c790
[28502.309277] be80: ef10beb4 ef10be90 c012bcb4 bf009fb0 c012bc1c
ef10a038 0001 c090209c
[28502.309300] bea0: 0006 c09795c0 ef10bf04 ef10beb8 c012b348
c012bc28 c0934314 ef10a000
[28502.309322] bec0: 0001 ef10a020   04208040
000a ef10bf04 
[28502.309345] bee0: c0934314 ef10a000 0001 ef10a020 
 ef10bf1c ef10bf08
[28502.309368] bf00: c012b48c c012b234 c012b44c ef056d00 ef10bf44
ef10bf20 c014f204 c012b458
[28502.309391] bf20: ef101e48  ef056d00 c014f098 
 ef10bfac ef10bf48
[28502.309413] bf40: c01455b4 c014f0a4 0001  ef056d00
 00030003 dead4ead
[28502.309436] bf60:   ef10bf68 ef10bf68 
 dead4ead 
[28502.309459] bf80:  ef10bf84 ef10bf84 271ae517 ef101e48
c01454ec  
[28502.309480] bfa0:  ef10bfb0 c0106118 c01454f8 
  
[28502.309500] bfc0:     

Re: [PATCH v5 00/14] usb: phy: msm: Fixes, cleanups and DT support

2014-03-10 Thread Felipe Balbi
Hi,

On Sat, Mar 08, 2014 at 06:46:52PM +0200, Ivan T. Ivanov wrote:
 Hi,
 
 On 03/08/2014 02:15 AM, Felipe Balbi wrote:
  On Wed, Mar 05, 2014 at 05:54:03PM -0800, Tim Bird wrote:
  Ivan,
 
  I'm still unsuccessful at getting this patch set to work on my kernel.
  See regs in dmesg log
 
 
 
 snip
 
  never got any reply to this, nor got a response to Sergei's comments.
  Not looking good, too late for v3.15.
  
 
 I am working with Tim to resolve this issue. Sergei's comment have
 been answered already :-)

the only answer was Thanks I'll fix it. To which there was never a
fix.

 It will be nice if you could pick up first several patches, which are
 just cleanups.

unfortunately I have already sent my pull request to Greg :-(

I could try to get some of those in during the -rc cycle, but it's
unlikely Greg will let me :-)


-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH RFC] usb: gadget: Add xilinx axi usb2 device support

2014-03-10 Thread Felipe Balbi
Hi,

On Mon, Mar 10, 2014 at 07:06:19PM +0530, sundeep subbaraya wrote:
 On Fri, Feb 21, 2014 at 9:09 PM, Felipe Balbi ba...@ti.com wrote:
  Hi,
 
  On Fri, Feb 21, 2014 at 11:27:07AM +, Subbaraya Sundeep Bhatta wrote:
   From the looks of it, I doubt this was actually tested, you need a lot
   of work on this driver.
  Tested on both ARM and Microblaze architectures with Mass storage gadget.
  Will send a v2 after addressing all your comments.
 
  clearly you didn't try to remove and reinsert the module or you would
  see a whole bunch of errors.
 
 
 Yes you are correct. My console hung up as soon as i rmmod my driver.
 Could you please point me where am wrong.

Many of your mistakes have already been pointed out here:

http://marc.info/?l=linux-usbm=139292068028649w=2

Please fix those and see if following script works:

#!/bin/sh

MODULE=xilinx_udc

for i in $(seq 500); do
modprobe $MODULE  /dev/null 21;
modprobe -r $MODULE  /dev/null 21;
if [ $? -eq 0 ]; then
echo -n .
else
echo -n F
fi
done

echo Finished

you shouldn't see any F characters and your machine shouldn't crash or
hang or reboot...

Also make sure to run g_zero testcases and mass storage tescases. I
wrote, long ago, a small tool to help testing UDC drivers running with
the mass storage gadget, which you can find in [1]. There's a runner
script which makes it easy to full test suite which you can find in [2].

[1] 
https://gitorious.org/usb/usb-tools/source/7eb7ef21de6cd124e0e0d0e7df9ddfff0e2f548e:msc.c
[2] 
https://gitorious.org/usb/usb-tools/source/7eb7ef21de6cd124e0e0d0e7df9ddfff0e2f548e:msc.sh

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 0/4] fix coccicenelle issues

2014-03-10 Thread Greg KH
On Mon, Mar 10, 2014 at 01:30:52PM -0500, Felipe Balbi wrote:
 Hi,
 
 I plan on sending these 4 patches after v3.15-rc1 is tagged.

Just send them to me now for 3.15-rc1, or I can just take these from the
patches themselves to make it easier for you...

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] rebind: Add rebind mechanism for runtime-resume

2014-03-10 Thread Greg KH
On Mon, Mar 10, 2014 at 05:27:17PM +, Poulain, Loic wrote:
 Despite the needs_rebind flag, the interface rebind was never
 done for the PM runtime resume. This patch fixes this issue
 by triggering the rebind in usb runtime resume.
 
 The rebind procedure needs to be called with the device lock.
 However, depending the call path (remote wakeup, local resume),
 the device lock may or may not already be held in usb runtime
 resume. So, use a work queue to take the lock unconditionally.
 Protect this work against any deadlock in the same way as
 reset_device.
 
 Signed-off-by: lpoulain loic.poul...@intel.com

You need to put a real name for your signed-off-by line.
--
To unsubscribe from this list: send the line unsubscribe 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] rebind: Add rebind mechanism for runtime-resume

2014-03-10 Thread Alan Stern
On Mon, 10 Mar 2014, Poulain, Loic wrote:

 Despite the needs_rebind flag, the interface rebind was never
 done for the PM runtime resume. This patch fixes this issue
 by triggering the rebind in usb runtime resume.
 
 The rebind procedure needs to be called with the device lock.
 However, depending the call path (remote wakeup, local resume),
 the device lock may or may not already be held in usb runtime
 resume. So, use a work queue to take the lock unconditionally.
 Protect this work against any deadlock in the same way as
 reset_device.
 
 Signed-off-by: lpoulain loic.poul...@intel.com

Although the basic idea is okay, this patch has a couple of weak spots.

 @@ -1662,6 +1662,52 @@ static void __usb_queue_reset_device(struct 
 work_struct *ws)
   }
  }
  
 +/*
 + * Internal function to queue an interface rebind
 + *
 + * This is initialized into the workstruct in 'struct
 + * usb_device-rebind_ws' that is launched by
 + * message.c:usb_set_configuration() when initializing each 'struct
 + * usb_interface'.
 + *
 + * It is safe to get the USB device without reference counts because
 + * the life cycle of @iface is bound to the life cycle of @udev. Then,
 + * this function will be ran only if @iface is alive (and before
 + * freeing it any scheduled instances of it will have been cancelled).
 + *
 + * We need to set a flag (usb_dev-rebind_running) because when we call
 + * the rebind, the interfaces will be unbound. The current interface
 + * cannot try to remove the queued work as it would cause a deadlock
 + * (you cannot remove your work from within your executing workqueue).
 + * This flag lets it know, so that usb_cancel_queued_rebind() doesn't
 + * try to do it.
 + */
 +static void __usb_queue_rebind_intf(struct work_struct *ws)
 +{
 + unsigned long jiffies_expire = jiffies + HZ;
 + struct usb_interface *iface =
 + container_of(ws, struct usb_interface, rebind_ws);
 + struct usb_device *udev = interface_to_usbdev(iface);
 +
 + /* Rather than sleeping to wait for the lock, poll repeatedly.
 +  * This is to prevent any deadlock with usb_unbind_interface */
 + while (!usb_trylock_device(udev)) {
 + /* If we can't acquire the lock after waiting one second,
 +  * we're probably deadlocked */
 + if (time_after(jiffies, jiffies_expire))
 + return;
 +
 + if (udev-state == USB_STATE_NOTATTACHED ||
 + iface-condition == USB_INTERFACE_UNBOUND)
 + return;
 + }

This loop is bad because it doesn't sleep.  Can't you just call 
usb_lock_device_for_reset() instead of basically rewriting it?

 --- a/include/linux/usb.h
 +++ b/include/linux/usb.h
 @@ -131,6 +131,10 @@ enum usb_interface_condition {
   *  thread. See __usb_queue_reset_device().
   * @resetting_device: USB core reset the device, so use alt setting 0 as
   *   current; needs bandwidth alloc after reset.
 + * @rebind_running: set to 1 if the interface is currently running a
 + *  queued rebind so that usb_cancel_queued_rebind() doesn't try to
 + *  remove from the workqueue when running inside the worker
 + *  thread. See __usb_queue_rebind_device()
   *
   * USB device drivers attach to interfaces on a physical device.  Each
   * interface encapsulates a single high level function, such as feeding

Where's the kerneldoc for rebind_ws?

Alan Stern

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


Re: [PATCH 0/4] fix coccicenelle issues

2014-03-10 Thread Felipe Balbi
On Mon, Mar 10, 2014 at 11:55:18AM -0700, Greg KH wrote:
 On Mon, Mar 10, 2014 at 01:30:52PM -0500, Felipe Balbi wrote:
  Hi,
  
  I plan on sending these 4 patches after v3.15-rc1 is tagged.
 
 Just send them to me now for 3.15-rc1, or I can just take these from the
 patches themselves to make it easier for you...

If you want to take them as patches, I'd appreciate it. Please go ahead.

Thank you Greg

-- 
balbi


signature.asc
Description: Digital signature


Re: MAX3421E: device giving NAKs forever?

2014-03-10 Thread Felipe Balbi
Hi,

On Mon, Mar 10, 2014 at 01:48:33PM -0600, David Mosberger wrote:
 Thanks for taking a look!
 
 I thought that there might be an bug in re-transmitting the OUT requests
 that are being NAK'd indefinitely, but a different flash drive works much
 longer and with that drive, I see many OUT requests that get NAK'd a couple
 of times, but eventually go through fine.  So I think OUT re-transmissions
 are fine.  That drive still fails eventually with infinite NAKs, but this
 one on a bulk-IN transaction.
 
 I agree, it's time to get a bus analyzer.

cheapest you can find is totalphase.com's USB 480. They have the added
benefit of working under windows, linux and mac osx.

I'd strongly suggest getting usb480 rather than usb12, as usb12 can only
do descriptor parsing :-(

http://www.totalphase.com/products/beagle-usb480-power-standard/

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] usb: gadget: f_fs: add missing spinlock and mutex unlock

2014-03-10 Thread Felipe Balbi
On Mon, Mar 10, 2014 at 02:05:47PM +0100, Michal Nazarewicz wrote:
 On Mon, Mar 10 2014, Robert Baldyga r.bald...@samsung.com wrote:
  This patch adds missing spin_unlock and mutex_unlock calls in
  error handling code.
 
  Signed-off-by: Robert Baldyga r.bald...@samsung.com
 
 Acked-by: Michal Nazarewicz min...@mina86.com

Greg, here's another one you can pick. It's also a coccicheck fix.

Acked-by: Felipe Balbi ba...@ti.com

  ---
   drivers/usb/gadget/f_fs.c |8 ++--
   1 file changed, 6 insertions(+), 2 deletions(-)
 
  diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
  index b7d273a..d6bd0a3 100644
  --- a/drivers/usb/gadget/f_fs.c
  +++ b/drivers/usb/gadget/f_fs.c
  @@ -802,7 +802,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
  ffs_io_data *io_data)
  if (io_data-aio) {
  req = usb_ep_alloc_request(ep-ep, GFP_KERNEL);
  if (unlikely(!req))
  -   goto error;
  +   goto error_lock;
   
  req-buf  = data;
  req-length   = io_data-len;
  @@ -817,7 +817,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
  ffs_io_data *io_data)
  ret = usb_ep_queue(ep-ep, req, GFP_ATOMIC);
  if (unlikely(ret)) {
  usb_ep_free_request(ep-ep, req);
  -   goto error;
  +   goto error_lock;
  }
  ret = -EIOCBQUEUED;
   
  @@ -863,6 +863,10 @@ static ssize_t ffs_epfile_io(struct file *file, struct 
  ffs_io_data *io_data)
   
  mutex_unlock(epfile-mutex);
  return ret;
  +
  +error_lock:
  +   spin_unlock_irq(epfile-ffs-eps_lock);
  +   mutex_unlock(epfile-mutex);
   error:
  kfree(data);
  return ret;
  -- 
  1.7.9.5
 
 
 -- 
 Best regards, _ _
 .o. | Liege of Serenely Enlightened Majesty of  o' \,=./ `o
 ..o | Computer Science,  Michał “mina86” Nazarewicz(o o)
 ooo +--m...@google.com--xmpp:min...@jabber.org--ooO--(_)--Ooo--





-- 
balbi


signature.asc
Description: Digital signature


Re: MAX3421E: device giving NAKs forever?

2014-03-10 Thread David Mosberger
[Resend in plain text mode...]

Thanks for taking a look!

I thought that there might be an bug in re-transmitting the OUT requests
that are being NAK'd indefinitely, but a different flash drive works much
longer and with that drive, I see many OUT requests that get NAK'd a couple
of times, but eventually go through fine.  So I think OUT re-transmissions
are fine.  That drive still fails eventually with infinite NAKs, but this
one on a bulk-IN transaction.

I agree, it's time to get a bus analyzer.

  --david

On Sun, Mar 9, 2014 at 9:11 AM, Alan Stern st...@rowland.harvard.edu wrote:
 On Fri, 7 Mar 2014, David Mosberger wrote:

 Felipe,

 Thanks for the tip about usbmon --- that looks interesting.  Of
 course, as luck would have it, turning on usbmon changes behavior:
 dd'ing to a mass-storage device (/dev/sda1) used to fail after
 ~500KiB.  With usbmon, it fails only after about 2MiB.

 I attached two logs: first one is the usb-storage debug output without
 usbmon (fails after about 500KB of writing to /dev/sda1), second is
 with usbmon (fails about 2MiB of writing to /dev/sda1).

 I didn't see anything unusual in the logs.  It looks like you'll have
 to use a bus analyzer to see the actual packets on the wire.

 Alan Stern




-- 
eGauge Systems LLC, http://egauge.net/, 1.877-EGAUGE1, fax 720.545.9768
--
To unsubscribe from this list: send the line unsubscribe 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-next] r8152: add skb_cow_head

2014-03-10 Thread David Miller
From: Hayes Wang hayesw...@realtek.com
Date: Mon, 10 Mar 2014 14:22:31 +0800

 Call skb_cow_head() before editing the tx packet header. The header
 would be reallocated if it is shared.
 
 Signed-off-by: Hayes Wang hayesw...@realtek.com
 ---
  drivers/net/usb/r8152.c | 13 +++--
  1 file changed, 11 insertions(+), 2 deletions(-)
 
 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
 index c7ef30d..faad39b 100644
 --- a/drivers/net/usb/r8152.c
 +++ b/drivers/net/usb/r8152.c
 @@ -1376,6 +1376,11 @@ static int msdn_giant_send_check(struct sk_buff *skb)
  {
   const struct ipv6hdr *ipv6h;
   struct tcphdr *th;
 + int ret;
 +
 + ret = skb_cow_head(skb, 0);
 + if (ret)
 + goto out1;
  
   ipv6h = ipv6_hdr(skb);
   th = tcp_hdr(skb);
 @@ -1383,7 +1388,8 @@ static int msdn_giant_send_check(struct sk_buff *skb)
   th-check = 0;
   th-check = ~tcp_v6_check(0, ipv6h-saddr, ipv6h-daddr, 0);
  
 - return 0;
 +out1:
 + return ret;
  }
  
  static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,

Please just return directly instead of goto out1.  There are no other
operations or pieces of state to undo if you fail at the beginning of
the function, and the label furthermore will have only one user, so
it seems completely unnecessary.  A simple return ret will work just
fine.

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


Re: usbnet: driver_info-stop required to stop USB interrupts?

2014-03-10 Thread Grant Grundler
On Mon, Mar 10, 2014 at 11:33 AM, Grant Grundler grund...@google.com wrote:
 I've trying to unravel a page fault panic I've run into a few times
 while testing load/unload of asix driver with ChromeOS 3.8.11 based
 kernel.  I'm running into this crash on both ARM and X86.

Correction - I can only confirm I've seen this on ARM.

sorry,
grant

 Panic output below is from Exynos 5422 system. Test script attached.

 My _guess_ is usbnet_stop() is racing with a USB interrupt from the
 device and loses. First glance at the stack trace implies the
 interrupt handler is trying to access something that has previously
 been released.

 usbnet_stop() calls driver_info-stop() if provided by the driver.  If
 my guess above is correct, does that mean stop() call is expected
 (required?) to stop interrupts coming from that USB device?
 Or is something else supposed to stop RX (or other USB) traffic?

 ax88179_178a.c appears to be the only usbnet driver that provides a
 .stop call and was able to complete 10K iterations. asix driver
 completes 200-5000 iterations before failing for different causes.

 thanks,
 grant

 invoke the reload_asix script and monitor test ---
 scp reload_asix $T:/tmp
 for i in `seq 1`; do echo -n RELOAD $i   ; ssh $T .
 /tmp/reload_asix eth0 100_full ; J=$? ; if [ $J -eq 255 ] ; then echo
  SSH timeout ; break ; fi ; ssh $T cat /var/log/reload-asix.out ;
 if [ $J -ne 0 ] ; then echo   ERROR $J ; fi ; sleep 3 ; done | tee
 ~/reload-AX88772-$IP-04.out

  tombstone from Exynos 5422 on asix driver unload 
 ...
 [28488.367522] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
 [28488.380574] asix 1-1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
 [28493.308354] usbcore: deregistering interface driver asix
 [28493.310775] asix 1-1:1.0 eth0: unregister 'asix'
 usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet
 [28494.369787] usbcore: registered new interface driver asix
 [28494.725186] asix 1-1:1.0 eth0: register 'asix' at
 usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet,
 c8:d7:19:d8:0b:d3
 [28494.725262] usb 1-1: authorized to connect
 [28495.545485] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
 [28497.455518] IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
 [28497.466586] asix 1-1:1.0 eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
 [28502.302851] usbcore: deregistering interface driver asix
 [28502.308652] asix 1-1:1.0 eth0: unregister 'asix'
 usb-xhci-hcd.4.auto-1, ASIX AX88772 USB 2.0 Ethernet
 [28502.308717] Unable to handle kernel paging request at virtual
 address e24cb004
 [28502.308739] pgd = ea514000
 [28502.308753] [e24cb004] *pgd=4241141e(bad)
 [28502.308782] Internal error: Oops: 800d [#1] SMP ARM
 [28502.308795] Modules linked in: asix(-) uvcvideo videobuf2_vmalloc
 i2c_dev uinput exynos_gsc v4l2_mem2mem btmrvl_sdio sbs_9018(C)
 mwifiex_sdio mwifiex btmrvl s5p_mfc videobuf2_core zram(C) bluetooth
 videobuf2_dma_contig videobuf2_memops rtc_s3c zuse cfg80211
 nf_conntrack_ipv6 nf_defrag_ipv6 ip6table_filter ip6_tables usbnet
 joydev [last unloaded: asix]
 [28502.308998] CPU: 0Tainted: G C(3.8.11 #6)
 [28502.309016] PC is at 0xe24cb004
 [28502.309039] LR is at __wake_up_common+0x5c/0x88
 [28502.309058] pc : [e24cb004]lr : [c014f848]psr: 8093
 [28502.309058] sp : ef10be10  ip : e24cb004  fp : ef10be3c
 [28502.309076] r10: e1a0c00d  r9 :   r8 : 0003
 [28502.309091] r7 :   r6 : 0001  r5 : e92d3ff4  r4 : ea409d14
 [28502.309106] r3 :   r2 :   r1 : 0003  r0 : c060ced4
 [28502.309122] Flags: Nzcv  IRQs off  FIQs on  Mode SVC_32  ISA ARM
 Segment kernel
 [28502.309138] Control: 10c5387d  Table: 4a51406a  DAC: 0015
 [28502.309153] Process ksoftirqd/0 (pid: 3, stack limit = 0xef10a240)
 [28502.309168] Stack: (0xef10be10 to 0xef10c000)
 [28502.309186] be00: 
 ea409d04 4013 0001
 [28502.309209] be20: 0003  0100 3f6fdf7c ef10be6c
 ef10be40 c0151c08 c014f7f8
 [28502.309231] be40:  ef10be50 c0529a44 ea5ac540 
 ea5ac64c  
 [28502.309254] be60: ef10be8c ef10be70 bf00a0e4 c0151bcc bf009fa4
 ea5ac6bc ea5ac6c0 c084c790
 [28502.309277] be80: ef10beb4 ef10be90 c012bcb4 bf009fb0 c012bc1c
 ef10a038 0001 c090209c
 [28502.309300] bea0: 0006 c09795c0 ef10bf04 ef10beb8 c012b348
 c012bc28 c0934314 ef10a000
 [28502.309322] bec0: 0001 ef10a020   04208040
 000a ef10bf04 
 [28502.309345] bee0: c0934314 ef10a000 0001 ef10a020 
  ef10bf1c ef10bf08
 [28502.309368] bf00: c012b48c c012b234 c012b44c ef056d00 ef10bf44
 ef10bf20 c014f204 c012b458
 [28502.309391] bf20: ef101e48  ef056d00 c014f098 
  ef10bfac ef10bf48
 [28502.309413] bf40: c01455b4 c014f0a4 0001  ef056d00
  00030003 dead4ead
 [28502.309436] bf60:   ef10bf68 ef10bf68 
  dead4ead 
 [28502.309459] 

Re: MAX3421E: device giving NAKs forever?

2014-03-10 Thread Felipe Balbi
Hi,

(please avoid top-posting)

On Mon, Mar 10, 2014 at 02:15:36PM -0600, David Mosberger wrote:
 I was thinking of the Salea Logic http://www.saleae.com/logic ($150).
  Are you aware of any limitations for this one that would get in the way?

for full-speed USB it should work, I guess. Never tried though. Can it
handle differential signalling ?

-- 
balbi


signature.asc
Description: Digital signature


[PATCH net-next v2] r8152: add skb_cow_head

2014-03-10 Thread Hayes Wang
Call skb_cow_head() before editing the tx packet header. The header
would be reallocated if it is shared.

Signed-off-by: Hayes Wang hayesw...@realtek.com
---
 drivers/net/usb/r8152.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index c7ef30d..a90a7eb9 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1376,6 +1376,11 @@ static int msdn_giant_send_check(struct sk_buff *skb)
 {
const struct ipv6hdr *ipv6h;
struct tcphdr *th;
+   int ret;
+
+   ret = skb_cow_head(skb, 0);
+   if (ret)
+   return ret;
 
ipv6h = ipv6_hdr(skb);
th = tcp_hdr(skb);
@@ -1383,7 +1388,7 @@ static int msdn_giant_send_check(struct sk_buff *skb)
th-check = 0;
th-check = ~tcp_v6_check(0, ipv6h-saddr, ipv6h-daddr, 0);
 
-   return 0;
+   return ret;
 }
 
 static int r8152_tx_csum(struct r8152 *tp, struct tx_desc *desc,
@@ -1412,8 +1417,11 @@ static int r8152_tx_csum(struct r8152 *tp, struct 
tx_desc *desc,
break;
 
case htons(ETH_P_IPV6):
+   if (msdn_giant_send_check(skb)) {
+   ret = TX_CSUM_TSO;
+   goto unavailable;
+   }
opts1 |= GTSENDV6;
-   msdn_giant_send_check(skb);
break;
 
default:
-- 
1.8.4.2

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


Re: usbnet: driver_info-stop required to stop USB interrupts?

2014-03-10 Thread Julius Werner
I think usbnet_stop() raced with the dev-bh tasklet, which by itself
might not be a problem (usbnet_stop() later kills the tasklet itself,
so it should expect that it can be running before that). The issue is
that it calls usbnet_terminate_urbs() before that, which temporarily
installs a waitqueue in dev-wait in order to be able to wait on the
tasklet to run and finish up some queues. The waiting itself looks
okay, but the access to 'dev-wait' is totally unprotected and can
race arbitrarily. I think in this case usbnet_bh() managed to succeed
it's dev-wait check just before usbnet_terminate_urbs() sets it back
to NULL. The latter then finishes and the waitqueue_t structure on its
stack gets overwritten by other functions halfway through the
wake_up() call in usbnet_bh().

I think the best solution would be to just make dev-wait a directly
embedded structure inside struct usbnet instead of a pointer to
something stack-allocated. usbnet_bh() could just call wake_up()
unconditionally (if empty it will be a noop), and then one other check
for !dev-wait could be replaced with a call to waitqueue_active().
Then the waitqueue-internal locks should be enough to protect all
accesses.
--
To unsubscribe from this list: send the line unsubscribe 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] u_ether: move hardware transmit to RX workqueue

2014-03-10 Thread Felipe Balbi
On Sat, Mar 08, 2014 at 09:47:38AM -0800, Greg Kroah-Hartman wrote:
 On Sun, Mar 09, 2014 at 01:27:48AM +0800, clanlab.proj wrote:
  Hi Greg, Dave and Felipe,
  
  On Sun, Mar 9, 2014 at 12:45 AM, Greg Kroah-Hartman
  gre...@linuxfoundation.org wrote:
   On Sat, Mar 08, 2014 at 03:39:48PM +0800, clanlab.proj wrote:
   Hi Dave and Greg,
  
Signed-off-by: Weinn Jheng clanlab.p...@gmail.com
Cc: David Brownell dbrown...@users.sourceforge.net
Cc: David S. Miller da...@davemloft.net
   
Dave, does this look ok from NAPI point of view ?
  
   I've found the another patch NAPI version has been taken by Greg.
  
   I did?  What git commit id is it?
  
  Ha! I found I saw before should be the merge notice.
  
  The patch may be actually taken by Felipe
  commit 808855f0615b2a5c8fd916e4988f3b9e748aac73 (patch)
  tree 7911e8bed2a7b99bbc5950d9cc67724999be7f13
  has been applied to my tree and can be found at:
  http://bit.ly/1oxoXwd
  
 
 Neither of those commits are in my USB tree, sorry.

here's the correct commit 716fb91dfe1777bd6d5e598f3d3572214b3ed296.

NAPI should be the way to go, using a plain workqueue is just wrong, let
the networking schedule skbs the way it wants. Also, the throughput
difference is only *slightly* better with workqueue.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] xhci: extend quirk for Renesas cards

2014-03-10 Thread Igor Gnatenko
On Mon, 2014-03-10 at 15:06 +0200, Mathias Nyman wrote: 
 On 03/09/2014 04:20 PM, Igor Gnatenko wrote:
  After suspend another Renesas PCI-X USB 3.0 card doesn't work.
  03:00.0 USB controller [0c03]: Renesas Technology Corp. uPD720202 USB 3.0 
  Host Controller [1912:0015] (rev 02) (prog-if 30 [XHCI])
 
  Reported-and-tested-by: Anatoly K. rfr-b...@yandex.ru
  Reference: http://redmine.russianfedora.pro/issues/1315
  Signed-off-by: Igor Gnatenko i.gnatenko.br...@gmail.com
  ---
drivers/usb/host/xhci-pci.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
 
  diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
  index 04f986d..13d4add 100644
  --- a/drivers/usb/host/xhci-pci.c
  +++ b/drivers/usb/host/xhci-pci.c
  @@ -143,9 +143,7 @@ static void xhci_pci_quirks(struct device *dev, struct 
  xhci_hcd *xhci)
  xhci-quirks |= XHCI_TRUST_TX_LENGTH;
  }
  if (pdev-vendor == PCI_VENDOR_ID_RENESAS 
  -   pdev-device == 0x0015 
  -   pdev-subsystem_vendor == PCI_VENDOR_ID_SAMSUNG 
  -   pdev-subsystem_device == 0xc0cd)
  +   pdev-device == 0x0015)
  xhci-quirks |= XHCI_RESET_ON_RESUME;
  if (pdev-vendor == PCI_VENDOR_ID_VIA)
  xhci-quirks |= XHCI_RESET_ON_RESUME;
 
 
 This will set the resume quirk for all devices with a Renesas  uPD720202 
 host.
 
 Do they all need this quirk, or should just this card manufacturer be 
 added to the quirk? (subsystem vendor/device)
I can't determine whay subsystem_(vendor|device) is needed for this
card. If you can help me determine this info - I can resend patch with
adding new quirk only for this device. 
 
 -Mathias
-- 
-Igor Gnatenko

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