This series aims at integrating configfs into FunctionFS, the way it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet and mass_storage. It contains everything that is required to provide the equivalent of g_ffs.ko with configfs. Configfs support in FunctionFS has been awaited by the Android folks as discussed during the LPC 2013. Apart from that a VLAIS (variable length array in a struct) patch is added. It is not strictly necessary, but it won't hurt and it will make the Clang people happy. FunctionFS is more complicated than most other USB functions, so the resulting patch series is a bit long. Howerver, it is supposed to do things in steps. 1) preliminary work: extend generic configfs support in USB gadget, convert g_ffs to new function interfaces of f_ecm, f_subset, f_rndis; g_ffs is the last user of the old interfaces so remove compatibility layers 2) factoring out a u_fs.h header and finally making f_fs a separate module with both old and new function interface 3) converting all users of f_fs (in fact only g_ffs) to the new interface and remove compatiblilty layer 4) add configfs support v4..v5: - don't take ffs_lock explicitly in g_ffs - simplify gfs_init, bugfix not decrementing the "i" in error recovery v3..v4: - small fixes after Michal's review, thank you, Michal! - export ffs_lock instead of ffs_dev_lock and ffs_dev_unlock, which are now static inline - improved ffs_find_dev, ffs_alloc_dev by introducing ffs_get_single_dev() - rearranged kfree invocations in ffs_free_dev - eliminated goto in ffs_acquire_dev - used explicit decrementation in gfs_init - removed some add/remove empty line hunks v2..v3: - a number of fixes regarding systems with multiple udcs, e.g. systems, where more than one gadget can be loaded at a time - cleanup of ffs devices handling: since they need to be registered by both g_ffs and configfs-based gadget, they need to be managed in one place; instead of static callbacks in f_fs.c now each device can have its own set of callbacks - callbacks are used by the g_ffs, while configfs-based gadget is happy with generic ffs_acquire/release_dev(), ffs_ready/closed() - functionfs_init() and functionfs_cleanup() now called when the first device is created and when the last is removed, respectively - removed gfs_lock from g_ffs in favor of a lock in f_fs.c protecting the devices list - thanks to all the above the ffs_alloc_inst() is greatly simplified compared to v2 - simplified the way how usb_f_fs user's (g_ffs's) refcount is maintained (no ffs_owner static in f_fs.c) - some of patches 12..16 used to contain Michal's Acked-by, but since there have been (relatively) many changes to those patches, I removed the Acked-by lines v1..v2: - fixes after Michal's review, thank you, Michal! - removal of unnecessary hunks, simplified VLAIS replacement code, used proper pointer dereferencing, simplified ffs_do_functionfs_bind(), ffs_alloc_inst() and ffs_free(), style corrections, allocated usb_function structures in one chunk for all configs in g_ffs Rebased onto Felipe's master. BACKWARD COMPATIBILITY ====================== Please note that the old g_ffs.ko is still available and works. USING THE NEW "GADGET" ====================== Please refer to this post: http://www.spinics.net/lists/linux-usb/msg76388.html for general information from Sebastian on how to use configfs-based gadgets (*). With configfs the procedure is as follows, compared to the information mentioned above (*): instead of mkdir functions/acm.ttyS1 do mkdir functions/ffs.<instance name> e.g. mkdir functions/ffs.ptp In functions/<function>.<instance name> there will be no attribute files at all, because all parameters are passed with FunctionFS. An example gadget with adb and ptp functions: (I assume there are ptpd and adbd daemons using FunctionFS available, a proof-of-concept adbd can be found here: https://android-review.googlesource.com/#/c/31640/, an early version of ptp which I used is here: http://www.spinics.net/lists/linux-usb/msg41963.html) $ modprobe libcomposite $ mount none cfg -t configfs $ mkdir cfg/usb_gadget/g1 $ cd cfg/usb_gadget/g1 $ mkdir configs/c.1 $ mkdir functions/ffs.adb $ mkdir functions/ffs.ptp $ mkdir strings/0x409 $ mkdir configs/c.1/strings/0x409 $ echo 0x2d01 > idProduct $ echo 0x04e8 > idVendor $ echo my-serial-num > strings/0x409/serialnumber $ echo my-manufacturer > strings/0x409/manufacturer $ echo "FunctionFS gadget (ptp, adb)" > strings/0x409/product $ echo "Conf 1" > configs/c.1/strings/0x409/configuration $ echo 120 > configs/c.1/MaxPower $ ln -s functions/ffs.ptp configs/c.1 $ ln -s functions/ffs.adb configs/c.1 $ mkdir /dev/usbffs $ mount ptp /dev/usbffs -t functionfs $ ptpd $ mkdir -p /dev/usbgadget/adb $ mount -t functionfs adb /dev/usbgadget/adb -o uid=2000,gid=2000 $ adbd $ echo s3c-hsotg > cfg/usb_gadget/g1/UDC After unbinding the gadget with echo "" > UDC the symbolic links in the configuration directory can be removed, the strings/* subdirectories in the configuration directory can be removed, the strings/* subdirectories at the gadget level can be removed and the configs/* subdirectories can be removed. The functions/* subdirectories can be removed. After that the gadget directory can be removed. FunctionFS instances should be unmounted, daemons need to be closed and then the respective modules can be unloaded. TESTING THE FUNCTIONS (actually there is only one) ===================== FunctionFS) device: connect the gadget, enable it host: mount the ptp device, adb shell Andrzej Pietrasiewicz (16): usb/gadget: configfs: allow setting function instance's name usb/gadget: g_ffs: remove a reduntant gfs_ether_setup variable usb/gadget: g_ffs: convert to new interface of f_ecm usb/gadget: f_ecm: remove compatibility layer usb/gadget: g_ffs: convert to new interface of f_subset usb/gadget: f_subset: remove compatibility layer usb/gadget: g_ffs: convert to new interface of f_rndis usb/gadget: f_rndis: remove compatibility layer usb/gadget: rndis: merge u_rndis.ko with usb_f_rndis.ko usb/gadget: FunctionFS: Remove VLAIS usage from gadget code usb/gadget: FunctionFS: create utility file usb/gadget: FunctionFS: add devices management code usb/gadget: FunctionFS: convert to new function interface with backward compatibility usb/gadget: g_ffs: convert to new interface of f_fs usb/gadget: FunctionFS: Remove compatibility layer usb/gadget: FunctionFS: add configfs support Documentation/ABI/testing/configfs-usb-gadget-ffs | 9 + drivers/usb/gadget/Kconfig | 26 +- drivers/usb/gadget/Makefile | 6 +- drivers/usb/gadget/configfs.c | 7 + drivers/usb/gadget/f_ecm.c | 73 +-- drivers/usb/gadget/f_fs.c | 897 +++++++++++++-------- drivers/usb/gadget/f_rndis.c | 94 +-- drivers/usb/gadget/f_subset.c | 60 +-- drivers/usb/gadget/g_ffs.c | 466 +++++++----- drivers/usb/gadget/rndis.c | 7 +- drivers/usb/gadget/u_ether.h | 41 - drivers/usb/gadget/u_fs.h | 269 ++++++ drivers/usb/gadget/u_rndis.h | 2 + include/linux/usb/composite.h | 2 + include/linux/usb/functionfs.h | 30 - 15 files changed, 1177 insertions(+), 812 deletions(-) create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-ffs create mode 100644 drivers/usb/gadget/u_fs.h -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html