home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / os2tk20 / c / os2h / dasd / scsi.h__ / SCSI.H
Encoding:
C/C++ Source or Header  |  1992-07-16  |  15.8 KB  |  322 lines

  1. /*static char *SCCSID = "src/dev/dasd/diskh/scsi.h, dasd, r205, 6421 92/06/25";*/
  2.  
  3. /************************************************************************/
  4. /*                                                                      */
  5. /* Driver Name: ADD/DM - Include Files                                  */
  6. /*              ----------------------                                  */
  7. /*                                                                      */
  8. /* Source File Name: SCSI.H                                             */
  9. /*                                                                      */
  10. /* Descriptive Name: SCSI CDB Data Structures and ADD/DM Status Block   */
  11. /*                   for SCSI Devices                                   */
  12. /*                                                                      */
  13. /* Function:                                                            */
  14. /*                                                                      */
  15. /*                                                                      */
  16. /*----------------------------------------------------------------------*/
  17. /*                                                                      */
  18. /* Copyright (C) 1992 IBM Corporation                                   */
  19. /*                                                                      */
  20. /* DISCLAIMER OF WARRANTIES.  The following [enclosed] code is          */
  21. /* provided to you solely for the purpose of assisting you in           */
  22. /* the development of your applications. The code is provided           */
  23. /* "AS IS", without warranty of any kind. IBM shall not be liable       */
  24. /* for any damages arising out of your use of this code, even if        */
  25. /* they have been advised of the possibility of such damages.           */
  26. /*                                                                      */
  27. /*----------------------------------------------------------------------*/
  28. /*                                                                      */
  29. /* Change Log                                                           */
  30. /*                                                                      */
  31. /* Mark    Date      Programmer  Comment                                */
  32. /* ----    ----      ----------  -------                                */
  33. /* @6994   06/18/92  R. Berkoff  PTR CP20 B736994                       */
  34. /*                               Remove ";" from SCSI_INQ_* defines     */
  35. /*                                                                      */
  36. /************************************************************************/
  37.  
  38. /* Typedefs to resolve forward references */
  39.  
  40. typedef struct _SCSIReqSenseData    SCSI_REQSENSE_DATA;
  41. typedef struct _SCSIReqSenseData    FAR *PSCSI_REQSENSE_DATA;
  42. typedef struct _SCSIReqSenseData    *NPSCSI_REQSENSE_DATA;
  43.  
  44. typedef struct _SCSICDB6      SCSICDB6;
  45. typedef struct _SCSICDB6      FAR *PSCSICDB6;
  46. typedef struct _SCSICDB6      *NPSCSICDB6;
  47.  
  48. typedef struct _SCSICDB10     SCSICDB10;
  49. typedef struct _SCSICDB10     FAR *PSCSICDB10;
  50. typedef struct _SCSICDB10     *NPSCSICDB10;
  51.  
  52. typedef struct _SCSICDB12     SCSICDB12;
  53. typedef struct _SCSICDB12     FAR *PSCSICDB12;
  54. typedef struct _SCSICDB12     *NPSCSICDB12;
  55.  
  56. typedef struct  _SCSIStatusBlock SCSI_STATUS_BLOCK;
  57. typedef struct  _SCSIStatusBlock FAR *PSCSI_STATUS_BLOCK;
  58. typedef struct  _SCSIStatusBlock *NPSCSI_STATUS_BLOCK;
  59.  
  60. typedef struct  _SCSIInqData  SCSI_INQDATA;
  61. typedef struct  _SCSIInqData  FAR *PSCSI_INQDATA;
  62. typedef struct  _SCSIInqData  *NPSCSI_INQDATA;
  63.  
  64. /****************************************************************************/
  65. /*    General SCSI definitions                                              */
  66. /****************************************************************************/
  67.  
  68.  
  69. /***************************/
  70. /*  SCSI Operation Codes   */
  71. /***************************/
  72.  
  73. #define SCSI_TEST_UNIT_READY    0x00    /* Test Unit Ready                  */
  74. #define SCSI_REZERO_UNIT        0x01    /* CD-ROM rezero unit               */
  75. #define SCSI_REWIND             0x01    /* Tape Rewind                      */
  76. #define SCSI_REQUEST_SENSE      0x03    /* Request Sense Command            */
  77. #define SCSI_READ_BLK_LIMITS    0x05    /* Read Block Limits                */
  78. #define SCSI_REQ_AUX_SENSE      0x06    /* Request Auxiliary Sense          */
  79. #define SCSI_REASSIGN_BLOCKS    0x07    /* Reassign Blocks                  */
  80. #define SCSI_READ_6             0x08    /* SCSI 6 byte Read                 */
  81. #define SCSI_WRITE_6            0x0A    /* SCSI 6 byte Write                */
  82. #define SCSI_WRITE_FILEMARKS    0x10    /* Tape Write Filemarks             */
  83. #define SCSI_SPACE              0x11    /* Tape Space                       */
  84. #define SCSI_INQUIRY            0x12    /* Inquiry command                  */
  85. #define SCSI_RECOVER_BUFFER     0x14    /* Tape Recover Buffer              */
  86. #define SCSI_MODE_SELECT        0x15    /* Mode Select                      */
  87. #define SCSI_RESERVE_UNIT       0x16    /* Tape Reserve Unit                */
  88. #define SCSI_RELEASE_UNIT       0x17    /* Tape Release Unit                */
  89. #define SCSI_ERASE              0x19    /* Tape Erase                       */
  90. #define SCSI_MODE_SENSE         0x1A    /* Mode Sense                       */
  91. #define SCSI_START_STOP_UNIT    0x1B    /* Start/Stop Unit                  */
  92. #define SCSI_LOAD_UNLOAD        0x1B    /* Tape Load/Unload Media           */
  93. #define SCSI_LOCK_UNLOCK        0x1E    /* Lock/Unlock drive door           */
  94. #define SCSI_READ_CAPACITY      0x25    /* Read Capacity                    */
  95. #define SCSI_READ_10            0x28    /* SCSI 10 byte Read                */
  96. #define SCSI_WRITE_10           0x2A    /* SCSI 10 byte Write               */
  97. #define SCSI_SEEK_10            0x2B    /* SCSI 10 byte Seek                */
  98. #define SCSI_LOCATE             0x2B    /* Tape Locate                      */
  99. #define SCSI_WRITE_VERIFY_10    0x2E    /* SCSI 10 byte Write w/Verify      */
  100. #define SCSI_VERIFY_10          0x2F    /* SCSI 10 byte Verify              */
  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_PLAY_MSF           0x47    /* Play Audio - MSF format          */
  104. #define SCSI_PAUSE_RESUME       0x4B    /* Pause/Resume Audio Play          */
  105.  
  106.  
  107.  
  108. /*******************************************/
  109. /*  SCSI Command Descriptor Block          */
  110. /*******************************************/
  111.  
  112.  
  113.  
  114. typedef struct _SCSICDB6 { /* CDB6 */ /* 6 byte Command Descriptor Block*/
  115.  
  116.         UCHAR   Opcode;             /* CDB Operation Code           */
  117.         UCHAR   Lun_MsbLBA;         /* SCSI LUN & 5 MSB bits of LBA */
  118.         UCHAR   MidLBA;             /* SCSI MID byte of LBA         */
  119.         UCHAR   LsbLBA;             /* SCSI LBA byte of LBA         */
  120.         UCHAR   XferLen;            /* SCSI Xfer length, Alloc length */
  121.         UCHAR   Control;            /* Control byte                 */
  122.  
  123. } SCSICDB6,FAR *PSCSICDB6, *NPSCSICDB6;
  124.  
  125.  
  126.  
  127. typedef struct _SCSICDB10 { /* CDB10 */ /* 10 byte Command Descriptor Block*/
  128.  
  129.         UCHAR   Opcode;            /* CDB Operation Code           */
  130.         UCHAR   Lun;               /* SCSI                         */
  131.         UCHAR   LBA[4];            /* SCSI LBA MSB->LSB            */
  132.         UCHAR   Res;               /* reserved byte                */
  133.         UCHAR   XferLen[2];        /* SCSI Xfer length (MSB first) */
  134.         UCHAR   Control;           /* Control byte                 */
  135.  
  136. } SCSICDB10,FAR *PSCSICDB10, *NPSCSICDB10;
  137.  
  138.  
  139. typedef struct _SCSICDB12 { /* CDB12 */ /* 12 byte Command Descriptor Block*/
  140.  
  141.  
  142.         UCHAR   Opcode;            /* CDB Operation Code           */
  143.         UCHAR   Lun;               /* SCSI                         */
  144.         UCHAR   LBA[4];            /* SCSI LBA MSB->LSB            */
  145.         UCHAR   XferLen[4];        /* SCSI Xfer length (MSB first) */
  146.         UCHAR   Res;               /* reserved byte                */
  147.         UCHAR   Control;           /* Control byte                 */
  148.  
  149. } SCSICDB12, FAR *PSCSICDB12, *NPSCSICDB12;
  150.  
  151.  
  152. /******************************/
  153. /* SCSI Status byte codes     */
  154. /******************************/
  155.  
  156.  
  157. #define SCSI_STAT_GOOD          0x00      /* Good status                  */
  158. #define SCSI_STAT_CHECKCOND     0x02      /* SCSI Check Condition         */
  159. #define SCSI_STAT_CONDMET       0x04      /* Condition Met                */
  160. #define SCSI_STAT_BUSY          0x08      /* Target busy status           */
  161. #define SCSI_STAT_INTER         0x10      /* Intermediate status          */
  162. #define SCSI_STAT_INTERCONDMET  0x14      /* Intermediate condition met   */
  163. #define SCSI_STAT_RESCONFLICT   0x18      /* Reservation conflict         */
  164. #define SCSI_STAT_CMDTERM       0x22      /* Command Terminated           */
  165. #define SCSI_STAT_QUEUEFULL     0x28      /* Queue Full                   */
  166.  
  167.  
  168.  
  169. /******************************/
  170. /*  Request Sense Data format */
  171. /******************************/
  172.  
  173. typedef struct  _SCSIReqSenseData { /* REQSEN */
  174.  
  175.  
  176.         UCHAR   ErrCode_Valid;       /* Error Code & Valid bit       */
  177.         UCHAR   SegNum;              /* Segment Number               */
  178.         UCHAR   SenseKey;            /* Sense Key,ILI,EOM, FM        */
  179.         UCHAR   INFO[4];             /* information field            */
  180.         UCHAR   AddLen;              /* additional length            */
  181.         UCHAR   CmdInfo[4];          /* command-specific info        */
  182.         UCHAR   AddSenseCode;        /* additional sense code        */
  183.         UCHAR   AddSenseCodeQual;    /* additional sense code qualifier */
  184.         UCHAR   FieldRepUnitCode;    /* field replaceable unit code  */
  185.         UCHAR   KeySpecific[3];      /* Sense-key specific           */
  186.  
  187. } SCSI_REQSENSE_DATA, FAR *PSCSI_REQSENSE_DATA, *NPSCSI_REQSENSE_DATA;
  188.  
  189.  
  190.  
  191. /**********************************/
  192. /*  Sense Data bit masks          */
  193. /**********************************/
  194.  
  195.  
  196. /* Byte 0 of sense data */
  197.  
  198.  
  199. #define SCSI_ERRCODE_MASK     0x7F            /* Error Code                   */
  200. #define SCSI_VALID_MASK       0x80            /* Information field valid bit  */
  201.  
  202.  
  203.  
  204. /* Byte 2 of sense data */
  205.  
  206.  
  207. #define SCSI_SENSEKEY_MASK     0xF             /* Sense key                    */
  208. #define SCSI_INCORRECT_LEN     0x20            /* Incorrect lenght indicator   */
  209. #define SCSI_SENSE_ENDOFMEDIUM 0x40            /* End-of-medium bit            */
  210. #define SCSI_SENSE_FM          0x80            /* filemark bit                 */
  211.  
  212.  
  213.  
  214. /*******************************/
  215. /*  Sense Key definitions      */
  216. /*******************************/
  217.  
  218.  
  219. #define SCSI_SK_NOSENSE          0x0     /* No sense                     */
  220. #define SCSI_SK_RECERR           0x1     /* Recovered Error              */
  221. #define SCSI_SK_NOTRDY           0x2     /* Not Ready Error              */
  222. #define SCSI_SK_MEDIUMERR        0x3     /* Medium Error                 */
  223. #define SCSI_SK_HARDWAREERR      0x4     /* HardWare Error               */
  224. #define SCSI_SK_ILLEGALREQ       0x5     /* Illegal Request              */
  225. #define SCSI_SK_UNITATTN         0x6     /* Unit Attention               */
  226. #define SCSI_SK_DATAPROTECT      0x7     /* Data Protect Error           */
  227. #define SCSI_SK_BLANKCHK         0x8     /* Blank Check                  */
  228. #define SCSI_SK_COPYABORT        0x0A    /* Copy Aborted                 */
  229. #define SCSI_SK_ABORTEDCMD       0x0B    /* Aborted Command              */
  230. #define SCSI_SK_EQUAL            0x0C    /* Equal Comparison satisfied   */
  231. #define SCSI_SK_VOLOVERFLOW      0x0D    /* Volume Overflow              */
  232. #define SCSI_SK_MISCOMPARE       0x0E    /* Miscompare                   */
  233.  
  234.  
  235. /************************************/
  236. /* SCSI IORB StatusBlock definition */
  237. /************************************/
  238.  
  239. #define SCSI_DIAGINFO_LEN        8
  240.  
  241. typedef struct  _SCSIStatusBlock {  /* STATBLK */
  242.  
  243.         USHORT  Flags;                   /* Status block flags           */
  244.         USHORT  AdapterErrorCode;        /* Translated Adapter Error     */
  245.         UCHAR   TargetStatus;            /* SCSI status codes            */
  246.         ULONG   ResidualLength;          /* Residual Length              */
  247.         UCHAR   AdapterDiagInfo[SCSI_DIAGINFO_LEN]; /* Raw adapter status*/
  248.         USHORT  ReqSenseLen;             /* amount of RS data requested  */
  249.         PSCSI_REQSENSE_DATA  SenseData;  /* pointer to Req Sense Data    */
  250.  
  251. } SCSI_STATUS_BLOCK, FAR *PSCSI_STATUS_BLOCK, *NPSCSI_STATUS_BLOCK;
  252.  
  253. /* Status Block flags definitions */
  254.  
  255. #define STATUS_SENSEDATA_VALID  0x0001   /* Sense Data Valid             */
  256. #define STATUS_RESIDUAL_VALID   0x0002   /* Residual Byte Count Valid    */
  257. #define STATUS_DIAGINFO_VALID   0x0004   /* Diagnostic Information Valid */
  258.  
  259. /*************************/
  260. /*  Inquiry Data format  */
  261. /*************************/
  262.  
  263. typedef struct  _SCSIInqData { /* INQ */
  264.  
  265.         UCHAR    DevType;               /* Periph Qualifier & Periph Dev Type*/
  266.         UCHAR    RMB_TypeMod;           /* rem media bit & Dev Type Modifier */
  267.         UCHAR    Vers;                  /* ISO, ECMA, & ANSI versions        */
  268.         UCHAR    RDF;                   /* AEN, TRMIOP, & response data format*/
  269.         UCHAR    AddLen;                /* length of additional data         */
  270.         UCHAR    Res1;                  /* reserved                          */
  271.         UCHAR    Res2;                  /* reserved                          */
  272.         UCHAR    Flags;                 /* RelADr,Wbus32,Wbus16,Sync,etc.    */
  273.         UCHAR    VendorID[8];           /* Vendor Identification             */
  274.         UCHAR    ProductID[16];         /* Product Identification            */
  275.         UCHAR    ProductRev[4];         /* Product Revision                  */
  276.  
  277.  
  278. } SCSI_INQDATA, FAR *PSCSI_INQDATA, *NPSCSI_INQDATA;
  279.  
  280.  
  281. /*  Inquiry byte 0 masks */
  282.  
  283.  
  284. #define SCSI_DEVTYPE        0x1F      /* Peripheral Device Type             */
  285. #define SCSI_PERIPHQUAL     0xE0      /* Peripheral Qualifier               */
  286.  
  287.  
  288. /*  Inquiry byte 1 mask */
  289.  
  290. #define SCSI_REMOVABLE_MEDIA  0x80    /* Removable Media bit (1=removable)  */
  291.  
  292.  
  293. /*  Peripheral Device Type definitions */
  294.  
  295.  
  296. #define SCSI_DASD                0x00      /* Direct-access Device         */
  297. #define SCSI_SEQACESS            0x01      /* Sequential-access device     */
  298. #define SCSI_PRINTER             0x02      /* Printer device               */
  299. #define SCSI_PROCESSOR           0x03      /* Processor device             */
  300. #define SCSI_WRITEONCE           0x04      /* Write-once device            */
  301. #define SCSI_CDROM               0x05      /* CD-ROM device                */
  302. #define SCSI_SCANNER             0x06      /* Scanner device               */
  303. #define SCSI_OPTICAL             0x07      /* Optical memory device        */
  304. #define SCSI_MEDCHGR             0x08      /* Medium changer device        */
  305. #define SCSI_COMM                0x09      /* Communications device        */
  306. #define SCSI_NODEV               0x1F      /* Unknown or no device type    */
  307.  
  308.  
  309.  
  310. /**********************************************/
  311. /* Inquiry flag definitions (Inq data byte 7) */
  312. /**********************************************/
  313.  
  314. #define SCSI_INQ_RELADR       0x80    /* device supports relative addressing*/
  315. #define SCSI_INQ_WBUS32       0x40    /* device supports 32 bit data xfers  */
  316. #define SCSI_INQ_WBUS16       0x20    /* device supports 16 bit data xfers  */
  317. #define SCSI_INQ_SYNC         0x10    /* device supports synchronous xfer   */
  318. #define SCSI_INQ_LINKED       0x08    /* device supports linked commands    */
  319. #define SCSI_INQ_CMDQUEUE     0x02    /* device supports command queueing   */
  320. #define SCSI_INQ_SFTRE        0x01    /* device supports soft resets */
  321.  
  322.