[PATCH v2 00/25] usb: gadget: f_tcm: Enhance UASP driver

Thinh Nguyen
2022-07-19T02:19:17Z

The Linux UASP gadget driver is incomplete and remained broken for a long time.
It was not implemented for performance either. This series adds some of the
required features for the UASP driver to work. It also makes some changes to
the target core.

This is tested against UASP CV and DWC_usb3x controller. It still needs some
fixes in the target core, which will be separated from this series.

There are still more room for performance improvement and fixes. However, this
series should be sufficient to bring up a working UASP device.

Changes in v2:
- Remove most target core changes from this series and only keep the must-have
ones
- Split the task-management patch to smaller patches
- Don't send failure Task Management response to target core, reducing
dependency
- Add UASP bringup script example in cover page
- Make various small updates according to feedbacks

Example script
==============
To test UASP, here's an example perl script snippet to bring it up.

Note: the script was cut down and quickly rewritten, so sorry if I make
mistakes. :)

my $MY_UAS_VID = xxxx;
my $MY_UAS_PID = yyyy;
my $SERIAL = "1234";
my $VENDOR = "VENDOR";
my $MY_VER = "VER";

my $vendor_id = "my_vid";
my $product_id = "my_pid";
my $revision = "my_rev";

# Must update:
my $backing_storage = "/tmp/some_file";
my $backing_storage_size = 1024*1024*16;
my $use_ramdisk = 0;

my $g = "/sys/kernel/config/usb_gadget/g1";

system("modprobe libcomposite");
system("modprobe usb_f_tcm");
system("mkdir -p $g");
system("mkdir -p $g/configs/c.1");
system("mkdir -p $g/functions/tcm.0");
system("mkdir -p $g/strings/0x409");
system("mkdir -p $g/configs/c.1/strings/0x409");

my $tp = "/sys/kernel/config/target/usb_gadget/naa.0/tpgt_1";

my $tf;
my $ctrl;

if ($use_ramdisk) {
$tf = "/sys/kernel/config/target/core/rd_mcp_0/ramdisk";
$ctrl = 'rd_pages=524288';
} else {
$tf = "/sys/kernel/config/target/core/fileio_0/fileio";
$ctrl = 'fd_dev_name=$backing_storage,fd_dev_size=$backing_storage_size,fd_async_io=1';
}

system("mkdir -p /etc/target");

system("mkdir -p $tp");
system("mkdir -p $tf");
system("mkdir -p $tp/lun/lun_0");

system("echo naa.0 > $tp/nexus");
system("echo $ctrl > $tf/control");
system("echo 1 > $tf/attrib/emulate_ua_intlck_ctrl");
system("echo 123 > $tf/wwn/vpd_unit_serial");
system("echo $vendor_id > $tf/wwn/vendor_id");
system("echo $product_id > $tf/wwn/product_id");
system("echo $revision > $tf/wwn/revision");
system("echo 1 > $tf/enable");

system("ln -s $tf $tp/lun/lun_0/virtual_scsi_port");
system("echo 1 > $tp/enable");

system("echo $MY_UAS_PID > $g/idProduct");

system("ln -s $g/functions/tcm.0 $g/configs/c.1");

system("echo $MY_UAS_VID > $g/idVendor");
system("echo $SERIAL > $g/strings/0x409/serialnumber");
system("echo $VENDOR > $g/strings/0x409/manufacturer");
system("echo \"$MY_VER\" > $g/strings/0x409/product");
system("echo \"Conf 1\" > $g/configs/c.1/strings/0x409/configuration");

system("echo super-speed-plus > $g/max_speed");

# Make sure the UDC is available
system("echo $my_udc > $g/UDC");

Thinh Nguyen (25):
target: Add overlapped response to tmrsp_table
target: Add common TMR enum
usb: gadget: f_tcm: Increase stream count
usb: gadget: f_tcm: Increase bMaxBurst
usb: gadget: f_tcm: Don't set static stream_id
usb: gadget: f_tcm: Allocate matching number of commands to streams
usb: gadget: f_tcm: Limit number of sessions
usb: gadget: f_tcm: Handle multiple commands in parallel
usb: gadget: f_tcm: Use extra number of commands
usb: gadget: f_tcm: Return ATA cmd direction
usb: gadget: f_tcm: Execute command on write completion
usb: gadget: f_tcm: Minor cleanup redundant code
usb: gadget: f_tcm: Don't free command immediately
usb: gadget: f_tcm: Translate error to sense
usb: gadget: f_tcm: Cleanup unused variable
usb: gadget: f_tcm: Update state on data write
usb: gadget: f_tcm: Handle abort command
usb: gadget: f_tcm: Cleanup requests on ep disable
usb: gadget: f_tcm: Decrement command ref count on cleanup
usb: gadget: f_tcm: Save CPU ID per command
usb: gadget: f_tcm: Get stream by tag
usb: gadget: f_tcm: Send sense on cancelled transfer
usb: gadget: f_tcm: Handle TASK_MANAGEMENT commands
usb: gadget: f_tcm: Check overlapped command
usb: gadget: f_tcm: Comply with UAS Task Management requirement

drivers/target/target_core_transport.c | 10 +
drivers/usb/gadget/function/f_tcm.c | 536 +++++++++++++++++++------
drivers/usb/gadget/function/tcm.h | 20 +-
include/target/target_core_base.h | 5 +
4 files changed, 436 insertions(+), 135 deletions(-)

base-commit: 88a15fbb47db483d06b12b1ae69f114b96361a96
--
2.28.0