scdisk SCSI Device Driver

Purpose

Supports the small computer system interface (SCSI) fixed disk, CD-ROM (compact disk read only memory), and read/write optical (optical memory) devices.

Syntax

#include <sys/devinfo.h>
#include <sys/scsi.h>
#include <sys/scdisk.h>
#include <sys/pcm.h>
#include <sys/mpio.h>

Device-Dependent Subroutines

Typical fixed disk, CD-ROM, and read/write optical drive operations are implemented using the open, close, read, write, and ioctl subroutines. The scdisk device driver has additional support added for MPIO capable devices.

open and close Subroutines

The open subroutine applies a reservation policy based on the ODM reserve_policy attribute. In the past, the open subroutine always applied a SCSI2 reserve. The open and close subroutines support working with multiple paths to a device if the device is a MPIO capable device.

The openx subroutine is intended primarily for use by diagnostic commands and utilities. Appropriate authority is required for execution. If an attempt is made to run the open subroutine without the proper authority, the subroutine returns a value of -1 and sets the errno global variable to a value of EPERM.

The ext parameter passed to the openx subroutine selects the operation to be used for the target device. The /usr/include/sys/scsi.h file defines possible values for the ext parameter.

The ext parameter can contain any combination of the following flag values logically ORed together:

Item Description
SC_DIAGNOSTIC Places the selected device in Diagnostic mode. This mode is singularly entrant; that is, only one process at a time can open it. When a device is in Diagnostic mode, SCSI operations are performed during open or close operations, and error logging is disabled. In Diagnostic mode, only the close and ioctl subroutine operations are accepted. All other device-supported subroutines return a value of -1 and set the errno global variable to a value of EACCES.

A device can be opened in Diagnostic mode only if the target device is not currently opened. If an attempt is made to open a device in Diagnostic mode and the target device is already open, the subroutine returns a value of -1 and sets the errno global variable to a value of EACCES.

SC_FORCED_OPEN_LUN On a device that supports Lun Level Reset, the device is reset regardless of any reservation placed by another initiator before the open sequence takes place. If the device does not support Lun Level Reset, and both SC_FORCED_OPEN_LUN and SC_FORCE_OPEN flags are set, then a target reset occurs before the open sequence takes place.
SC_FORCED_OPEN Forces a bus device reset, regardless of whether another initiator has the device reserved. The SCSI bus device reset is sent to the device before the open sequence begins. In other respects, the open operation runs normally.
SC_RETAIN_RESERVATION Retains the reservation of the device after a close operation by not issuing the release. This flag prevents other initiators from using the device unless they break the host machine's reservation.
SC_NO_RESERVE Prevents the reservation of a device during an openx subroutine call to that device. This operation is provided so a device can be controlled by two processors that synchronize their activity by their own software means.
SC_SINGLE Places the selected device in Exclusive Access mode. Only one process at a time can open a device in Exclusive Access mode.

A device can be opened in Exclusive Access mode only if the device is not currently open. If an attempt is made to open a device in Exclusive Access mode and the device is already open, the subroutine returns a value of -1 and sets the errno global variable to a value of EBUSY. If the SC_DIAGNOSTIC flag is specified along with the SC_SINGLE flag, the device is placed in Diagnostic mode.

SC_PR_SHARED_REGISTER In a multi-initiator shared device environment, a Persistent Reserve with service action Register and Ignore Key is sent to the device as part of the open sequence. This feature is aimed at the cluster environment, where an upper management software needs to follow an advisory lock mechanism to control when the initiator reads or writes. The device is required to support Persistent Reserve (refer to SCSI Primary Command version 2 description of Persistent Reserve).

SCSI Options to the openx Subroutine in AIX® Version 7.1 Kernel Extensions and Device Support Programming Concepts gives more specific information on the open operations.

readx and writex Subroutines

The readx and writex subroutines provide additional parameters which affect the raw data transfer. These subroutines pass the ext parameter, which specifies request options. The options are constructed by logically ORing zero or more of the following values:

Item Description
HWRELOC Indicates a request for hardware relocation (safe relocation only)
UNSAFEREL Indicates a request for unsafe hardware relocation
WRITEV Indicates a request for write verification

ioctl Subroutine

ioctl subroutine operations that are used for the scdisk device driver are specific to the following categories:

Fixed Disk and Read/Write Optical Devices

The following ioctl operations are available for the fixed disk and read/write optical devices:

Item Description
DKIOWRSE Provides a means for issuing a write command to the device and obtaining the target-device sense data when an error occurs. If the DKIOWRSE operation returns a value of -1 and the status_validity field is set to a value of sc_valid_sense, valid sense data is returned. Otherwise, target sense data is omitted.

The DKIOWRSE operation is provided for diagnostic use. It allows the limited use of the target device while operating in an active system environment. The arg parameter to the DKIOWRSE operation contains the address of an sc_rdwrt structure. This structure is defined in the /usr/include/sys/scsi.h file.

The devinfo structure defines the maximum transfer size for a write operation. If an attempt is made to transfer more than the maximum, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

DKLOGSENSE

Provides a means to issue the LOG SENSE command on devices that has been successfully opened. Any application issuing this ioctl operation need to pass the address of the struct sc_log_sense (defined in /usr/include/sys/scsi.h) and the structure is filled as follows:

  1. page_code and subpage_code for the requested LOG Page
  2. pc set to the value CUMUL_VAL.
  3. allocation_length – If this field is set to zero only the log page header consisting of the page code and the log page length is returned. If this field is non zero, this should equal the length of the log page excluding the log page header of size 4 bytes. If the user specifies an allocation length less than the actual log page length, then only the requested length of log data is returned.
  4. log_data contains the address of the memory allocated for storing the data returned from the ioctl operation.

If the requested log page is SCSI_BSR_LOG_PAGE (defined in /usr/include/sys/scsi.h) then the log_data points to the struct sc_bsr_log_data allocated by the caller. The caller also allocates the memory for the struct sc_bms_log_data such that total of sizeof struct sc_bsr_log_data and memory allocated for the struct sc_bms_log_data will be equal to the allocation_length.

