This series aims at integrating configfs into mass storage, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex and phonet.
It contains everything that is required to provide the equivalent of
g_mass_storage.ko with configfs.

Mass storage itself is quite large, so the resulting patch series is a bit
lengthy. However, it is supposed to be done in steps like this:

1) preliminary work, e.g. factoring out a header file, creating a utility
u_ms.ko module, use usb_gstrings_attach
2) prepare for initializing the fsg_common structure in smaller steps instead
of in one big step
3) usual stuff, similar to functions previously converted to configfs

v1..v2:

- simplified adding a level of indirection for fsg_lun storing
- reworked lun debugging macros in order not to use struct device
[both after discussion with Alan, thanks]

v2..v3:

- implemented changes resulting from Michal's comments [thanks, Michal]
- used static inline fsg_common_remove_sysfs wherever possible
- some small bugfixes

v3..v4:

-rebased onto 3.12-rc1

v4..v5:

- rebased onto Felipe's "testing" (3.12-rc3)
- the same code as in v4, just distributed over patches in such a way that
there are no compiler warnings

v5..v6:

- changes after Michal's review (thanks, Michal!):
- removed redundant "if (likely(common->buffhds))" in fsg_common_release()
- simplified device_remove_file() invocations based on the fact that all they
need is a file name which is the same for e.g. lun->cdrom and !lun->cdrom
- not allocating a buffer for struct fsg_lun->name; just used a pointer to a
buffer which is supposed to live longer than any references to fsg_lun->name
- in fsg_common_setup() the "zero" argument is not introduced in anticipation
of a future use; instead it is added when it is first needed (patch 10/14)
- fixed some style issues in fsg_common_set_num_buffers(), simplified error
recovery path based on the fact that kfree() is a no-op for NULL
- staticized _fsg_common_remove_luns()
- removed fsg_common_set_private_data() since it is a one-liner
- fsg_common_set_ops() definition is delayed until it is needed (patch 11/14)
- simplified error recovery in fsg_common_set_cdev() if usb_gstrings_attach()
fails
- returning early from fsg_common_create_lun() in case the lun is not removable
and no filename is given for its backing file
- unindented a block by moving a variable definition to the top of the
fsg_common_create_lun()
- reduced the buffer size for creating lun names to 8 bytes
- reduced the number of preprocessor #ifndefs and #endifs by introducing
a temporary macro EXPORT_SYMBOL_GPL_IF_MODULE() (to be removed together with the
compatibility layer)
- renamed ret to rc in fsg_alloc_inst()
- ifdef'ed a part of fsg_unbind() instead of introducing its old_fsg_unbind()
counterpart
- used tabs consistently in fsg_alloc()
- added fsg_opts_from_func_inst() to avoid repeated container_of() invocations

A branch 'usb-gadget-configfs-3.12' is available at:
git://git.linaro.org/people/mszyprowski/linux-srpol.git

BACKWARD COMPATIBILITY
======================

Please note that the old g_mass_storage.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/<mass_storage>.<instance name>

e.g. mkdir functions/mass_storage.0

In functions/<function>.<instance name> there will be the following attribute
files:

        stall           - Set to permit function to halt bulk endpoints.
                        Disabled on some USB devices known not to work
                        correctly. You should set it to true.
        num_buffers     - Number of pipeline buffers. Valid numbers
                        are 2..4. Available only if
                        CONFIG_USB_GADGET_DEBUG_FILES is set.

and a default lun.0 directory corresponding to SCSI LUN #0.

A new lun can be added with mkdir:

$ mkdir functions/mass_storage.0/partition.5

Lun numbering does not have to be continuous, except for lun #0 which is
created by default. A maximum of 8 luns can be specified and they all must be
named following the <name>.<number> scheme. The numbers can be 0..8.
Probably a good convention is to name the luns "lun.<number>",
although it is not mandatory.

