public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: ffs: add eventfd notification about ffs events
@ 2015-01-23  9:28 Robert Baldyga
       [not found] ` <CA+pa1O0nZJ6G1NpPF+qHvchnfSuCvi-f0KMROkOkVq6pNkMX3Q@mail.gmail.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Baldyga @ 2015-01-23  9:28 UTC (permalink / raw)
  To: balbi; +Cc: gregkh, mina86, linux-usb, linux-kernel, k.opasiak,
	Robert Baldyga

Add eventfd which notifies userspace about ep0 events and AIO completion
events. It simplifies using of FunctionFS with event loop, because now
we need to poll on single file (instead of polling on ep0 and eventfd's
supplied to AIO layer).

FunctionFS eventfd is not triggered if another eventfd is supplied to
AIO layer (in AIO request). It can be useful, for example, when we want
to handle AIO transations for chosen endpoint in separate thread.

Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
 drivers/usb/gadget/function/f_fs.c  | 29 ++++++++++++++++++++++++++++-
 drivers/usb/gadget/function/u_fs.h  |  1 +
 include/uapi/linux/usb/functionfs.h |  1 +
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index e78a2c6..dc7f816 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -31,6 +31,7 @@
 #include <linux/aio.h>
 #include <linux/mmu_context.h>
 #include <linux/poll.h>
+#include <linux/eventfd.h>
 
 #include "u_fs.h"
 #include "u_f.h"
@@ -153,6 +154,8 @@ struct ffs_io_data {
 
 	struct usb_ep *ep;
 	struct usb_request *req;
+
+	struct ffs_data *ffs;
 };
 
 struct ffs_desc_helper {
@@ -674,6 +677,9 @@ static void ffs_user_copy_worker(struct work_struct *work)
 
 	aio_complete(io_data->kiocb, ret, ret);
 
+	if (io_data->ffs->ffs_eventfd && !io_data->kiocb->ki_eventfd)
+		eventfd_signal(io_data->ffs->ffs_eventfd, 1);
+
 	usb_ep_free_request(io_data->ep, io_data->req);
 
 	io_data->kiocb->private = NULL;
@@ -827,6 +833,7 @@ static ssize_t ffs_epfile_io(struct file *file, struct ffs_io_data *io_data)
 			io_data->buf = data;
 			io_data->ep = ep->ep;
 			io_data->req = req;
+			io_data->ffs = epfile->ffs;
 
 			req->context  = io_data;
 			req->complete = ffs_epfile_async_io_complete;
@@ -1510,6 +1517,9 @@ static void ffs_data_clear(struct ffs_data *ffs)
 	if (ffs->epfiles)
 		ffs_epfiles_destroy(ffs->epfiles, ffs->eps_count);
 
+	if (ffs->ffs_eventfd)
+		eventfd_ctx_put(ffs->ffs_eventfd);
+
 	kfree(ffs->raw_descs_data);
 	kfree(ffs->raw_strings);
 	kfree(ffs->stringtabs);
@@ -2169,7 +2179,8 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
 			      FUNCTIONFS_HAS_HS_DESC |
 			      FUNCTIONFS_HAS_SS_DESC |
 			      FUNCTIONFS_HAS_MS_OS_DESC |
-			      FUNCTIONFS_VIRTUAL_ADDR)) {
+			      FUNCTIONFS_VIRTUAL_ADDR |
+			      FUNCTIONFS_EVENTFD)) {
 			ret = -ENOSYS;
 			goto error;
 		}
@@ -2180,6 +2191,20 @@ static int __ffs_data_got_descs(struct ffs_data *ffs,
 		goto error;
 	}
 
+	if (flags & FUNCTIONFS_EVENTFD) {
+		if (len < 4)
+			goto error;
+		ffs->ffs_eventfd =
+			eventfd_ctx_fdget((int)get_unaligned_le32(data));
+		if (IS_ERR(ffs->ffs_eventfd)) {
+			ffs->ffs_eventfd = NULL;
+			ret = PTR_ERR(ffs->ffs_eventfd);
+			goto error;
+		}
+		data += 4;
+		len  -= 4;
+	}
+
 	/* Read fs_count, hs_count and ss_count (if present) */
 	for (i = 0; i < 3; ++i) {
 		if (!(flags & (1 << i))) {
@@ -2454,6 +2479,8 @@ static void __ffs_event_add(struct ffs_data *ffs,
 	pr_vdebug("adding event %d\n", type);
 	ffs->ev.types[ffs->ev.count++] = type;
 	wake_up_locked(&ffs->ev.waitq);
+	if (ffs->ffs_eventfd)
+		eventfd_signal(ffs->ffs_eventfd, 1);
 }
 
 static void ffs_event_add(struct ffs_data *ffs,
diff --git a/drivers/usb/gadget/function/u_fs.h b/drivers/usb/gadget/function/u_fs.h
index 284a1f0..6013985 100644
--- a/drivers/usb/gadget/function/u_fs.h
+++ b/drivers/usb/gadget/function/u_fs.h
@@ -272,6 +272,7 @@ struct ffs_data {
 		kgid_t				gid;
 	}				file_perms;
 
+	struct eventfd_ctx *ffs_eventfd;
 	bool no_disconnect;
 	struct work_struct reset_work;
 
diff --git a/include/uapi/linux/usb/functionfs.h b/include/uapi/linux/usb/functionfs.h
index 295ba29..108dd79 100644
--- a/include/uapi/linux/usb/functionfs.h
+++ b/include/uapi/linux/usb/functionfs.h
@@ -20,6 +20,7 @@ enum functionfs_flags {
 	FUNCTIONFS_HAS_SS_DESC = 4,
 	FUNCTIONFS_HAS_MS_OS_DESC = 8,
 	FUNCTIONFS_VIRTUAL_ADDR = 16,
+	FUNCTIONFS_EVENTFD = 32,
 };
 
 /* Descriptor of an non-audio endpoint */
-- 
1.9.1


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

* Re: [PATCH] usb: gadget: ffs: add eventfd notification about ffs events
       [not found] ` <CA+pa1O0nZJ6G1NpPF+qHvchnfSuCvi-f0KMROkOkVq6pNkMX3Q@mail.gmail.com>
