Solved Help with scsi_target example

I've been trying to set up one of my machines to serve as a SCSI drive to retro computers. I'd like to use my FreeBSD machine to host fast, easily backed-up disk images for them rather than using noisy worn-out SCSI drives.

I'm running FreeBSD 10.3 amd64 on an Intel i7.
The target machine has an Adaptec 29160 (ahc driver) set to unit #7.
The test initiator machine also runs the same version of FreeBSD and has an LSI ultra160 card of some kind (mpt driver) set to unit #6.
Both machines are connected by a 68 pin internal SCSI cable to their internal LVD connectors with the cases open.
No other SCSI devices are in the systems.

I've followed most closely to the steps referenced in targ(4) which are available here: http://www.root.org/~nate/freebsd/scsi/README.targ

I've built my kernel with this configuration:
Code:
include GENERIC
ident TARGET

device scbus
device da
device targ
device targbh
options CAMDEBUG
options VFS_AIO
device ahc
options AHC_TMODE_ENABLE=0x7f

I create a test file as shown in the link above.

I build /usr/share/examples/scsi_target/ and then run it with either 8 or 16 bit wide options:
./scsi_target -d 0:3:0 test_file
or
./scsi_target -W 16 -d 0:3:0 test_file

So far, so good. It seems to be waiting for an initiator.

Code:
root@:/usr/share/examples/scsi_target # ./scsi_target -W 16 -d 0:3:0 test_file
scsi_target: volume_size: 512 bytes x 40960 sectors
scsi_target: aio support tested ok
scsi_target: opened /dev/targ
scsi_target: sending ccb (0x4)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: sending ccb (0x332)
scsi_target: sending ccb (0x336)
scsi_target: main loop beginning

When I power on the other machine and it begins to scan devices I get the following:
Code:
scsi_target: read ready
scsi_target: event -1 done
scsi_target: Working on INOT 0x80180f720
scsi_target: abort_all_pending
scsi_target: Aborting pending CCB 0x801806200

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f100

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806400

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f1e0

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806600

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f2c0

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806800

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f3a0

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806a00

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f480

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806c00

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f560

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801806e00

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x80180f640

scsi_target: sending ccb (0x10)
scsi_target: Aborting pending CCB 0x801807000

scsi_target: sending ccb (0x10)
scsi_target: sending ccb (0x336)
scsi_target: Queue frozen receiving CCB, releasing
scsi_target: sending ccb (0x5)
scsi_target: read ready
scsi_target: event -1 done
scsi_target: Working on INOT 0x80180f3a0
scsi_target: INOT 0x80180f3a0 aborted
scsi_target: sending ccb (0x336)
scsi_target: read ready
scsi_target: event -1 done
scsi_target: Working on INOT 0x80180f640
scsi_target: INOT 0x80180f640 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on INOT 0x80180f560
scsi_target: INOT 0x80180f560 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on INOT 0x80180f480
scsi_target: INOT 0x80180f480 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on INOT 0x80180f2c0
scsi_target: INOT 0x80180f2c0 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on INOT 0x80180f1e0
scsi_target: INOT 0x80180f1e0 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on INOT 0x80180f100
scsi_target: INOT 0x80180f100 aborted
scsi_target: sending ccb (0x336)
scsi_target: Working on ATIO 0x801806200
scsi_target: ATIO 0x80180e040 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806400
scsi_target: ATIO 0x80180e080 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806600
scsi_target: ATIO 0x80180e0c0 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806800
scsi_target: ATIO 0x80180e100 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806a00
scsi_target: ATIO 0x80180e140 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806c00
scsi_target: ATIO 0x80180e180 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801806e00
scsi_target: ATIO 0x80180e1c0 aborted: Invalid argument
scsi_target: sending ccb (0x332)
scsi_target: Working on ATIO 0x801807000
scsi_target: ATIO 0x80180e200 aborted: Invalid argument
scsi_target: sending ccb (0x332)

Running camcontrol rescan 0 on the initiator finds no new drives.

camcontrol devlist shows only my sata devices.

I'm stumped. Thanks for any help you may be able to offer.
 
Just an update, I noticed that a lot of changes to this code had taken place for FreeBSD 9.0, so I installed 8.4.

The output of scsi_target is dramatically different. It spits out a lot more information before booting the initiator machine, then stops, but (I couldn't get the output here, it was a very bare installation) once the other machine scans for drives, it outputs a huge amount of information then eventually crashes.

I'm curious if anyone else has successfully tried this since the FreeBSD 6 days.
 
Solved! Either the old Adaptec 29160 (full height) was defective or there is some minor difference with the card itself.

I ordered another 29160lp from ebay and the same setup now works.

One thing that wasn't clear to me originally was the value you use for AHC_TMODE_ENABLE.

Because the term "unit number" isn't unique in this context, I was confused. It's apparently not the SCSI unit number, it is the ahc unit number.

For example, for using only ahc0 you would use AHC_TMODE_ENABLE=0x1 (bit 0 set) regardless of the emulated scsi drive unit numbers you pass to scsi_target.

Also unclear is how the 0:3:0 parameter is determined for scsi_target.

The first digit is the scsi hba unit number from camcontrol devlist -b. On my system I've used hints to place ahc0 as scbus0, so I use 0:.

The second digit is any scsi unit number that is not already in use on that scsi chain. Apparently most Adaptec cards can respond to multiple unit numbers simultaneously, but multiple instances of scsi_target will lock up my machine. My guess is that this functionality requires the target emulation to be within the same application rather than running multiple instances or that the simple example is just too simple.

I have been unable to use a LUN other than 0 with a FreeBSD initiator so far. The target is simply not found during the bus rescan. I have not yet tried another OS as initiator.

Hopefully this will help someone in the future.
 
Last edited:
Back
Top