[PATCH v3 00/19] Equivalent of g_mass_storage with configfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

- simpified 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

A branch will be available here since 31st July:
git://git.infradead.org/users/kmpark/linux-samsung usb-gadget-configfs

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 (19):
  usb/gadget: configfs: add a method to unregister the gadget
  usb/gadget: create a utility module for mass_storage
  usb/gadget: f_mass_storage: factor out a header file
  usb/gadget: f_mass_storage: add a level of indirection for luns
    storage
  usb/gadget: f_mass_storage: use usb_gstrings_attach
  usb/gadget: f_mass_storage: split fsg_common initialization into a
    number of functions
  usb/gadget: f_mass_storage: use fsg_common_setup in fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_set_num_buffers in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_set_nluns in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_set_ops/_private_data in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_set_cdev in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_create_luns in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_set_inquiry_string in
    fsg_common_init
  usb/gadget: f_mass_storage: use fsg_common_run_thread 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                         |   21 +
 drivers/usb/gadget/Makefile                        |    4 +
 drivers/usb/gadget/acm_ms.c                        |   18 +-
 drivers/usb/gadget/configfs.c                      |    8 +
 drivers/usb/gadget/configfs.h                      |    6 +
 drivers/usb/gadget/f_mass_storage.c                | 1371 +++++++++++++++-----
 drivers/usb/gadget/f_mass_storage.h                |  183 +++
 drivers/usb/gadget/mass_storage.c                  |  125 ++-
 drivers/usb/gadget/multi.c                         |   18 +-
 drivers/usb/gadget/storage_common.c                |  385 ++----
 drivers/usb/gadget/storage_common.h                |  228 ++++
 12 files changed, 1784 insertions(+), 614 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-mass-storage
 create mode 100644 drivers/usb/gadget/configfs.h
 create mode 100644 drivers/usb/gadget/f_mass_storage.h
 create mode 100644 drivers/usb/gadget/storage_common.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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux