scsi1Lib.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:26k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* scsi1Lib.h - SCSI library header file */
  2. /* Copyright 1984-1994 Wind River Systems, Inc. */
  3. /*
  4. modification history
  5. --------------------
  6. 02k,10oct94,jds  fixed for SCSI1 and SCSI2 compatability
  7. 02j,11jan93,ccc  added #ifndef _ASMLANGUAGE.
  8. 02i,30sep92,ccc  added two new errno's.
  9. 02h,24sep92,ccc  removed timeout parameter to scsiAutoConfig().
  10. 02g,22sep92,rrr  added support for c++
  11. 02f,27aug92,ccc  added timeout to SCSI_TRANSACTION structure.
  12. 02e,26jul92,rrr  Removed decl of scsiSyncTarget, it was made LOCAL.
  13. 02d,20jul92,eve  Remove conditional compilation.
  14. 02c,14jul92,eve  added a pScsiXaction info in SCSI_PHYS_DEV structure to
  15.  maintain the data direction information to support
  16.  cache coherency in drivers.
  17. 02b,06jul92,eve  added declaration for extended sync functionalities.
  18. 02a,04jul92,jcf  cleaned up.
  19. 01l,26may92,rrr  the tree shuffle
  20. 01k,07apr92,yao  changed BYTE_ORDER to _BYTE_ORDER, BIG_ENDIAN to _BIG_ENDIAN.
  21. 01j,04oct91,rrr  passed through the ansification filter
  22.   -fixed #else and #endif
  23.   -changed READ, WRITE and UPDATE to O_RDONLY O_WRONLY O_RDWR
  24.   -changed VOID to void
  25.   -changed copyright notice
  26. 01i,07mar91,jcc  added SCSI_BLK_DEV_LIST and SCSI_BLK_DEV_NODE definitions;
  27.  added SCSI_SWAB macro. added a few error codes.
  28. 01h,05oct90,shl  added ANSI function prototypes.
  29.                  added copyright notice.
  30. 01g,02oct90,jcc  changed SEM_ID's to SEMAPHORE's in SCSI_PHYS_DEV and SCSI_CTRL
  31.  structures; modified structures to return variable length
  32.  REQUEST SENSE data; miscellaneous.
  33. 01f,20aug90,jcc  added conditional defines and typedefs for 4.0.2 compatibility.
  34. 01e,10aug90,dnw  changed scsiBusReset and scsiSelTimeOutCvt to VOIDFUNCPTR.
  35. 01d,07aug90,shl  moved function declarations to end of file.
  36. 01c,12jul90,jcc  misc. enhancements and changes.
  37. 01b,08jun90,jcc  added scsiMsgInAck to SCSI_CTRL, which routine is invoked
  38.  to accept incoming messages.
  39. 01a,17apr89,jcc  written.
  40. */
  41. #ifndef __INCscsi1Libh
  42. #define __INCscsi1Libh
  43. #ifndef _ASMLANGUAGE
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #include "vwModNum.h"
  48. #include "blkIo.h"
  49. #include "lstLib.h"
  50. #include "private/semLibP.h"
  51. #ifndef WAIT_FOREVER    /* the following is for 4.0.2 backward compatibility */
  52. #define WAIT_FOREVER    (-1)
  53. typedef void            (*VOIDFUNCPTR) ();  /* ptr to function returning void */
  54. typedef unsigned char   UINT8;
  55. typedef unsigned short  UINT16;
  56. #endif /* WAIT_FOREVER */
  57. /* SCSI direct-access device and general purpose command opcodes are enumerated.
  58.  * NOTE: Some commands are optional and may not be supported by all devices.
  59.  */
  60. #define SCSI_OPCODE_TEST_UNIT_READY     ((UINT8) 0x00)  /* test unit ready */
  61. #define SCSI_OPCODE_REZERO_UNIT         ((UINT8) 0x01)  /* rezero unit */
  62. #define SCSI_OPCODE_REWIND ((UINT8) 0x01)  /* rewind */
  63. #define SCSI_OPCODE_REQUEST_SENSE       ((UINT8) 0x03)  /* request sense */
  64. #define SCSI_OPCODE_FORMAT_UNIT         ((UINT8) 0x04)  /* format unit */
  65. #define SCSI_OPCODE_READ_BLOCK_LIMITS ((UINT8) 0x05)  /* read block limits */
  66. #define SCSI_OPCODE_REASSIGN_BLOCKS     ((UINT8) 0x07)  /* reassign blocks */
  67. #define SCSI_OPCODE_READ                ((UINT8) 0x08)  /* read */
  68. #define SCSI_OPCODE_RECEIVE ((UINT8) 0x08)  /* receive */
  69. #define SCSI_OPCODE_WRITE               ((UINT8) 0x0a)  /* write */
  70. #define SCSI_OPCODE_PRINT               ((UINT8) 0x0a)  /* print */
  71. #define SCSI_OPCODE_SEND ((UINT8) 0x0a)  /* send */
  72. #define SCSI_OPCODE_SEEK                ((UINT8) 0x0b)  /* seek */
  73. #define SCSI_OPCODE_TRACK_SELECT ((UINT8) 0x0b)  /* track select */
  74. #define SCSI_OPCODE_SLEW_AND_PRINT ((UINT8) 0x0b)  /* slew and print */
  75. #define SCSI_OPCODE_READ_REVERSE ((UINT8) 0x0f)  /* read reverse */
  76. #define SCSI_OPCODE_WRITE_FILEMARKS ((UINT8) 0x10)  /* write filemarks */
  77. #define SCSI_OPCODE_FLUSH_BUFFER ((UINT8) 0x10)  /* flush buffer */
  78. #define SCSI_OPCODE_SPACE ((UINT8) 0x11)  /* space */
  79. #define SCSI_OPCODE_INQUIRY             ((UINT8) 0x12)  /* inquiry */
  80. #define SCSI_OPCODE_VERIFY_SEQ ((UINT8) 0x13)  /* seq. access verify */
  81. #define SCSI_OPCODE_RECOVER_BUF_DATA ((UINT8) 0x14)  /* rec. buffered data */
  82. #define SCSI_OPCODE_MODE_SELECT         ((UINT8) 0x15)  /* mode select */
  83. #define SCSI_OPCODE_RESERVE             ((UINT8) 0x16)  /* reserve */
  84. #define SCSI_OPCODE_RELEASE             ((UINT8) 0x17)  /* release */
  85. #define SCSI_OPCODE_COPY ((UINT8) 0x18)  /* copy */
  86. #define SCSI_OPCODE_ERASE ((UINT8) 0x19)  /* erase */
  87. #define SCSI_OPCODE_MODE_SENSE          ((UINT8) 0x1a)  /* mode sense */
  88. #define SCSI_OPCODE_START_STOP_UNIT     ((UINT8) 0x1b)  /* start/stop unit */
  89. #define SCSI_OPCODE_LOAD_UNLOAD ((UINT8) 0x1b)  /* load/unload */
  90. #define SCSI_OPCODE_STOP_PRINT ((UINT8) 0x1b)  /* stop print */
  91. #define SCSI_OPCODE_RECV_DIAG_RESULTS ((UINT8) 0x1c)  /* recv diag results */
  92. #define SCSI_OPCODE_SEND_DIAGNOSTIC     ((UINT8) 0x1d)  /* send diagnostic */
  93. #define SCSI_OPCODE_CTRL_MEDIUM_REMOVAL ((UINT8) 0x1e)  /* ctrl med. removal */
  94. #define SCSI_OPCODE_READ_CAPACITY       ((UINT8) 0x25)  /* read capacity */
  95. #define SCSI_OPCODE_READ_EXT ((UINT8) 0x28)  /* read extended */
  96. #define SCSI_OPCODE_WRITE_EXT       ((UINT8) 0x2a)  /* write extended */
  97. #define SCSI_OPCODE_SEEK_EXT        ((UINT8) 0x2b)  /* seek extended */
  98. #define SCSI_OPCODE_WRITE_AND_VERIFY    ((UINT8) 0x2e)  /* write and verify */
  99. #define SCSI_OPCODE_VERIFY              ((UINT8) 0x2f)  /* verify */
  100. #define SCSI_OPCODE_SEARCH_DATA_HIGH ((UINT8) 0x30)  /* search data high */
  101. #define SCSI_OPCODE_SEARCH_DATA_EQUAL ((UINT8) 0x31)  /* search data equal */
  102. #define SCSI_OPCODE_SEARCH_DATA_LOW ((UINT8) 0x32)  /* search data low */
  103. #define SCSI_OPCODE_SET_LIMITS ((UINT8) 0x33)  /* set limits */
  104. #define SCSI_OPCODE_READ_DEFECT_DATA    ((UINT8) 0x37)  /* read defect data */
  105. #define SCSI_OPCODE_COMPARE     ((UINT8) 0x39)  /* compare */
  106. #define SCSI_OPCODE_COPY_AND_VERIFY ((UINT8) 0x3a)  /* copy and verify */
  107. #define SCSI_OPCODE_WRITE_BUFFER        ((UINT8) 0x3b)  /* write buffer */
  108. #define SCSI_OPCODE_READ_BUFFER         ((UINT8) 0x3c)  /* read buffer */
  109. /* SCSI general purpose sense keys are enumerated.
  110.  * NOTE: Some sense keys are optional and may not be supported by all devices.
  111. */
  112. #define SCSI_SENSE_KEY_NO_SENSE         0x00  /* no sense sense key */
  113. #define SCSI_SENSE_KEY_RECOVERED_ERROR  0x01  /* recovered error sense key */
  114. #define SCSI_SENSE_KEY_NOT_READY        0x02  /* not ready sense key */
  115. #define SCSI_SENSE_KEY_MEDIUM_ERROR     0x03  /* medium error sense key */
  116. #define SCSI_SENSE_KEY_HARDWARE_ERROR   0x04  /* hardware error sense key */
  117. #define SCSI_SENSE_KEY_ILLEGAL_REQUEST  0x05  /* illegal request sense key */
  118. #define SCSI_SENSE_KEY_UNIT_ATTENTION   0x06  /* unit attention sense key */
  119. #define SCSI_SENSE_KEY_DATA_PROTECT     0x07  /* data protect sense key */
  120. #define SCSI_SENSE_KEY_BLANK_CHECK      0x08  /* blank check sense key */
  121. #define SCSI_SENSE_KEY_VENDOR_UNIQUE    0x09  /* vendor unique sense key */
  122. #define SCSI_SENSE_KEY_COPY_ABORTED     0x0a  /* copy aborted sense key */
  123. #define SCSI_SENSE_KEY_ABORTED_COMMAND  0x0b  /* aborted command sense key */
  124. #define SCSI_SENSE_KEY_EQUAL            0x0c  /* key equal sense key */
  125. #define SCSI_SENSE_KEY_VOLUME_OVERFLOW  0x0d  /* volume overflow sense key */
  126. #define SCSI_SENSE_KEY_MISCOMPARE       0x0e  /* miscompare sense key */
  127. #define SCSI_SENSE_KEY_RESERVED         0x0f  /* reserved sense key */
  128. /* SCSI status byte codes are enumerated.
  129.  * NOTE: Some status codes are optional and may not be supported by all devices.
  130. */
  131. #define SCSI_STATUS_MASK            ((UINT8) 0x1e) /* mask vend uniq status */
  132. #define SCSI_STATUS_GOOD            ((UINT8) 0x00) /* good status */
  133. #define SCSI_STATUS_CHECK_CONDITION ((UINT8) 0x02) /* check condition status */
  134. #define SCSI_STATUS_CONDITION_MET   ((UINT8) 0x04) /* condition met/good stat */
  135. #define SCSI_STATUS_BUSY            ((UINT8) 0x08) /* busy status */
  136. #define SCSI_STATUS_INTMED_GOOD     ((UINT8) 0x10) /* intermediate/good stat */
  137. #define SCSI_STATUS_INTMED_COND_MET ((UINT8) 0x14) /* interm./cond. met stat */
  138. #define SCSI_STATUS_RESERV_CONFLICT ((UINT8) 0x18) /* reservation conflict */
  139. #define SCSI_STATUS_QUEUE_FULL      ((UINT8) 0x28) /* queue full status */
  140. /* SCSI message codes are enumerated.
  141.  * NOTE: Some message codes are optional and may not be supported by all
  142.  *       devices.
  143. */
  144. #define SCSI_MSG_COMMAND_COMPLETE   ((UINT8) 0x00) /* command complete msg. */
  145. #define SCSI_MSG_EXTENDED_MESSAGE   ((UINT8) 0x01) /* extended message msg. */
  146. #define SCSI_MSG_SAVE_DATA_POINTER  ((UINT8) 0x02) /* save data pointer msg. */
  147. #define SCSI_MSG_RESTORE_POINTERS   ((UINT8) 0x03) /* restore pointers msg. */
  148. #define SCSI_MSG_DISCONNECT         ((UINT8) 0x04) /* disconnect msg. */
  149. #define SCSI_MSG_INITOR_DETECT_ERR  ((UINT8) 0x05) /* initor. detect err msg. */
  150. #define SCSI_MSG_ABORT              ((UINT8) 0x06) /* abort msg. */
  151. #define SCSI_MSG_MESSAGE_REJECT     ((UINT8) 0x07) /* message reject msg. */
  152. #define SCSI_MSG_NO_OP              ((UINT8) 0x08) /* no operation msg. */
  153. #define SCSI_MSG_MSG_PARITY_ERR     ((UINT8) 0x09) /* message parity err msg. */
  154. #define SCSI_MSG_LINK_CMD_COMPLETE  ((UINT8) 0x0a) /* linked cmd. comp. msg. */
  155. #define SCSI_MSG_LINK_CMD_FLAG_COMP ((UINT8) 0x0b) /* link cmd w/flag comp. */
  156. #define SCSI_MSG_BUS_DEVICE_RESET   ((UINT8) 0x0c) /* bus device reset msg. */
  157. #define SCSI_MSG_IDENT_DISCONNECT   ((UINT8) 0x40) /* identify disconnect bit */
  158. #define SCSI_MSG_IDENTIFY      ((UINT8) 0x80) /* identify msg bit mask */
  159. /* SCSI extended message codes */
  160. #define SCSI_EXT_MSG_MODIFY_DATA_PTR ((UINT8) 0x00)  /* modify data pointer */
  161. #define SCSI_EXT_MSG_SYNC_XFER_REQ   ((UINT8) 0x01)  /* sync. data xfer. req. */
  162. #define SCSI_EXT_MSG_WIDE_XFER_REQ   ((UINT8) 0x03)  /* wide data xfer req. */
  163. /* SCSI extended message lengths */
  164. #define SCSI_MODIFY_DATA_PTR_MSG_LENGTH  5  /* modify data pointer */
  165. #define SCSI_SYNC_XFER_REQ_MSG_LENGTH    3  /* sync. data xfer. req. */
  166. #define SCSI_WIDE_XFER_REQ_MSG_LENGTH    2  /* wide data xfer req. */
  167. /* the largest SCSI ID and LUN a target drive can have */
  168. #define SCSI_MIN_BUS_ID 0 /* min. bus ID under SCSI */
  169. #define SCSI_MAX_BUS_ID 7 /* max. bus ID under SCSI */
  170. #define SCSI_MIN_LUN 0 /* min. logical unit number */
  171. #define SCSI_MAX_LUN 7 /* max. logical unit number */
  172. /* scsiLib errno's */
  173. #define S_scsiLib_DEV_NOT_READY (M_scsiLib | 1)
  174. #define S_scsiLib_WRITE_PROTECTED (M_scsiLib | 2)
  175. #define S_scsiLib_MEDIUM_ERROR (M_scsiLib | 3)
  176. #define S_scsiLib_HARDWARE_ERROR (M_scsiLib | 4)
  177. #define S_scsiLib_ILLEGAL_REQUEST (M_scsiLib | 5)
  178. #define S_scsiLib_BLANK_CHECK (M_scsiLib | 6)
  179. #define S_scsiLib_ABORTED_COMMAND (M_scsiLib | 7)
  180. #define S_scsiLib_VOLUME_OVERFLOW (M_scsiLib | 8)
  181. #define S_scsiLib_UNIT_ATTENTION (M_scsiLib | 9)
  182. #define S_scsiLib_SELECT_TIMEOUT (M_scsiLib | 10)
  183. #define S_scsiLib_LUN_NOT_PRESENT (M_scsiLib | 11)
  184. #define S_scsiLib_ILLEGAL_BUS_ID (M_scsiLib | 12)
  185. #define S_scsiLib_NO_CONTROLLER (M_scsiLib | 13)
  186. #define S_scsiLib_REQ_SENSE_ERROR (M_scsiLib | 14)
  187. #define S_scsiLib_DEV_UNSUPPORTED (M_scsiLib | 15)
  188. #define S_scsiLib_ILLEGAL_PARAMETER (M_scsiLib | 16)
  189. #define S_scsiLib_EARLY_PHASE_CHANGE (M_scsiLib | 17)
  190. #define S_scsiLib_PHASE_CHANGE_TIMEOUT (M_scsiLib | 18)
  191. #define S_scsiLib_ILLEGAL_OPERATION (M_scsiLib | 19)
  192. #define S_scsiLib_DEVICE_EXIST          (M_scsiLib | 20)
  193. #define S_scsiLib_SYNC_UNSUPPORTED      (M_scsiLib | 21)
  194. #define S_scsiLib_SYNC_VAL_UNSUPPORTED  (M_scsiLib | 22)
  195. #define S_scsiLib_DATA_TRANSFER_TIMEOUT (M_scsiLib | 23)
  196. #define S_scsiLib_UNKNOWN_PHASE (M_scsiLib | 24)
  197. /* default select timeout (usec) */
  198. #define SCSI_DEF_SELECT_TIMEOUT ((UINT) 250000)
  199. /* default auto-config timeout (usec) */
  200. #define SCSI_DEF_CONFIG_TIMEOUT ((UINT) 1000)
  201. #define SCSI_TIMEOUT_5SEC ((UINT) 5000000)
  202. #define SCSI_TIMEOUT_1SEC ((UINT) 1000000)
  203. #define SCSI_TIMEOUT_FULL ((UINT) 0x7fffffff)
  204. /* default bus ID for a vxWorks SCSI port */
  205. #define SCSI_DEF_CTRL_BUS_ID 7
  206. /* values in status register for SCSI bus phases */
  207. #define SCSI_DATA_OUT_PHASE 0x0
  208. #define SCSI_DATA_IN_PHASE 0x1
  209. #define SCSI_COMMAND_PHASE 0x2
  210. #define SCSI_STATUS_PHASE 0x3
  211. #define SCSI_MSG_OUT_PHASE 0x6
  212. #define SCSI_MSG_IN_PHASE 0x7
  213. #define SCSI_BUS_FREE_PHASE 0x8
  214. /* device status enumeration */
  215. typedef enum scsiPhysDevStatus
  216.     {
  217.     IDLE,
  218.     SELECT_REQUESTED,
  219.     SELECT_IN_PROGRESS,
  220.     SELECT_SUCCESSFUL,
  221.     SELECT_TIMEOUT,
  222.     SELECT_LOST_ARBIT,
  223.     DISCONNECTED,
  224.     RECONNECTED
  225.     } SCSI_DEV_STATUS;
  226. /* device type enumeration */
  227. #define SCSI_DEV_DIR_ACCESS ((UINT8) 0x00) /* direct-access dev (disk) */
  228. #define SCSI_DEV_SEQ_ACCESS ((UINT8) 0x01) /* sequent'l-access dev (tape) */
  229. #define SCSI_DEV_PRINTER ((UINT8) 0x02) /* printer dev */
  230. #define SCSI_DEV_PROCESSOR ((UINT8) 0x03) /* processor dev */
  231. #define SCSI_DEV_WORM ((UINT8) 0x04) /* write-once read-mult dev */
  232. #define SCSI_DEV_RO_DIR_ACCESS ((UINT8) 0x05) /* read-only direct-access dev */
  233. #define SCSI_LUN_NOT_PRESENT ((UINT8) 0x7f) /* logical unit not present */
  234. #define MAX_SCSI_PHYS_DEVS 64
  235. #define MAX_MSG_IN_BYTES 8
  236. #define MAX_MSG_OUT_BYTES 8
  237. #define VENDOR_ID_LENGTH 8
  238. #define PRODUCT_ID_LENGTH 16
  239. #define REV_LEVEL_LENGTH 4
  240. typedef struct scsiBlkDevList
  241.     {
  242.     SEMAPHORE listMutexSem;
  243.     LIST blkDevNodes;
  244.     } SCSI_BLK_DEV_LIST;
  245. /* structure to pass to ioctl call to execute an SCSI command*/
  246. typedef struct  /* SCSI_TRANSACTION - information about a SCSI transaction */
  247.     {
  248.     UINT8 *cmdAddress;          /* address of SCSI command bytes */
  249.     int cmdLength;              /* length of command in bytes */
  250.     UINT8 *dataAddress;         /* address of data buffer */
  251.     int dataDirection;          /* direction of data transfer */
  252.     int dataLength;             /* length of data buffer in bytes (0=no data) */    int addLengthByte;          /* if != -1 , byte # of additional length */
  253.     UINT8 statusByte;           /* status byte returned from target */
  254.     int cmdTimeout; /* number of usec for this command timeout */
  255.     } SCSI_TRANSACTION;
  256. /* NOTE: Not all of the fields in the following structure
  257.  *       are currently supported or used.
  258.  */
  259. typedef struct  /* SCSI_PHYS_DEV - SCSI physical device info */
  260.     {
  261.     SEMAPHORE devMutexSem; /* semaphore for exclusive access */
  262.     SEMAPHORE devSyncSem; /* semaphore for waiting on I/O interrupt */
  263.     int scsiDevBusId; /* device's address on SCSI bus */
  264.     int scsiDevLUN; /* device's logical unit number */
  265.     UINT selTimeOut; /* device select time-out (units var.) */
  266.     UINT8 scsiDevType; /* SCSI device type */
  267.     TBOOL disconnect;           /* whether device supports disconnect */
  268.     TBOOL expectDisconnect;     /* TRUE if a disconnect is expected */
  269.     TBOOL xmitsParity;      /* TRUE if dev. xmits parity */
  270.     TBOOL useIdentify; /* whether to use identify message at select */
  271.     TBOOL syncXfer; /* TRUE for synchronous data transfer */
  272.     int syncXferOffset; /* synchronous xfer maximum offset */
  273.     int syncXferPeriod; /* synchronous xfer mimimum period */
  274.     UINT8 *savedTransAddress;   /* saved data pointer address */
  275.     int savedTransLength;       /* saved data pointer length */
  276.     BOOL resetFlag; /* set TRUE when dev reset sensed */
  277.     FUNCPTR postResetRtn; /* routine to call when dev has been reset */
  278.     char devVendorID [VENDOR_ID_LENGTH + 1];  /* vendor ID in ASCII */
  279.     char devProductID [PRODUCT_ID_LENGTH + 1]; /* product ID in ASCII */
  280.     char devRevLevel [REV_LEVEL_LENGTH + 1]; /* revision level in ASCII */
  281.     BOOL removable; /* whether medium is removable */
  282.     UINT8 lastSenseKey; /* last sense key returned by dev */
  283.     UINT8 lastAddSenseCode; /* last additional sense code returned by dev */
  284.     int controlByte; /* vendor unique control byte for commands */
  285.     int numBlocks; /* number of blocks on the physical device */
  286.     int blockSize; /* size of an SCSI disk sector */
  287.     struct scsiCtrl *pScsiCtrl; /* ptr to dev's SCSI controller info */
  288.     SCSI_DEV_STATUS devStatus; /* status of most recent device operation */
  289.      /* list of outgoing messages */
  290.     UINT8 msgOutArray [MAX_MSG_OUT_BYTES + 1];/* msg[0] reserved for identify */
  291.     int msgLength; /* number of bytes in outgoing message */
  292.     BOOL extendedSense; /* whether device returns extended sense */
  293.     UINT8 *pReqSenseData; /* ptr to last REQ SENSE data returned by dev */
  294.     int reqSenseDataLength; /* size of REQ SENSE data array */
  295.      /* ptr to first block dev created on device */
  296.     struct scsiBlkDevList blkDevList;
  297.     struct scsiBlkDev *pScsiBlkDev;
  298.     int useMsgout;              /* whether to send a message out at select */
  299.     int syncReserved1;          /* Reserved for hardware sync register value */
  300.     int syncReserved2;          /* Reserved for hardware sync register value */
  301.     SCSI_TRANSACTION  *pScsiXaction; /* current scsi action requested */
  302.     } SCSI_PHYS_DEV;
  303. /* Step scsi period ( look at the scsi ANSI ) */
  304. #define SCSI_SYNC_STEP_PERIOD     4     /* scsi step period in sync msg */
  305. /* Used to negotiate a scsi sync agreement for the synchronous transfert
  306.  * to return parameters computed both by the driver and target
  307.  */
  308. typedef struct
  309.      {
  310.      int syncPeriodCtrl;     /* Closest period available with the controller */
  311.      int syncOffsetCtrl;     /* Closest offset available with the controller */
  312.      int syncPeriodTarget;   /* Period value returned by the target */
  313.      int syncOffsetTarget;   /* Offset value returned by the target */
  314.      } SCSI_SYNC_AGREEMENT;
  315. typedef SCSI_PHYS_DEV *SCSI_PHYS_DEV_ID;
  316. typedef struct scsiBlkDev /* SCSI_BLK_DEV -
  317.    SCSI logical block device info */
  318.     {
  319.     BLK_DEV blkDev; /* generic logical block device info */
  320.     SCSI_PHYS_DEV *pScsiPhysDev;/* ptr to SCSI physical device info */
  321.     int numBlocks; /* number of blocks on the logical device */
  322.     int blockOffset; /* address of first block on logical device */
  323.     } SCSI_BLK_DEV;
  324. typedef SCSI_BLK_DEV *SCSI_BLK_DEV_ID;
  325. typedef struct scsiBlkDevNode
  326.     {
  327.     NODE blkDevNode;
  328.     SCSI_BLK_DEV scsiBlkDev;
  329.     } SCSI_BLK_DEV_NODE;
  330. typedef struct scsiCtrl /* SCSI_CTRL - generic SCSI controller info */
  331.     {
  332.     SEMAPHORE ctrlMutexSem; /* semaphore for exclusive access */
  333.     SEMAPHORE ctrlSyncSem; /* semaphore for waiting on I/O interrupt */
  334.     VOIDFUNCPTR scsiBusReset; /* function for resetting the SCSI bus */
  335.     FUNCPTR scsiTransact; /* function for managing a SCSI transaction */
  336.     FUNCPTR scsiDevSelect; /* function for selecting a SCSI device */
  337.     FUNCPTR scsiBytesIn; /* function for SCSI input */
  338.     FUNCPTR scsiBytesOut; /* function for SCSI output */
  339.     FUNCPTR scsiDmaBytesIn; /* function for SCSI DMA input */
  340.     FUNCPTR scsiDmaBytesOut; /* function for SCSI DMA output */
  341.     FUNCPTR scsiBusPhaseGet; /* function returning the current bus phase */
  342.     FUNCPTR scsiMsgInAck; /* function for accepting an incoming message */
  343.     VOIDFUNCPTR scsiSelTimeOutCvt; /* func. for converting a select time-out */
  344.     UINT maxBytesPerXfer; /* upper bound of ctrl. tansfer counter */
  345.     UINT clkPeriod; /* period of the controller clock (nsec) */
  346.     int scsiCtrlBusId; /* SCSI bus ID of this SCSI controller */
  347.     int scsiPriority; /* priority of task when doing SCSI I/O */
  348.     int scsiBusPhase;           /* current phase of SCSI */
  349.     TBOOL disconnect; /* globally enable / disable disconnect */
  350. /* info on devs. attached to this controller */
  351.     SCSI_PHYS_DEV *physDevArr [MAX_SCSI_PHYS_DEVS];
  352.     FUNCPTR scsiSyncMsgConvert; /* function for converting extended sync
  353.                                  * message in hardware register value */
  354.     VOIDFUNCPTR scsiSetAtn;     /* function to set atn */
  355.     } SCSI_CTRL;
  356. /* definitions relating to SCSI commands */
  357. #define MAX_SCSI_CMD_LENGTH 12  /* maximum length in bytes of a SCSI command */
  358. typedef UINT8 SCSI_COMMAND [MAX_SCSI_CMD_LENGTH];
  359. #define SCSI_GROUP_0_CMD_LENGTH  6
  360. #define SCSI_GROUP_1_CMD_LENGTH 10
  361. #define SCSI_GROUP_5_CMD_LENGTH 12
  362. /* some useful defines and structures for CCS commands */
  363. #define SCSI_FORMAT_DATA_BIT ((UINT8) 0x10)
  364. #define SCSI_COMPLETE_LIST_BIT ((UINT8) 0x08)
  365. #define DEFAULT_INQUIRY_DATA_LENGTH 36
  366. #define REQ_SENSE_ADD_LENGTH_BYTE 7
  367. #define INQUIRY_ADD_LENGTH_BYTE 4
  368. #define MODE_SENSE_ADD_LENGTH_BYTE 0
  369. #define INQUIRY_REMOVABLE_MED_BIT ((UINT8) 0x80)
  370. typedef struct  /* RD_CAP_DATA - results from O_RDONLY CAPACITY */
  371.     {
  372.     int lastLogBlkAdrs; /* address of last logical block on device */
  373.     int blkLength; /* block length of last logical block */
  374.     } RD_CAP_DATA;
  375. #define NON_EXT_SENSE_DATA_LENGTH 4
  376. #define SCSI_SENSE_DATA_CLASS 0x70
  377. #define SCSI_SENSE_DATA_CODE 0x0f
  378. #define SCSI_SENSE_KEY_MASK 0x0f
  379. #define SCSI_EXT_SENSE_CLASS 0x70
  380. #define SCSI_EXT_SENSE_CODE 0x00
  381. /* Min/Max sync value in 4ns step */
  382. #define MAX_SCSI_SYNC_PERIOD  0xfa            /* ~1Mbytes/s value */
  383. #define MIN_SCSI_SYNC_PERIOD  0x19            /* ~10Mbytes/s value */
  384. #define DEFAULT_SCSI_OFFSET   0x4             /* scsi default offset */
  385. /* Type of msgout to send */
  386. #define SCSI_NO_MSGOUT          0x00000000    /* No msgout capability */
  387. #define SCSI_SYNC_MSGOUT        0x00000001    /* Build and send sync message */
  388. #define SCSI_WIDE_MSGOUT        0x00000002    /* Build and send wide message */
  389. #define SCSI_DEV_RST_MSGOUT     0x00000004    /* Build and send wide message */
  390. #define SCSI_OTHER_MSGOUT       0x00000008    /* Send user message */
  391. /* external variable declarations */
  392. IMPORT BOOL            scsiDebug;  /* enable task level debug messages */
  393. IMPORT BOOL            scsiIntsDebug; /* enable int level debug messages */
  394. IMPORT SCSI_CTRL *     pSysScsiCtrl;
  395. IMPORT SCSI_FUNC_TBL * pScsiIfTbl;      /* scsiLib interface function table */
  396. IMPORT UINT32          scsiSelectTimeout;
  397. IMPORT int             blkDevListMutexOptions;
  398. IMPORT int             scsiCtrlMutexOptions;
  399. IMPORT int             scsiCtrlSemOptions;
  400. IMPORT int             scsiPhysDevMutexOptions;
  401. IMPORT int             scsiPhysDevSemOptions;
  402. /* macros */
  403. #define SCSI_MSG
  404. logMsg
  405. #define SCSI_DEBUG_MSG
  406.     if (scsiDebug)
  407. SCSI_MSG
  408. #define SCSI_INT_DEBUG_MSG
  409.     if (scsiIntsDebug)
  410. logMsg
  411. /* macros to get msgout pointer Identify and msg array */
  412. #define SCSI_GET_PTR_IDENTIFY(pScsiPhysDev)    (&pScsiPhysDev->msgOutArray[0])
  413. #define SCSI_GET_PTR_MSGOUT(pScsiPhysDev)      (&pScsiPhysDev->msgOutArray[1])
  414. /*******************************************************************************
  415. *
  416. * SCSI_SWAB - swap bytes on little-endian machines
  417. *
  418. * All fields which are defined as integers (short or long) by the SCSI spec
  419. * and which are passed during the data phase should be pre- or post-processed
  420. * by this macro. The macro does nothing on big-endian machines, but swaps
  421. * bytes for little-endian machines. All SCSI quantities are big-endian.
  422. *
  423. * NOMANUAL
  424. */
  425. #if (_BYTE_ORDER == _BIG_ENDIAN)
  426. #define SCSI_SWAB(pBuffer, bufLength)
  427. #else
  428. #define SCSI_SWAB(pBuffer, bufLength)
  429.     do
  430. {
  431. char temp;
  432. char *pHead = (char *) pBuffer;
  433. char *pTail = (char *) pBuffer + bufLength - 1;
  434. while (pHead < pTail)
  435.     {
  436.     temp = *pTail;
  437.     *pTail-- = *pHead;
  438.     *pHead++ = temp;
  439.     }
  440. } while (FALSE)
  441. #endif
  442. /* function declarations */
  443. extern void   scsi1IfInit ();
  444. #if defined(__STDC__) || defined(__cplusplus)
  445. extern BLK_DEV *       scsiBlkDevCreate (SCSI_PHYS_DEV *, int, int);
  446. extern SCSI_PHYS_DEV * scsiPhysDevCreate (SCSI_CTRL *, int, int, int, int, 
  447.  BOOL, int, int);
  448. extern SCSI_PHYS_DEV * scsiPhysDevIdGet (SCSI_CTRL *, int, int);
  449. extern STATUS         scsiAutoConfig (SCSI_CTRL *);
  450. extern STATUS         scsiBusReset (SCSI_CTRL *);
  451. extern STATUS         scsiCmdBuild (SCSI_COMMAND, int *, UINT8, int, BOOL, 
  452.                                      int, int , UINT8);
  453. extern STATUS         scsiCtrlInit (SCSI_CTRL *);
  454. extern STATUS         scsiFormatUnit (SCSI_PHYS_DEV *, BOOL, int, int, int, 
  455.                                        char *, int);
  456. extern STATUS         scsiInquiry (SCSI_PHYS_DEV *, char *, int);
  457. extern STATUS         scsiIoctl (SCSI_PHYS_DEV *, int, int);
  458. extern STATUS         scsiModeSelect (SCSI_PHYS_DEV *, int, int, char *, int);
  459. extern STATUS         scsiModeSense (SCSI_PHYS_DEV *, int, int, char *, int);
  460. extern STATUS         scsiPhysDevDelete (SCSI_PHYS_DEV *);
  461. extern STATUS         scsiRdSecs (SCSI_BLK_DEV *, int, int, char *);
  462. extern STATUS         scsiReadCapacity (SCSI_PHYS_DEV *, int *, int *);
  463. extern STATUS         scsiReqSense (SCSI_PHYS_DEV *, char *, int);
  464. extern STATUS         scsiShow (SCSI_CTRL *);
  465. extern STATUS         scsiTestUnitRdy (SCSI_PHYS_DEV *);
  466. extern STATUS         scsiTransact (SCSI_PHYS_DEV *, SCSI_TRANSACTION *);
  467. extern STATUS         scsiWrtSecs (SCSI_BLK_DEV *, int, int, char *);
  468. extern char *        scsiPhaseNameGet (int);
  469. extern void         scsiBlkDevInit (SCSI_BLK_DEV *, int, int);
  470. extern void         scsiBlkDevShow (SCSI_PHYS_DEV *);
  471. extern STATUS          scsiBuildByteMsgOut (UINT8 *,UINT8);
  472. extern STATUS          scsiBuildExtMsgOut (UINT8 *,UINT8);
  473. #else /* __STDC__ */
  474. extern BLK_DEV *       scsiBlkDevCreate ();
  475. extern SCSI_PHYS_DEV * scsiPhysDevCreate ();
  476. extern SCSI_PHYS_DEV * scsiPhysDevIdGet ();
  477. extern STATUS         scsiAutoConfig ();
  478. extern STATUS         scsiBusReset ();
  479. extern STATUS         scsiCmdBuild ();
  480. extern STATUS         scsiCtrlInit ();
  481. extern STATUS         scsiFormatUnit ();
  482. extern STATUS         scsiInquiry ();
  483. extern STATUS         scsiIoctl ();
  484. extern STATUS         scsiModeSelect ();
  485. extern STATUS         scsiModeSense ();
  486. extern STATUS         scsiPhysDevDelete ();
  487. extern STATUS         scsiRdSecs ();
  488. extern STATUS         scsiReadCapacity ();
  489. extern STATUS         scsiReqSense ();
  490. extern STATUS         scsiShow ();
  491. extern STATUS         scsiTestUnitRdy ();
  492. extern STATUS         scsiTransact ();
  493. extern STATUS         scsiWrtSecs ();
  494. extern char *        scsiPhaseNameGet ();
  495. extern void         scsiBlkDevInit ();
  496. extern void         scsiBlkDevShow ();
  497. extern STATUS          scsiBuildByteMsgOut ();
  498. extern STATUS          scsiBuildExtMsgOut ();
  499. #endif /* __STDC__ */
  500. #ifdef __cplusplus
  501. }
  502. #endif
  503. #endif /* _ASMLANGUAGE */
  504. #endif /* __INCscsi1Libh */