SCSI命令.docx

上传人:b****5 文档编号:5233138 上传时间:2022-12-14 格式:DOCX 页数:25 大小:26.30KB
下载 相关 举报
SCSI命令.docx_第1页
第1页 / 共25页
SCSI命令.docx_第2页
第2页 / 共25页
SCSI命令.docx_第3页
第3页 / 共25页
SCSI命令.docx_第4页
第4页 / 共25页
SCSI命令.docx_第5页
第5页 / 共25页
点击查看更多>>
下载资源
资源描述

SCSI命令.docx

《SCSI命令.docx》由会员分享,可在线阅读,更多相关《SCSI命令.docx(25页珍藏版)》请在冰豆网上搜索。

SCSI命令.docx

SCSI命令

SCSI命令的发行

1.uscsi接口

Solaris通过uscsi(userSCSIcommandinterface)接口来发行SCSI命令.接口函数是ioctl:

#include

ioctl(intfildes,intrequest,structuscsi_cmd*cmd);

↓↓

设备描述符USCSICMD

uscsi_cmd结构体包含以下的成员:

intuscsi_flags;/*read,write,etc.seebelow*/

shortuscsi_status;/*resultingstatus*/

shortuscsi_timeout;/*CommandTimeout*/

caddr_tuscsi_cdb;/*CDBtosendtotarget*/

caddr_tuscsi_bufaddr;/*i/osource/destination*/

u_intuscsi_buflen;/*sizeofi/ototakeplace*/

u_intuscsi_resid;/*residfromi/ooperation*/

u_charuscsi_cdblen;/*#ofvalidCDBbytes*/

u_charuscsi_rqlen;/*sizeofuscsi_rqbuf*/

u_charuscsi_rqstatus;/*statusofrequestsensecmd*/

u_charuscsi_rqresid;/*residofrequestsensecmd*/

caddr_tuscsi_rqbuf;/*requestsensebuffer*/

void*uscsi_reserved_5;/*Reservedforfutureuse*/

 

1.1.uscsi_cmd:

:

uscsi_flags

uscsi_flags设置I/O的方向以及其他一些细节:

名称

可选值

描述

uscsi_flags

USCSI_READ

从设备中读取数据

USCSI_WRITE

向设备发行数据

USCSI_RQENABLE

获取sense信息有效

USCSI_SILENT

禁止向console打印出错或警告信息

USCSI_DIAGNOSE

SCSI命令异常终止后,禁止retry或recovery机制

USCSI_ISOLATE

禁止此SCSI命令与其他命令同时发行

USCSI_ASYNC

设置SCSIbus为异步模式

USCSI_SYNC

设置SCSIbus为同步模式

USCSI_RESET

向设备发送reset消息

USCSI_RESET_ALL

ResetSCSIbus

我们常用的是USCSI_READ,USCSI_WRITE;而USCSI_RQENABLE做为获取sense信息的必要条件,常常被做为复选值设置.比如:

ucmd.uscsi_flags=USCSI_READ|USCSI_RQENABLE|…;或

ucmd.uscsi_flags|=USCSI_RQENABLE;

1.2.uscsi_cmd:

:

uscsi_cdb

uscsi_cdb是指向设置的CDB指针,其中存储了向设备发行哪种SCSI命令的具体信息.

SCSI命令格式CDB

CDB(Command/Descriptor/Block)存储了准备向设备发行的命令信息.

CDBformat

Bit

Byte

7

6

5

4

3

2

1

0

0

OperationCode

1~(N-1)

CommandSpec.Parameter

N

Controller

OperationCodeFormat

Bit

Byte

7

6

5

4

3

2

1

0

GroupCode

CommandCode

GroupCode0[000b]:

6ByteCommand

1[001b]:

10ByteCommand

2[010b]:

10ByteCommand

3[011b]:

Reserve

4[100b]:

16ByteCommand

5[101b]:

12ByteCommand

6[110b]:

VendorSpecification

7[111b]:

VendorSpecification

※有关各SCSI命令的OperationCode,请参考[Appendix1:

SCSICommandList]

※关于各SCSI命令的CDB具体信息,请参考富士通SCSI相关资料

编程中的实例如下,发行Read(10),此命令的CDB格式如下表所示:

Read(10)

Bit

Byte

OperationCode(28h)

1

Reserved

(000)b

DPO

FUA

(0)b

Reserved

(000)b

RelAdr(0)b

(MSB)

LBA

(LSB)

Reserved(00h)

(MSB)

TransferLength(LSB)

Controller

structuscsi_cmdmy_cmd;

unsignedcharmy_scsi_cdb[10];

/*Initializemy_scsi_cdbasaRead(10)*/

my_scsi_cdb[0]=0x28;/*OperationCode28h*/

my_scsi_cdb[1]=0x00;/*Flag*/

my_scsi_cdb[2]=0x01;/*LBA:

0x01020304*/

my_scsi_cdb[3]=0x02;

my_scsi_cdb[4]=0x03;

my_scsi_cdb[5]=0x04;

my_scsi_cdb[6]=0x00;/*Reserved*/

