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