In each lun directory there are the following attribute files:

        file            - The path to the backing file for the LUN.
                        Required if LUN is not marked as removable.
        ro              - Flag specifying access to the LUN shall be
                        read-only. This is implied if CD-ROM emulation
                        is enabled as well as when it was impossible
                        to open "filename" in R/W mode.
        removable       - Flag specifying that LUN shall be indicated as
                        being removable.
        cdrom           - Flag specifying that LUN shall be reported as
                        being a CD-ROM.
        nofua           - Flag specifying that FUA flag
                        in SCSI WRITE(10,12)

The rest of the procedure (*) remains the same.

An example gadget with two luns:

$ modprobe libcomposite
 
$ mount none cfg -t configfs
 
$ mkdir cfg/usb_gadget/g1
$ cd cfg/usb_gadget/g1
 
$ mkdir configs/c.1
$ mkdir functions/mass_storage.0
$ echo /root/lun0.img > functions/mass_storage.0/lun.0/file
$ mkdir functions/mass_storage.0/lun.1
$ echo /root/lun1.img > functions/mass_storage.0/lun.1/file
$ mkdir strings/0x409
$ mkdir configs/c.1/strings/0x409
 
$ echo 0xa4a2 > idProduct
$ echo 0x0525 > idVendor
$ echo my-serial-num > strings/0x409/serialnumber
$ echo my-manufacturer > strings/0x409/manufacturer
$ echo "Mass Storage Gadget" > strings/0x409/product
 
$ echo "Conf 1" > configs/c.1/strings/0x409/configuration
$ echo 120 > configs/c.1/MaxPower
$ ln -s functions/mass_storage.0 configs/c.1
 
$ echo s3c-hsotg > 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.
After that the respective modules can be unloaded.


TESTING THE FUNCTIONS (actually there is only one)
=====================

mass_storage)

device: connect the gadget, enable it
host: dmesg, see the USB drives appear (if system configured to automatically
mount)




Andrzej Pietrasiewicz (14):
  usb/gadget: f_mass_storage: create _fsg_common_free_buffers
  usb/gadget: f_mass_storage: make sysfs interface optional
  usb/gadget: f_mass_storage: create fsg_common_setup for use in
    fsg_common_init
  usb/gadget: f_mass_storage: create fsg_common_set_num_buffers for use
    in fsg_common_init
  usb/gadget: f_mass_storage: create lun handling helpers for use in
    fsg_common_init
  usb/gadget: f_mass_storage: create fsg_common_set_cdev for use in
    fsg_common_init
  usb/gadget: f_mass_storage: create lun creation helpers for use in
    fsg_common_init
  usb/gadget: f_mass_storage: create fsg_common_set_inquiry_string for
    use in fsg_common_init
  usb/gadget: f_mass_storage: create fsg_common_run_thread for use in
    fsg_common_init
  usb/gadget: f_mass_storage: convert to new function interface with
    backward compatibility
  usb/gadget: mass_storage: convert to new interface of f_mass_storage
  usb/gadget: storage_common: make attribute operations more generic
  usb/gadget: storage_common: add methods to show/store 'cdrom' and
    'removable'
  usb/gadget: f_mass_storage: add configfs support

 .../ABI/testing/configfs-usb-gadget-mass-storage   |   31 +
 drivers/usb/gadget/Kconfig                         |   15 +
 drivers/usb/gadget/Makefile                        |    2 +
 drivers/usb/gadget/acm_ms.c                        |    1 +
 drivers/usb/gadget/f_mass_storage.c                | 1116 ++++++++++++++++----
 drivers/usb/gadget/f_mass_storage.h                |   61 ++
 drivers/usb/gadget/mass_storage.c                  |  106 ++-
 drivers/usb/gadget/multi.c                         |    1 +
 drivers/usb/gadget/storage_common.c                |   73 +-
 drivers/usb/gadget/storage_common.h                |   46 +-
 10 files changed, 1183 insertions(+), 269 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-mass-storage

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to