mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance
@ 2015-10-14 10:15 Peter Mamonov
  2015-10-14 10:15 ` [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error Peter Mamonov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Peter Mamonov @ 2015-10-14 10:15 UTC (permalink / raw)
  To: barebox

The second patch of this patch set adds reentrance detection to 
the the following functions: usb_submit_int_msg, usb_control_msg and
usb_bulk_msg. These functions will return -EAGAIN if reentered. 
Other public usb_* functions call one of these three functions.
This patch enables one to use regular *delay() functions
throughout the ehci-hcd.c.

The first patch adds check for -EAGAIN return value to the usb keyboard
driver. The driver will skip keyboard poll upon getting this error value
from either usb_submit_int_msg() or usb_get_report() functions.

Peter Mamonov (2):
	input: usb_kbd: skip poll on -EAGAIN error
	usb: core: return -EAGAIN on usb_* functions reentrance

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error
  2015-10-14 10:15 [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
@ 2015-10-14 10:15 ` Peter Mamonov
  2015-10-14 10:15 ` [PATCH 2/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
  2015-10-14 14:09 ` [PATCH 0/2] " Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Mamonov @ 2015-10-14 10:15 UTC (permalink / raw)
  To: barebox; +Cc: Peter Mamonov

Skip poll if either usb_submit_int_msg() or usb_get_report()
returned -EAGAIN.

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/input/usb_kbd.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/input/usb_kbd.c b/drivers/input/usb_kbd.c
index 8c08aba..655d0c7 100644
--- a/drivers/input/usb_kbd.c
+++ b/drivers/input/usb_kbd.c
@@ -274,7 +274,7 @@ static void usb_kbd_poll(struct poller_struct *poller)
 	struct usb_kbd_pdata *data = container_of(poller,
 						  struct usb_kbd_pdata, poller);
 	struct usb_device *usbdev = data->usbdev;
-	int diff, tout;
+	int diff, tout, ret;
 
 	if (data->lock)
 		return;
@@ -284,7 +284,10 @@ static void usb_kbd_poll(struct poller_struct *poller)
 		goto exit;
 	data->last_poll = get_time_ns();
 