my_scsi_cdb[7]=0x00;/*Length:

0x00ff*/

my_scsi_cdb[8]=0xff;

my_scsi_cdb[9]=0x00;/*Controller*/

my_cmd.uscsi_cdb=my_scsi_cdb;/*We'llbeusingthearrayabovefortheCDB*/

my_cmd.uscsi_cdblen=10;/*TheCDBis6byteslong*/

1.3.uscsi_cmd:

:

uscsi_cdblen

定义了uscsi_cdb的长度.

1.4.uscsi_cmd:

:

uscsi_status

当ioctl发行后,uscsi_status用来返回SCSIstatusbyte,指示命令返回的状态.SCSIstatusbyte只有bit1~5有效,表示状态值,而bit0,6,7保留,如下所示:

7

6

5

4

3

2

1

0

R

R

R

返回的状态值有以下几种:

Bitofstatusbyte

76543210

ValueinHex

Meaning

RR00000R

00

GoodStatus

RR00001R

02

CheckCondition

RR00010R

04

ConditionMet/Good

RR00100R

08

Busy

RR01000R

10

Intermediate/Good

RR01010R

14

Intermediate/ConditionMet/Good

RR01100R

18

ReservationConflict

RR10001R

22

CommandTerminated

RR10100R

28

QueueFull

xx

OtherCodesAreReserved

当返回值为02(CheckCondition)时,在USCSI_RQENABLE设置的情况下,设备驱动会自动发行RequestSenseCommand,从而可以进一步对sensedata进行分析.

根据以上的特性,在编程过程中可以选择如下的方法:

#defineSTATUS_MASK0x3E

#defineSTATUS_GOOD0x00

#defineSTATUS_CHECK0x02

ret=ioctl(fd,USCSICMD,&req);

if(ret<0){

/*APIerrorhandle*/

}

else{/*Devicedriverexecuteresult*/

if((req.uscsi_status&STATUS_MASK)==STATUS_GOOD){

/*Good*/

}elseif((req.uscsi_status&STATUS_MASK)==STATUS_CHECK){

/*CheckCondition*/

/*CheckSensekey,AdditionalSenseCodes/Qualifiers(ASC/ASCQ)…*/

}else{

/*other*/

}

}

1.5.uscsi_cmd:

:

uscsi_bufaddr

用户定义的buffer,SCSI命令从设备读取/写入的信息,都存储在此buffer中.

1.6.uscsi_cmd:

:

uscsi_buflen

定义了uscsi_bufaddr的长度,以byte计数.

1.7.uscsi_cmd:

:

uscsi_resid

如果数据传输在完成所有被要求的数据传送之前终止,则剩余部分(remainder/residue)的数据个数被存储在uscsi_resid中.当然,uscsi_resid的期待值应该是0.

1.8.uscsi_cmd:

:

uscsi_rqlen

如果设置了USCSI_RQENABL位,caddr_tuscsi_rqlen规定了要得到的Sensebuffer的长度,以byte计数.

1.9.uscsi_cmd:

:

uscsi_rqstatus

如果设置了USCSI_RQENABL位,并且uscsi_status返回位02(CheckCondition),系统将自动发行RequestSensecommand来获取Sense信息,uscsi_rqstatus用来接受RequestSensecommand的返回值.性质和uscsi_status相同.

1.10.uscsi_cmd:

:

uscsi_rqresid

如果为RequestSense信息定义的buffer过小,uscsi_rqresid表示了没有被存储进来的数目.性质和uscsi_resid相同.

1.11.uscsi_cmd:

:

uscsi_rqbuf

uscsi_rqbuf指针指向了存储RequestSense信息的buffer.

1.12.uscsi_cmd:

:

uscsi_timeout

允许命令运行的时间,以秒为单位,一般设置几秒到几分钟不等.如果系统在规定时间内没有完成,则认为失败.

my_cmd.uscsi_timeout=15;/*Allow15secondsforcompletion*/

1.13.uscsi_cmd:

:

uscsi_reserved_5

这5个字节,他(她)们还没有被用到.

2.SenseData

当设备返回02(Checkcondition)状态,且设置了USCSI_RQENABL标志位,系统执行ReqeuestSenseCommand生成sensedata,sense信息可以帮助我们找出错误的原因.

格式如下:

Bit

7

6

5

4

3

2

1

0

Byte0

Valid

ErrorCode(70h)

1

Segmentnumber(00h)

2

0

0

0

0

SenseKey

3

[MSB]

[LSB]

4

5

6

7

AdditionalSenseDataLength

8

CommandSpecificInformation

9

10

11

12

SenseCode(ASC)

13

SubSenseCode(ASCQ)

14

FRUcode

15

SKSV

(00h)

16

SenseKeySpecificInformation

17

18

DestinationID(LOOPID)

19

HOSToperationCommand

20

FaultFactorCode

21

Reserved

22~23

LUN

24~55

DetailInformation–1

56~71

DetailInformation–1

SenseKey表示了什么错误原因导致了sensedata.下表列出了SenseKey各值的意义:

SenseKey

Name

Description

0

NOSENSE

NospecificSenseKeyexists

1

RECOVEREDERROR

a)Thelastcommandexecutedsuccessfullyterminatedalongwiththerecoveroperation.Ifamultiplenumberoferrorsthatweresuccessfullycorrectionoccurredduringtheprocessofacommand,thelastoneis

reported.

b)TheRoundingProcessoftheMODESELECTParameterwasexecuted.

2

NOTREADY

TheLogicalDevicecannotbeaccessed.

3

MEDIUMERROR

Duetodefectivemediaorerrorsinrecordeddata,unrecoverableerrorshavebeendetected.

4

HARDWAREERROR

UnrecoverableErrorsdetectedinhardwarewhileexecutingacommandortheself-diag.Process.

5

ILLEGALREQUEST

IllegalvaluedetectedinCDBortransferredparameter.OrtheLUNspecificationiswrong.

6

UNITATTENTION

UnitAttentionConditionoccurred.

7

DATAPROTECT

IllegalexecutionofoperationintheRead/WriteInhibitedArea.(commandnotexecuted)TheSETLIMITScommandoccurredtwiceinalinkcommandgroup.

8

BLANKCHECK

Notused

9

VENDERSPECIFIC

Notused

A

COPYABORTED

Notused

B

ABORTEDCOMMAND

Executedcommandabnormallyterminated.INITnormallyreissuesthecommandinanattempttosuccessfullycompletethecommand.

C

EQUAL

Notused

D

VOLUMEOVERFLOW

Notused

E

MISCOMPARE

NomatchwhendatacomparisonwasmadeduringtheVerifyCommandByteCheckprocess.

F

(Reserved)

Notused

SenseCode(BYTE12)和SubsenseCode(BYTE13)提供了更具体的信息,有关具体意义请参考[Appendix2:

AdditionalSenseCodes/Qualifiers(ASC/ASCQ)].

3.实现时的注意点

3.1.设备打开方式

如果是DirectAccess,打开设备时应使用O_NDELAY方式,如:

fd=open(“/dev/rdsk/c3t0d0s2”,O_RDWR|O_NDELAY);

3.2.Endian差异

具体请参考上次介绍Endian的文档.

Appendix1:

SCSICommandList

OperatoinCode-CommandName

∙00-TestUnitReady

∙01-Rewind(SequentialDevices)

∙01-RezeroUnit(otherDevices)

∙03-RequestSense

∙04-FormatUnit

∙05-ReadBlockLimits(Sequential)

∙07-ReassignBlocks

∙08-Read(6)(SequentialDevices)

∙0A-Write(6)(SequentialDevices)

∙0B-Seek

∙0F-ReadReverse(Sequential)

∙10-WriteFilemarks(Seq.Devices)

∙11-Space(Sequential)

∙12-Inquiry

∙13-Verify(Sequential)

∙14-RecoverBufferedData(Seqntl)

∙15-ModeSelect(6)

∙16-ReserveUnit(6)

∙17-ReleaseUnit(6)

∙18-Copy

∙19-Erase(SequentialDevices)

∙1A-ModeSense(6)

∙1B-Load/Unload(Sequential)

∙1C-Stop/StartUnit

∙1D-SendDiagnostics

∙1E-Prevent/AllowMediaRemoval

∙24-SetWindow

∙25-ReadCapacity

∙28-Read(10)(DirectAccessDevices)

∙29-Read(10)Generation

∙2A-Write(10)(DirectAccessDevices)

∙2B-Seek(10)

∙2C-Erase(10)

∙2D-ReadUpdatedBlock

∙2E-WriteandVerify

∙2F-Verify

∙30-SearchDataHigh

∙31-SearchDataEqual

∙32-SearchDataLow

∙33-SetLimits

∙34-Pre-Fetch

∙35-SynchronizeCache

∙36-Lock/UnlockCache

∙37-ReadDefectData

∙38-MediumScan

∙39-Compare

∙3A-CopyandVerify

∙3B-WriteBuffer

∙3C-ReadBuffer

∙3D-UpdateBlock

∙3E-ReadLong

∙3F-WriteLong

∙40-ChangeDefinition

∙41-WriteSame

∙42-ReadSub-Channel

∙43-ReadTOC

∙44-ReadHeader

∙45-PlayAudio(10)

∙47-PlayAudioMSF

∙48-PlayAudioTrackIndex

∙49-PlayTrackRelative(10)

∙4B-Pause/Resume

∙4C-LogSelect

∙4D-LogSense

∙55-ModeSelect(10)

∙5A-ModeSense(10)

∙A5-MoveMedium

∙A6-ExchangeMedium

∙A8-Read(12)

∙A9-PlayTrackRelative(12)

∙AA-Write(12)

∙AC-Erase(12)

∙AE-WriteandVerify(12)

∙AF-Verify(12)

∙B0-SearchDataHigh(12)

∙B1-SearchDataEqual(12)

∙B2-SearchDataLow(12)

∙B3-SetLimits(12)

∙B5-RequestVolumeElementAddress

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1