Skip to contentSkip to conversation

usb: gadget: f_fs: expose ready state in configfs

PATCH Superseded Peter Korsgaard 2 participants 3 messages Jan 18, 2024 USB

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: f_fs: expose ready state in configfs

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.

---
 drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/usb/gadget/function/f_fs.c +15 -0
index fdd0fc7b8f25..ae44dd5f3a94 100644
@@ -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,
 };
 
Signature · 1 line
2.39.2
#1 lore raw
Quoted 25 lines · 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.

---
 drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/usb/gadget/function/f_fs.c +3 -0
index fdd0fc7b8f25..ae44dd5f3a94 100644
@@ -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);

drivers/usb/gadget/function/f_fs.c static inline struct f_fs_opts *to_ffs_opts(struct config_item *item) · line 3461

Quoted 10 lines
drivers/usb/gadget/function/f_fs.c +10 -0
+
+	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

#2 lore raw
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Greg" == Greg Kroah-Hartman <[email protected]> writes:

Quoted 22 lines · 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.

---
drivers/usb/gadget/function/f_fs.c | 15 +++++++++++++++

1 file changed, 15 insertions(+)
drivers/usb/gadget/function/f_fs.c +0 -0
index fdd0fc7b8f25..ae44dd5f3a94 100644
@@ -3446,6 +3446,20 @@ static inline struct f_fs_opts *to_ffs_opts(struct config_item *item)
 func_inst.group);
 }
 
Quoted 15 lines

drivers/usb/gadget/function/f_fs.c static inline struct f_fs_opts *to_ffs_opts(struct config_item *item) · line 3461

Quoted 13 lines
drivers/usb/gadget/function/f_fs.c +13 -0
+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.

Signature · 1 line
Bye, Peter Korsgaard