Appendix F.     SCSI commands and Sense Codes

        Sometimes, if you try to access, format or verify a drive,
        you get error codes from the formatting program or BIOS
        - usually including the command that was sent to the device.

        For example, Ian Sweeney tried a "Verify Disk Media" and got
        the following message:

        Target SCSI ID: 6 SCSI CDB Sent: 25 00 00 00 00 00 00 00 00 00
        Host Adapter Status: 00h - No host adapter error
        Target Status: 02h - Check condition
        Sense Key: 0Bh
        +Sense Code: 47h
        +Sense Code Qualifier: 00h

        Now, the codes alone aren't very helpful if you don't have a
        reference handy - that's where i try to jump in <g>. I won't
        list command parameters or explain SCSI commands here, but in
        many cases you can obtain a direction where to search from the
        command that was issued and the error it creates.
        
        The case above means the host adapter sent a "Read capacity"
        command and got back a "Check Condition" status byte -
        basically an error message. When the host adapter requested
        precise error information via a REQUEST SENSE command, he got
        back a Sense Key 0Bh (Command aborted) and the Sense Code 47h
        (SCSI parity error), together with the Extended Sense Code 00h
        - in this case just a null byte to fill the sense data.
        So, this points to a potential parity problem - meaning the bus
        cable, the parity generator on the device, the parity settings
        of the device and the host adapter and possibly bad contact on
        a jumper related to parity. Of course, that means anything,
        but at least it gives a direction to start searching.

        To make this more clear - the host adapter issues a command
        and gets back a status. If this status isn't GOOD (00h), it
        has to issue a REQUEST SENSE command _immediately_ afterwards
        to ensure it gets the right sense data, not the - likely
        different - ones of a following command.
        As result of REQUEST SENSE, the hostadapter gets back up to
        255 Bytes of sense data, where the first 17 bytes are
        mandatory and all other bytes are optional - so-called
        "additional sense bytes". Those first 17 Bytes contain - with
        other information - the Error code, Sense key and Sense codes.
        The error code is simple - 70h means the error occurred at
        the actual command, while 71 means it came from an earlier
        command, for example, if a buffered write command couldn't be
        executed successfully.

        Now, let's list the various codes, starting with the SCSI
        Commands ....