Otherwise (for log pages other than SCSI_BSR_LOG_PAGE) , it points to a chunk of memory equal to allocation_length.

Following is the example code for filling the sc_log_sense structure:

struct sc_log_sense log_sense;

melog_sense, '\0', sizeof(struct sc_log_sense));
log_sense.page_code = SCSI_BSR_LOG_PAGE ;
log_sense.subpage_code = 0; 
log_sense.pc = CUMUL_VAL;
log_sense.allocation_length = 16; 
if (log_sense.allocation_length) 
 {  
 if (log_sense.page_code == SCSI_BSR_LOG_PAGE)
  {    
   log_sense.log_data = (struct sc_bsr_log_data *) malloc(sizeof(struct sc_bsr_log_data));  
  }
  else 
  { 
   log_sense.log_data = (char *) malloc(log_sense.allocation_length); 
  }      
  if (log_sense.log_data == NULL)   
  exit(-1); 
  if (log_sense.page_code == SCSI_BSR_LOG_PAGE)
  {
   bms_param_len = log_sense.allocation_length - sizeof(struct sc_scan_status);
   ((struct sc_bsr_log_data *)(log_sense.log_data))-> bms_log_data = (struct sc_bms_log_data *)
	 malloc(bms_param_len); 
  if (((struct sc_bsr_log_data *)(log_sense.log_data))-> bms_log_data == NULL)
  exit(-1);
  }
 }
 rc = ioctl(fd, DKLOGSENSE,&log_sense);
 
The DKLOGSENSE ioctl operation returns the following data using the struct sc_log_sense (rc=0 indicates success):
  1. returned_length field contains the length of the bytes requested or zero if the user specified an allocation length of zero.
  2. adapter_status, scsi_status, sense_key, scsi_asc, scsi_ascq set with the error return status for the LOG SENSE command.
  3. log_data field points to the memory containing the data returned by the LOG SENSE command. Driver will parse and fill fields for the struct sc_bsr_log_data and struct bms_log_data for the Background Scan Results log page. The ioctl caller shall print structure fields to view the data. Otherwise, this memory will be a char * to the log data of returned_length. Note that the data will be excluding the log page header.
if (log_sense.page_code == SCSI_BSR_LOG_PAGE) 
{
    bms_cnt = (log_sense.returned_length - 16)/24;
    printf("Background Scan Results Log Page:\n");
    printf("Scanning Status Parameter:\n");
    bsr_log_data = (struct sc_bsr_log_data *)log_sense.log_data;
    scan_status  = &(bsr_log_data->scan_status);
    printf("Parameter Code \t:\t %x\n", scan_status->param_code);
    printf("Parameter Control Byte \t:\t %x",scan_status->param_ctrl_bits);
    printf("Parameter Length \t:\t %x\n", scan_status->param_length);
    printf("Power Age \t:\t %x\n", scan_status->power_age);
    printf("Scan Status \t:\t %x\n", scan_status->scan_status);
    printf("Scan Count \t:\t %x\n", scan_status->scan_count);
    printf("Scan Progress \t:\t %x \n", scan_status->scan_progress);
    printf("BMS Count \t:\t %x\n", scan_status->bms_count);
    printf("Background Medium Scan Parameter for %d Elements:\n",bms_cnt);
       
    for (i=0; <ibms_cnt; i++)
    {
        bms_data = bsr_log_data->bms_log_data;
        printf("Parameter Code \t:\t %x\n", bms_data->param_code);
        printf("Parameter Control Byte \t:\t%x",bms_data->param_ctrl_bits);
        printf("Parameter Length \t:\t %x\n", bms_data->param_length);
        printf("Power Age \t:\t %x\n", bms_data->power_age);
        printf("SenseKey & Reassign Status \t:\t %x\n",bms_data->status_snskey);
        printf("ASC \t:\t %x\n", bms_data->asc);
        printf("ASCQ \t:\t %x\n", bms_data->ascq);

        for (j=0; j<5; j++)
            printf("vendor_data[%d] \t:\t%x\n",j,bms_data->vendor_data[j]);

        printf("LBA \t:\t %llx\n", bms_data->lba);
    }

} else {
    Log data received is a char buffer of ‘returned_length' size.
    So print the data byte by byte.
}
DKLOGSELECT

Provides a means to issue the LOG SELECT command.

Any application issuing the DKLOGSELECT ioctl operation is expected to pass the address of the DKLOGSELECT (defined in /usr/include/sys/scsi.h) filled as follows:
  1. page_code and subpage_code for the requested LOG Page
  2. pcr, sp, pc, and param_length as per the SCSI Primary Commands Standard Version 4 (SPC4) requirements.
  3. log_data points to the memory containing the parameters which need to be sent to the LOG SELECT command.
Following is an example for filling the sc_log_select structure in order to clear the SCSI_BSR_LOG_PAGE data**.
struct sc_log_select log_select;

memset(&log_select, '\0', sizeof(struct sc_log_select));
log_select.page_code = SCSI_BSR_LOG_PAGE;
log_select.subpage_code = 0;
log_select.pcr = 1;
log_select.sp = 0;
log_select.pc = CUMUL_VAL;
log_select.param_length = 0;
if (log_select.param_length) 
{
 log_select.log_data = (char *)malloc(log_select.param_length);
 if (log_select.log_data == NULL) exit(-1);
} 
rc = ioctl(fd, DKLOGSELECT,&log_select);   
This ioctl operation will return the following data using the struct sc_log_select (rc=0 indicates success) adapter_status,scsi_status, sense_key, scsi_asc, and scsi_ascq fields reporting the error completion status of the LOG SELECT command.

CD-ROM Devices Only

The following ioctl operation is available for CD-ROM devices only:

