Skip to content

Commit 43a0297

Browse files
jacmetgregkh
authored andcommitted
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. Signed-off-by: Peter Korsgaard <peter@korsgaard.com> Link: https://lore.kernel.org/r/20240126203208.2482573-1-peter@korsgaard.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2d2a334 commit 43a0297

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Documentation/ABI/testing/configfs-usb-gadget-ffs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ KernelVersion: 3.13
44
Description: The purpose of this directory is to create and remove it.
55

66
A corresponding USB function instance is created/removed.
7-
There are no attributes here.
87

9-
All parameters are set through FunctionFS.
8+
All attributes are read only:
9+
10+
============= ============================================
11+
ready 1 if the function is ready to be used, E.G.
12+
if userspace has written descriptors and
13+
strings to ep0, so the gadget can be
14+
enabled - 0 otherwise.
15+
============= ============================================
16+
17+
All other parameters are set through FunctionFS.

Documentation/usb/gadget-testing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,14 @@ the standard procedure for using FunctionFS (mount it, run the userspace
206206
process which implements the function proper). The gadget should be enabled
207207
by writing a suitable string to usb_gadget/<gadget>/UDC.
208208

209+
The FFS function provides just one attribute in its function directory:
210+
211+
ready
212+
213+
The attribute is read-only and signals if the function is ready (1) to be
214+
used, E.G. if userspace has written descriptors and strings to ep0, so
215+
the gadget can be enabled.
216+
209217
Testing the FFS function
210218
------------------------
211219

drivers/usb/gadget/function/f_fs.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,25 @@ static inline struct f_fs_opts *to_ffs_opts(struct config_item *item)
34453445
func_inst.group);
34463446
}
34473447

3448+
static ssize_t f_fs_opts_ready_show(struct config_item *item, char *page)
3449+
{
3450+
struct f_fs_opts *opts = to_ffs_opts(item);
3451+
int ready;
3452+
3453+
ffs_dev_lock();
3454+
ready = opts->dev->desc_ready;
3455+
ffs_dev_unlock();
3456+
3457+
return sprintf(page, "%d\n", ready);
3458+
}
3459+
3460+
CONFIGFS_ATTR_RO(f_fs_opts_, ready);
3461+
3462+
static struct configfs_attribute *ffs_attrs[] = {
3463+
&f_fs_opts_attr_ready,
3464+
NULL,
3465+
};
3466+
34483467
static void ffs_attr_release(struct config_item *item)
34493468
{
34503469
struct f_fs_opts *opts = to_ffs_opts(item);
@@ -3458,6 +3477,7 @@ static struct configfs_item_operations ffs_item_ops = {
34583477

34593478
static const struct config_item_type ffs_func_type = {
34603479
.ct_item_ops = &ffs_item_ops,
3480+
.ct_attrs = ffs_attrs,
34613481
.ct_owner = THIS_MODULE,
34623482
};
34633483

0 commit comments

Comments
 (0)