F.1.    SCSI commands

        In the commands list, keep in mind that a command can have
        multiple meanings, depending on the device classes.
        For example, 1Bh means "START/STOP UNIT" for disk drives,
        "LOAD/UNLOAD" for tape drives, "STOP PRINT" for SCSI printers
        and "SCAN" for scanners - similar meanings, if applied to the
        type of device, but slightly confusing if you get a list
        containing all meanings. So, i mostly concentrate on disk
        commands here, unless stated otherwise. Commands not listed
        are either not defined, valid for specific non-disk classes
        only, or totally manufacturer specific - without even a name.

        On a second thought, i included the CDROM-specific commands
        from 42 to 4B and from A5 to B3

        SCSI commands:
        
        00 TEST UNIT READY                              mandatory
        01 REZERO UNIT or REWIND                        optional
        03 REQUEST SENSE                                mandatory
        04 FORMAT UNIT                                  mandatory
        05 READ BLOCK LIMITS            -- manufacturer specific
                                        for tape drives mandatory
        06                              -- manufacturer specific
        07 REASSIGN BLOCKS                              optional
        08 READ (06)                                    optional
        09                              -- manufacturer specific
        0A WRITE (06), PRINT for printers               optional
                                        for tape drives mandatory
        0B SEEK (06)                                    optional
        0F READ REVERSE                 -- manufacturer specific
        10 WRITE FILEMARKS                              optional
                                        for tape drives mandatory
        11 SPACE                                        optional
        12 INQUIRY                                      mandatory
        13 VERIFY (06)                  -- manufacturer specific
        14 RECOVER BUFFERED DATA        -- manufacturer specific
        15 MODE SELECT (06)                             optional
        16 RESERVE or RESERVE UNIT                      mandatory
        17 RELEASE or RELEASE UNIT                      mandatory
        18 COPY                                         optional
        19 ERASE                                        optional
                                        for tape drives mandatory
        1A MODE SENSE (06)                              optional
                                        for tape drives mandatory
        1B START/STOP UNIT                              optional
        1C RECEIVE DIAGNOSTIC RESULTS                   optional
        1D SEND DIAGNOSTICS                             mandatory
        1E PREVENT/ALLOW MEDIUM REMOVAL                 optional
        24 SET WINDOW                   -- manufacturer specific
                                           for scanners mandatory
        25 READ CAPACITY                                mandatory
        28 READ (10)                                    mandatory
        29 READ GENERATION              -- manufacturer specific
        2A WRITE (10)                                   mandatory
        2B SEEK (10)                                    optional
        2C ERASE (10)                   -- manufacturer specific
        2D READ UPDATED BLOCK           -- manufacturer specific


        SCSI commands by opcode:
        
        2E WRITE AND VERIFY (10)                        optional
        2F VERIFY (10)                                  optional
        30 SEARCH DATA HIGH (10)                        optional
        31 SEARCH DATA EQUAL (10)                       optional
        32 SEARCH DATA LOW (10)                         optional
        33 SET LIMITS (10)                              optional
        34 PRE-FETCH                                    optional
        35 SYNCHRONIZE CACHE                            optional
        36 LOCK UNLOCK CACHE                            optional
        37 READ DEFECT DATA (10)                        optional
        39 COMPARE                                      optional
        3A COPY AND VERIFY                              optional
        3B WRITE BUFFER                                 optional
        3C READ BUFFER                                  optional
        3E READ LONG                                    optional
        3F WRITE LONG                                   optional
        40 CHANGE DEFINITION                            optional
        41 WRITE SAME                                   optional
        42 READ SUB CHANNEL                 CDROM only, optional
        43 READ TOC                         CDROM only, optional
        44 READ HEADER                      CDROM only, optional
        45 PLAY AUDIO (10)                  CDROM only, optional
        47 PLAY AUDIO MSF                   CDROM only, optional
        48 PLAY AUDIO TRACK INDEX           CDROM only, optional
        49 PLAY TRACK RELATIVE (10)         CDROM only, optional
        4B PAUSE / RESUME                   CDROM only, optional
        4C LOG SELECT                                   optional
        4D LOG SENSE                                    optional
        55 MODE SELECT (10)                             optional
        5A MODE SENSE (10)                              optional
        A5 PLAY AUDIO (12)                  CDROM only, optional
        A8 READ (12)                        CDROM only, optional
        A9 PLAY TRACK RELATIVE (12)         CDROM only, optional
        AF VERIFY (12)                      CDROM only, optional
        B0 SEARCH DATA HIGH (12)            CDROM only, optional
        B1 SEARCH DATA EQUAL (12)           CDROM only, optional
        B2 SEARCH DATA LOW (12)             CDROM only, optional
        B3 SET LIMITS (12)                  CDROM only, optional



F.2.    SCSI Status Bytes

        
        00 Good              The command was completed successfully.
        02 Check Condition   The command couldn't be completed
                             successfully. Now, a REQUEST SENSE
                             command should be used to get more
                             precise information.
        04 Condition Met     Used by various commands, for example
                             SEARCH DATA, to report a positive result.
        08 Busy              The device is busy and couldn't accept
                             the command.
        10 Intermediate      GOOD status, but in a command chain.
        14 Intermediate      as 04, a positive result, but in a
           Condition Met     command chain.
        18 Reservation       At the moment, the requested LUN is
           Conflict          reserved for another SCSI device
                             - basically means "try later!"
        22 Command           The target stopped the command with a
           Terminated        TERMINATE I/O PROCESS message.
        28 Queue Full        The command should have been entered
                             in a command queue, but this queue
                             was full.

        What you will get usually are 00, 02, and 08. The other codes
        aren't likely to occur in a DOS environment, but who knows...


