linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_fs: expose ready state in configfs
@ 2024-01-18 12:18 Peter Korsgaard
  2024-01-18 12:28 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Korsgaard @ 2024-01-18 12:18 UTC (permalink / raw)
  To: linux-usb, Greg Kroah-Hartman, Michal Nazarewicz; +Cc: Peter Korsgaard

When a USB gadget is configured through configfs with 1 or more f_fs
functions, then the logic setting up the gadget configuration has to wait
until the user space code (typically separate applications) responsible for
those functions have written their descriptors before the gadget can be
activated.

The f_fs instance already knows if this has been done, so expose it through
a "ready" attribute in configfs for easier synchronization.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
---
 drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
index fdd0fc7b8f25..ae44dd5f3a94 100644
--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -3446,6 +3446,20 @@ static inline struct f_fs_opts *to_ffs_opts(struct config_item *item)
 			    func_inst.group);
 }
 
+static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page)
+{
+	struct f_fs_opts *opts = to_ffs_opts(item);
+
+	return sprintf(page, "%d\n", opts->dev->desc_ready);
+}
+
+CONFIGFS_ATTR_RO(f_fs_opts_, ready);
+
+static struct configfs_attribute *ffs_attrs[] = {
+	&f_fs_opts_attr_ready,
+	NULL,
+};
+
 static void ffs_attr_release(struct config_item *item)
 {
 	struct f_fs_opts *opts = to_ffs_opts(item);
@@ -3459,6 +3473,7 @@ static struct configfs_item_operations ffs_item_ops = {
 
 static const struct config_item_type ffs_func_type = {
 	.ct_item_ops	= &ffs_item_ops,
+	.ct_attrs	= ffs_attrs,
 	.ct_owner	= THIS_MODULE,
 };
 
-- 
2.39.2


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

* Re: [PATCH] usb: gadget: f_fs: expose ready state in configfs
  2024-01-18 12:18 [PATCH] usb: gadget: f_fs: expose ready state in configfs Peter Korsgaard
@ 2024-01-18 12:28 ` Greg Kroah-Hartman
  2024-01-18 12:43   ` Peter Korsgaard
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2024-01-18 12:28 UTC (permalink / raw)
  To: Peter Korsgaard; +Cc: linux-usb, Michal Nazarewicz

On Thu, Jan 18, 2024 at 01:18:16PM +0100, Peter Korsgaard wrote:
> When a USB gadget is configured through configfs with 1 or more f_fs
> functions, then the logic setting up the gadget configuration has to wait
> until the user space code (typically separate applications) responsible for
> those functions have written their descriptors before the gadget can be
> activated.
> 
> The f_fs instance already knows if this has been done, so expose it through
> a "ready" attribute in configfs for easier synchronization.
> 
> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
> ---
>  drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
> 
> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
> index fdd0fc7b8f25..ae44dd5f3a94 100644
> --- a/drivers/usb/gadget/function/f_fs.c
> +++ b/drivers/usb/gadget/function/f_fs.c
> @@ -3446,6 +3446,20 @@ static inline struct f_fs_opts *to_ffs_opts(struct config_item *item)
>  			    func_inst.group);
>  }
>  
> +static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page)
> +{
> +	struct f_fs_opts *opts = to_ffs_opts(item);
> +
> +	return sprintf(page, "%d\n", opts->dev->desc_ready);
> +}
> +
> +CONFIGFS_ATTR_RO(f_fs_opts_, ready);
> +
> +static struct configfs_attribute *ffs_attrs[] = {
> +	&f_fs_opts_attr_ready,
> +	NULL,
> +};

No documentation entry for this new attribute?

thanks,

greg k-h

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

* Re: [PATCH] usb: gadget: f_fs: expose ready state in configfs
  2024-01-18 12:28 ` Greg Kroah-Hartman
@ 2024-01-18 12:43   ` Peter Korsgaard
  0 siblings, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2024-01-18 12:43 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Michal Nazarewicz

>>>>> "Greg" == Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

 > On Thu, Jan 18, 2024 at 01:18:16PM +0100, Peter Korsgaard wrote:
 >> When a USB gadget is configured through configfs with 1 or more f_fs
 >> functions, then the logic setting up the gadget configuration has to wait
 >> until the user space code (typically separate applications) responsible for
 >> those functions have written their descriptors before the gadget can be
 >> activated.
 >> 
 >> The f_fs instance already knows if this has been done, so expose it through
 >> a "ready" attribute in configfs for easier synchronization.
 >> 
 >> Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
 >> ---
 >> drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++
 >> 1 file changed, 15 insertions(+)
 >> 
 >> diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/function/f_fs.c
 >> index fdd0fc7b8f25..ae44dd5f3a94 100644
 >> --- a/drivers/usb/gadget/function/f_fs.c
 >> +++ b/drivers/usb/gadget/function/f_fs.c
 >> @@ -3446,6 +3446,20 @@ static inline struct f_fs_opts *to_ffs_opts(struct config_item *item)
 >> func_inst.group);
 >> }
 >> 
 >> +static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page)
 >> +{
 >> +	struct f_fs_opts *opts = to_ffs_opts(item);
 >> +
 >> +	return sprintf(page, "%d\n", opts->dev->desc_ready);
 >> +}
 >> +
 >> +CONFIGFS_ATTR_RO(f_fs_opts_, ready);
 >> +
 >> +static struct configfs_attribute *ffs_attrs[] = {
 >> +	&f_fs_opts_attr_ready,
 >> +	NULL,
 >> +};

 > No documentation entry for this new attribute?

Ups, I'll add a snippet to Documentation/usb/gadget-testing.rst and send
a v2.

-- 
Bye, Peter Korsgaard

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

end of thread, other threads:[~2024-01-18 12:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-18 12:18 [PATCH] usb: gadget: f_fs: expose ready state in configfs Peter Korsgaard
2024-01-18 12:28 ` Greg Kroah-Hartman
2024-01-18 12:43   ` Peter Korsgaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).