📄 scsi.h
字号:
#define CSW_STATUS_CMD_FAIL 0x01
#define CSW_STATUS_PHASE_ERROR 0x02
#define CBW_FLAG_IN 0x80
#define CBW_FLAG_OUT 0x00
#define CB_LENGTH_TEST_UNIT_READY 0x06
#define CB_LENGTH_REQUEST_SENSE 0x0C
#define CB_LENGTH_INQUIRY 0x06
#define CB_LENGTH_MODE_SENSE 0x06
//#define CB_LENGTH_ALLOW_MEDIUM_REMOVAL 0x1e
#define CB_LENGTH_READ_CAPACITY 0x0A
#define CB_LENGTH_READ_10 0x0A
#define CB_LENGTH_WRITE_10 0x0A
#define DATA_LENGTH_INQUIRY 36
#define DATA_LENGTH_MODE_SENSE 192
#define DATA_LENGTH_REQUEST_SENSE 18
#define DATA_LENGTH_READ_CAPACITY 8
//=================== 3.Structure Definition =============================================================
//========================================================================================================
//typedef struct CommandBlockWrapper
//{
// UINT32 u32Signature;
// INT32U u32Tag;
// INT32U u32DataTransferLength;
// INT8U u8Flags;
// INT8U u8LUN;
// INT8U u8CBLength;
// INT8U u8CB[16];
//} CBW;
//typedef struct CommandStatusWrapper
//{
// INT32U u32Signature;
// INT32U u32Tag;
// INT32U u32DataResidue;
// INT8U u8Status;
//} CSW;
typedef enum
{
SCSI_OPSTATE_TEST_UNIT_READY = 0,
SCSI_OPSTATE_REQUEST_SENSE,
SCSI_OPSTATE_INQUIRY,
SCSI_OPSTATE_MODE_SELECT,
SCSI_OPSTATE_MODE_SENSE,
SCSI_OPSTATE_ALLOW_MEDIUM_REMOVAL,
SCSI_OPSTATE_READ_CAPACITY,
SCSI_OPSTATE_READ_10,
SCSI_OPSTATE_WRITE_10
} ScsiOpState;
typedef struct ScsiDevice
{
// Get by INQUIRY command
UINT8 u8DeviceType;
UINT8 u8VendorID[8];
UINT8 u8ProductID[16];
UINT8 u8ProductVer[4];
} Scsi_Device;
// extern Scsi_Device tScsi_Device;
struct scsi_cmnd
{
// int sc_magic; //no use
// struct Scsi_Host *host;
// unsigned short state; //no use
// unsigned short owner; //no use
// Scsi_Device device;
// Scsi_Request *sc_request;
// struct scsi_cmnd *next; //no use
// struct scsi_cmnd *reset_chain; //no use
// int eh_state; //no use
/* Used for state tracking in error handlr */
// void (*done) (struct scsi_cmnd *); //no use
/* Mid-level done function */
/*
A SCSI Command is assigned a nonzero serial_number when internal_cmnd
passes it to the driver's queue command function. The serial_number
is cleared when scsi_done is entered indicating that the command has
been completed. If a timeout occurs, the serial number at the moment
of timeout is copied into serial_number_at_timeout. By subsequently
comparing the serial_number and serial_number_at_timeout fields
during abort or reset processing, we can detect whether the command
has already completed. This also detects cases where the command has
completed and the SCSI Command structure has already being reused
for another command, so that we can avoid incorrectly aborting or
resetting the new command.
*/
unsigned long serial_number; // CBW Tag
// unsigned long serial_number_at_timeout; //no use
// int retries; //no use
// int allowed; //no use
// int timeout_per_command; //no use
// int timeout_total; //no use
// int timeout; //no use
/*
* We handle the timeout differently if it happens when a reset,
* abort, etc are in process.
*/
// unsigned volatile char internal_timeout; //no use
// struct scsi_cmnd *bh_next; //no use
/* To enumerate the commands waiting
to be processed. */
// unsigned int target; //no use
unsigned char lun; //no use??
// unsigned int channel; //no use
unsigned char cmd_len;
// unsigned char old_cmd_len; //no use
unsigned char sc_data_direction;
// unsigned char sc_old_data_direction; //no use
/* These elements define the operation we are about to perform */
unsigned char cmnd[MAX_COMMAND_SIZE];
unsigned request_bufflen; /* Actual request size */
// struct timer_list eh_timeout; /* Used to time out the command. */
void *request_buffer; /* Actual requested buffer */
/* These elements define the operation we ultimately want to perform */
// unsigned char data_cmnd[MAX_COMMAND_SIZE]; //no use
// unsigned short old_use_sg; //no use
/* We save use_sg here when requesting
* sense info */
unsigned short use_sg; /* Number of pieces of scatter-gather */
// unsigned short sglist_len; //no use
/* size of malloc'd scatter-gather list */
// unsigned short abort_reason; //no use
/* If the mid-level code requests an
* abort, this is the reason. */
// unsigned bufflen; //no use
/* Size of data buffer */
// void *buffer; //no use
/* Data buffer */
// unsigned underflow; //no use
/* Return error if less than
this amount is transferred */
// unsigned old_underflow; //no use
/* save underflow here when reusing the
* command for error handling */
// unsigned transfersize; //no use
/* How much we are guaranteed to
transfer with each SCSI transfer
(ie, between disconnect /
reconnects. Probably == sector
size */
int resid;
/* Number of bytes requested to be
transferred less actual number
transferred (0 if not supported) */
// struct request *request; //no use
/* The command we are
working on */
unsigned char sense_buffer[SCSI_SENSE_BUFFERSIZE]; /* obtained by REQUEST SENSE
* when CHECK CONDITION is
* received on original command
* (auto-sense) */
unsigned flags;
/*
* Used to indicate that a command which has timed out also
* completed normally. Typically the completion function will
* do nothing but set this flag in this instance because the
* timeout handler is already running.
*/
// unsigned done_late:1; //no use
/* Low-level done function - can be used by low-level driver to point
* to completion function. Not used by mid/upper level code. */
void (*scsi_done) (struct scsi_cmnd *);
/*
* The following fields can be written to by the host specific code.
* Everything else should be left alone.
*/
// Scsi_Pointer SCp; /* Scratchpad used by some host adapters */
// unsigned char *host_scribble; //no use
/* The host adapter is allowed to
* call scsi_malloc and get some memory
* and hang it here. The host adapter
* is also expected to call scsi_free
* to release this memory. (The memory
* obtained by scsi_malloc is guaranteed
* to be at an address < 16Mb). */
int result; /* Status code from lower level driver */
unsigned char tag; /* SCSI-II queued command tag */
// unsigned long pid; /* Process ID, starts at 0 */
};
typedef struct scsi_cmnd Scsi_Cmnd;
struct LUN_Device
{
UINT8 u8LunNum;
/* file system : YPING add */
FileSysStruct FileSys;
// Get by READ CAPACITY command
UINT32 u32BlockSize;
UINT32 u32BlockTotalNum;
// Get by TEST UNIT READY command
UINT8 bDeviceReady;
// Save Write Protection information
UINT8 bWriteProtect;
};
struct us_data {
Scsi_Cmnd *srb; /* current srb */
Scsi_Device device;
UINT8 max_lun;
// For one Device but have many LUN
BOOLEAN bFileSystemInit;
struct LUN_Device* Mass_stor_device;
};
//=================== 4.Extern Function Definition =======================================================
//========================================================================================================
//extern void vSCSI_REQUEST_SENSE(void);
extern void vSCSI_REQUEST_SENSE(void);
extern BOOLEAN bSCSI_INQUIRY(void);
extern BOOLEAN bSCSI_READ_CAPACITY(void);
extern BOOLEAN bSCSI_TEST_UNIT_READY(void);
extern void vUSBDisk_FileSystem_Remove(void);
extern BOOLEAN bUSBDisk_FileSystem_Initial(void);
extern BOOLEAN bSCSI_Initial(struct LUN_Device* LunDevice);
extern BOOLEAN bSCSI_ERASE( struct LUN_Device* LunDevice, UINT32 u32BlockAddr, UINT32 u32BlockNum,
UINT32 u32SectorSize);
extern BOOLEAN bSCSI_READ_10( struct LUN_Device* LunDevice, UINT32 u32BlockAddr, UINT32 u32BlockNum,
UINT32 u32SectorSize, UINT8 *u8Buffer);
extern BOOLEAN bSCSI_Write_10( struct LUN_Device* LunDevice, UINT32 u32BlockAddr, UINT32 u32BlockNum,
UINT32 u32SectorSize, UINT8 *u8Buffer);
extern BOOLEAN bSCSI_MODE_SENSE(void);
extern BOOLEAN bSCSI_TEST_UNIT_READY(void);
//=================== 5.Extern Variable Definition =======================================================
//========================================================================================================
extern struct us_data *Mass_stor_us;
extern struct us_data us_data_Signal;
extern struct LUN_Device Mass_stor_device_1;
extern INT8U u8Drive;
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -