scsi.h
上传用户:poi891205
上传日期:2013-07-15
资源大小:9745k
文件大小:14k
源码类别:

DVD

开发平台:

C/C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // SUNPLUS---WORLDPLUS
  3. ////////////////////////////////////////////////////////////////////////////////
  4. // File: scsi.h
  5. // Purpose:     SPHE8200 firmware to master SL811 Embedded Host. 
  6. //              Contains SL811-related control firmware.This file
  7. //              describes the scsi data structure!  
  8. //              
  9. // H/W Target:  SL811HST + SPHE8200 DVD SYSTEM
  10. // IMPORTANT :  
  11. //              the hardware could sustain USB host and USB slave. 
  12. //
  13. // Creator:     Liweihua and Zhaoyanhua 2003-9-20
  14. ////////////////////////////////////////////////////////////////////////////////
  15. #ifndef   SCSI_H
  16. #define   SCSI_H
  17. #include "config.h"
  18. #include "global.h"
  19. #include "macro.h"
  20. #include "regmap.h"
  21. #include "emuio.h"
  22. #include "Types.h"
  23. //*****************************************************************************************
  24. // Constant and data structue  Defines
  25. //*****************************************************************************************
  26. //----define the max sector number when send scci read/write command-----------
  27. //liweihua 2004-5-28 15:47
  28. #define SCSIREAD_MAX_SECTOR     0x10
  29. #define SCSIWRITE_MAX_SECTOR    0x10
  30. //----define the CBW constant----------------
  31. #define CBWSignature        0x43425355
  32. #define CBWOut              0x00
  33. #define CBWIn               0x80
  34. #define CBWSix              0x06
  35. #define CBWTen              0x0A
  36. #define CBWTwel             0x0C
  37. #define CBWLen              0x1F
  38. //----define the CSW constant----------------
  39. #define CSWSignature    0x53425355
  40. #define CSWLen          0x0D
  41. //---- define SCSI-2 Commands ----------------
  42. #define SCSICMD_TEST_UNIT_READY                 0x00
  43. #define SCSICMD_REZERO_UNIT                     0x01
  44. #define SCSICMD_REQUEST_SENSE                   0x03
  45. #define SCSICMD_FORMAT_UNIT                     0x04
  46. #define SCSICMD_READ_BLOCK_LIMITS               0x05
  47. #define SCSICMD_REASSIGN_BLOCKS                 0x07
  48. #define SCSICMD_READ_06                         0x08
  49. #define SCSICMD_WRITE_06                        0x0a
  50. #define SCSICMD_SEEK_06                         0x0b
  51. #define SCSICMD_READ_REVERSE                    0x0f
  52. #define SCSICMD_WRITE_FILEMARKS                 0x10
  53. #define SCSICMD_SPACE                           0x11
  54. #define SCSICMD_INQUIRY                         0x12
  55. #define SCSICMD_VERIF06                         0x13
  56. #define SCSICMD_RECOVER_BUFFERED_DATA           0x14
  57. #define SCSICMD_MODE_SELECT_06                  0x15
  58. #define SCSICMD_RESERVE                         0x16
  59. #define SCSICMD_RELEASE                         0x17
  60. #define SCSICMD_COPY                            0x18
  61. #define SCSICMD_ERASE                           0x19
  62. #define SCSICMD_MODE_SENSE_06                   0x1a
  63. #define SCSICMD_START_STOP_UNIT                 0x1b
  64. #define SCSICMD_RECEIVE_DIAGNOSTIC_RESULTS      0x1c
  65. #define SCSICMD_SEND_DIAGNOSTIC                 0x1d
  66. #define SCSICMD_PREVENT_ALLOW_MEDIUM_REMOVAL    0x1e
  67. #define SCSICMD_READ_FORMAT_CAPACITIES          0x23
  68. #define SCSICMD_SET_WINDOW                      0x24
  69. #define SCSICMD_READ_CAPACITY                   0x25
  70. #define SCSICMD_READ_10                         0x28
  71. #define SCSICMD_READ_GENERATION                 0x29
  72. #define SCSICMD_WRITE_10                        0x2a
  73. #define SCSICMD_SEEK_10                         0x2b
  74. #define SCSICMD_ERASE_10                        0x2c
  75. #define SCSICMD_READ_UPDATED_BLOCK              0x2d
  76. #define SCSICMD_WRITE_AND_VERIFY_10             0x2e
  77. #define SCSICMD_VERIFY_10                       0x2f
  78. #define SCSICMD_SEARCH_DATA_HIGH_10             0x30
  79. #define SCSICMD_SEARCH_DATA_EQUAL_10            0x31
  80. #define SCSICMD_SEARCH_DATA_LOW_10              0x32
  81. #define SCSICMD_SET_LIMITS                      0x33
  82. #define SCSICMD_PREFETCH                        0x34
  83. #define SCSICMD_SYNCHRONIZE_CACHE               0x35
  84. #define SCSICMD_LOCK_UNLOCK_CACHE               0x36
  85. #define SCSICMD_READ_DEFECT_DATA_10             0x37
  86. #define SCSICMD_MEDIUM_SCAN                     0x38
  87. #define SCSICMD_COMPARE                         0x39
  88. #define SCSICMD_COPAND_VERIFY                   0x3a
  89. #define SCSICMD_WRITE_BUFFER                    0x3b
  90. #define SCSICMD_READ_BUFFER                     0x3c
  91. #define SCSICMD_UPDATE_BLOCK                    0x3d
  92. #define SCSICMD_READ_LONG                       0x3e
  93. #define SCSICMD_WRITE_LONG                      0x3f
  94. #define SCSICMD_CHANGE_DEFINITION               0x40
  95. #define SCSICMD_WRITE_SAME                      0x41
  96. #define SCSICMD_READ_SUBCHANNEL                 0x42
  97. #define SCSICMD_READ_TOC                        0x43
  98. #define SCSICMD_READ_HEADER                     0x44
  99. #define SCSICMD_PLAY_AUDIO_10                   0x45
  100. #define SCSICMD_PLAY_AUDIO_MSF                  0x47
  101. #define SCSICMD_PLAY_AUDIO_TRACK_INDEX          0x48
  102. #define SCSICMD_PLAY_TRACK_RELATIVE             0x49
  103. #define SCSICMD_PAUSE_RESUME                    0x4b
  104. #define SCSICMD_LOG_SELECT                      0x4c
  105. #define SCSICMD_LOG_SENSE                       0x4d
  106.      
  107. #define SCSICMD_MODE_SELECT_10                  0x55        
  108.    
  109. #define SCSICMD_MODE_SENSE_10                   0x5a        
  110.    
  111. #define SCSICMD_READ_12                         0xa8
  112. #define SCSICMD_WRITE_12                        0xaa
  113. //*****************************************************************************************
  114. // data struct Type Definition
  115. //*****************************************************************************************
  116. //Standard CBW package
  117. typedef struct
  118. {
  119.     UINT32 dCBWSignature;           //identify CBW
  120.     UINT32 dCBWTag;                 //a command block tag ,echo with dCSWTag
  121. UINT32 dCBWDataTransferLength;  //expect to transfer data length 
  122. UINT8   bmCBWFlags;             //direction
  123. UINT8   bCBWLUN;                //the device logical unit number
  124. UINT8   bCBWCBLength;           //the valid length of CBWCB 
  125. UINT8   CBWCB[16];              //the command block
  126. }sCBW,*pCBW;
  127. //Standard CSW package
  128. //define CSW status constant
  129. #define CSWStatePhaseErr        0x02
  130. #define CSWStateCommandFailed   0x01
  131. #define CSWStateCommandGood     0x00
  132. typedef struct
  133.     UINT32 dCSWSignature;                  //identify CSW
  134.     UINT32 dCSWTag;                            //echo dCBWTag
  135.     UINT32 dCSWDataResidue;              //the remainder data length 
  136.     UINT8   bCSWStatus;                       //indicate the success or failure of the command
  137. }sCSW,*pCSW;
  138. //---- SCSI-2 Commands ----------------
  139. //6-byte Command
  140. typedef struct 
  141. {
  142.     UINT8    operationCode;
  143.     UINT8    serviceAction; 
  144.     UINT16  logicalBlockAddress;
  145.     UINT8    dataLength;
  146.     UINT8    controlByte;
  147. } SCSICMD_06BYTE, *PSCSICMD_06BYTE;
  148. //10-byte Command
  149. typedef struct 
  150. {
  151.     UINT8   operationCode;
  152.     UINT8   serviceAction;
  153.     UINT32 logicalBlockAddress;
  154.     UINT8   reserved;
  155.     UINT8   dataLength;
  156.     UINT8   controlByte;
  157. } SCSICMD_10BYTE, *PSCSICMD_10BYTE;
  158. //12-byte Command
  159. typedef struct 
  160. {
  161.     UINT8   operationCode;
  162.     UINT8   serviceAction;
  163.     UINT32 logicalBlockAddress;
  164.     UINT32 dataLength;
  165.     UINT8   reserved;
  166.     UINT8   controlByte;
  167. } SCSICMD_12BYTE, *PSCSICMD_12BYTE;
  168. //16-byte Command
  169. typedef struct 
  170. {
  171.     UINT8   operationCode;
  172.     UINT8   serviceAction;
  173.     UINT32 logicalBlockAddress;
  174.     UINT32 addtionalCdbData;
  175.     UINT32 dataLength;
  176.     UINT8   reserved;
  177.     UINT8   controlByte;
  178. } SCSICMD_16BYTE, *PSCSICMD_16BYTE;
  179. //----the returned data after  SCSI-2 Commands  ----------------
  180. //Test UINT Ready
  181. #define SCSIDATA_TEST_SIZE                      0x00
  182. #define SCSICMD_TEST_CBWTag                     0x10300120
  183. //INQUIRY
  184. #define SCSIDATA_INQUIRY_SIZE                       0x24
  185. #define SCSICMD_INQUIRY_CBWTag                      0x00000120
  186. typedef struct 
  187. {
  188.       UINT8  peripheralDeviceType;//the bit0--bit5 represent the peripheral device type
  189.       UINT8  RMB;                             //bit7 represent RBM
  190.       UINT8  Version;                       //bit6-bit7 show ISOversion, bit3--bit5 show ECMA version,bit0--bit2 show ANSI version
  191.       UINT8  responseDataFormat; //bit0--bit3 show response data format 
  192.       UINT8  additionalLength; //0x1f                              
  193.       UINT8  reserved0[3];
  194.       UINT8  vendorInformation[8];
  195.       UINT8  productIdentification[16];
  196.       UINT8  productRevisionLevel[4];
  197. } SCSIDATA_INQUIRY, *PSCSIDATA_INQUIRY;
  198. //Read10
  199. #define SCSICMD_READ10_CBWTag                     0x22000120
  200. typedef struct
  201. {
  202.      UINT8  Read10OpCode;
  203.      UINT8  Read10LUNDPRelAdr;//bit5--bit7:LUN,bit4:DP0,bit3:FUA,bit1--bit2:Reserved,bit0:RelAddr
  204.      UINT32 Read10LBA;
  205.      UINT8   Read10Reserved;
  206.      UINT16  Read10BlockNum;
  207.      UINT8   Read10Control;
  208. }Read10Comm,*PRead10Comm;
  209. //Write 10
  210. #define  SCSICMD_WRITE10_CBWTag    0x22030120
  211. //MODE SENSE 06
  212. //MODE SELECT 06
  213. //Mode Parameter Header
  214. #define SCSIDATA_MODE_PARAMETER_HEADER_SIZE     0x08
  215. #define SCSICMD_MODE_CBWTag                     0x00303120
  216. typedef struct 
  217. {
  218.     UINT16  DataLength;
  219.     UINT8    mediumTypeCode;
  220.     UINT8    WPDPOFUA;//bit7 show WP,bit4 show DPOFUA,bit0--bir3 and bit5---bit6 is reserved
  221.     UINT8    reserved[4];
  222. } SCSIDATA_MODE_PARAMETER_HEADER, *PSCSIDATA_MODE_PARAMETER_HEADER;
  223. //READ CAPACITY
  224. #define SCSIDATA_READ_CAPACITY_SIZE                     0x08
  225. #define SCSICMD_READ_CAPACITY_CBWTag                    0x40303120
  226. typedef struct 
  227. {
  228.     UINT32  lastLogicalBlockAddress;
  229.     UINT32  blockLengthInBytes;
  230. } SCSIDATA_READ_CAPACITY, *PSCSIDATA_READ_CAPACITY;
  231. //READ FORMAT CAPACITY
  232. #define SCSIDATA_READ_FORMAT_CAPACITY_LIST_HEADER_SIZE          0x04
  233. //SCSICMD_READ_FORMAT_CAPACITIES
  234. #define SCSIDATA_READ_FORMAT_CAPACITIES_SIZE                    0xfc
  235. #define SCSIDATA_FORMAT_CAPACITIES_SIZE                         12
  236. #define SCSICMD_READ_FORMAT_CAPACITIES_CBWTag                   0x02000120
  237. typedef struct
  238. {
  239.     UINT8    reserved0;
  240.     UINT8    reserved1;
  241.     UINT8    reserved2;
  242.     UINT8    capacityListLength;
  243. } SCSIDATA_READ_CAPACITY_LIST_HEADER, *PSCSIDATA_READ_CAPACITY_LIST_HEADER;
  244. #define SCSIDATA_READ_FORMAT_MAXIMUM_SIZE                       0x08
  245. typedef struct 
  246. {
  247.     UINT32    numberOfBlocks;
  248.     UINT8      descCode;             //bit0-bit1 represent the desciptor code 
  249.     UINT8      blockLength[3];    
  250. } SCSIDATA_READ_FORMAT_MAXIMUM, *PSCSIDATA_READ_FORMAT_MAXIMUM;
  251. //Request Sense
  252. #define SCSIDATA_REQUESTSENSE_SIZE                              0x12
  253. #define SCSICMD_REQUESTSENSE_CBWTag                             0x02030120
  254. typedef struct
  255. {
  256.     UINT8    VErrCode;//bit7---valid;bit0--6:Error Code
  257.     UINT8    Reserved;
  258.     UINT8    SenseKey;//bit0--bit3:Sense Key
  259.     UINT32   Information;
  260.     UINT8    AdditionalSenseLen;
  261.     UINT8    Reserved1[4];
  262.     UINT8    ASC;//Additional Sense Code(Mandatory)
  263.     UINT8    ASCQ;//Additional Sense Code Qualifier(Mandatory)
  264.     UINT8    Reserver2[4];
  265. }SCSIDATA_REQUEST_SENSE,*pSCSIDATA_REQUEST_SENSE;
  266. //system state
  267. typedef struct
  268. {
  269.     UINT8 MainState; // main state
  270.     UINT8 SubState; // upper nibble: sub-state; lower nibble: extension state
  271. }STATE;
  272. #if defined(FAT_Write_File_System)||defined(FILE_MODE_WRITE)  //added by wangwei,2004-11-15 13:23(get total capacity of storage).
  273. extern UINT32 uiTotalCapacity;
  274. #endif
  275. //*****************************************************************************************
  276. //micro function  define
  277. //*****************************************************************************************
  278. #define ChangeSysMainState(x) Sys.MainState = (x); Sys.SubState = 0x00
  279. #define ChangeSysSubState(x)   Sys.SubState = x
  280. enum USBSys_MAIN_STATE
  281. {
  282.     USBSys_Init_MainState=0x01,                 //execute SCSI command :test uint ready,inquiry,read capacity
  283.     USBSys_GetFatInfo_MainState=0x02,     //get boot record,fat table,dir information
  284.     USBSys_GetFileData_MainState=0x03,   //get the file data in the mass storage
  285.     USBSys_ModifyFatInfo_MainState=0x04 //realize format,del,built new file and dir and so on
  286. };
  287. enum USBSys_Init_SubSTATE
  288. {
  289.     USB_Test_SubState=0x10,
  290.     USB_Inquiry_SubState  =0x11, 
  291.     USB_ReadFormatCapacities_SubState=0x12,
  292.     USB_RequestSense_SubState=0x13,
  293.     USB_Readcapcity_SubState=0x14
  294.  };
  295. enum  USBSys_GetFatInfo_SubSTATE
  296. {
  297.     USB_GetMBR_SubState=0x20,
  298.     USB_BootRecord_SubState  =0x21, 
  299.     USB_GetFatTable_SubState=0x22,
  300.     USB_GetDir_SubState=0x23
  301.  };
  302. enum USBSys_GetFileData_SubSTATE
  303. {
  304.     USB_Directory_SubState=0x30,
  305.     USB_FindFile_SubState=0x31,
  306.     USB_RecieveFile_SubState  =0x32
  307.  };
  308. #define USB_PRINTF printf  
  309. /*request sense error code*/
  310. #define   SCSI_NO_ERR               510    //sense key=0
  311. #define   SCSI_RECOVERED_ERR        511    //sense key=1
  312. #define   SCSI_NOT_READY_ERR        512    //sense key=2
  313. #define   SCSI_NO_REF_POS_ERR       513
  314. #define   SCSI_COMMUN_FAIL_ERR      514
  315. #define   SCSI_MED_NOT_PRE_ERR      515
  316. #define   SCSI_UNKNOWN_ERR          519
  317. #define   SCSI_MEDIUM_ERR           520    //sense key=3
  318. #define   SCSI_HARDWARE_ERR         521    //sense key=4
  319. #define   SCSI_ILLEGAL_REQ_ERR      522    //sense key=5
  320. #define   SCSI_UINT_ATTEN_ERR       523   //sense key=6
  321. #define   SCSI_DATA_PROT_ERR        524   //sense key=7
  322. #define   SCSI_ABORT_COMM_ERR       525   //sense key=0XBh
  323. #define   SCSI_VOL_OVERF_ERR        526  ////sense key=0XDh
  324. typedef  INT32 (*FUNCTION_RECERR_FUNCTION)();
  325. //*****************************************************************************************
  326. // function  section
  327. //*****************************************************************************************
  328. UINT8 CSWInXfer(UINT8 usbaddr,UINT32 Tag);
  329. UINT8 SCSICMD_Inquiry(UINT8 usbaddr);
  330. UINT8 SCSICMD_TestUnitReady(UINT8 ,UINT8);
  331. UINT8 SCSICMD_ReadCapcity(UINT8 usbaddr);
  332. UINT8 SCSICMD_ReadFormatCapcity(UINT8 usbaddr);
  333. INT32 SCSICMD_RequestSense(UINT8 usbaddr);
  334. UINT32  UsbTestReady();
  335. int SCSICMD_ReadSector(UINT32 ,UINT32 ,BYTE *);
  336. //#ifdef SPHE8202_USB_WRITE//WRITE_USB
  337. #if defined(SPHE8202_FAT_WRITE_API)||defined(SPHE8202_USB_WRITE)//lijd 2005-1-5 18:17
  338. int SCSICMD_WriteSector(UINT32 lba,UINT32 nSec,BYTE *buf);
  339.  int  SCSICMD_ModeSense(UINT8 usbaddr);
  340. #endif //#define   SPHE8202_USB_Write//WRITE_USB
  341. #endif //#define   SCSI_H