Re: USB gadget target & targetcli

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

 



Hi Andrzej,

(Adding Sebastian CC')

On Thu, 2015-09-24 at 12:25 +0200, Andrzej Pietrasiewicz wrote:
> Hello All,
> 
> I am trying to set up a tcm_usb_gadget on a board with DWC3 UDC.
> 
> I've downloaded targetcli from
> 
> https://github.com/Datera/targetcli
> 
> built a deb package and installed it.
> 
> I downloaded it instead of installing from distribution package
> to be sure I get the latest version.
> 
> Prior to that I have built and properly deployed tcm_usb_gadget.ko,
> that is copied it to system location /lib/modules/`uname -r` and
> calculated module dependencies with depmod -a.
> 
> When targetcli deb package was installed, a bunch of messages
> appeared, including this:
> 
> [....] Fabric module tcm_usb_gadget is not loaded ... (warning).
> 
> Any idea why is that?

Mmmm.  With the same userspace builds on a Debian based v4.3-rc1 setup,
tcm_usb_gadget is getting loaded automatically:

root@scsi-mq:/usr/src/target-pending.git# /etc/init.d/target start
[ ok ] The Linux SCSI Target is already stopped.
[info] The Linux SCSI Target looks properly installed.
[info] The configfs filesystem is already mounted.
[info] Loaded core module target_core_mod.
[info] Loaded core module target_core_pscsi.
[info] Loaded core module target_core_iblock.
[info] Loaded core module target_core_file.
[info] Loaded fabric module vhost_scsi.
[info] Loaded fabric module tcm_fc.
[info] Loaded fabric module ib_srpt.
[info] Loaded fabric module tcm_qla2xxx.
[info] Loaded fabric module tcm_loop.
[info] Loaded fabric module tcm_usb_gadget.
[info] Loaded fabric module iscsi_target_mod.
[info] Loaded /etc/target/scsi_target.lio.
[ ok ] Started The Linux SCSI Target.

Module                  Size  Used by
iscsi_target_mod      251714  7 
tcm_usb_gadget         21050  4 
tcm_loop               15500  1 
tcm_qla2xxx            23666  1 
ib_srpt                36234  1 
tcm_fc                 20357  1 
vhost_scsi             22522  1 
target_core_file       10281  2 
target_core_iblock      9322  0 
target_core_pscsi      13248  0 
target_core_mod       300866  35 target_core_iblock,tcm_usb_gadget,tcm_qla2xxx,target_core_pscsi,iscsi_target_mod,tcm_fc,ib_srpt,target_core_file,vhost_scsi,tcm_loop

> 
> Then I manually load tcm_usb_gadget: modprobe tcm_usb_gadget.
> After that when targetcli is run usb_gadget fabric directory
> appears.
> 
> Then I create the following hierarchy:
> 
> /> ls
> o- / ..................................................................... [...]
>    o- backstores .......................................................... [...]
>    | o- fileio ............................................... [1 Storage Object]
>    | | o- abc ...................................... [10.0M, /root/f.img, in use]
>    | o- iblock ............................................... [0 Storage Object]
>    | o- pscsi ................................................ [0 Storage Object]
>    | o- rd_mcp ............................................... [0 Storage Object]
>    o- iscsi ......................................................... [0 Targets]
>    o- loopback ...................................................... [0 Targets]
>    o- usb_gadget ..................................................... [1 Target]
>      o- naa.60014051babd31e4 ....................... [nexus WWN 600140515a36d7db]
>        o- luns .......................................................... [1 LUN]
>          o- lun0 ..................................... [fileio/abc (/root/f.img)]
> 
> 
> and exit targetcli:
> 
> /> exit
> Comparing startup and running configs...
> Invalid fabric identifier 'usb_gadget': expected type 'loopback', 'iscsi', 'ib_srpt', 'vhost', 'tcm_fc', 'qla2xxx'
> 
> Why is 'usb_gadget' fabric unknown?
> 

For rtslib/targetcli v3.0 code, usb-gadget is missing the following
policy file:

root@scsi-mq:/# cat /var/target/policy/fabric_usb_gadget.lio 
fabric usb_gadget {
    target %naa {
        nexus_wwn %naa
        lun %int backend %backend
    }
}

Also, it looks like usb_gadget is stripping off the 'naa.' from the
nexus input, that is making the rtslib v3.0 sanity checks for nexus WWPN
formatting unhappy.

Here's a quick patch to fix that:

diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_g
index c3c4808..b3631aa 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c

@@ -1665,7 +1669,7 @@ static ssize_t tcm_usbg_tpg_store_nexus(
        if (i_port[strlen(i_port) - 1] == '\n')
                i_port[strlen(i_port) - 1] = '\0';
 
-       ret = tcm_usbg_make_nexus(tpg, &i_port[4]);
+       ret = tcm_usbg_make_nexus(tpg, &i_port[0]);
        if (ret < 0)
                return ret;
        return count;

> The gadget goes alive, I can list it on my Linux host, but I
> repeatedly get:
> 
> [  177.628876] g_target gadget: high-speed config #1: Linux Target
> [  177.633411] Using the BOT protocol
> [  198.459512] ERR bot_status_complete(64)
> [  198.621077] g_target gadget: high-speed config #1: Linux Target
> [  198.625607] Using the BOT protocol
> [  219.451560] ERR bot_status_complete(64)
> ...
> 
> Any ideas, why?
> 

With the above patch in place, v4.3-rc1 code appears to be working
now using dummy_hcd.

/> cd /usb_gadget 
/usb_gadget> create 
Created target naa.60014051d601ad20.
/usb_gadget> cd naa.60014051d601ad20/
/usb_gadget/n...14051d601ad20> ./luns create lun=0 storage_object=/backstores/fileio/tmpfile  
Created LUN 0.
/usb_gadget/n...14051d601ad20> disable 
The TPG has been disabled.
/usb_gadget/n...14051d601ad20> enable 
The TPG has been enabled.
/usb_gadget/n...14051d601ad20> ls /usb_gadget/
o- usb_gadget .................................................................... [1 Target]
  o- naa.60014051d601ad20 .................................. [nexus WWN naa.6001405c8f91fa92]
    o- luns ......................................................................... [1 LUN]
      o- lun0 ............................................... [fileio/tmpfile (/root/fileio)]
/usb_gadget/n...14051d601ad20> 

[   63.698312] dummy_hcd dummy_hcd.0: USB Host+Gadget Emulator, driver 02 May 2005
[   63.709515] dummy_hcd dummy_hcd.0: Dummy host controller
[   63.722241] dummy_hcd dummy_hcd.0: new USB bus registered, assigned bus number 1
[   63.758657] hub 1-0:1.0: USB hub found
[   63.763240] hub 1-0:1.0: 1 port detected
[   72.839346] g_target gadget: g_target ready
[   72.846854] udc_bind_to_driver: 0
[   73.060250] usb 1-1: new high-speed USB device number 2 using dummy_hcd
[   73.244219] g_target gadget: high-speed config #1: Linux Target
[   73.247685] Using the BOT protocol
[   73.317603] usb-storage 1-1:1.0: USB Mass Storage device detected
[   73.325750] usb-storage 1-1:1.0: Quirks match for vid 0525 pid a4a5: 10000
[   73.331335] scsi host0: usb-storage 1-1:1.0
[   73.351713] usbcore: registered new interface driver usb-storage
[   74.352193] No LUNs configured?
[   84.618554] usb 1-1: USB disconnect, device number 2
[   85.597708] g_target gadget: g_target ready
[   85.600641] udc_bind_to_driver: 0
[   85.816185] usb 1-1: new high-speed USB device number 3 using dummy_hcd
[   85.996223] g_target gadget: high-speed config #1: Linux Target
[   85.999791] Using the BOT protocol
[   86.013201] usb-storage 1-1:1.0: USB Mass Storage device detected
[   86.018596] usb-storage 1-1:1.0: Quirks match for vid 0525 pid a4a5: 10000
[   86.022647] scsi host1: usb-storage 1-1:1.0
[   87.052737] scsi 1:0:0:0: Direct-Access     LIO-ORG  FILEIO           4.0  PQ: 0 ANSI: 5
[   87.088839] sd 1:0:0:0: [sda] 4194304 512-byte logical blocks: (2.14 GB/2.00 GiB)
[   87.108419] sd 1:0:0:0: [sda] Write Protect is off
[   87.113042] sd 1:0:0:0: [sda] Mode Sense: 43 00 00 08
[   87.120664] sd 1:0:0:0: Attached scsi generic sg0 type 0
[   87.124484] sd 1:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[   87.264468] sd 1:0:0:0: [sda] Attached SCSI disk
[   87.288299] target: Unknown data direction for SCSI Opcode 0xa1

Note there still appears to be a nexus memory leak on shutdown and/or
usb_composite_probe() failure, but the above should at least get you up
and running.

Will send out a separate patch to address the reference leak.

Thanks for reporting!

--nab

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



[Index of Archives]     [Linux SCSI]     [Kernel Newbies]     [Linux SCSI Target Infrastructure]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Device Mapper]

  Powered by Linux