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