Target-Mode ioctl Commands
The following SCIOSTARTTGT and SCIOSTOPTGT operations must be sent by the SCSI device driver (for the open and close routines, respectively) for each target-mode device instance. This causes the SCSI adapter device driver to allocate and initialize internal resources, and, if necessary, prepare the hardware for operation.
Target-mode support in the SCSI device driver and SCSI adapter device driver is optional. A failing return code from these commands, in the absence of any programming error, indicates target mode is not supported. If the SCSI device driver requires target mode, it must check the return code to verify the SCSI adapter device driver supports it.
Only a kernel process or device driver can call these ioctls. If attempted by a user process, the ioctl will fail, and the errno global variable will be set to EPERM.
The following information is provided on the various target-mode ioctl operations:
- SCIOSTARTTGT
- This operation opens
a logical path to a SCSI initiator device. It allocates and initializes
SCSI device-dependent information local to the SCSI adapter device
driver. This is run by the SCSI device driver in its open routine.
Subsequent SCIOSTARTTGT commands to the same ID (LUN is always
0) are unsuccessful unless an intervening SCIOSTOPTGT is issued.
This command also causes the SCSI adapter device driver to allocate
system buffer areas to hold data received from the initiator, and
makes the adapter ready to receive data from the selected initiator.
The arg parameter to the SCIOSTARTTGT should be set to the address of an sc_strt_tgt structure, which is defined in the /usr/include/sys/scsi.h file. The following parameters are supported:
- id
- The caller fills in the SCSI ID of the attached SCSI initiator.
- lun
- The caller sets the LUN to 0, as the initiator LUN is ignored for received data.
- buf_size
- The caller specifies size in bytes to be used for each receive buffer allocated for this host target instance.
- num_bufs
- The caller specifies how many buffers to allocate for this target instance.
- tm_correlator
- The caller optionally places a value in this field to be passed back in each tm_buf for this target instance.
- recv_func
- The caller places in this field the address of a pinned routine the SCSI adapter device driver should call to pass tm_bufs received for this target instance.
- free_func
- This is an output parameter the SCSI adapter device driver fills with the address of a pinned routine that the SCSI device driver calls to pass tm_bufs after they have been processed. The SCSI adapter device driver ignores the value passed as input.
Note: All reserved fields should be set to 0 by the caller.The following values for the errno global variable are supported:
- 0
- Indicates successful completion.
- EINVAL
- An SCIOSTARTTGT command has already been issued to this SCSI ID.
The passed SCSI ID is the same as that of the adapter.
The LUN ID field is not set to zero.
The buf_size is not valid. This is an adapter dependent value.
The Num_bufs is not valid. This is an adapter dependent value.
The recv_func value, which cannot be null, is not valid.
- EPERM
- Indicates the caller is not running in kernel mode, which is the only mode allowed to run this operation.
- ENOMEM
- Indicates that a memory allocation failure has occurred.
- EIO
- Indicates an I/O error occurred, preventing the device driver from completing SCIOSTARTTGT processing.
- SCIOSTOPTGT
- This operation closes
a logical path to a SCSI initiator device. It causes the SCSI adapter
device driver to deallocate device dependent information areas allocated
in response to a SCIOSTARTTGT operation. It also causes the
SCSI adapter device driver to deallocate system buffer areas used
to hold data received from the initiator, and to disable the host
adapter's ability to receive data from the selected initiator.
The arg parameter to the SCIOSTOPTGT ioctl should be set to the address of an sc_stop_tgt structure, which is defined in the /usr/include/sys/scsi.h file. The caller fills in the id field with the SCSI ID of the SCSI initiator, and sets the lun field to 0 as the initiator LUN is ignored for received data. Reserved fields should be set to 0 by the caller.
The following values for the errno global variable should be supported:
- 0
- Indicates successful completion.
- EINVAL
- An SCIOSTARTTGT command has not been previously issued to this SCSI ID.
- EPERM
- Indicates the caller is not running in kernel mode, which is the only mode allowed to run this operation.