Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Peter Korsgaard and committed by
Greg Kroah-Hartman
43a02972 2d2a3349

+38 -2
+10 -2
Documentation/ABI/testing/configfs-usb-gadget-ffs
··· 4 4 Description: The purpose of this directory is to create and remove it. 5 5 6 6 A corresponding USB function instance is created/removed. 7 - There are no attributes here. 8 7 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.
+8
Documentation/usb/gadget-testing.rst
··· 206 206 process which implements the function proper). The gadget should be enabled 207 207 by writing a suitable string to usb_gadget/<gadget>/UDC. 208 208 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 + 209 217 Testing the FFS function 210 218 ------------------------ 211 219
+20
drivers/usb/gadget/function/f_fs.c
··· 3445 3445 func_inst.group); 3446 3446 } 3447 3447 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 + 3448 3467 static void ffs_attr_release(struct config_item *item) 3449 3468 { 3450 3469 struct f_fs_opts *opts = to_ffs_opts(item); ··· 3477 3458 3478 3459 static const struct config_item_type ffs_func_type = { 3479 3460 .ct_item_ops = &ffs_item_ops, 3461 + .ct_attrs = ffs_attrs, 3480 3462 .ct_owner = THIS_MODULE, 3481 3463 }; 3482 3464