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