xref: /freebsd/share/man/man4/targ.4 (revision 069ac184)
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.Dd December 13, 2011
26.Dt TARG 4
27.Os
28.Sh NAME
29.Nm targ
30.Nd SCSI target emulator driver
31.Sh SYNOPSIS
32To compile this driver into the kernel,
33place the following line in your
34kernel configuration file:
35.Bd -ragged -offset indent
36.Cd "device targ"
37.Ed
38.Sh DESCRIPTION
39The
40.Nm
41driver provides an interface for usermode programs to emulate SCSI target
42devices.
43A sample program that emulates a disk drive (similar to
44.Xr da 4 )
45can be found in
46.Pa /usr/share/examples/scsi_target .
47.Pp
48The
49.Nm
50driver supplies the control device
51.Pa /dev/targ .
52After opening the device, the file descriptor must be bound to a
53specific bus/target/LUN and enabled to process CCBs using the
54.Dv TARGIOCENABLE
55ioctl.
56The process then uses
57.Xr write 2
58to send CCBs to the SIM and
59.Xr poll 2
60or
61.Xr kqueue 2
62to see if responses are ready.
63Pointers 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.Sh IOCTLS
67The following
68.Xr ioctl 2
69calls are defined in the header file
70.In cam/scsi/scsi_targetio.h .
71.Bl -tag -width ".Dv TARGIOCDISABLE"
72.It Dv TARGIOCENABLE
73.Pq Vt "struct ioc_enable_lun"
74Enable target mode on the LUN specified by the following structure:
75.Bd -literal -offset indent
76struct ioc_enable_lun {
77	path_id_t	path_id;
78	target_id_t	target_id;
79	lun_id_t	lun_id;
80	int		grp6_len;
81	int		grp7_len;
82};
83.Ed
84.Pp
85The selected path (bus), target, and LUN must not already be in use or
86.Er EADDRINUSE
87is returned.
88If
89.Va grp6_len
90or
91.Va grp7_len
92are non-zero, reception of vendor-specific commands
93is enabled.
94.It Dv TARGIOCDISABLE
95Disable target mode and abort all pending CCBs.
96The CCBs may optionally be read as they complete.
97.Dv TARGIOCENABLE
98can then be called to activate a different LUN.
99Multiple disable calls have no effect.
100The
101.Xr close 2
102system call automatically disables target mode if enabled.
103.It Dv TARGIOCDEBUG
104.Pq Vt int
105Enables
106.Dv CAM_PERIPH
107debugging if the argument is non-zero, otherwise disables
108it.
109.El
110.Sh FILES
111.Bl -tag -width ".Pa /sys/cam/scsi/scsi_target.c" -compact
112.It In cam/scsi/scsi_targetio.h
113describes the usermode interface.
114.It Pa /sys/cam/scsi/scsi_target.c
115is the driver source file.
116.It Pa /dev/targ
117is the control device.
118.El
119.Sh SEE ALSO
120.Pa /usr/share/examples/scsi_target ,
121.Xr ahc 4 ,
122.Xr isp 4 ,
123.Xr scsi 4
124.Rs
125.%T "FreeBSD Target Information"
126.%U http://www.root.org/~nate/freebsd/
127.Re
128.Sh AUTHORS
129.An -nosplit
130The
131.Nm
132driver first appeared in
133.Fx 3.0
134and was written by
135.An Justin T. Gibbs .
136It was rewritten
137for
138.Fx 5.0
139by
140.An Nate Lawson Aq Mt nate@root.org .
141.Sh BUGS
142Currently, only the
143.Xr ahc 4
144and
145.Xr isp 4
146drivers fully support target mode.
147.Pp
148The
149.Xr ahc 4
150driver does not support tagged queuing in target mode.
151