home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / aspio02.zip / scsi.h < prev    next >
Text File  |  1999-08-17  |  15KB  |  450 lines

  1. /*
  2.  * $Source: r:/source/aspi/RCS/scsi.h,v $
  3.  * $Revision: 1.5 $
  4.  * $Date: 1999/08/18 02:13:02 $
  5.  * $Locker:  $
  6.  *
  7.  *    Describes SCSI structures.  Created from DDK header with
  8.  *    same name, so IBM copyrights may be active?
  9.  *    Expanded to contain more opcodes, mode pages, ...
  10.  *
  11.  * $Log: scsi.h,v $
  12.  * Revision 1.5  1999/08/18 02:13:02  vitus
  13.  * - added SCSI_READ_DEFECT_DATA_*
  14.  *
  15.  * Revision 1.4  1998/03/03 03:13:17  vitus
  16.  * added SCSI_MODEPAGE_D typedef
  17.  *
  18.  * Revision 1.3  1997/09/22 02:33:18  vitus
  19.  * added typedefs for some mode pages
  20.  *
  21.  * Revision 1.2  1997/09/21 03:52:09  vitus
  22.  * added sample interesting mode pages (2,8,10)
  23.  *
  24.  * Revision 1.1  1997/09/17 02:17:48  vitus
  25.  * Initial revision
  26.  * ----------------------------------------
  27.  * Sample code to demonstrate use of ASPI Interface.
  28.  */
  29.  
  30.  
  31.  
  32. /* Typedefs to resolve forward references */
  33.  
  34. #if !defined(__IBMC__)  &&  !defined(__EMX__)
  35. typedef struct _SCSIReqSenseData    SCSI_REQSENSE_DATA;
  36. typedef struct _SCSIReqSenseData FAR *    PSCSI_REQSENSE_DATA;
  37. typedef struct _SCSIReqSenseData *    NPSCSI_REQSENSE_DATA;
  38.  
  39. typedef struct _SCSICDB6    SCSICDB6;
  40. typedef struct _SCSICDB6 FAR *    PSCSICDB6;
  41. typedef struct _SCSICDB6 *    NPSCSICDB6;
  42.  
  43. typedef struct _SCSICDB10    SCSICDB10;
  44. typedef struct _SCSICDB10 FAR *    PSCSICDB10;
  45. typedef struct _SCSICDB10 *    NPSCSICDB10;
  46.  
  47. typedef struct _SCSICDB12    SCSICDB12;
  48. typedef struct _SCSICDB12 FAR *    PSCSICDB12;
  49. typedef struct _SCSICDB12 *    NPSCSICDB12;
  50.  
  51. typedef struct  _SCSIStatusBlock    SCSI_STATUS_BLOCK;
  52. typedef struct  _SCSIStatusBlock FAR *    PSCSI_STATUS_BLOCK;
  53. typedef struct  _SCSIStatusBlock *    NPSCSI_STATUS_BLOCK;
  54.  
  55. typedef struct  _SCSIInqData        SCSI_INQDATA;
  56. typedef struct  _SCSIInqData FAR *    PSCSI_INQDATA;
  57. typedef struct  _SCSIInqData *        NPSCSI_INQDATA;
  58. #endif
  59.  
  60. /*
  61. **    General SCSI definitions
  62. */
  63.  
  64.  
  65. /*
  66. **  SCSI Operation Codes
  67. */
  68.  
  69. #define SCSI_TEST_UNIT_READY    0x00    /* Test Unit Ready */
  70. #define SCSI_REZERO_UNIT    0x01    /* CD-ROM rezero unit */
  71. #define SCSI_REWIND        0x01    /* Tape Rewind */
  72. #define SCSI_REQUEST_SENSE    0x03    /* Request Sense Command */
  73. #define SCSI_READ_BLK_LIMITS    0x05    /* Read Block Limits */
  74. #define SCSI_REQ_AUX_SENSE    0x06    /* Request Auxiliary Sense */
  75. #define SCSI_REASSIGN_BLOCKS    0x07    /* Reassign Blocks */
  76. #define SCSI_READ_6        0x08    /* SCSI 6 byte Read */
  77. #define SCSI_WRITE_6        0x0A    /* SCSI 6 byte Write */
  78. #define SCSI_SEEK_6        0x0B    /* SCSI 6 byte Seek */
  79. #define SCSI_WRITE_FILEMARKS    0x10    /* Tape Write Filemarks */
  80. #define SCSI_SPACE        0x11    /* Tape Space */
  81. #define SCSI_INQUIRY        0x12    /* Inquiry command */
  82. #define SCSI_RECOVER_BUFFER    0x14    /* Tape Recover Buffer */
  83. #define SCSI_MODE_SELECT    0x15    /* Mode Select */
  84. #define SCSI_RESERVE_UNIT    0x16    /* Tape Reserve Unit */
  85. #define SCSI_RELEASE_UNIT    0x17    /* Tape Release Unit */
  86. #define SCSI_ERASE        0x19    /* Tape Erase */
  87. #define SCSI_MODE_SENSE        0x1A    /* Mode Sense */
  88. #define SCSI_START_STOP_UNIT    0x1B    /* Start/Stop Unit */
  89. #define SCSI_LOAD_UNLOAD    0x1B    /* Tape Load/Unload Media */
  90. #define SCSI_SEND_DIAGNOSTIC    0x1D    /* Send Diagnostic */
  91. #define SCSI_LOCK_UNLOCK    0x1E    /* Lock/Unlock drive door */
  92. #define SCSI_READ_CAPACITY    0x25    /* Read Capacity */
  93. #define SCSI_READ_10        0x28    /* SCSI 10 byte Read */
  94. #define SCSI_WRITE_10        0x2A    /* SCSI 10 byte Write */
  95. #define SCSI_SEEK_10        0x2B    /* SCSI 10 byte Seek */
  96. #define SCSI_LOCATE        0x2B    /* Tape Locate */
  97. #define SCSI_WRITE_VERIFY_10    0x2E    /* SCSI 10 byte Write w/Verify */
  98. #define SCSI_VERIFY_10        0x2F    /* SCSI 10 byte Verify */
  99. #define SCSI_PREFETCH        0x34    /* Prefetch */
  100. #define SCSI_READ_DEFECT_DATA    0x37    /* Primary or Grown Defects */
  101. #define SCSI_READ_SUB_CHAN    0x42    /* Read Sub-Channel (CD-ROM) */
  102. #define SCSI_READ_TOC        0x43    /* Read Table of Contents */
  103. #define SCSI_READ_HEADER    0x44    /* Read Header */
  104. #define SCSI_PLAY_AUDIO_10    0x45    /* Play Audio 10 byte */
  105. #define SCSI_PLAY_MSF        0x47    /* Play Audio - MSF format */
  106. #define SCSI_PLAY_TRACK_INDEX    0x48    /* Play Audio - Track Index */
  107. #define SCSI_PLAY_TRACK_REL    0x49    /* Play Audio - Track Relative */
  108. #define SCSI_PAUSE_RESUME    0x4B    /* Pause/Resume Audio Play */
  109. #define SCSI_MODE_SELECT_10    0x55    /* Mode Select */
  110. #define SCSI_MODE_SENSE_10    0x5A    /* SCSI 10 Mode Sense */
  111. #define SCSI_PLAY_AUDIO_12    0xA5    /* Play Audio - 12 byte */
  112. #define SCSI_READ_12        0xA8    /* SCSI 12 byte read */
  113. #define SCSI_PLAY_TRACK_REL_12    0xA9    /* Play Audio - Trace Relative 12 */
  114. #define SCSI_READ_DEFECT_DATA_12 0xB7    /* Primary or Grown Defects */
  115.  
  116.  
  117.  
  118.  
  119. /*
  120. **  SCSI Command Descriptor Block
  121. */
  122.  
  123.  
  124.  
  125. typedef struct _SCSICDB6 { /* CDB6 - 6 byte Command Descriptor Block*/
  126.  
  127.     UCHAR    Opcode;            /* CDB Operation Code           */
  128.     UCHAR    Lun_MsbLBA;        /* SCSI LUN & 5 MSB bits of LBA */
  129.     UCHAR    MidLBA;            /* SCSI MID byte of LBA */
  130.     UCHAR    LsbLBA;            /* SCSI LBA byte of LBA */
  131.     UCHAR    XferLen;        /* SCSI Xfer length, Alloc length */
  132.     UCHAR    Control;        /* Control byte */
  133.  
  134. } SCSICDB6,FAR *PSCSICDB6, *NPSCSICDB6;
  135.  
  136.  
  137.  
  138. typedef struct _SCSICDB10 { /* CDB10 - 10 byte Command Descriptor Block*/
  139.  
  140.     UCHAR    Opcode;            /* CDB Operation Code */
  141.     UCHAR    Lun;            /* SCSI */
  142.     UCHAR    LBA[4];            /* SCSI LBA MSB->LSB */
  143.     UCHAR    Res;            /* reserved byte */
  144.     UCHAR    XferLen[2];        /* SCSI Xfer length (MSB first) */
  145.     UCHAR    Control;        /* Control byte */
  146.  
  147. } SCSICDB10,FAR *PSCSICDB10, *NPSCSICDB10;
  148.  
  149.  
  150. typedef struct _SCSICDB12 { /* CDB12 - 12 byte Command Descriptor Block*/
  151.  
  152.     UCHAR    Opcode;            /* CDB Operation Code */
  153.     UCHAR    Lun;            /* SCSI */
  154.     UCHAR    LBA[4];            /* SCSI LBA MSB->LSB */
  155.     UCHAR    XferLen[4];        /* SCSI Xfer length (MSB first) */
  156.     UCHAR    Res;            /* reserved byte */
  157.     UCHAR    Control;        /* Control byte */
  158.  
  159. } SCSICDB12, FAR *PSCSICDB12, *NPSCSICDB12;
  160.  
  161.  
  162. /*
  163. ** SCSI Status byte codes
  164. */
  165.  
  166.  
  167. #define SCSI_STAT_GOOD        0x00    /* Good status */
  168. #define SCSI_STAT_CHECKCOND    0x02    /* SCSI Check Condition */
  169. #define SCSI_STAT_CONDMET    0x04    /* Condition Met */
  170. #define SCSI_STAT_BUSY        0x08    /* Target busy status */
  171. #define SCSI_STAT_INTER        0x10    /* Intermediate status */
  172. #define SCSI_STAT_INTERCONDMET    0x14    /* Intermediate condition met */
  173. #define SCSI_STAT_RESCONFLICT    0x18    /* Reservation conflict */
  174. #define SCSI_STAT_CMDTERM    0x22    /* Command Terminated */
  175. #define SCSI_STAT_QUEUEFULL    0x28    /* Queue Full */
  176.  
  177.  
  178.  
  179. /*
  180. **  Request Sense Data format
  181. */
  182.  
  183. typedef struct  _SCSIReqSenseData { /* REQSEN */
  184.  
  185.     UCHAR    ErrCode_Valid;        /* Error Code & Valid bit */
  186.     UCHAR    SegNum;            /* Segment Number */
  187.     UCHAR    SenseKey;        /* Sense Key,ILI,EOM, FM */
  188.     UCHAR    INFO[4];        /* information field */
  189.     UCHAR    AddLen;            /* additional length */
  190.     UCHAR    CmdInfo[4];        /* command-specific info */
  191.     UCHAR    AddSenseCode;        /* additional sense code */
  192.     UCHAR    AddSenseCodeQual;    /* additional sense code qualifier */
  193.     UCHAR    FieldRepUnitCode;    /* field replaceable unit code */
  194.     UCHAR    KeySpecific[3];        /* Sense-key specific */
  195.  
  196. } SCSI_REQSENSE_DATA, FAR *PSCSI_REQSENSE_DATA, *NPSCSI_REQSENSE_DATA;
  197.  
  198.  
  199.  
  200. /*
  201. **  Sense Data bit masks
  202. */
  203.  
  204.  
  205. /* Byte 0 of sense data */
  206.  
  207.  
  208. #define SCSI_ERRCODE_MASK    0x7F    /* Error Code */
  209. #define SCSI_VALID_MASK        0x80    /* Information field valid bit */
  210.  
  211.  
  212.  
  213. /* Byte 2 of sense data */
  214.  
  215.  
  216. #define SCSI_SENSEKEY_MASK    0xF    /* Sense key */
  217. #define SCSI_INCORRECT_LEN    0x20    /* Incorrect lenght indicator */
  218. #define SCSI_SENSE_ENDOFMEDIUM    0x40    /* End-of-medium bit */
  219. #define SCSI_SENSE_FM        0x80    /* filemark bit */
  220.  
  221.  
  222.  
  223. /*
  224. **  Sense Key definitions
  225. */
  226.  
  227.  
  228. #define SCSI_SK_NOSENSE        0x00    /* No sense */
  229. #define SCSI_SK_RECERR        0x01    /* Recovered Error */
  230. #define SCSI_SK_NOTRDY        0x02    /* Not Ready Error */
  231. #define SCSI_SK_MEDIUMERR    0x03    /* Medium Error */
  232. #define SCSI_SK_HARDWAREERR    0x04    /* HardWare Error */
  233. #define SCSI_SK_ILLEGALREQ    0x05    /* Illegal Request */
  234. #define SCSI_SK_UNITATTN    0x06    /* Unit Attention */
  235. #define SCSI_SK_DATAPROTECT    0x07    /* Data Protect Error */
  236. #define SCSI_SK_BLANKCHK    0x08    /* Blank Check */
  237. #define SCSI_SK_COPYABORT    0x0A    /* Copy Aborted */
  238. #define SCSI_SK_ABORTEDCMD    0x0B    /* Aborted Command */
  239. #define SCSI_SK_EQUAL        0x0C    /* Equal Comparison satisfied */
  240. #define SCSI_SK_VOLOVERFLOW    0x0D    /* Volume Overflow */
  241. #define SCSI_SK_MISCOMPARE    0x0E    /* Miscompare */
  242.  
  243.  
  244. /*
  245. **  Additional Sense Code definitions
  246. */
  247.  
  248.  
  249. #define ASC_NO_SEEK_COMPLETE        0x02
  250. #define ASC_UNIT_NOT_READY        0x04
  251. #define ASC_UNIT_COMM_FAIL        0x08
  252. #define ASC_SERVO_FAIL            0x09
  253. #define ASC_UNRECOVERED_ERROR        0x11
  254. #define ASC_NO_ADDRESS_MARK        0x12
  255. #define ASC_SEEK_POSITIONING_ERROR    0x15
  256. #define ASC_DATA_SYNC_ERROR        0x16
  257. #define ASC_INVALID_COMMAND_OPCODE    0x20
  258. #define ASC_ILLEGAL_LBA            0x21
  259. #define ASC_INVALID_FIELD        0x24
  260. #define ASC_UNIT_NOT_SUPPORTED        0x25
  261. #define ASC_INVALID_PARMLIST        0x26
  262. #define ASC_MEDIUM_CHANGED        0x28
  263. #define ASC_RESET            0x29
  264. #define ASC_INCOMPATIBLE_CARTRIDGE    0x30
  265. #define ASC_INTERNAL_TARGET_FAIL    0x44
  266. #define ASC_TOC_RECOVERY_FAIL        0x57
  267. #define ASC_END_USER_AREA        0x63
  268. #define ASC_ILLEGAL_MODE_FOR_TRACK    0x64
  269.  
  270. #define ASCV_NOT_AUDIO_TRACK        0x88
  271. #define ASCV_NOT_DATA_TRACK        0x89
  272. #define ASCV_NOT_AUDIO_PLAY_STATE    0x8A
  273.  
  274.  
  275. /*
  276. ** SCSI IORB StatusBlock definition
  277. */
  278.  
  279. #define SCSI_DIAGINFO_LEN    8
  280.  
  281. typedef struct  _SCSIStatusBlock { /* STATBLK */
  282.  
  283.     USHORT    Flags;            /* Status block flags */
  284.     USHORT    AdapterErrorCode;    /* Translated Adapter Error */
  285.     UCHAR    TargetStatus;        /* SCSI status codes */
  286.     ULONG    ResidualLength;        /* Residual Length */
  287.     UCHAR    AdapterDiagInfo[SCSI_DIAGINFO_LEN]; /* Raw adapter status */
  288.     USHORT    ReqSenseLen;        /* amount of RS data requested */
  289.     PSCSI_REQSENSE_DATA    SenseData;    /* pointer to Req Sense Data */
  290.  
  291. } SCSI_STATUS_BLOCK, FAR *PSCSI_STATUS_BLOCK, *NPSCSI_STATUS_BLOCK;
  292.  
  293. /* Status Block flags definitions */
  294.  
  295. #define STATUS_SENSEDATA_VALID    0x0001    /* Sense Data Valid */
  296. #define STATUS_RESIDUAL_VALID    0x0002    /* Residual Byte Count Valid */
  297. #define STATUS_DIAGINFO_VALID    0x0004    /* Diagnostic Information Valid */
  298.  
  299.  
  300. /*
  301. **  Inquiry Data format
  302. */
  303.  
  304. typedef struct  _SCSIInqData { /* INQ */
  305.  
  306.     UCHAR    DevType;        /* Periph Qualifier & Periph Dev Type */
  307.     UCHAR    RMB_TypeMod;        /* rem media bit & Dev Type Modifier */
  308.     UCHAR    Vers;            /* ISO, ECMA, & ANSI versions */
  309.     UCHAR    RDF;            /* AEN, TRMIOP, & response data format */
  310.     UCHAR    AddLen;            /* length of additional data */
  311.     UCHAR    Res1;            /* reserved */
  312.     UCHAR    Res2;            /* reserved */
  313.     UCHAR    Flags;            /* RelADr,Wbus32,Wbus16,Sync,etc. */
  314.     UCHAR    VendorID[8];        /* Vendor Identification */
  315.     UCHAR    ProductID[16];        /* Product Identification */
  316.     UCHAR    ProductRev[4];        /* Product Revision */
  317.  
  318. } SCSI_INQDATA, FAR *PSCSI_INQDATA, *NPSCSI_INQDATA;
  319.  
  320.  
  321. /*  Inquiry byte 0 masks */
  322.  
  323.  
  324. #define SCSI_DEVTYPE        0x1F    /* Peripheral Device Type */
  325. #define SCSI_PERIPHQUAL        0xE0    /* Peripheral Qualifier */
  326.  
  327.  
  328. /*  Inquiry byte 1 mask */
  329.  
  330. #define SCSI_REMOVABLE_MEDIA    0x80    /* Removable Media bit (1=removable) */
  331.  
  332.  
  333. /*  Peripheral Device Type definitions */
  334.  
  335.  
  336. #define SCSI_DASD        0x00    /* Direct-access Device */
  337. #define SCSI_SEQACESS        0x01    /* Sequential-access device */
  338. #define SCSI_PRINTER        0x02    /* Printer device */
  339. #define SCSI_PROCESSOR        0x03    /* Processor device */
  340. #define SCSI_WRITEONCE        0x04    /* Write-once device */
  341. #define SCSI_CDROM        0x05    /* CD-ROM device */
  342. #define SCSI_SCANNER        0x06    /* Scanner device */
  343. #define SCSI_OPTICAL        0x07    /* Optical memory device */
  344. #define SCSI_MEDCHGR        0x08    /* Medium changer device */
  345. #define SCSI_COMM        0x09    /* Communications device */
  346. #define SCSI_NODEV        0x1F    /* Unknown or no device type */
  347.  
  348.  
  349.  
  350. /*
  351. ** Inquiry flag definitions (Inq data byte 7)
  352. */
  353.  
  354. #define SCSI_INQ_RELADR        0x80    /* device supports relative addressing */
  355. #define SCSI_INQ_WBUS32        0x40    /* device supports 32 bit data xfers */
  356. #define SCSI_INQ_WBUS16        0x20    /* device supports 16 bit data xfers */
  357. #define SCSI_INQ_SYNC        0x10    /* device supports synchronous xfer */
  358. #define SCSI_INQ_LINKED        0x08    /* device supports linked commands */
  359. #define SCSI_INQ_CMDQUEUE    0x02    /* device supports command queueing */
  360. #define SCSI_INQ_SFTRE        0x01    /* device supports soft resets */
  361.  
  362.  
  363.  
  364. /*
  365.  * Some mode pages
  366.  */
  367.  
  368. typedef struct _SCSI_MODEPAGE_HDR {
  369.  
  370.     UCHAR    len;
  371.     UCHAR    medium;
  372.     UCHAR    specific;
  373.     UCHAR    descrlen;
  374.  
  375. } SCSI_MODEPAGE_HDR, * PSCSI_MODEPAGE_HDR;
  376.  
  377.  
  378. typedef struct _SCSI_MODEPAGE_DESCR {
  379.  
  380.     UCHAR    density;
  381.     UCHAR    blocks[3];
  382.     UCHAR    reserved;
  383.     UCHAR    blklen[3];
  384.  
  385. } SCSI_MODEPAGE_DESCR, * PSCSI_MODEPAGE_DESCR;
  386.  
  387.  
  388.  
  389. typedef struct _SCSI_MODEPAGE_2 {        /* disconnect-reconnect */
  390.  
  391.     UCHAR    pcode;                /* <0:5> page code
  392.                            <7>   page is savable */
  393.     UCHAR    plength;            /* excluding this field */
  394.     UCHAR    bfull;                /* reads: x/256 before device
  395.                            reconnects */
  396.     UCHAR    bempty;                /* write: x/256 before device
  397.                            reconnects */
  398.     UCHAR    businactive[2];            /* max time in 100us */
  399.     UCHAR    disconnect[2];            /* max time in 100us */
  400.     UCHAR    connect[2];            /* max time in 100us */
  401.     UCHAR    burst[2];            /* max sectors per data burst */
  402.     UCHAR    dtdc;                /* disable/enable disconnect
  403.                            in data transfers */
  404.     UCHAR    reserved[3];
  405.  
  406. } SCSI_MODEPAGE_2, * PSCSI_MODEPAGE_2;
  407.  
  408.  
  409. typedef struct _SCSI_MODEPAGE_8 {        /* caching */
  410.  
  411.     UCHAR    pcode;                /* s.a. */
  412.     UCHAR    plength;            /* s.a. */
  413.     UCHAR    cache;                /* <0>  read cache disable
  414.                            <2>  write cache enable */
  415.     UCHAR    priority;            /* pre-fetch priority */
  416.     UCHAR    disprefetch[2];            /* disable pre-fetch on long
  417.                            transfers */
  418.     UCHAR    minprefetch[2];            /* minimum pre-fetch done */
  419.     UCHAR    maxprefetch[2];            /* maximum pre-fetch done */
  420.     UCHAR    prefetchceiling[2];        /* maximum pre-fetch done */
  421.  
  422. } SCSI_MODEPAGE_8, * PSCSI_MODEPAGE_8;
  423.  
  424.  
  425. typedef struct _SCSI_MODEPAGE_A {        /* control */
  426.  
  427.     UCHAR    pcode;                /* s.a. */
  428.     UCHAR    plength;            /* s.a. */
  429.     UCHAR    reserved1;
  430.     UCHAR    queuing;            /* <0>   disable tagged queuing
  431.                            <4:7> queue algorithm */
  432.     UCHAR    events;                /* enable asynchr. events */
  433.     UCHAR    reserved2;
  434.     UCHAR    aenholdoff[2];            /* related to asynchr. events */
  435.  
  436. } SCSI_MODEPAGE_A, * PSCSI_MODEPAGE_A;
  437.  
  438.  
  439. typedef struct _SCSI_MODEPAGE_D {        /* CD-ROM */
  440.  
  441.     UCHAR    pcode;                /* s.a. */
  442.     UCHAR    plength;            /* s.a. */
  443.     UCHAR    reserved1;
  444.     UCHAR    multiplier;            /* timeout code (see SCSI-II) */
  445.     UCHAR    s_units[2];            /* ??? */
  446.     UCHAR    f_units[2];            /* ??? */
  447.  
  448. } SCSI_MODEPAGE_D, * PSCSI_MODEPAGE_D;
  449.  
  450.