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 /* 157 * These are the values that the SCpnt->sc_data_direction and 158 * SRpnt->sr_data_direction can take. These need to be set 159 * The SCSI_DATA_UNKNOWN value is essentially the default. 160 * In the event that the command creator didn't bother to 161 * set a value, you will see SCSI_DATA_UNKNOWN. 162 */ 163 #define SCSI_DATA_UNKNOWN 0 164 #define SCSI_DATA_WRITE 1 165 #define SCSI_DATA_READ 2 166 #define SCSI_DATA_NONE 3 167 168 /* 169 * SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft 170 * T10/1561-D Revision 4 Draft dated 7th November 2002. 171 */ 172 #define SAM_STAT_GOOD 0x00 173 #define SAM_STAT_CHECK_CONDITION 0x02 174 #define SAM_STAT_CONDITION_MET 0x04 175 #define SAM_STAT_BUSY 0x08 176 #define SAM_STAT_INTERMEDIATE 0x10 177 #define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14 178 #define SAM_STAT_RESERVATION_CONFLICT 0x18 179 #define SAM_STAT_COMMAND_TERMINATED 0x22 /* obsolete in SAM-3 */ 180 #define SAM_STAT_TASK_SET_FULL 0x28 181 #define SAM_STAT_ACA_ACTIVE 0x30 182 #define SAM_STAT_TASK_ABORTED 0x40 183 184 185 /* 186 * Overrides for Emacs so that we follow Linus's tabbing style. 187 * Emacs will notice this stuff at the end of the file and automatically 188 * adjust the settings for this buffer only. This must remain at the end 189 * of the file. 190 * --------------------------------------------------------------------------- 191 * Local variables: 192 * c-indent-level: 4 193 * c-brace-imaginary-offset: 0 194 * c-brace-offset: -4 195 * c-argdecl-indent: 4 196 * c-label-offset: -4 197 * c-continued-statement-offset: 4 198 * c-continued-brace-offset: 0 199 * indent-tabs-mode: nil 200 * tab-width: 8 201 * End: 202 */ 203 #define CBW_TAG 0x01020304 // temp 204 205 #define CBW_SIGNATE 0x43425355 206 #define CSW_SIGNATE 0x53425355 207 #define CSW_STATUS_CMD_PASS 0x00 208 #define CSW_STATUS_CMD_FAIL 0x01 209 #define CSW_STATUS_PHASE_ERROR 0x02 210 211 #define CBW_FLAG_IN 0x80 212 #define CBW_FLAG_OUT 0x00 213 214 #define CB_LENGTH_TEST_UNIT_READY 0x06 215 #define CB_LENGTH_REQUEST_SENSE 0x0C 216 #define CB_LENGTH_INQUIRY 0x06 217 #define CB_LENGTH_MODE_SENSE 0x06 218 #define CB_LENGTH_MODE_SENSE_5A 0x0A 219 //#define CB_LENGTH_ALLOW_MEDIUM_REMOVAL 0x1e 220 #define CB_LENGTH_READ_CAPACITY 0x0A 221 #define CB_LENGTH_READ_10 0x0A 222 #define CB_LENGTH_WRITE_10 0x0A 223 224 225 226 #define DATA_LENGTH_INQUIRY 36 227 #define DATA_LENGTH_MODE_SENSE 32 //192 , yuwen 228 #define DATA_LENGTH_MODE_SENSE_OperCode5A 32 229 #define DATA_LENGTH_REQUEST_SENSE 18 230 #define DATA_LENGTH_READ_CAPACITY 8 231 232 233 234 235 236 237 //=================== 3.Structure Definition ============================================================= 238 //======================================================================================================== 239 240 241 //typedef struct CommandBlockWrapper 242 //{ 243 // UINT32 u32Signature; 244 // INT32U u32Tag; 245 // INT32U u32DataTransferLength; 246 // INT8U u8Flags; 247 // INT8U u8LUN; 248 // INT8U u8CBLength; 249 // INT8U u8CB[16]; 250 //} CBW; 251 252 //typedef struct CommandStatusWrapper 253 //{ 254 // INT32U u32Signature; 255 // INT32U u32Tag; 256 // INT32U u32DataResidue; 257 // INT8U u8Status; 258 //} CSW; 259 260 typedef enum 261 { 262 SCSI_OPSTATE_TEST_UNIT_READY = 0, 263 SCSI_OPSTATE_REQUEST_SENSE, 264 SCSI_OPSTATE_INQUIRY, 265 SCSI_OPSTATE_MODE_SELECT, 266 SCSI_OPSTATE_MODE_SENSE, 267 SCSI_OPSTATE_ALLOW_MEDIUM_REMOVAL, 268 SCSI_OPSTATE_READ_CAPACITY, 269 SCSI_OPSTATE_READ_10, 270 SCSI_OPSTATE_WRITE_10 271 } ScsiOpState; 272 273 274 typedef struct ScsiDevice 275 { 276 // Get by INQUIRY command 277 UINT8 u8DeviceType; 278 //UINT8 u8VendorID[8]; //Colin, moved to LUN device 279 //UINT8 u8ProductID[16]; 280 //UINT8 u8ProductVer[4]; 281 } Scsi_Device; 282 283 // extern Scsi_Device tScsi_Device; 284 #define BUFFER_LOGI 0 285 #define BUFFER_PHY 1 286 struct scsi_cmnd 287 { 288 289 unsigned char lun; //no use?? 290 // unsigned int channel; //no use 291 unsigned char cmd_len; 292 // unsigned char old_cmd_len; //no use 293 unsigned char sc_data_direction; 294 // unsigned char sc_old_data_direction; //no use 295 296 /* These elements define the operation we are about to perform */ 297 // unsigned char cmnd[MAX_COMMAND_SIZE]; 298 U32 request_bufflen; /* Actual request size */ 299 300 U32 request_buffer; /* Actual requested buffer */ 301 302 U8 result; /* Status code from lower level driver */ 303 304 unsigned char tag; /* SCSI-II queued command tag */ 305 // unsigned long pid; /* Process ID, starts at 0 */ 306 }; 307 308 typedef struct scsi_cmnd Scsi_Cmnd; 309 310 311 struct LUN_Device 312 { 313 UINT8 u8LunNum; 314 /* file system : YPING add */ 315 // FAT_FileSysStruct FileSys; 316 317 // Get by READ CAPACITY command 318 UINT32 u32BlockSize; 319 UINT32 u32BlockTotalNum; 320 321 // Get by TEST UNIT READY command 322 UINT8 bDeviceReady; 323 UINT8 bDeviceValid; 324 // Save Write Protection information 325 UINT8 bWriteProtect; 326 UINT8 bRMB; 327 328 UINT8 u8VendorID[8]; 329 UINT8 u8ProductID[16]; 330 UINT8 u8ProductVer[4]; 331 }; 332 333 334 struct us_data { 335 336 Scsi_Cmnd *srb; /* current srb */ 337 Scsi_Device device; 338 UINT8 max_lun; 339 // For one Device but have many LUN 340 BOOLEAN bFileSystemInit; 341 struct LUN_Device* Mass_stor_device; 342 }; 343 344 345 346 //=================== 4.Extern Function Definition ======================================================= 347 //======================================================================================================== 348 349 //extern void vSCSI_REQUEST_SENSE(void); 350 extern BOOLEAN vSCSI_REQUEST_SENSE_Port2(U8); 351 extern BOOLEAN bSCSI_INQUIRY_Port2(U8); 352 extern BOOLEAN bSCSI_READ_CAPACITY_Port2(U8); 353 extern BOOLEAN bSCSI_TEST_UNIT_READY_Port2(U8); 354 355 extern BOOLEAN bInit_USB_LUN_Port2(U8); 356 357 358 extern BOOLEAN bSCSI_Initial_Port2(void); 359 360 extern BOOLEAN bSCSI_ERASE( struct LUN_Device* LunDevice, UINT32 u32BlockAddr, UINT32 u32BlockNum, 361 UINT32 u32SectorSize); 362 //extern BOOLEAN bSCSI_Read_10(U8 lun, UINT32 u32BlockAddr, UINT32 u32BlockNum,UINT32 u8Buffer); 363 //extern BOOLEAN bSCSI_Write_10(U8 lun, UINT32 u32BlockAddr, UINT32 u32BlockNum, UINT32 u8Buffer); 364 extern BOOLEAN bSCSI_Read_Write10_Port2(BOOLEAN DoWrite, U8 lun, INT32U u32BlockAddr, INT32U u32BlockNum,U32 u8Buffer); 365 extern BOOLEAN vSCSI_EJECT_DEVICE_Port2(U8 lun); 366 367 extern BOOLEAN bSCSI_MODE_SENSE_Port2(U8); 368 extern BOOLEAN bSCSI_MODE_SENSE_OperCode5A_Port2(U8); 369 //=================== 5.Extern Variable Definition ======================================================= 370 //======================================================================================================== 371 extern struct us_data Mass_stor_us1_port2; 372 373 //extern struct us_data *Mass_stor_us; 374 extern struct us_data us_data_Signal; 375 //extern INT8U u8Drive; 376 extern struct LUN_Device Mass_stor_device_1_port2; 377 378 379 380 381 382 383 #endif 384 385