xref: /freebsd/share/man/man4/targ.4 (revision 5773cccf19ef7b97e56c1101aa481c43149224da)
1.\" Copyright (c) 2002
2.\"	Nate Lawson.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Neither the name of the author nor the names of any co-contributors
10.\"    may be used to endorse or promote products derived from this software
11.\"    without specific prior written permission.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY Nate Lawson AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd November 15, 2002
28.Dt targ 4
29.Os
30.Sh NAME
31.Nm targ
32.Nd SCSI target emulator driver
33.Sh SYNOPSIS
34.Cd device targ
35.Sh DESCRIPTION
36The
37.Nm
38driver provides an interface for usermode programs to emulate SCSI target
39devices.  A sample program that emulates a disk drive (similar to
40.Xr da 4 )
41can be found in /usr/share/examples/scsi_target.
42.Pp
43The
44.Nm
45driver supplies control devices,
46.Pa /dev/targ0 ,
47.Pa /dev/targ1 ,
48etc.
49If a device is already in use, the open will fail and
50.Va errno
51will be set to
52.Er EBUSY .
53After opening the device, the file descriptor must be bound to a
54specific bus/target/lun and enabled to process CCBs using the
55.Pa TARGIOCENABLE
56ioctl.
57The process then uses
58.Xr write 2
59to send CCBs to the SIM and
60.Xr poll 2
61or
62.Xr kqueue 2
63to see if responses are ready.  Pointers to completed CCBs are returned via
64.Xr read 2 .
65Any data transfers requested by the user CCBs are done via zero-copy IO.
66.Pp
67.Sh IOCTLS
68The following
69.Xr ioctl 2
70calls are defined in the header file
71.Aq Pa cam/scsi/scsi_targetio.h .
72.Bl -tag -width TARGIOCDISABLE
73.It Dv TARGIOCENABLE
74.Pq Li "struct ioc_enable_lun"
75Enable target mode on the LUN specified by the following structure:
76.Bd -literal -offset indent
77struct ioc_enable_lun {
78	path_id_t	path_id;
79	target_id_t	target_id;
80	lun_id_t	lun_id;
81	int		grp6_len;
82	int		grp7_len;
83};
84.Ed
85.Pp
86The selected path (bus), target, and lun must not already be in use or
87.Er EADDRINUSE
88is returned.
89If grp6_len or grp7_len are non-zero, reception of vendor-specific commands
90is enabled.
91.It Dv TARGIOCDISABLE
92Disable target mode and abort all pending CCBs.
93The CCBs may optionally be read as they complete.
94.Pa TARGIOCENABLE
95can then be called to activate a different LUN.
96Multiple disable calls have no effect.
97The
98.Xr close 2
99system call automatically disables target mode if enabled.
100.It Dv TARGIOCDEBUG
101.Pq Li "int"
102Enables CAM_PERIPH debugging if the argument is non-zero, otherwise disables
103it.
104.El
105.Sh FILES
106.Bl -tag -width /sys/cam/scsi/scsi_target.c -compact
107.It Aq Pa cam/scsi/scsi_targetio.h
108describes the usermode interface.
109.It Pa /sys/cam/scsi/scsi_target.c
110is the driver source file.
111.It Pa /dev/targ*
112are the control devices.
113.El
114.Sh SEE ALSO
115.Xr /usr/share/examples/scsi_target ,
116.Xr scsi 4
117.Rs
118.%T "FreeBSD Target Information"
119.%O http://www.root.org/~nate/freebsd/
120.Re
121.Sh BUGS
122Currently, only the
123.Xr ahc 4
124driver fully supports target mode.  The
125.Xr isp 4
126and
127.Xr sym 4
128drivers have some target mode support but are untested.
129.Pp
130The
131.Xr ahc 4
132driver does not support tagged queuing in target mode.
133.Sh AUTHORS
134The
135.Nm
136driver first appeared in
137.Fx 3.0 and was written by
138.An Justin T. Gibbs .
139It was rewritten
140for
141.Fx 5.0
142by
143.An Nate Lawson Aq nate@root.org .
144