F.3.    SCSI Sense Keys

        The sense key is a basic error code. Depending on the sense
        key, it is neccessary to check the sense codes also to get
        information about the real error


        SCSI Sense Keys
        
        0  No Sense     No sense data are available. This means mostly
                        a successful command (besides some special
                        cases).
        1  Recovered    The last command executed successfully, but
           Error        the target needed an error correction task
        2  Not Ready    The addressed unit couldn't be accessed. It
                        might need spin-up time or operator attention
                        or the like...
        3  Medium       The command terminated with a nonrecoverable
           Error        error due to a medium flaw or data error.
                        Also, this could be used instead of "Hardware
                        Error" (key 4).
        4  Hardware     The target detected a hardware failure. This
           Error        could be a hardware error or a parity error.
        5  Illegal      The command contained an illegal parameter
           Request      somewhere in the command descriptor block or
                        in the additional parameters.
        6  Unit         Usually, Unit Attention indicates that a
           Attention    device was reset by some reasons - bus reset,
                        or a media change, or a change in the mode
                        parameters.
        7  Data         If a read or write operation is issued for a
           Protect      protected block, it is not performed and the
                        target indicates this by a "Data Protect" key.
        8  Blank        Either a medium was blank on a read operation
           Check        where it should contain data, or a write-once
                        device tried to write a non-blank sector.
        9  Vendor       In this sense key the device can give back
           specific     vendor-specific information.
        A  Copy         Indicates that a COPY, COMPARE or COPY/VERIFY
           Aborted      was aborted due to an error condition from one
                        of the involved devices.
        B  Aborted      The target aborted the command. Usually the
           Command      initiator tries to repeat the command until it
                        can be completed or a more precise error
                        condition occurs.
        C  Equal        Equal indicates a satisfactory comparison in a
                        SEARCH DATA command.
        D  Volume       Indicates that a buffered device has reached
           Overflow     the end of the volume or partition and
                        unwritten data are in the buffer. The
                        Initiator can get the unwritten data via a
                        RECOVER BUFFERED DATA command.
        E  Miscompare   indicates that the source data did not match
                        the data read from the medium.
        F  Reserved



