1 //<MStar Software> 2 //****************************************************************************** 3 // MStar Software 4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved. 5 // All software, firmware and related documentation herein ("MStar Software") are 6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by 7 // law, including, but not limited to, copyright law and international treaties. 8 // Any use, modification, reproduction, retransmission, or republication of all 9 // or part of MStar Software is expressly prohibited, unless prior written 10 // permission has been granted by MStar. 11 // 12 // By accessing, browsing and/or using MStar Software, you acknowledge that you 13 // have read, understood, and agree, to be bound by below terms ("Terms") and to 14 // comply with all applicable laws and regulations: 15 // 16 // 1. MStar shall retain any and all right, ownership and interest to MStar 17 // Software and any modification/derivatives thereof. 18 // No right, ownership, or interest to MStar Software and any 19 // modification/derivatives thereof is transferred to you under Terms. 20 // 21 // 2. You understand that MStar Software might include, incorporate or be 22 // supplied together with third party`s software and the use of MStar 23 // Software may require additional licenses from third parties. 24 // Therefore, you hereby agree it is your sole responsibility to separately 25 // obtain any and all third party right and license necessary for your use of 26 // such third party`s software. 27 // 28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as 29 // MStar`s confidential information and you agree to keep MStar`s 30 // confidential information in strictest confidence and not disclose to any 31 // third party. 32 // 33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any 34 // kind. Any warranties are hereby expressly disclaimed by MStar, including 35 // without limitation, any warranties of merchantability, non-infringement of 36 // intellectual property rights, fitness for a particular purpose, error free 37 // and in conformity with any international standard. You agree to waive any 38 // claim against MStar for any loss, damage, cost or expense that you may 39 // incur related to your use of MStar Software. 40 // In no event shall MStar be liable for any direct, indirect, incidental or 41 // consequential damages, including without limitation, lost of profit or 42 // revenues, lost or damage of data, and unauthorized system use. 43 // You agree that this Section 4 shall still apply without being affected 44 // even if MStar Software has been modified by MStar in accordance with your 45 // request or instruction for your use, except otherwise agreed by both 46 // parties in writing. 47 // 48 // 5. If requested, MStar may from time to time provide technical supports or 49 // services in relation with MStar Software to you for your use of 50 // MStar Software in conjunction with your or your customer`s product 51 // ("Services"). 52 // You understand and agree that, except otherwise agreed by both parties in 53 // writing, Services are provided on an "AS IS" basis and the warranty 54 // disclaimer set forth in Section 4 above shall apply. 55 // 56 // 6. Nothing contained herein shall be construed as by implication, estoppels 57 // or otherwise: 58 // (a) conferring any license or right to use MStar name, trademark, service 59 // mark, symbol or any other identification; 60 // (b) obligating MStar or any of its affiliates to furnish any person, 61 // including without limitation, you and your customers, any assistance 62 // of any kind whatsoever, or any information; or 63 // (c) conferring any license or right under any intellectual property right. 64 // 65 // 7. These terms shall be governed by and construed in accordance with the laws 66 // of Taiwan, R.O.C., excluding its conflict of law rules. 67 // Any and all dispute arising out hereof or related hereto shall be finally 68 // settled by arbitration referred to the Chinese Arbitration Association, 69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration 70 // Rules of the Association by three (3) arbitrators appointed in accordance 71 // with the said Rules. 72 // The place of arbitration shall be in Taipei, Taiwan and the language shall 73 // be English. 74 // The arbitration award shall be final and binding to both parties. 75 // 76 //****************************************************************************** 77 //<MStar Software> 78 /////////////////////////////////////////////////////////////////////////////// 79 // 80 // File name: drvScsi.h 81 // Version: 1.0 82 // Date: 2003/7/13 83 // Description: 84 // 85 // 86 // Author: 87 // Email: 88 // Phone: (03) 578-7888 89 // Company: Faraday Tech. Corp. 90 /////////////////////////////////////////////////////////////////////////////// 91 #ifndef SCSI_H 92 #define SCSI_H 93 94 95 96 /* 97 * This header file contains public constants and structures used by 98 * the scsi code for linux. 99 */ 100 //=================== 1.Condition Definition ============================================================ 101 //======================================================================================================== 102 #define ScsiCmd_Fail_Retry 3 103 #define TestUnitReady_Fail_Retry 0xff 104 #define Scsi_Max_Transfer_Len 16384 //65536;;yuwen 105 #define SCSI_DbgPrint printf 106 //#define printk printf 107 //=================== 2.Define Data Type ================================================================ 108 //======================================================================================================== 109 110 #ifndef BOOLEAN 111 #define BOOLEAN UINT8 112 #endif 113 #define INT32U UINT32 114 #define INT16U UINT16 115 #define INT8U UINT8 116 /* 117 * SCSI opcodes 118 */ 119 120 #define TEST_UNIT_READY 0x00 121 #define REQUEST_SENSE 0x03 122 #define FORMAT_UNIT 0x04 //Option (unsupport) 123 #define INQUIRY 0x12 124 #define MODE_SELECT 0x15 //(unsupport) 125 #define RESERVE 0x16 //Option (unsupport) 126 #define RELEASE 0x17 //Option (unsupport) 127 #define MODE_SENSE 0x1a 128 #define MODE_SENSE_5A 0x5a 129 #define START_STOP 0x1b // (unsupport) 130 #define ALLOW_MEDIUM_REMOVAL 0x1e 131 #define READ_CAPACITY 0x25 132 #define READ_FORMAT_CAPACITY 0x23 133 #define READ_10 0x28 134 #define WRITE_10 0x2a 135 #define VERIFY 0x2f //(unsupport) 136 #define SYNCHRONIZE_CACHE 0x35 //Option (unsupport) 137 #define WRITE_BUFFER 0x3b //Option (unsupport) 138 #define PERSISTENT_RESERVE_IN 0x5e //Option (unsupport) 139 #define PERSISTENT_RESERVE_OUT 0x5f //Option (unsupport) 140 141 #define SEND_DIAGNOSTIC 0x1d //(unsupport) 142 143 #define TYPE_DISK 0x00 144 145 /* 146 * FIXME(eric) - one of the great regrets that I have is that I failed to define 147 * these structure elements as something like sc_foo instead of foo. This would 148 * make it so much easier to grep through sources and so forth. I propose that 149 * all new elements that get added to these structures follow this convention. 150 * As time goes on and as people have the stomach for it, it should be possible to 151 * go back and retrofit at least some of the elements here with with the prefix. 152 */ 153 #define MAX_COMMAND_SIZE 16 154 #define SCSI_SENSE_BUFFERSIZE 64 155 156 #define DID_OK 0x00 /* NO error */ 157 #define DID_NO_CONNECT 0x01 /* Couldn't connect before timeout period */ 158 #define DID_BUS_BUSY 0x02 /* BUS stayed busy through time out period */ 159 #define DID_TIME_OUT 0x03 /* TIMED OUT for other reason */ 160 #define DID_BAD_TARGET 0x04 /* BAD target. */ 161 #define DID_ABORT 0x05 /* Told to abort for some other reason */ 162 #define DID_PARITY 0x06 /* Parity error */ 163 #define DID_ERROR 0x07 /* Internal error */ 164 #define DID_RESET 0x08 /* Reset by somebody. */ 165 #define DID_BAD_INTR 0x09 /* Got an interrupt we weren't expecting. */ 166 #define DID_PASSTHROUGH 0x0a /* Force command past mid-layer */ 167 #define DID_SOFT_ERROR 0x0b /* The low level driver just wish a retry */ 168 #define DRIVER_OK 0x00 /* Driver status */ 169 170 /* 171 * These are the values that the SCpnt->sc_data_direction and 172 * SRpnt->sr_data_direction can take. These need to be set 173 * The SCSI_DATA_UNKNOWN value is essentially the default. 174 * In the event that the command creator didn't bother to 175 * set a value, you will see SCSI_DATA_UNKNOWN. 176 */ 177 #define SCSI_DATA_UNKNOWN 0 178 #define SCSI_DATA_WRITE 1 179 #define SCSI_DATA_READ 2 180 #define SCSI_DATA_NONE 3 181 182 /* 183 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 184 * T10/1561-D Revision 4 Draft dated 7th November 2002. 185 */ 186 #define SAM_STAT_GOOD 0x00 187 #define SAM_STAT_CHECK_CONDITION 0x02 188 #define SAM_STAT_CONDITION_MET 0x04 189 #define SAM_STAT_BUSY 0x08 190 #define SAM_STAT_INTERMEDIATE 0x10 191 #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 192 #define SAM_STAT_RESERVATION_CONFLICT 0x18 193 #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ 194 #define SAM_STAT_TASK_SET_FULL 0x28 195 #define SAM_STAT_ACA_ACTIVE 0x30 196 #define SAM_STAT_TASK_ABORTED 0x40 197 198 199 /* 200 * Overrides for Emacs so that we follow Linus's tabbing style. 201 * Emacs will notice this stuff at the end of the file and automatically 202 * adjust the settings for this buffer only. This must remain at the end 203 * of the file. 204 * --------------------------------------------------------------------------- 205 * Local variables: 206 * c-indent-level: 4 207 * c-brace-imaginary-offset: 0 208 * c-brace-offset: -4 209 * c-argdecl-indent: 4 210 * c-label-offset: -4 211 * c-continued-statement-offset: 4 212 * c-continued-brace-offset: 0 213 * indent-tabs-mode: nil 214 * tab-width: 8 215 * End: 216 */ 217 #define CBW_TAG 0x01020304 // temp 218 219 #define CBW_SIGNATE 0x43425355 220 #define CSW_SIGNATE 0x53425355 221 #define CSW_STATUS_CMD_PASS 0x00 222 #define CSW_STATUS_CMD_FAIL 0x01 223 #define CSW_STATUS_PHASE_ERROR 0x02 224 225 #define CBW_FLAG_IN 0x80 226 #define CBW_FLAG_OUT 0x00 227 228 #define CB_LENGTH_TEST_UNIT_READY 0x06 229 #define CB_LENGTH_REQUEST_SENSE 0x0C 230 #define CB_LENGTH_INQUIRY 0x06 231 #define CB_LENGTH_MODE_SENSE 0x06 232 #define CB_LENGTH_MODE_SENSE_5A 0x0A 233 //#define CB_LENGTH_ALLOW_MEDIUM_REMOVAL 0x1e 234 #define CB_LENGTH_READ_CAPACITY 0x0A 235 #define CB_LENGTH_READ_10 0x0A 236 #define CB_LENGTH_WRITE_10 0x0A 237 238 239 240 #define DATA_LENGTH_INQUIRY 36 241 #define DATA_LENGTH_MODE_SENSE 32 //192 , yuwen 242 #define DATA_LENGTH_MODE_SENSE_OperCode5A 32 243 #define DATA_LENGTH_REQUEST_SENSE 18 244 #define DATA_LENGTH_READ_CAPACITY 8 245 246 247 248 249 250 251 //=================== 3.Structure Definition ============================================================= 252 //======================================================================================================== 253 254 255 //typedef struct CommandBlockWrapper 256 //{ 257 // UINT32 u32Signature; 258 // INT32U u32Tag; 259 // INT32U u32DataTransferLength; 260 // INT8U u8Flags; 261 // INT8U u8LUN; 262 // INT8U u8CBLength; 263 // INT8U u8CB[16]; 264 //} CBW; 265 266 //typedef struct CommandStatusWrapper 267 //{ 268 // INT32U u32Signature; 269 // INT32U u32Tag; 270 // INT32U u32DataResidue; 271 // INT8U u8Status; 272 //} CSW; 273 274 typedef enum 275 { 276 SCSI_OPSTATE_TEST_UNIT_READY = 0, 277 SCSI_OPSTATE_REQUEST_SENSE, 278 SCSI_OPSTATE_INQUIRY, 279 SCSI_OPSTATE_MODE_SELECT, 280 SCSI_OPSTATE_MODE_SENSE, 281 SCSI_OPSTATE_ALLOW_MEDIUM_REMOVAL, 282 SCSI_OPSTATE_READ_CAPACITY, 283 SCSI_OPSTATE_READ_10, 284 SCSI_OPSTATE_WRITE_10 285 } ScsiOpState; 286 287 288 typedef struct ScsiDevice 289 { 290 // Get by INQUIRY command 291 UINT8 u8DeviceType; 292 //UINT8 u8VendorID[8]; //Colin, moved to LUN device 293 //UINT8 u8ProductID[16]; 294 //UINT8 u8ProductVer[4]; 295 } Scsi_Device; 296 297 // extern Scsi_Device tScsi_Device; 298 #define BUFFER_LOGI 0 299 #define BUFFER_PHY 1 300 struct scsi_cmnd 301 { 302 303 unsigned char lun; //no use?? 304 // unsigned int channel; //no use 305 unsigned char cmd_len; 306 // unsigned char old_cmd_len; //no use 307 unsigned char sc_data_direction; 308 // unsigned char sc_old_data_direction; //no use 309 310 /* These elements define the operation we are about to perform */ 311 // unsigned char cmnd[MAX_COMMAND_SIZE]; 312 U32 request_bufflen; /* Actual request size */ 313 314 U32 request_buffer; /* Actual requested buffer */ 315 316 U8 result; /* Status code from lower level driver */ 317 318 unsigned char tag; /* SCSI-II queued command tag */ 319 // unsigned long pid; /* Process ID, starts at 0 */ 320 }; 321 322 typedef struct scsi_cmnd Scsi_Cmnd; 323 324 325 struct LUN_Device 326 { 327 UINT8 u8LunNum; 328 /* file system : YPING add */ 329 // FAT_FileSysStruct FileSys; 330 331 // Get by READ CAPACITY command 332 UINT32 u32BlockSize; 333 UINT32 u32BlockTotalNum; 334 335 // Get by TEST UNIT READY command 336 UINT8 bDeviceReady; 337 UINT8 bDeviceValid; 338 // Save Write Protection information 339 UINT8 bWriteProtect; 340 UINT8 bRMB; 341 342 UINT8 u8VendorID[8]; 343 UINT8 u8ProductID[16]; 344 UINT8 u8ProductVer[4]; 345 }; 346 347 348 struct us_data { 349 350 Scsi_Cmnd *srb; /* current srb */ 351 Scsi_Device device; 352 UINT8 max_lun; 353 // For one Device but have many LUN 354 BOOLEAN bFileSystemInit; 355 struct LUN_Device* Mass_stor_device; 356 }; 357 358 359 360 //=================== 4.Extern Function Definition ======================================================= 361 //======================================================================================================== 362 363 //extern void vSCSI_REQUEST_SENSE(void); 364 extern BOOLEAN vSCSI_REQUEST_SENSE_Port4(U8); 365 extern BOOLEAN bSCSI_INQUIRY_Port4(U8); 366 extern BOOLEAN bSCSI_READ_CAPACITY_Port4(U8); 367 extern BOOLEAN bSCSI_TEST_UNIT_READY_Port4(U8); 368 369 extern BOOLEAN bInit_USB_LUN_Port4(U8); 370 371 372 extern BOOLEAN bSCSI_Initial_Port4(void); 373 374 extern BOOLEAN bSCSI_ERASE( struct LUN_Device* LunDevice, UINT32 u32BlockAddr, UINT32 u32BlockNum, 375 UINT32 u32SectorSize); 376 //extern BOOLEAN bSCSI_Read_10(U8 lun, UINT32 u32BlockAddr, UINT32 u32BlockNum,UINT32 u8Buffer); 377 //extern BOOLEAN bSCSI_Write_10(U8 lun, UINT32 u32BlockAddr, UINT32 u32BlockNum, UINT32 u8Buffer); 378 extern BOOLEAN bSCSI_Read_Write10_Port4(BOOLEAN DoWrite, U8 lun, INT32U u32BlockAddr, INT32U u32BlockNum,U32 u8Buffer); 379 extern BOOLEAN vSCSI_EJECT_DEVICE_Port4(U8 lun); 380 381 extern BOOLEAN bSCSI_MODE_SENSE_Port4(U8); 382 extern BOOLEAN bSCSI_MODE_SENSE_OperCode5A_Port4(U8); 383 //=================== 5.Extern Variable Definition ======================================================= 384 //======================================================================================================== 385 extern struct us_data Mass_stor_us1_port4; 386 387 //extern struct us_data *Mass_stor_us; 388 extern struct us_data us_data_Signal; 389 //extern INT8U u8Drive; 390 extern struct LUN_Device Mass_stor_device_1_port4; 391 392 393 394 395 396 397 #endif 398 399