@ 2015-01-23 12:34   ` Robert Baldyga
  2015-01-27 15:25     ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Robert Baldyga @ 2015-01-23 12:34 UTC (permalink / raw)
  To: Michał Nazarewicz
  Cc: Greg Kroah-Hartman, Krzysztof Opasiak, balbi, linux-kernel,
	linux-usb

On 01/23/2015 01:21 PM, Michał Nazarewicz wrote:
> 23 sty 2015 10:28 "Robert Baldyga" <r.baldyga@samsung.com
> <mailto:r.baldyga@samsung.com>> napisał(a):
>> Add eventfd which notifies userspace about ep0 events and AIO completion
>> events. It simplifies using of FunctionFS with event loop, because now
>> we need to poll on single file (instead of polling on ep0 and eventfd's
>> supplied to AIO layer).
>>
>> FunctionFS eventfd is not triggered if another eventfd is supplied to
>> AIO layer (in AIO request). It can be useful, for example, when we want
>> to handle AIO transations for chosen endpoint in separate thread.
>>
>> Signed-off-by: Robert Baldyga
> 
> I don't know much about eventfd interface bit from ffs point of view:
> 
> Acked-by: Michal Nazarewicz <mina86@mina86.com <mailto:mina86@mina86.com>>
> 
>> @@ -2180,6 +2191,20 @@ static int __ffs_data_got_descs(struct ffs_data
> *ffs,
>>                 goto error;
>>         }
>>
>> +       if (flags & FUNCTIONFS_EVENTFD) {
>> +               if (len < 4)
>> +                       goto error;
>> +               ffs->ffs_eventfd =
>> +                       eventfd_ctx_fdget((int)get_unaligned_le32(data));
>> +               if (IS_ERR(ffs->ffs_eventfd)) {
>> +                       ffs->ffs_eventfd = NULL;
>> +                       ret = PTR_ERR(ffs->ffs_eventfd);
> 
> Need to swap those lines.
> 
>> +                       goto error;
>> +               }
>> +               data += 4;
>> +               len  -= 4;
>> +       }
>> +
>>         /* Read fs_count, hs_count and ss_count (if present) */
>>         for (i = 0; i < 3; ++i) {
>>                 if (!(flags & (1 << i))) {
> 

Good catch, thanks!

Best regards,
Robert Baldyga

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

* Re: [PATCH] usb: gadget: ffs: add eventfd notification about ffs events
  2015-01-23 12:34   ` Robert Baldyga
@ 2015-01-27 15:25     ` Felipe Balbi
  2015-01-27 15:26       ` Felipe Balbi
  0 siblings, 1 reply; 4+ messages in thread
From: Felipe Balbi @ 2015-01-27 15:25 UTC (permalink / raw)
  To: Robert Baldyga
  Cc: Michał Nazarewicz, Greg Kroah-Hartman, Krzysztof Opasiak,
	balbi, linux-kernel, linux-usb

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]