Item Description
CDIOCMD Allows SCSI commands to be issued directly to the attached CD-ROM device. The CDIOCMD operation preserves binary compatibility for CD-ROM applications that were compiled on earlier releases of the operating system. It is recommended that newly written CD-ROM applications use the DKIOCMD operation instead. For the CDIOCMD operation, the device must be opened in Diagnostic mode. The CDIOCMD operation parameter specifies the address of a sc_iocmd structure. This structure is defined in the /usr/include/sys/scsi.h file.

If this operation is attempted on a device other than CD-ROM, it is interpreted as a DKIORDSE operation. In this case, the arg parameter is treated as an sc_rdwrt structure.

If the CDIOCMD operation is attempted on a device not in Diagnostic mode, the subroutine returns a value of -1 and sets the errno global variable to a value of EACCES. Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Note: Diagnostic mode is required only for the CDIOCMD and DKIOCMD operations.

Fixed Disk, CD-ROM, and Read/Write Optical Devices

The following ioctl operations are available for fixed disk, CD-ROM, and read/write optical devices:

Item Description
IOCINFO Returns the devinfo structure defined in the /usr/include/sys/devinfo.h file. The IOCINFO operation is the only operation defined for all device drivers that use the ioctl subroutine. The remaining operations discussed in this article are all specific to fixed disk, CD-ROM, and read/write optical devices.
DKIORDSE Provides a means for issuing a read command to the device and obtaining the target-device sense data when an error occurs. If the DKIORDSE operation returns a value of -1 and the status_validity field is set to a value of sc_valid_sense, valid sense data is returned. Otherwise, target sense data is omitted.

The DKIORDSE operation is provided for diagnostic use. It allows the limited use of the target device while operating in an active system environment. The arg parameter to the DKIORDSE operation contains the address of an sc_rdwrt structure. This structure is defined in the /usr/include/sys/scsi.h file.

The devinfo structure defines the maximum transfer size for a read operation. If an attempt is made to transfer more than the maximum, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Note: The CDIORDSE operation may be substituted for the DKIORDSE operation when issuing a read command to and obtaining sense data from a CD-ROM device. DKIORDSE is the recommended operation.
DKIOCMD When the device has been successfully opened in the Diagnostic mode, the DKIOCMD operation provides the means for issuing any SCSI command to the specified device. If the DKIOCMD operation is issued when the device is not in Diagnostic mode, the subroutine returns a value of -1 and sets the errno global variable to a value of EACCES. The device driver performs no error recovery or logging on failures of this operation.

The SCSI status byte and the adapter status bytes are returned through the arg parameter, which contains the address of a sc_iocmd structure (defined in the /usr/include/sys/scsi.h file). If the DKIOCMD operation fails, the subroutine returns a value of -1 and sets the errno global variable to a nonzero value. In this case, the caller should evaluate the returned status bytes to determine why the operation was unsuccessful and what recovery actions should be taken.

The devinfo structure defines the maximum transfer size for the command. If an attempt is made to transfer more than the maximum, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Note: Diagnostic mode is required only for the CDIOCMD and DKIOCMD operations.
DKPMR Issues a SCSI prevent media removal command when the device has been successfully opened. This command prevents media from being ejected until the device is closed, powered off and back on, or until a DKAMR operation is issued. The arg parameter for the DKPMR operation is null. If the DKPMR operation is successful, the subroutine returns a value of 0. If the device is a SCSI fixed disk, the DKPMR operation fails, and the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. If the DKPMR operation fails for any other reason, the subroutine returns a value of -1 and sets the errno global variable to a value of EIO.
DKAMR Issues an allow media removal command when the device has been successfully opened. As a result media can be ejected using either the drive's eject button or the DKEJECT operation. The arg parameter for this ioctl is null. If the DKAMR operation is successful, the subroutine returns a value of 0. If the device is a SCSI fixed disk, the DKAMR operation fails, and the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. For any other failure of this operation, the subroutine returns a value of -1 and sets the errno global variable to a value of EIO.
DKEJECT Issues an eject media command to the drive when the device has been successfully opened. The arg parameter for this operation is null. If the DKEJECT operation is successful, the subroutine returns a value of 0. If the device is a SCSI fixed disk, the DKEJECT operation fails, and the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. For any other failure of this operation, the subroutine returns a value of -1 and sets the errno global variable to a value of EIO.
DKFORMAT Issues a format unit command to the specified device when the device has been successfully opened.