-	if (0 > data->do_poll(data)) {
+	ret = data->do_poll(data);
+	if (ret == -EAGAIN)
+		goto exit;
+	if (ret < 0) {
 		/* exit and lock forever */
 		dev_err(&usbdev->dev,
 			"usb_submit_int_msg() failed. Keyboard disconnect?\n");
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] usb: core: return -EAGAIN on usb_* functions reentrance
  2015-10-14 10:15 [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
  2015-10-14 10:15 ` [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error Peter Mamonov
@ 2015-10-14 10:15 ` Peter Mamonov
  2015-10-14 14:09 ` [PATCH 0/2] " Sascha Hauer
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Mamonov @ 2015-10-14 10:15 UTC (permalink / raw)
  To: barebox; +Cc: Peter Mamonov

Signed-off-by: Peter Mamonov <pmamonov@gmail.com>
---
 drivers/usb/core/usb.c | 40 +++++++++++++++++++++++++++++++++++++++-
 include/usb/usb.h      |  1 +
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index a3fb1e8..ce229f2 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -84,10 +84,25 @@ static void print_usb_device(struct usb_device *dev)
 
 static int host_busnum = 1;
 
+static inline int usb_host_acquire(struct usb_host *host)
+{
+	if (host->sem)
+		return -EAGAIN;
+	host->sem++;
+	return 0;
+}
+
+static inline void usb_host_release(struct usb_host *host)
+{
+	if (host->sem > 0)
+		host->sem--;
+}
+
 int usb_register_host(struct usb_host *host)
 {
 	list_add_tail(&host->list, &host_list);
 	host->busnum = host_busnum++;
+	host->sem = 0;
 	asynch_allowed = 1;
 	return 0;
 }
@@ -563,8 +578,17 @@ int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
 			void *buffer, int transfer_len, int interval)
 {
 	struct usb_host *host = dev->host;
+	int ret;
+
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
+	ret = host->submit_int_msg(dev, pipe, buffer, transfer_len, interval);
 
-	return host->submit_int_msg(dev, pipe, buffer, transfer_len, interval);
+	usb_host_release(host);
+
+	return ret;
 }
 
 /*
@@ -590,6 +614,10 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 		return -1;
 	}
 
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
 	/* set setup command */
 	setup_packet->requesttype = requesttype;
 	setup_packet->request = request;
@@ -603,6 +631,9 @@ int usb_control_msg(struct usb_device *dev, unsigned int pipe,
 
 	ret = host->submit_control_msg(dev, pipe, data, size, setup_packet,
 			timeout);
+
+	usb_host_release(host);
+
 	if (ret)
 		return ret;
 
@@ -623,8 +654,15 @@ int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
 	if (len < 0)
 		return -1;
 
+	ret = usb_host_acquire(host);
+	if (ret)
+		return ret;
+
 	dev->status = USB_ST_NOT_PROC; /* not yet processed */
 	ret = host->submit_bulk_msg(dev, pipe, data, len, timeout);
+
+	usb_host_release(host);
+
 	if (ret)
 		return ret;
 
diff --git a/include/usb/usb.h b/include/usb/usb.h
index 8f3ce2a..aedc527 100644
--- a/include/usb/usb.h
+++ b/include/usb/usb.h
@@ -152,6 +152,7 @@ struct usb_host {
 	struct device_d *hw_dev;
 	int busnum;
 	struct usb_device *root_dev;
+	int sem;
 };
 
 int usb_register_host(struct usb_host *);
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance
  2015-10-14 10:15 [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
  2015-10-14 10:15 ` [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error Peter Mamonov
  2015-10-14 10:15 ` [PATCH 2/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
@ 2015-10-14 14:09 ` Sascha Hauer
  2015-10-15 12:38   ` Peter Mamonov
  2 siblings, 1 reply; 5+ messages in thread
From: Sascha Hauer @ 2015-10-14 14:09 UTC (permalink / raw)
  To: Peter Mamonov; +Cc: barebox

Hi Peter,

On Wed, Oct 14, 2015 at 01:15:47PM +0300, Peter Mamonov wrote:
> The second patch of this patch set adds reentrance detection to 
> the the following functions: usb_submit_int_msg, usb_control_msg and
> usb_bulk_msg. These functions will return -EAGAIN if reentered. 
> Other public usb_* functions call one of these three functions.
> This patch enables one to use regular *delay() functions
> throughout the ehci-hcd.c.
> 
> The first patch adds check for -EAGAIN return value to the usb keyboard
> driver. The driver will skip keyboard poll upon getting this error value
> from either usb_submit_int_msg() or usb_get_report() functions.
> 
> Peter Mamonov (2):
> 	input: usb_kbd: skip poll on -EAGAIN error
> 	usb: core: return -EAGAIN on usb_* functions reentrance

Applied on -next. I believe we no longer need mdelay_non_interruptible
in the ehci-hcd driver, right? Also we don't have to detect re-entrancy
in the ehci driver anymore. I have applied some patches removing that
to -next. Could you check the result?

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance
  2015-10-14 14:09 ` [PATCH 0/2] " Sascha Hauer
@ 2015-10-15 12:38   ` Peter Mamonov
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Mamonov @ 2015-10-15 12:38 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On Wed, 14 Oct 2015 16:09:08 +0200
Sascha Hauer <s.hauer@pengutronix.de> wrote:

> Hi Peter,
> 
> On Wed, Oct 14, 2015 at 01:15:47PM +0300, Peter Mamonov wrote:
> > The second patch of this patch set adds reentrance detection to 
> > the the following functions: usb_submit_int_msg, usb_control_msg and
> > usb_bulk_msg. These functions will return -EAGAIN if reentered. 
> > Other public usb_* functions call one of these three functions.
> > This patch enables one to use regular *delay() functions
> > throughout the ehci-hcd.c.
> > 
> > The first patch adds check for -EAGAIN return value to the usb
> > keyboard driver. The driver will skip keyboard poll upon getting
> > this error value from either usb_submit_int_msg() or
> > usb_get_report() functions.
> > 
> > Peter Mamonov (2):
> > 	input: usb_kbd: skip poll on -EAGAIN error
> > 	usb: core: return -EAGAIN on usb_* functions reentrance
> 
> Applied on -next. I believe we no longer need mdelay_non_interruptible
> in the ehci-hcd driver, right? Also we don't have to detect
> re-entrancy in the ehci driver anymore. I have applied some patches
> removing that to -next. Could you check the result?

Yes.
Yes.
I've tested the current "next" branch - the usb stuff works fine.

> 
> Sascha
> 
> 


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-10-15 12:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-14 10:15 [PATCH 0/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
2015-10-14 10:15 ` [PATCH 1/2] input: usb_kbd: skip poll on -EAGAIN error Peter Mamonov
2015-10-14 10:15 ` [PATCH 2/2] usb: core: return -EAGAIN on usb_* functions reentrance Peter Mamonov
2015-10-14 14:09 ` [PATCH 0/2] " Sascha Hauer
2015-10-15 12:38   ` Peter Mamonov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox