freebsd-nq/share/man/man4/targ.4
Nate Lawson c38b150ae4 New SCSI target emulator code
This code allows a user program to enable target mode on a SIM and
then emulate any number of devices (disks, tape drives, etc.)  All
decisions about device behavior (UA, CA, inquiry response) are left
to the usermode program and the kernel driver is merely a conduit
for CCBs.  This enables multiple concurrent target emulators, each
using its own backing store and IO model.

Also included is a user program that emulates a disk (RBC) using a
file as a backing store.  This provides functionality similar to
md(4) at the CAM layer.

Code has been tested on ahc(4) and should also work on isp(4) (and
other SIMs that gain target mode support).  It is a complete rewrite
of /sys/cam/scsi_target* and /usr/share/examples/scsi_target.

Design, comments from:	gibbs
Supported by:		Cryptography Research
Approved by:		re
2002-11-22 22:55:51 +00:00

144 lines
4.0 KiB
Groff

.\" Copyright (c) 2002
.\" Nate Lawson. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Neither the name of the author nor the names of any co-contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY Nate Lawson AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $FreeBSD$
.\"
.Dd November 15, 2002
.Dt targ 4
.Os
.Sh NAME
.Nm targ
.Nd SCSI target emulator driver
.Sh SYNOPSIS
.Cd device targ
.Sh DESCRIPTION
The
.Nm
driver provides an interface for usermode programs to emulate SCSI target
devices. A sample program that emulates a disk drive (similar to
.Xr da 4 )
can be found in /usr/share/examples/scsi_target.
.Pp
The
.Nm
driver supplies control devices,
.Pa /dev/targ0 ,
.Pa /dev/targ1 ,
etc.
If a device is already in use, the open will fail and
.Va errno
will be set to
.Er EBUSY .
After opening the device, the file descriptor must be bound to a
specific bus/target/lun and enabled to process CCBs using the
.Pa TARGIOCENABLE
ioctl.
The process then uses
.Xr write 2
to send CCBs to the SIM and
.Xr poll 2
or
.Xr kqueue 2
to see if responses are ready. Pointers to completed CCBs are returned via
.Xr read 2 .
Any data transfers requested by the user CCBs are done via zero-copy IO.
.Pp
.Sh IOCTLS
The following
.Xr ioctl 2
calls are defined in the header file
.Aq Pa cam/scsi/scsi_targetio.h .
.Bl -tag -width TARGIOCDISABLE
.It Dv TARGIOCENABLE
.Pq Li "struct ioc_enable_lun"
Enable target mode on the LUN specified by the following structure:
.Bd -literal -offset indent
struct ioc_enable_lun {
path_id_t path_id;
target_id_t target_id;
lun_id_t lun_id;
int grp6_len;
int grp7_len;
};
.Ed
.Pp
The selected path (bus), target, and lun must not already be in use or
.Er EADDRINUSE
is returned.
If grp6_len or grp7_len are non-zero, reception of vendor-specific commands
is enabled.
.It Dv TARGIOCDISABLE
Disable target mode and abort all pending CCBs.
The CCBs may optionally be read as they complete.
.Pa TARGIOCENABLE
can then be called to activate a different LUN.
Multiple disable calls have no effect.
The
.Xr close 2
system call automatically disables target mode if enabled.
.It Dv TARGIOCDEBUG
.Pq Li "int"
Enables CAM_PERIPH debugging if the argument is non-zero, otherwise disables
it.
.El
.Sh FILES
.Bl -tag -width /sys/cam/scsi/scsi_target.c -compact
.It Aq Pa cam/scsi/scsi_targetio.h
describes the usermode interface.
.It Pa /sys/cam/scsi/scsi_target.c
is the driver source file.
.It Pa /dev/targ*
are the control devices.
.El
.Sh SEE ALSO
.Xr /usr/share/examples/scsi_target ,
.Xr scsi 4
.Rs
.%T "FreeBSD Target Information"
.%O http://www.root.org/~nate/freebsd/
.Re
.Sh BUGS
Currently, only the
.Xr ahc 4
driver fully supports target mode. The
.Xr isp 4
and
.Xr sym 4
drivers have some target mode support but are untested.
.Pp
The
.Xr ahc 4
driver does not support tagged queuing in target mode.
.Sh AUTHORS
The
.Nm
driver first appeared in
.Fx 3.0 and was written by
.An Justin T. Gibbs .
It was rewritten
for
.Fx 5.0
by
.An Nate Lawson Aq nate@root.org .