scsi_decoder.h

Go to the documentation of this file.
00001 /*This file has been prepared for Doxygen automatic documentation generation.*/
00013 
00014 /* Copyright (c) 2007, Atmel Corporation All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * 1. Redistributions of source code must retain the above copyright notice,
00020  * this list of conditions and the following disclaimer.
00021  *
00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
00023  * this list of conditions and the following disclaimer in the documentation
00024  * and/or other materials provided with the distribution.
00025  *
00026  * 3. The name of ATMEL may not be used to endorse or promote products derived
00027  * from this software without specific prior written permission.
00028  *
00029  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
00030  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00031  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
00032  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
00033  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00038  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 #ifndef _SCSI_DECODER_H_
00041 #define _SCSI_DECODER_H_
00042 
00043 //_____ M A C R O S ________________________________________________________
00044 
00045 typedef struct
00046 {
00047   U8      key;
00048   U8      asc;
00049   U8      ascq;
00050 } s_scsi_sense;
00051 
00052 
00053 //_____ D E C L A R A T I O N S ____________________________________________
00054 
00055 Bool scsi_decode_command  (void);
00056 
00057 
00058 /****************************************************************************/
00059 /* Command for all SCSI device types                                        */
00060 /****************************************************************************/
00061 
00062 // Mandatory Command set list from SBC-2
00063 // (subclass 6, peripheral device type 0, version 5)
00064 // FORMAT UNIT
00065 // INQUIRY
00066 // READ (6)
00067 // READ (10)
00068 // READ (16)
00069 // READ CAPACITY (10)
00070 // READ CAPACITY (16)
00071 // REQUEST SENSE
00072 // SEND DIAGNOSTIC
00073 // TEST UNIT READY
00074 
00075 #define SBC_CMD_TEST_UNIT_READY                   (0x00)
00076 #define SBC_CMD_REQUEST_SENSE                     (0x03)
00077 #define SBC_CMD_FORMAT_UNIT                       (0x04)
00078 #define SBC_CMD_READ_6                            (0x08)
00079 #define SBC_CMD_INQUIRY                           (0x12)
00080 #define SBC_CMD_MODE_SELECT_6                     (0x15)
00081 #define SBC_CMD_READ_FORMAT_CAPACITY              (0x23)
00082 #define SBC_CMD_MODE_SENSE_6                      (0x1A)
00083 #define SBC_CMD_START_STOP_UNIT                   (0x1B)
00084 #define SBC_CMD_RECEIVE_DIAGNOSTICS               (0x1C)
00085 #define SBC_CMD_SEND_DIAGNOSTIC                   (0x1D)
00086 #define SBC_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL      (0x1E)
00087 #define SBC_CMD_READ_LONG                         (0x23)
00088 #define SBC_CMD_READ_CAPACITY                     (0x25)
00089 #define SBC_CMD_READ_CD_ROM_CAPACITY              (0x25)
00090 #define SBC_CMD_READ_10                           (0x28)
00091 #define SBC_CMD_WRITE_10                          (0x2A)
00092 #define SBC_CMD_SEEK                              (0x2B)
00093 #define SBC_CMD_WRITE_VERIFY_10                   (0x2E)
00094 #define SBC_CMD_VERIFY_10                         (0x2F)
00095 #define SBC_CMD_SYNCHRONIZE_CACHE                 (0x35)
00096 #define SBC_CMD_WRITE_BUFFER                      (0x3B)
00097 #define SBC_CMD_CHANGE_DEFINITION                 (0x40)
00098 #define SBC_CMD_READ_TOC                          (0x43)
00099 #define SBC_CMD_MODE_SELECT_10                    (0x55)
00100 #define SBC_CMD_RESERVE_10                        (0x56)
00101 #define SBC_CMD_RELEASE_10                        (0x57)
00102 #define SBC_CMD_MODE_SENSE_10                     (0x5A)
00103 
00104 #define SBC_CONTROL_BYTE                          (0x00)
00105 #define SBC_CMD_DIR_IN                            (0x80)
00106 #define SBC_CMD_DIR_OUT                           (0x00)
00107 
00108 
00109 /****************************************************************************/
00110 /* Sense Key Code                                                           */
00111 /****************************************************************************/
00112 #define SBC_SENSE_KEY_NO_SENSE                        (0x00)
00113 #define SBC_SENSE_KEY_RECOVERED_ERROR                 (0x01)
00114 #define SBC_SENSE_KEY_NOT_READY                       (0x02)
00115 #define SBC_SENSE_KEY_MEDIUM_ERROR                    (0x03)
00116 #define SBC_SENSE_KEY_HARDWARE_ERROR                  (0x04)
00117 #define SBC_SENSE_KEY_ILLEGAL_REQUEST                 (0x05)
00118 #define SBC_SENSE_KEY_UNIT_ATTENTION                  (0x06)
00119 #define SBC_SENSE_KEY_DATA_PROTECT                    (0x07)
00120 #define SBC_SENSE_KEY_BLANK_CHECK                     (0x08)
00121 #define SBC_SENSE_KEY_VENDOR_SPECIFIC                 (0x09)
00122 #define SBC_SENSE_KEY_COPY_ABORTED                    (0x0A)
00123 #define SBC_SENSE_KEY_ABORTED_COMMAND                 (0x0B)
00124 #define SBC_SENSE_KEY_VOLUME_OVERFLOW                 (0x0D)
00125 #define SBC_SENSE_KEY_MISCOMPARE                      (0x0E)
00126 
00127 /****************************************************************************/
00128 /* ASC code assignments                                                     */
00129 /****************************************************************************/
00130 #define SBC_ASC_NO_ADDITIONAL_SENSE_INFORMATION       (0x00)
00131 #define SBC_ASC_LOGICAL_UNIT_NOT_READY                (0x04)
00132 #define SBC_ASC_INVALID_FIELD_IN_CDB                  (0x24)
00133 #define SBC_ASC_WRITE_PROTECTED                       (0x27)
00134 #define SBC_ASC_FORMAT_ERROR                          (0x31)
00135 #define SBC_ASC_INVALID_COMMAND_OPERATION_CODE        (0x20)
00136 #define SBC_ASC_NOT_READY_TO_READY_CHANGE             (0x28)
00137 #define SBC_ASC_MEDIUM_NOT_PRESENT                    (0x3A)
00138 
00139 /****************************************************************************/
00140 /* ASCQ code assignments                                                    */
00141 /****************************************************************************/
00142 #define SBC_ASCQ_FORMAT_COMMAND_FAILED                (0x01)
00143 #define SBC_ASCQ_INITIALIZING_COMMAND_REQUIRED        (0x02)
00144 #define SBC_ASCQ_OPERATION_IN_PROGRESS                (0x07)
00145 
00146 
00147 /****************************************************************************/
00148 /* REQUEST SENSE PARAMETERS                                                 */
00149 /****************************************************************************/
00150 #define SBC_RESPONSE_CODE_SENSE                       (0x70)
00151 #define SBC_ADDITIONAL_SENSE_LENGTH                   (0x0A)
00152 #define SBC_COMMAND_SPECIFIC_INFORMATION_3            (0x00)
00153 #define SBC_COMMAND_SPECIFIC_INFORMATION_2            (0x00)
00154 #define SBC_COMMAND_SPECIFIC_INFORMATION_1            (0x00)
00155 #define SBC_COMMAND_SPECIFIC_INFORMATION_0            (0x00)
00156 #define SBC_FIELD_REPLACEABLE_UNIT_CODE               (0x00)
00157 #define SBC_SENSE_KEY_SPECIFIC_2                      (0x00)
00158 #define SBC_SENSE_KEY_SPECIFIC_1                      (0x00)
00159 #define SBC_SENSE_KEY_SPECIFIC_0                      (0x00)
00160 
00161 /******* number of bytes of READ CAPACITY response *********/
00162 #define SBC_READ_CAPACITY_LENGTH                      (0x08)
00163 
00164 
00165 /****************************************************************************/
00166 /*MODE SENSE and REQUEST SENSE DEFINITIONS                                  */
00167 /****************************************************************************/
00168 
00169 /*************** Direct access medium type ****************/
00170 #define SBC_DEFAULT_MEDIUM_TYPE                       (0x00)
00171 #define SBC_FLEXIBLE_DISK_SINGLE_SIDED_UNSPECIFIED    (0x01)
00172 #define SBC_FLEXIBLE_DISK_DOUBLE_SIDED_UNSPECIFIED    (0x02)
00173 
00174 #define SBC_MEDIUM_TYPE                               SBC_DEFAULT_MEDIUM_TYPE
00175 
00176 #define SBC_DEV_SPEC_PARAM_WR_ENABLE                  (0x00)
00177 #define SBC_DEV_SPEC_PARAM_WR_PROTECT                 (0x80)
00178 #define SBC_BLOCK_DESCRIPTOR_LENGTH                   (0x00)
00179 
00180 #define SBC_MSK_DBD                                   (0x08)
00181 #define SBC_MSK_PAGE_CONTROL                          (0xC0)
00182 #define SBC_MSK_PAGE_CODE                             (0x3F)
00183 
00184 
00185 /************ General Page Code paramaters *****************/
00186 
00187 // Mode page codes for direct-access devices (list in SBC specification)
00188 #define SBC_PAGE_CODE_READ_WRITE_ERROR_RECOVERY       (0x01) // SBC
00189 #define SBC_PAGE_CODE_FORMAT_DEVICE                   (0x03) // SBC
00190 #define SBC_PAGE_CODE_FLEXIBLE_DISK                   (0x05) // SBC
00191 #define SBC_PAGE_CODE_CACHING_MODE_PAGE               (0x08) // SBC
00192 #define SBC_PAGE_CODE_INFORMATIONAL_EXCEPTIONS        (0x1C) // SPC
00193 #define SBC_PAGE_CODE_ALL                             (0x3F) // SPC
00194 
00195 #define SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS      (0x0A)
00196 #define SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY     (0x0A)
00197 #define SBC_PAGE_LENGTH_FLEXIBLE_DISK                 (0x1E)
00198 #define SBC_PAGE_LENGTH_FORMAT_DEVICE                 (0x16)
00199 
00200 
00201 
00202 #define SBC_MODE_DATA_LENGTH_INFORMATIONAL_EXCEPTIONS   (SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + 3)
00203 #define SBC_MODE_DATA_LENGTH_READ_WRITE_ERROR_RECOVERY  (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + 3 )
00204 #define SBC_MODE_DATA_LENGTH_FLEXIBLE_DISK              (SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2 + 3 )
00205 #define SBC_MODE_DATA_LENGTH_FORMAT_DEVICE              (SBC_PAGE_LENGTH_FORMAT_DEVICE + 2 + 3 )
00206 /*SBC_PAGE_LENGTH_FLEXIBLE_DISK + 2  + \*/
00207 #define SBC_MODE_DATA_LENGTH_CODE_ALL                 (SBC_PAGE_LENGTH_READ_WRITE_ERROR_RECOVERY + 2 + \
00208                                                        SBC_PAGE_LENGTH_INFORMATIONAL_EXCEPTIONS + 2 + \
00209                                                        SBC_BLOCK_DESCRIPTOR_LENGTH + \
00210                                                        + 3 )
00211 
00212 /*                                                       SBC_MODE_DATA_LENGTH_FORMAT_DEVICE + 2 + \*/
00213 /****** Information exceptions control page parameters *****/
00214 #define SBC_MRIE                                      (0x05)
00215 
00216 /*************** Format device page parameters *************/
00217 #define SBC_TRACK_PER_ZONE_MSB                        (0x00)
00218 #define SBC_TRACK_PER_ZONE_LSB                        (0x00)
00219 #define SBC_ALTERNATE_SECTORS_PER_ZONE_MSB            (0x00)
00220 #define SBC_ALTERNATE_SECTORS_PER_ZONE_LSB            (0x00)
00221 #define SBC_ALTERNATE_TRACK_PER_ZONE_MSB              (0x00)
00222 #define SBC_ALTERNATE_TRACK_PER_ZONE_LSB              (0x00)
00223 #define SBC_ALTERNATE_TRACK_PER_LU_MSB                (0x00)
00224 #define SBC_ALTERNATE_TRACK_PER_LU_LSB                (0x00)
00225 
00226 /************* Flexible Disk page Parameters ***************/
00227 #define SBC_TRANSFER_RATE_MSB                         (0x13)
00228 #define SBC_TRANSFER_RATE_LSB                         (0x88)
00229 /* 1388h    5 Mbit/s   */
00230 /* 07D0h    2 Mbit/s   */
00231 /* 03E8h    1 Mbit/s   */
00232 /* 01F4h    500 kbit/s */
00233 /* 012Ch    300 kbit/s */
00234 /* 00FAh    250 kbit/s */
00235 
00236 #define SBC_NUMBER_OF_HEAD                            (0x04)
00237 #define SBC_SECTOR_PER_TRACK                          (0x20)
00238 #define SBC_DATA_BYTE_PER_SECTOR_MSB                  (0x02)
00239 #define SBC_DATA_BYTE_PER_SECTOR_LSB                  (0x00)
00240 #define SBC_NUMBER_OF_CYLINDERS_MSB                   (0x01)
00241 #define SBC_NUMBER_OF_CYLINDERS_LSB                   (0xE9)
00242 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_MSB  (0x00)
00243 #define SBC_STARTING_CYLINDER_WRITE_COMPENSATION_LSB  (0x00)
00244 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_MSB       (0x00)
00245 #define SBC_STARTING_CYLINDER_REDUCED_WRITE_LSB       (0x00)
00246 #define SBC_DEVICE_STEP_RATE_MSB                      (0x00)
00247 #define SBC_DEVICE_STEP_RATE_LSB                      (0x00)
00248 #define SBC_DEVICE_STEP_PULSE_WIDTH                   (0x00)
00249 #define SBC_HEAD_SETTLE_DELAY_MSB                     (0x00)
00250 #define SBC_HEAD_SETTLE_DELAY_LSB                     (0x00)
00251 #define SBC_MOTOR_ON_DELAY                            (0x00)
00252 #define SBC_MOTOR_OFF_DELAY                           (0x00)
00253 #define SBC_STEP_PULSE_PER_CYLINDER                   (0x00)
00254 #define SBC_WRITE_COMPENSATION                        (0x00)
00255 #define SBC_HEAD_LOAD_DELAY                           (0x00)
00256 #define SBC_HEAD_UNLOAD_DELAY                         (0x00)
00257 #define SBC_PIN34_PIN2                                (0x00)
00258 #define SBC_PIN4_PIN1                                 (0x00)
00259 #define SBC_MEDIUM_ROTATION_RATE_MSB                  (0x00)
00260 #define SBC_MEDIUM_ROTATION_RATE_LSB                  (0x00)
00261 
00262 /************ Read/Write Error Recovery parameters**********/
00263 #define SBC_READ_RETRY_COUNT                          (0x03)
00264 #define SBC_WRITE_RETRY_COUNT                         (0x80)
00265 #define SBC_CORRECTION_SPAN                           (0x00)
00266 #define SBC_HEAD_OFFSET_COUNT                         (0x00)
00267 #define SBC_DATA_STROBE_OFFSET                        (0x00)
00268 #define SBC_RECOVERY_LIMIT_MSB                        (0x00)
00269 #define SBC_RECOVERY_LIMIT_LSB                        (0x00)
00270 
00271 
00272 /*_____ D E F I N I T I O N ________________________________________________*/
00273 
00274 #define SBC_MAX_INQUIRY_DATA                          (0x60) // value ?
00275 
00276 struct sbc_st_std_inquiry_data
00277 {
00278   Byte    DeviceType : 5;
00279   Byte    PeripheralQualifier : 3;
00280 
00281   Byte    Reserved1 : 7;
00282   Byte    RemovableMedia : 1;
00283 
00284   Byte    Version;
00285 
00286   Byte    Reserved3 : 5;
00287   Byte    NormACA : 1;
00288   Byte    Obsolete0 : 1;
00289   Byte    AERC : 1;
00290 
00291   Byte    Reserved4[3];
00292 
00293   Byte    SoftReset : 1;
00294   Byte    CommandQueue : 1;
00295   Byte    Reserved5 : 1;
00296   Byte    LinkedCommands : 1;
00297   Byte    Synchronous : 1;
00298   Byte    Wide16Bit : 1;
00299   Byte    Wide32Bit : 1;
00300   Byte    RelativeAddressing : 1;
00301 };
00302 
00303 
00304 //_____ D E C L A R A T I O N S ____________________________________________
00305 
00306 #define Sbc_send_failed()                    (g_scsi_status = COMMAND_FAILED)
00307 #define Sbc_send_check_condition()           (g_scsi_status = CHECK_CONDITION)
00308 #define Sbc_send_good()                      (g_scsi_status = COMMAND_PASSED)
00309 #define Sbc_build_sense(skey, sasc, sascq)   ( g_scsi_sense.key  = skey, \
00310                                                g_scsi_sense.asc  = sasc, \
00311                                                g_scsi_sense.ascq = sascq )
00312 #define Sbc_valid_write_usb(length)          ( Usb_send_in(), \
00313                                                g_scsi_data_remaining -= length )
00314 
00315 
00316 #define COMMAND_PASSED                0x00
00317 #define COMMAND_FAILED                0x01
00318 #define CHECK_CONDITION               0x02
00319 #define PHASE_ERROR                   0x02
00320 
00321 
00322 Bool  sbc_inquiry                      (void);
00323 Bool  sbc_mode_sense                   ( Bool sense_10 );
00324 Bool  sbc_mode_select_6                (void);
00325 Bool  sbc_request_sense                (void);
00326 Bool  sbc_format                       (void);
00327 Bool  sbc_write_10                     (void);
00328 Bool  sbc_read_10                      (void);
00329 Bool  sbc_test_unit_ready              (void);
00330 Bool  sbc_read_capacity                (void);
00331 Bool  sbc_prevent_allow_medium_removal (void);
00332 
00333 void  sbc_lun_status_is_good           (void);
00334 void  sbc_lun_status_is_busy_or_change (void);
00335 void  sbc_lun_status_is_not_present    (void);
00336 void  sbc_lun_status_is_fail           (void);
00337 void  sbc_lun_status_is_protected      (void);
00338 void  sbc_lun_status_is_cdb_field      (void);
00339 
00340 #endif // _SCSI_DECODER_H_
00341 

Generated on Fri May 15 15:41:36 2009 for ATMEL by  doxygen 1.5.3