F.4.    SCSI Sense Codes

        The sense codes contain the more precise information about the
        error. There's a bit of confusion in the naming - the spec
        officially calls the Additional Sense Code (ASQ) and
        Additional Sense Code Qualifier (ASCQ), but in "real life" the
        terms "Sense Code" and "Extended Sense Code" are mostly used.
        The following list is complete according to the SCSI-2 spec.
        Some codes are not defined in the spec, so i didn't list them.

        ASC ASCQ    DESCRIPTION
        
         00  00     no additional sense information
         00  01     filemark detected
         00  02     end-of-partition/medium detected
         00  03     setmark detected
         00  04     beginning-of-partition/medium detected
         00  05     end-of-data detected
         00  06     i/o process terminated
         00  11     audio play operation in progress
         00  12     audio play operation paused
         00  13     audio play operation successfully completed
         00  14     audio play operation stopped due to error
         00  15     no current audio status to return
         01  00     no index/sector signal
         02  00     no seek complete
         03  00     peripheral device write fault
         03  01     no write current
         03  02     excessive write errors
         04  00     logical unit not ready, cause not reportable
         04  01     logical unit is in process of becoming ready
         04  02     logical unit not ready, init. command required
         04  03     logical unit not ready, intervention required
         04  04     logical unit not ready, format in progress
         05  00     logical unit does not respond to selection
         06  00     reference position not found
         07  00     multiple peripheral devices selected
         08  00     logical unit communication failure
         08  01     logical unit communication time-out
         08  02     logical unit communication parity error
         09  00     track following error
         09  01     tracking servo failure
         09  02     focus servo failure
         09  03     spindle servo failure
         0A  00     error log overflow
         0C  00     write error
         0C  01     write error recovered with auto reallocation
         0C  02     write error - auto reallocation failed
         10  00     id crc or ecc error
         11  00     unrecovered read error
         11  01     read retries exhausted
         11  02     error too long to correct
         11  03     multiple read errors


        ASC ASCQ    DESCRIPTION
        
         11  04     unrecovered read error - auto reallocate failed
         11  05     l-ec uncorrectable error
         11  06     circ unrecovered error
         11  07     data resynchronization error
         11  08     incomplete block read
         11  09     no gap found
         11  0A     miscorrected error
         11  0B     unrecovered read error - recommend reassignment
         11  0C     unrecovered read error - recommend rewrite data
         12  00     address mark not found for id field
         13  00     address mark not found for data field
         14  00     recorded entity not found
         14  01     record not found
         14  02     filemark or setmark not found
         14  03     end-of-data not found
         14  04     block sequence error
         15  00     random positioning error
         15  01     mechanical positioning error
         15  02     positioning error detected by read of medium
         16  00     data synchronization mark error
         17  00     recovered data with no error correction applied
         17  01     recovered data with retries
         17  02     recovered data with positive head offset
         17  03     recovered data with negative head offset
         17  04     recovered data with retries and/or circ applied
         17  05     recovered data using previous sector id
         17  06     recovered data without ecc - data auto-reallocated
         17  07     recovered data without ecc - recommend reassignment
         17  08     recovered data without ecc - recommend rewrite
         18  00     recovered data with error correction applied
         18  01     recovered data with error correction & retries applied
         18  02     recovered data - data auto-reallocated
         18  03     recovered data with circ
         18  04     recovered data with lec
         18  05     recovered data - recommend reassignment
         18  06     recovered data - recommend rewrite
         19  00     defect list error
         19  01     defect list not available
         19  02     defect list error in primary list
         19  03     defect list error in grown list
         1A  00     parameter list length error
         1B  00     synchronous data transfer error
         1C  00     defect list not found
         1C  01     primary defect list not found
         1C  02     grown defect list not found
         1D  00     miscompare during verify operation
         1E  00     recovered id with ecc
         20  00     invalid command operation code
         21  00     logical block address out of range
         21  01     invalid element address
         22  00     illegal function (should use 20 00, 24 00, or 26 00)
         24  00     invalid field in cdb
         25  00     logical unit not supported
         26  00     invalid field in parameter list
         26  01     parameter not supported
         26  02     parameter value invalid
         26  03     threshold parameters not supported


        ASC ASCQ    DESCRIPTION
        
         27  00     write protected
         28  00     not ready to ready transition(medium may have changed)
         28  01     import or export element accessed
         29  00     power on, reset, or bus device reset occurred
         2A  00     parameters changed
         2A  01     mode parameters changed
         2A  02     log parameters changed
         2B  00     copy cannot execute since host cannot disconnect
         2C  00     command sequence error
         2C  01     too many windows specified
         2C  02     invalid combination of windows specified
         2D  00     overwrite error on update in place
         2F  00     command(s) cleared by another initiator
         30  00     incompatible medium installed
         30  01     cannot read medium - unknown format
         30  02     cannot read medium - incompatible format
         30  03     cleaning cartridge installed
         31  00     medium format corrupted
         31  01     format command failed
         32  00     no defect spare location available
         32  01     defect list update failure
         33  00     tape length error
         36  00     ribbon, ink, or toner failure
         37  00     rounded parameter
         39  00     saving parameters not supported
         3A  00     medium not present
         3B  00     sequential positioning error
         3B  01     tape position error at beginning-of-medium
         3B  02     tape position error at end-of-medium
         3B  03     tape or electronic vertical forms unit not ready
         3B  04     slew failure
         3B  05     paper jam
         3B  06     failed to sense top-of-form
         3B  07     failed to sense bottom-of-form
         3B  08     reposition error
         3B  09     read past end of medium
         3B  0A     read past beginning of medium
         3B  0B     position past end of medium
         3B  0C     position past beginning of medium
         3B  0D     medium destination element full
         3B  0E     medium source element empty
         3D  00     invalid bits in identify message
         3E  00     logical unit has not self-configured yet
         3F  00     target operating conditions have changed
         3F  01     microcode has been changed
         3F  02     changed operating definition
         3F  03     inquiry data has changed
         40  00     ram failure (should use 40 nn)
         40  NN     diagnostic failure on component nn (80h-ffh)
         41  00     data path failure (should use 40 nn)
         42  00     power-on or self-test failure (should use 40 nn)
         43  00     message error
         44  00     internal target failure
         45  00     select or reselect failure
         46  00     unsuccessful soft reset


        ASC ASCQ    DESCRIPTION
        
         47  00     scsi parity error
         48  00     initiator detected error message received
         49  00     invalid message error
         4A  00     command phase error
         4B  00     data phase error
         4C  00     logical unit failed self-configuration
         4E  00     overlapped commands attempted
         50  00     write append error
         50  01     write append position error
         50  02     position error related to timing
         51  00     erase failure
         52  00     cartridge fault
         53  00     media load or eject failed
         53  01     unload tape failure
         53  02     medium removal prevented
         54  00     scsi to host system interface failure
         55  00     system resource failure
         57  00     unable to recover table-of-contents
         58  00     generation does not exist
         59  00     updated block read
         5A  00     operator request or state change input (unspecified)
         5A  01     operator medium removal request
         5A  02     operator selected write protect
         5A  03     operator selected write permit
         5B  00     log exception
         5B  01     threshold condition met
         5B  02     log counter at maximum
         5B  03     log list codes exhausted
         5C  00     rpl status change
         5C  01     spindles synchronized
         5C  02     spindles not synchronized
         60  00     lamp failure
         61  00     video acquisition error
         61  01     unable to acquire video
         61  02     out of focus
         62  00     scan head positioning error
         63  00     end of user area encountered on this track
         64  00     illegal mode for this track

         80  xxh \
          through > Vendor-specific.
         FF  xxh /

         xxh 80 \
         through >  Vendor-specific QUALIFICATION OF STANDARD ASC.
         xxh FF /