On Fri, Jan 23, 2015 at 01:34:45PM +0100, Robert Baldyga wrote:
> On 01/23/2015 01:21 PM, Michał Nazarewicz wrote:
> > 23 sty 2015 10:28 "Robert Baldyga" <r.baldyga@samsung.com
> > <mailto:r.baldyga@samsung.com>> napisał(a):
> >> Add eventfd which notifies userspace about ep0 events and AIO completion
> >> events. It simplifies using of FunctionFS with event loop, because now
> >> we need to poll on single file (instead of polling on ep0 and eventfd's
> >> supplied to AIO layer).
> >>
> >> FunctionFS eventfd is not triggered if another eventfd is supplied to
> >> AIO layer (in AIO request). It can be useful, for example, when we want
> >> to handle AIO transations for chosen endpoint in separate thread.
> >>
> >> Signed-off-by: Robert Baldyga
> > 
> > I don't know much about eventfd interface bit from ffs point of view:
> > 
> > Acked-by: Michal Nazarewicz <mina86@mina86.com <mailto:mina86@mina86.com>>
> > 
> >> @@ -2180,6 +2191,20 @@ static int __ffs_data_got_descs(struct ffs_data
> > *ffs,
> >>                 goto error;
> >>         }
> >>
> >> +       if (flags & FUNCTIONFS_EVENTFD) {
> >> +               if (len < 4)
> >> +                       goto error;
> >> +               ffs->ffs_eventfd =
> >> +                       eventfd_ctx_fdget((int)get_unaligned_le32(data));
> >> +               if (IS_ERR(ffs->ffs_eventfd)) {
> >> +                       ffs->ffs_eventfd = NULL;
> >> +                       ret = PTR_ERR(ffs->ffs_eventfd);
> > 
> > Need to swap those lines.
> > 
> >> +                       goto error;
> >> +               }
> >> +               data += 4;
> >> +               len  -= 4;
> >> +       }
> >> +
> >>         /* Read fs_count, hs_count and ss_count (if present) */
> >>         for (i = 0; i < 3; ++i) {
> >>                 if (!(flags & (1 << i))) {
> > 
> 
> Good catch, thanks!

Are you sending a new version, or should I fix this myself?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

* Re: [PATCH] usb: gadget: ffs: add eventfd notification about ffs events
  2015-01-27 15:25     ` Felipe Balbi
@ 2015-01-27 15:26       ` Felipe Balbi
  0 siblings, 0 replies; 4+ messages in thread
From: Felipe Balbi @ 2015-01-27 15:26 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Robert Baldyga, Michał Nazarewicz, Greg Kroah-Hartman,
	Krzysztof Opasiak, linux-kernel, linux-usb

[-- Attachment #1: Type: text/plain, Size: 2159 bytes --]

On Tue, Jan 27, 2015 at 09:25:30AM -0600, Felipe Balbi wrote:
> On Fri, Jan 23, 2015 at 01:34:45PM +0100, Robert Baldyga wrote:
> > On 01/23/2015 01:21 PM, Michał Nazarewicz wrote:
> > > 23 sty 2015 10:28 "Robert Baldyga" <r.baldyga@samsung.com
> > > <mailto:r.baldyga@samsung.com>> napisał(a):
> > >> Add eventfd which notifies userspace about ep0 events and AIO completion
> > >> events. It simplifies using of FunctionFS with event loop, because now
> > >> we need to poll on single file (instead of polling on ep0 and eventfd's
> > >> supplied to AIO layer).
> > >>
> > >> FunctionFS eventfd is not triggered if another eventfd is supplied to
> > >> AIO layer (in AIO request). It can be useful, for example, when we want
> > >> to handle AIO transations for chosen endpoint in separate thread.
> > >>
> > >> Signed-off-by: Robert Baldyga
> > > 
> > > I don't know much about eventfd interface bit from ffs point of view:
> > > 
> > > Acked-by: Michal Nazarewicz <mina86@mina86.com <mailto:mina86@mina86.com>>
> > > 
> > >> @@ -2180,6 +2191,20 @@ static int __ffs_data_got_descs(struct ffs_data
> > > *ffs,
> > >>                 goto error;
> > >>         }
> > >>
> > >> +       if (flags & FUNCTIONFS_EVENTFD) {
> > >> +               if (len < 4)
> > >> +                       goto error;
> > >> +               ffs->ffs_eventfd =
> > >> +                       eventfd_ctx_fdget((int)get_unaligned_le32(data));
> > >> +               if (IS_ERR(ffs->ffs_eventfd)) {
> > >> +                       ffs->ffs_eventfd = NULL;
> > >> +                       ret = PTR_ERR(ffs->ffs_eventfd);
> > > 
> > > Need to swap those lines.
> > > 
> > >> +                       goto error;
> > >> +               }
> > >> +               data += 4;
> > >> +               len  -= 4;
> > >> +       }
> > >> +
> > >>         /* Read fs_count, hs_count and ss_count (if present) */
> > >>         for (i = 0; i < 3; ++i) {
> > >>                 if (!(flags & (1 << i))) {
> > > 
> > 
> > Good catch, thanks!
> 
> Are you sending a new version, or should I fix this myself?

nevermind, found v2 :)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

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

end of thread, other threads:[~2015-01-27 15:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-23  9:28 [PATCH] usb: gadget: ffs: add eventfd notification about ffs events Robert Baldyga
     [not found] ` <CA+pa1O0nZJ6G1NpPF+qHvchnfSuCvi-f0KMROkOkVq6pNkMX3Q@mail.gmail.com>
2015-01-23 12:34   ` Robert Baldyga
2015-01-27 15:25     ` Felipe Balbi
2015-01-27 15:26       ` Felipe Balbi

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