Various ioctl operations must be performed for proper operation of the SCSI adapter device driver. The ioctl operations described here are the minimum set of commands the SCSI adapter device driver must implement to support SCSI device drivers. Other operations may be required in the SCSI adapter device driver to support, for example, system management facilities and diagnostics. SCSI device driver writers also need to understand these ioctl operations.
Every SCSI adapter device driver must support the IOCINFO ioctl operation. The structure to be returned to the caller is the devinfo structure, including the scsi union definition for the SCSI adapter, which can be found in the /usr/include/sys/devinfo.h file. The SCSI device driver should request the IOCINFO ioctl operation (probably during its open routine) to get the maximum transfer size of the adapter.
Note: The SCSI adapter device driver ioctl operations can only be called from the process level. They cannot be executed from a call on any more favored priority levels. Attempting to call them from a more favored priority level can result in a system crash.
The following SCIOSTART and SCIOSTOP operations must be sent by the SCSI device driver (for the open and close routines, respectively) for each device. They cause the SCSI adapter device driver to allocate and initialize internal resources. The SCIOHALT ioctl operation is used to abort pending or running commands, usually after signal processing by the SCSI device driver. This might be used by a SCSI device driver to end an operation instead of waiting for completion or a time out. The SCIORESET operation is provided for clearing device hard errors and competing initiator reservations during open processing by the SCSI device driver. The SCIOGTHW operation is supported by SCSI adapter device drivers that support gathered write commands to target devices.
Except where noted otherwise, the arg parameter for each of the ioctl operations described here must contain a long integer. In this field, the least significant byte is the SCSI LUN and the next least significant byte is the SCSI ID value. (The upper two bytes are reserved and should be set to 0.) This provides the information required to allocate or deallocate resources and perform SCSI bus operations for the ioctl operation requested.
The following information is provided on the various ioctl operations:
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:
Note: All reserved fields should be set to 0 by the caller. The following values for the errno global variable are supported:
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.
| ||||||||||||||||||||||||
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:
|
For either target or initiator mode, the SCSI device driver may issue an SCIOEVENT ioctl operation to register for receiving asynchronous event status from the SCSI adapter device driver for a particular device instance. This is an optional call for the SCSI device driver, and is optionally supported for the SCSI adapter device driver. A failing return code from this command, in the absence of any programming error, indicates it is not supported. If the SCSI device driver requires this function, it must check the return code to verify the SCSI adapter device driver supports it.
Only a kernel process or device driver can invoke these ioctls. If attempted by a user process, the ioctl will fail, and the errno global variable will be set to EPERM.
The event registration performed by this ioctl operation is allowed once per device session. Only the first SCIOEVENT ioctl operation is accepted after the device session is opened. Succeeding SCIOEVENT ioctl operations will fail, and the errno global variable will be set to EINVAL. The event registration is canceled automatically when the device session is closed.
The arg parameter to the SCIOEVENT ioctl operation should be set to the address of an sc_event_struct structure, which is defined in the /usr/include/sys/scsi.h file. The following parameters are supported:
id | The caller sets id to the SCSI ID of the attached SCSI target device for initiator-mode. For target-mode, the caller sets the id to the SCSI ID of the attached SCSI initiator device. | ||||
lun | The caller sets the lun field to the SCSI LUN of the attached SCSI target device for initiator-mode. For target-mode, the caller sets the lun field to 0. | ||||
mode | Identifies whether the initiator- or target-mode device is being registered. These values are possible:
| ||||
async_correlator | The caller places a value in this optional field which is saved by the SCSI adapter device driver and returned when an event occurs in this field in the sc_event_info structure. This structure is defined in the /user/include/sys/scsi.h file. | ||||
async_func | The caller fills in the address of a pinned routine which the SCSI adapter device driver calls whenever asynchronous event status is available. The SCSI adapter device driver passes a pointer to a sc_event_info structure to the caller's async_func routine. |
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 | Either an SCIOSTART or SCIOSTARTTGT has not been issued to this device instance, or this device is already registered for async events. |
EPERM | Indicates the caller is not running in kernel mode, which is the only mode allowed to execute this operation. |