If the arg parameter for this operation is null, the format unit sets the format options valid (FOV) bit to 0 (that is, it uses the drive's default setting). If the arg parameter for the DKFORMAT operation is not null, the first byte of the defect list header is set to the value specified in the first byte addressed by the arg parameter. This allows the creation of applications to format a particular type of read/write optical media uniquely.

The driver initially tries to set the FmtData and CmpLst bits to 0. If that fails, the driver tries the remaining three permutations of these bits. If all four permutations fail, this operation fails, and the subroutine sets the errno global variable to a value of EIO.

If the DKFORMAT operation is specified for a fixed disk, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. If the DKFORMAT operation is attempted when the device is not in Exclusive Access mode, the subroutine returns a value of -1 and sets the errno global variable to a value of EACCES. If the media is write-protected, the subroutine returns a value of -1 and sets the errno global variable to a value of EWRPROTECT. If the format unit exceeds its timeout value, the subroutine returns a value of -1 and sets the errno global variable to a value of ETIMEDOUT. For any other failure of this operation, the subroutine returns a value of -1 and sets the errno global variable to a value of EIO.

DKAUDIO Issues play audio commands to the specified device and controls the volume on the device's output ports. Play audio commands include: play, pause, resume, stop, determine the number of tracks, and determine the status of a current audio operation. The DKAUDIO operation plays audio only through the CD-ROM drive's output ports. The arg parameter of this operation is the address of a cd_audio_cmds structure, which is defined in the /usr/include/sys/scdisk.h file. Exclusive Access mode is required.

If DKAUDIO operation is attempted when the device's audio-supported attribute is set to No, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. If the DKAUDIO operation fails, the subroutine returns a value of -1 and sets the errno global variable to a nonzero value. In this case, the caller should evaluate the returned status bytes to determine why the operation failed and what recovery actions should be taken.

DK_CD_MODE Determines or changes the CD-ROM data mode for the specified device. The CD-ROM data mode specifies what block size and special file are used for data read across the SCSI bus from the device. The DK_CD_MODE operation supports the following CD-ROM data modes:
CD-ROM Data Mode 1
512-byte block size through both raw (dev/rcd*) and block special (/dev/cd*) files
CD-ROM Data Mode 2 Form 1
2048-byte block size through both raw (dev/rcd*) and block special (/dev/cd*) files
CD-ROM Data Mode 2 Form 2
2336-byte block size through the raw (dev/rcd*) special file only
CD-DA (Compact Disc Digital Audio)
2352-byte block size through the raw (dev/rcd*) special file only
DVD-ROM
2048-byte block size through both raw (/dev/rcd*) and block special (/dev/cd*) files
DVD-RAM
2048-byte block size through both raw (/dev/rcd*) and block special (/dev/cd*) files
DVD-RW
2048-byte block size through both raw (/dev/rcd*) and block special (/dev/cd*) files

The DK_CD_MODE arg parameter contains the address of the mode_form_op structure defined in the /usr/include/sys/scdisk.h file. To have the DK_CD_MODE operation determine or change the CD-ROM data mode, set the action field of the change_mode_form structure to one of the following values:

CD_GET_MODE
Returns the current CD-ROM data mode in the cd_mode_form field of the mode_form_op structure, when the device has been successfully opened.
CD_CHG_MODE
Changes the CD-ROM data mode to the mode specified in the cd_mode_form field of the mode_form_op structure, when the device has been successfully opened in the Exclusive Access mode.

If a CD-ROM has not been configured for different data modes (via mode-select density codes), and an attempt is made to change the CD-ROM data mode (by setting the action field of the change_mode_form structure set to CD_CHG_MODE), the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. Attempts to change the CD-ROM mode to any of the DVD modes will also result in a return value of -1 and the errno global variable set to EINVAL.

If the DK_CD_MODE operation for CD_CHG_MODE is attempted when the device is not in Exclusive Access mode, the subroutine returns a value of -1 and sets the errno global variable to a value of EACCES. For any other failure of this operation, the subroutine returns a value of -1 and sets the errno global variable to a value of EIO.

DK_PASSTHRU When the device has been successfully opened, the DK_PASSTHRU operation provides the means for issuing any SCSI command to the specified device. The device driver will perform limited error recovery if this operation fails. The DK_PASSTHRU operation differs from the DKIOCMD operation in that it does not require an openx command with the ext argument of SC_DIAGNOSTIC. Because of this, a DK_PASSTHRU operation can be issued to devices that are in use by other operations.

The SCSI status byte and the adapter status bytes are returned through the arg parameter, which contains the address of a sc_passthru structure (defined in the /usr/include/sys/scsi.h file). If the DK_PASSTHRU operation fails, the subroutine returns a value of -1 and sets the errno global variable to a nonzero value. If this happens the caller should evaluate the returned status bytes to determine why the operation was unsuccessful and what recovery actions should be taken.

If a DK_PASSTHRU operation fails because a field in the sc_passthru structure has an invalid value, the subroutine will return a value of -1 and set the errno global variable to EINVAL. The einval_arg field will be set to the field number (starting with 1 for the version field) of the field that had an invalid value. A value of 0 for the einval_arg field indicates no additional information on the failure is available.

DK_PASSTHRU (continued)

DK_PASSTHRU operations are further subdivided into requests which quiesce other I/O prior to issuing the request and requests that do not quiesce I/O. These subdivisions are based on the devflags field of the sc_passthru structure. When the devflags field of the sc_passthru structure has a value of SC_MIX_IO, the DK_PASSTHRU operation will be mixed with other I/O requests. SC_MIX_IO requests that write data to devices are prohibited and will fail. When this happens -1 is returned, and the errno global variable is set to EINVAL. When the devflags field of the sc_passthru structure has a value of SC_QUIESCE_IO, all other I/O requests will be quiesced before the DK_PASSTHRU request is issued to the device. If an SC_QUIESCE_IO request has its timeout_value field set to 0, the DK_PASSTHRU request will be failed with a return code of -1, the errno global variable will be set to EINVAL, and the einval_arg field will be set to a value of SC_PASSTHRU_INV_TO (defined in the /usr/include/sys/scsi.h file). If an SC_QUIESCE_IO request has a nonzero timeout value that is too large for the device, the DK_PASSTHRU request will be failed with a return code of -1, the errno global variable will be set to EINVAL, the einval_arg field will be set to a value of SC_PASSTHRU_INV_TO (defined in the /usr/include/sys/scsi.h file), and the timeout_value will be set to the largest allowed value.

Note: The following two paragraphs pertain only to AIX 5L™ with 5200-03 and later.
The version field of the sc_passthru structure can be set to the value of SC_VERSION_2, and the user can provide the following fields:
  • variable_cdb_ptr is a pointer to a buffer that contains the Variable SCSI cdb.
  • variable_cdb_length determines the length of the cdb variable to which the variable_cdb_ptr field points.
On completion of the DK_PASSTHRU ioctl request, the residual field will indicate the leftover data that device did not fully satify for this request. On a successful completion, the residual field would indicate the device does not have the all data that is requested or the device has less then the amount of data that is requested. On a failure completion, the user needs to check the status_validity field to determine if a valid SCSI bus problem exists. In this case, the residual field would indicate the number bytes that the device failed to complete for this request.
 

The devinfo structure defines the maximum transfer size for the command. If an attempt is made to transfer more than the maximum transfer size, the subroutine returns a value of -1, sets the errno global variable to a value of EINVAL, and sets the einval_arg field to a value of SC_PASSTHRU_INV_D_LEN (defined in the /usr/include/sys/scsi.h file).

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

DKPRES_READKEYS

When the device is successfully opened, the DKPRES_READKEYS operation provides a means to read the Persistent Reserve Registration Keys on the device. The arg parameter to the DKPRES_READKEYS contains the address of the dk_pres_in structure. This structure is defined in /usr/include/sys/scdisk.h. The user must provide a buffer area and size for the registered keys to be returned. The returned_length variable sets the number of bytes returned.

In a shared-access or clustered environment, this operation identifies all registered keys for a particular lun.

Note: For the DKPRES_READKEYS operation and following Persistent Reserve related operation, the interpretation of the returned value and scsi status is as follows:
  • On successful attempt of the call, a 0 is returned.
  • After a call fails, a -1 is returned and the errno global variable is set. For a specific description of the errno value, refer to /usr/include/erno.h. In addition, the SCSI status, along with the Sense Code, ASC and ASCQ, will be set to provide further information on why the command failed. Refer to SCSI Specification on the interpretation of the SCSI status failure code.
DKPRES_READRES

When the device is successfully opened, the DKPRES_READRES operation provides a means to read the Persistent Reserve Reservation Keys on the device. The arg parameter to the DKPRES_READKEYS contains the address of the dk_pres_in structure. This structure is defined in /usr/include/sys/scdisk.h. The user must provide a buffer area and size for the reservation information to be returned. The returned_length variable sets the number of bytes returned. In a shared-access or clustered environment, this operation identifies the primary initiator that holds the reservation.

DKPRES_CLEAR

When the device is successfully opened, the DKPRES_CLEAR operation provides a means to clear all Persistent Reserve Reservation Keys and Registration Keys on the device. The arg parameter to DKPRES_CLEAR contains the address of the dk_pres_clear structure. This structure is defined in /usr/include/sys/scdisk.h.

Attention: Attention: Exercise care when issuing the DKPRES_CLEAR operation. This operation leaves the device unreserved, which could allow a foreign initiator to access the device.
DKPRES_PREEMPT

When the device is successfully opened, the DKPRES_PREEMPT operation provides a means to preempt a Persistent Reserve Reservation Key or Registration Key on the device. The arg parameter to the DKPRES_PREEMPT contains the address of the dk_pres_preempt structure. This structure is defined in /usr/include/sys/scdisk.h. The user must provide the second party initiator key on the device to be preempted. If the second party initiator holds the reservation to the device, then the initiator that issues the preemption becomes the owner of the reservation. Otherwise, the second party initiator access is revoked.

In order for this operation to succeed, the initiator must be registered with the device first before any preemption can occur. In a shared-access or clustered environment, this operation is used to preempt any operative or inoperative initiator, or any initiator that is not recognized to be part of the shared group.

DKPRES_PREEMPT_ABORT

This operation is the same as the DKPRES_PREEMPT, except the device follows the SCSI Primary Command Specification in aborting tasks that belong to the preempted initiator.

DKPRES_REGISTER

When the device is successfully opened, the DKPRES_REGISTER operation provides a means to register a Key with the device. The Key is extracted from ODM Customize Attribute and passed to the device driver during configuration. The arg parameter to the DKPRES_REGISTER contains the address of the dk_pres_register structure. This structure is defined in /usr/include/sys/scdisk.h.

In a shared-access or clustered environment, this operation attempts a registration with the device, then follows with a read reservation to determine whether the device has been reserved. If the device is not reserved, then a reservation is placed with the device.

DK_RWBUFFER When the device has been successfully opened, the DK_RWBUFFER operation provides the means for issuing one or more SCSI Write Buffer commands to the specified device. The device driver will perform full error recovery upon failures of this operation. The DK_RWBUFFER operation differs from the DKIOCMD operation in that it does not require an exclusive open of the device (for example, openx with the ext argument of SC_DIAGNOSTIC). Thus, a DK_RWBUFFER operation can be issued to devices that are in use by others. It can be used in conjunction with the DK_PASSTHRU ioctl, which (like DK_RWBUFFER) does not require an exclusive open of the device.

The arg parameter contains the address of a sc_rwbuffer structure (defined in the /usr/include/sys/scsi.h file). Before the DK_RWBUFFER ioctl is invoked, the fields of this structure should be set according to the desired behavior. The mode field corresponds to the mode field of the SCSI Command Descriptor Block (CDB) as defined in the SCSI Primary Commands (SPC) Specification. Supported modes are listed in the header file /usr/include/sys/scsi.h.

The device driver will quiesce all other I/O from the initiator issuing the Write Buffer ioctl until the entire operation completes. Once the Write Buffer ioctl completes, all quiesced I/O will be resumed.

The SCSI status byte and the adapter status bytes are returned through the arg parameter, which contains the address of a sc_rwbuffer structure (defined in the /usr/include/sys/scsi.h file). If the DK_RWBUFFER operation fails, the subroutine returns a value of -1 and sets the errno global variable to a nonzero value. In this case, the caller should evaluate the returned status bytes to determine why the operation was unsuccessful and what recovery actions should be taken.

 

If a DK_RWBUFFER operation fails because a field in the sc_rwbuffer structure has an invalid value, the subroutine will return a value of -1 and set the errno global variable to EINVAL.

The DK_RWBUFFER ioctl allows the user to issue multiple SCSI Write Buffer commands (CDBs) to the device through a single ioctl invocation. This is useful for applications such as microcode download where the user provides a pointer to the entire microcode image, but, due to size restrictions of the device buffer(s), desires that the images be sent in fragments until the entire download is complete.

If the DK_RWBUFFER ioctl is invoked with the fragment_size member of the sc_rwbuffer struct equal to data_length, a single Write Buffer command will be issued to the device with the buffer_offset and buffer_ID of the SCSI CDB set to the values provided in the sc_rwbuffer struct.

DK_RWBUFFER (continued)
If data_length is greater than fragment_size and fragment_size is a nonzero value, multiple Write Buffer commands will be issued to the device. The number of Write Buffer commands (SCSI CDBs) issued will be calculated by dividing the data_length by the desired fragment_size. This value will be incremented by 1 if the data_length is not an even multiple of fragment_size, and the final data transfer will be the size of this residual amount. For each Write Buffer command issued, the buffer_offset will be set to the value provided in the sc_rwbuffer struct (microcode downloads to SCSD devices requires this to be set to 0). For the first command issued, the buffer_ID will be set to the value provided in the sc_rwbuffer struct. For each subsequent Write Buffer command issued, the buffer_ID will be incremented by 1 until all fragments have been sent. Writing to noncontiguous buffer_IDs through a single DK_RWBUFFER ioctl is not supported. If this functionality is desired, multiple DK_RWBUFFER ioctls must be issued with the buffer_ID set appropriately for each invocation.
Note: No I/O is quiesced between ioctl invocations.

If fragment_size is set to zero, an errno of EINVAL will be returned. If the desire is to send the entire buffer with one SCSI Write buffer command, this field should be set equal to data_length. An error of EINVAL will also be returned if the fragment_size is greater than the data_length.

The Parameter List Length (fragment_size) plus the Buffer Offset can not exceed the capacity of the specified buffer of the device. It is the responsibility of the caller of the Write Buffer ioctl to ensure that the fragment_size setting satisfies this requirement. A fragment_size larger than the device can accommodate will result in a SCSI error at the device, and the Write Buffer ioctl will simply report this error but take no action to recover.

The devinfo structure defines the maximum transfer size for the command. If an attempt is made to transfer more than the maximum transfer size, the subroutine returns a value of -1 and sets the errno global variable to a value of EINVAL. Refer to the Small Computer System Interface (SCSI) Specification for the format of the request sense data for a particular device.

DKPATHIOCMD This command is only available for MPIO capable devices. The DKPATHIOCMD command takes as input a pointer argument which points to a single scdisk_pathiocmd structure. The DKPATHIOCMD command behaves exactly like the DKIOCMD command, except that the input path is used rather than normal path selection. The DKPATHIOCMD path is used for the DKIOCMD command regardless of any path specified by a DKPATHFORCE ioctl command. A path cannot be unconfigured while it is being forced.
DKPATHFORCE This command is only available for MPIO capable devices. The DKPATHFORCE command takes as input a ushort path id. The path id should correspond to one of the path ids in CuPath ODM. The path id specifies a path to be used for all subsequent I/O commands, overriding any previous DKPATHFORCE path. A zero argument specifies that path forcing is terminated and that normal MPIO path selection is to be resumed. I/O commands sent in with the DKPATHIOCMD command will override the DKPATHFORCE option and send the I/O down the path specified in scdisk_pathiocmd structure.
DKPATHRWBUFFER This command is only available for MPIO capable devices. The DKPATHRWBUFFER command takes as input a pointer argument which points to a single scdisk_pathiocmd structure. The DKPATHRWBUFFER command behaves exactly like the DKRWBUFFER command, except that the input path is used rather than normal path selection. The DKPATHRWBUFFER path is used for the DKRWBUFFER command regardless of any path specified by a DKPATHFORCE ioctl command.
DKPATHPASSTHRU This command is only available for MPIO capable devices. The DKPATHPASSTHRU command takes as input a pointer argument which points to a single scdisk_pathiocmd structure. The DKPATHPASSTHRU command behaves exactly like the DKPASSTHRU command, except that the input path is used rather than normal path selection. The DKPATHPASSTHRU path is used for the DKPASSTHRU command regardless of any path specified by a DKPATHFORCE ioctl command.
DKPCMPASSTHRU This command is only available for MPIO capable devices. The DKPCMPASSTHRU command takes as input a structure which is PCM specific, it is not defined by AIX. The PCM specific structure is passed to the PCM directly. This structure can be used to move information to or from a PCM.

Device Requirements

SCSI fixed disk, CD-ROM, and read/write optical drives have the following hardware requirements:

Error Conditions

Possible errno values for ioctl, open, read, and write subroutines when using the scdisk device driver include:

Item Description
EACCES Indicates one of the following circumstances:
  • An attempt was made to open a device currently open in Diagnostic or Exclusive Access mode.
  • An attempt was made to open a Diagnostic mode session on a device already open.
  • The user attempted a subroutine other than an ioctl or close subroutine while in Diagnostic mode.
  • A DKIOCMD or CDIOCMD operation was attempted on a device not in Diagnostic mode.
  • A DK_CD_MODE ioctl subroutine operation was attempted on a device not in Exclusive Access mode.
  • A DKFORMAT operation was attempted on a device not in Exclusive Access mode.
EBUSY Indicates one of the following circumstances:
  • An attempt was made to open a session in Exclusive Access mode on a device already opened.
  • The target device is reserved by another initiator.
EFAULT Indicates an illegal user address.
EFORMAT Indicates the target device has unformatted media or media in an incompatible format.
EINPROGRESS Indicates a CD-ROM drive has a play-audio operation in progress.
EINVAL Indicates one of the following circumstances:
  • A DKAUDIO (play-audio) operation was attempted for a device that is not configured to use the SCSI-2 play-audio commands.
  • The read or write subroutine supplied an nbyte parameter that is not an even multiple of the block size.
  • A sense data buffer length of greater than 255 bytes is not valid for a CDIORDSE, DKIOWRSE, or DKIORDSE ioctl subroutine operation.
  • The data buffer length exceeded the maximum defined in the devinfo structure for a CDIORDSE, CDIOCMD, DKIORDSE, DKIOWRSE, or DKIOCMD ioctl subroutine operation.
  • An unsupported ioctl subroutine operation was attempted.
  • A data buffer length greater than that allowed by the CD-ROM drive is not valid for a CDIOCMD ioctl subroutine operation.
  • An attempt was made to configure a device that is still open.
  • An illegal configuration command has been given.
  • A DKPMR (Prevent Media Removal), DKAMR (Allow Media Removal), or DKEJECT (Eject Media) command was sent to a device that does not support removable media.
  • A DKEJECT (Eject Media) command was sent to a device that currently has its media locked in the drive.
  • The data buffer length exceeded the maximum defined for a strategy operation.
EIO Indicates one of the following circumstances:
  • The target device cannot be located or is not responding.
  • The target device has indicated an unrecoverable hardware error.
EMEDIA Indicates one of the following circumstances:
  • The target device has indicated an unrecoverable media error.
  • The media was changed.
EMFILE Indicates an open operation was attempted for an adapter that already has the maximum permissible number of opened devices.
ENODEV Indicates one of the following circumstances:
  • An attempt was made to access an undefined device.
  • An attempt was made to close an undefined device.
ENOTREADY Indicates no media is in the drive.
ENXIO Indicates one of the following circumstances:
  • The ioctl subroutine supplied an invalid parameter.
  • A read or write operation was attempted beyond the end of the fixed disk.
EPERM Indicates the attempted subroutine requires appropriate authority.
ESTALE Indicates a read-only optical disk was ejected (without first being closed by the user) and then either reinserted or replaced with a second optical disk.
ETIMEDOUT Indicates an I/O operation has exceeded the given timer value.
EWRPROTECT Indicates one of the following circumstances:
  • An open operation requesting read/write mode was attempted on read-only media.
  • A write operation was attempted to read-only media.

Reliability and Serviceability Information

SCSI fixed disk devices, CD-ROM drives, and read/write optical drives return the following errors:

Item Description
ABORTED COMMAND Indicates the device ended the command
ADAPTER ERRORS Indicates the adapter returned an error
GOOD COMPLETION Indicates the command completed successfully
HARDWARE ERROR Indicates an unrecoverable hardware failure occurred during command execution or during a self-test
ILLEGAL REQUEST Indicates an illegal command or command parameter
MEDIUM ERROR Indicates the command ended with an unrecoverable media error condition
NOT READY Indicates the logical unit is offline or media is missing
RECOVERED ERROR Indicates the command was successful after some recovery was applied
UNIT ATTENTION Indicates the device has been reset or the power has been turned on

Error Record Values for Media Errors

The fields defined in the error record template for fixed disk, CD-ROM, and read/write optical media errors are:

Item Description
Comment Indicates fixed disk, CD-ROM, or read/write optical media error.
Class Equals a value of H, which indicates a hardware error.
Report Equals a value of True, which indicates this error should be included when an error report is generated.
Log Equals a value of True, which indicates an error log entry should be created when this error occurs.
Alert Equals a value of False, which indicates this error is not alertable.
Err_Type Equals a value of Perm, which indicates a permanent failure.
Err_Desc Equals a value of 1312, which indicates a disk operation failure.
Prob_Causes Equals a value of 5000, which indicates media.
User_Causes Equals a value of 5100, which indicates the media is defective.
User_Actions Equals the following values:
  • 0000, which indicates problem-determination procedures should be performed
  • 1601, which indicates the removable media should be replaced and retried
Inst_Causes None.
Inst_Actions None.
Fail_Causes Equals the following values:
  • 5000, which indicates a media failure
  • 6310, which indicates a disk drive failure
Fail_Actions Equals the following values:
  • 0000, which indicates problem-determination procedures should be performed
  • 1601, which indicates the removable media should be replaced and retried
Detail_Data Equals a value of 156, 11, HEX. This value indicates hexadecimal format.
Note:
The Detail_Data field in the err_rec structure contains the sc_error_log_df structure. The err_rec structure is defined in the /usr/include/sys/errids.h file. The sc_error_log_df structure is defined in the /usr/include/sys/scsi.h file.

The sc_error_log_df structure contains the following fields:

req_sense_data
Contains the request-sense information from the particular device that had the error, if it is valid.
reserved2
Contains the segment count, which is the number of megabytes read from the device at the time the error occurred.
reserved3
Contains the number of bytes read since the segment count was last increased.

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Error Record Values for Hardware Errors

The fields defined in the error record template for fixed disk, CD-ROM, and read/write optical hardware errors, as well as hard-aborted command errors are:

Item Description
Comment Indicates fixed disk, CD-ROM, or read/write optical hardware error.
Class Equals a value of H, which indicates a hardware error.
Report Equals a value of True, which indicates this error should be included when an error report is generated.
Log Equals a value of True, which indicates an error log entry should be created when this error occurs.
Alert Equal to a value of FALSE, which indicates this error is not alertable.
Err_Type Equals a value of Perm, which indicates a permanent failure.
Err_Desc Equals a value of 1312, which indicates a disk operation failure.
Prob_Causes Equals a value of 6310, which indicates disk drive.
User_Causes None.
User_Actions None.
Inst_Causes None.
Inst_Actions None.
Fail_Causes Equals the following values:
  • 6310, which indicates a disk drive failure
  • 6330, which indicates a disk drive electronics failure
Fail_Actions Equals a value of 0000, which indicates problem-determination procedures should be performed.
Detail_Data Equals a value of 156, 11, HEX. This value indicates hexadecimal format.
Note:
The Detail_Data field in the err_rec structure contains the sc_error_log_df structure. The err_rec structure is defined in the /usr/include/sys/errids.h file. The sc_error_log_df structure is defined in the /usr/include/sys/scsi.h file.

The sc_error_log_df structure contains the following fields:

req_sense_data
Contains the request-sense information from the particular device that had the error, if it is valid.
reserved2
Contains the segment count, which is the number of megabytes read from the device at the time the error occurred.
reserved3
Contains the number of bytes read since the segment count was last increased.

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Error Record Values for Adapter-Detected Hardware Failures

The fields defined in the error record template for fixed disk, CD-ROM, and read/write optical media errors adapter-detected hardware errors are:

Item Description
Comment Indicates adapter-detected fixed disk, CD-ROM, or read/write optical hardware failure.
Class Equals a value of H, which indicates a hardware error.
Report Equals a value of True, which indicates this error should be included when an error report is generated.
Log Equals a value of True, which indicates an error-log entry should be created when this error occurs.
Alert Equal to a value of FALSE, which indicates this error is not alertable.
Err_Type Equals a value of Perm, which indicates a permanent failure.
Err_Desc Equals a value of 1312, which indicates a disk operation failure.
Prob_Causes Equals the following values:
  • 3452, which indicates a device cable failure
  • 6310, which indicates a disk drive failure
User_Causes None.
User_Actions None.
Inst_Causes None.
Inst_Actions None.
Fail_Causes Equals the following values:
  • 3452, which indicates a storage device cable failure
  • 6310, which indicates a disk drive failure
  • 6330, which indicates a disk-drive electronics failure
Fail_Actions Equals a value of 0000, which indicates problem-determination procedures should be performed.
Detail_Data Equals a value of 156, 11, HEX. This value indicates hexadecimal format.
Note:
The Detail_Data field in the err_rec structure contains the sc_error_log_df structure. The err_rec structure is defined in the /usr/include/sys/errids.h file. The sc_error_log_df structure is defined in the /usr/include/sys/scsi.h file.

The sc_error_log_df structure contains the following fields:

req_sense_data
Contains the request-sense information from the particular device that had the error, if it is valid.
reserved2
Contains the segment count, which is the number of megabytes read from the device at the time the error occurred.
reserved3
Contains the number of bytes read since the segment count was last increased.

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Error Record Values for Recovered Errors

The fields defined in the error record template for fixed disk, CD-ROM, and read/write optical media errors recovered errors are:

Item Description
Comment Indicates fixed disk, CD-ROM, or read/write optical recovered error.
Class Equals a value of H, which indicates a hardware error.
Report Equals a value of True, which indicates this error should be included when an error report is generated.
Log Equals a value of True, which indicates an error log entry should be created when this error occurs.
Alert Equal to a value of FALSE, which indicates this error is not alertable.
Err_Type Equals a value of Temp, which indicates a temporary failure.
Err_Desc Equals a value of 1312, which indicates a physical volume operation failure.
Prob_Causes Equals the following values:
  • 5000, which indicates a media failure
  • 6310, which indicates a disk drive failure
User_Causes Equals a value of 5100, which indicates media is defective.
User_Actions Equals the following values:
  • 0000, which indicates problem-determination procedures should be performed
  • 1601, which indicates the removable media should be replaced and retried
Inst_Causes None.
Inst_Actions None.
Fail_Causes Equals the following values:
  • 5000, which indicates a media failure
  • 6310, which indicates a disk drive failure
Fail_Actions Equals the following values:
  • 0000, which indicates problem-determination procedures should be performed
  • 1601, which indicates the removable media should be replaced and retried
Detail_Data Equals a value of 156, 11, HEX. This value indicates hexadecimal format.
Note:
The Detail_Data field in the err_rec structure contains the sc_error_log_df structure. The err_rec structure is defined in the /usr/include/sys/errids.h file. The sc_error_log_df structure is defined in the /usr/include/sys/scsi.h file.

The sc_error_log_df structure contains the following fields:

req_sense_data
Contains the request-sense information from the particular device that had the error, if it is valid.
reserved2
Contains the segment count, which is the number of megabytes read from the device at the time the error occurred.
reserved3
Contains the number of bytes read since the segment count was last increased.

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Error Record Values for Unknown Errors

The fields defined in the error record template for fixed disk, CD-ROM, and read/write optical media errors unknown errors are:

Item Description
Comment Indicates fixed disk, CD-ROM, or read/write optical unknown failure.
Class Equals a value of H, which indicates a hardware error.
Report Equals a value of True, which indicates this error should be included when an error report is generated.
Log Equals a value of True, which indicates an error log entry should be created when this error occurs.
Alert Equal to a value of FALSE, which indicates this error is not alertable.
Err_Type Equals a value of Unkn, which indicates the type of error is unknown.
Err_Desc Equals a value of FE00, which indicates an undetermined error.
Prob_Causes Equals the following values:
  • 3300, which indicates an adapter failure
  • 5000, which indicates a media failure
  • 6310, which indicates a disk drive failure
User_Causes None.
User_Actions None.
Inst_Causes None.
Inst_Actions None.
Fail_Causes Equals a value of FFFF, which indicates the failure causes are unknown.
Fail_Actions Equals the following values:
  • 0000, which indicates problem-determination procedures should be performed
  • 1601, which indicates the removable media should be replaced and retried
Detail_Data Equals a value of 156, 11, HEX. This value indicates hexadecimal format.
Note:
The Detail_Data field in the err_rec structure contains the sc_error_log_df structure. The err_rec structure is defined in the /usr/include/sys/errids.h file. The sc_error_log_df structure is defined in the /usr/include/sys/scsi.h file.

The sc_error_log_df structure contains the following fields:

req_sense_data
Contains the request-sense information from the particular device that had the error, if it is valid.
reserved2
Contains the segment count, which is the number of megabytes read from the device at the time the error occurred.
reserved3
Contains the number of bytes read since the segment count was last increased.

Refer to the Small Computer System Interface (SCSI) Specification for the format of the request-sense data for a particular device.

Special Files

The scdisk SCSI device driver uses raw and block special files in performing its functions.

Attention: Data corruption, loss of data, or loss of system integrity (system crash) will occur if devices supporting paging, logical volumes, or mounted file systems are accessed using block special files. Block special files are provided for logical volumes and disk devices and are solely for system use in managing file systems, paging devices, and logical volumes. These files should not be used for other purposes.

The special files used by the scdisk device driver include the following (listed by type of device):