init commit for spc/sbc

This commit is contained in:
Lei Xue
2015-12-27 20:44:54 +08:00
parent e7366b4ed1
commit d770eb33ac
11 changed files with 788 additions and 124 deletions

View File

@@ -16,26 +16,46 @@ limitations under the License.
package scsi
import "errors"
var (
DefaultBlockShift int = 9
DefaultSenseBufferSize int = 252
)
type SAMStat byte
type SCSIDeviceType byte
var (
SAM_STAT_GOOD SAMStat = 0x00
SAM_STAT_CHECK_CONDITION SAMStat = 0x02
SAM_STAT_CONDITION_MET SAMStat = 0x04
SAM_STAT_BUSY SAMStat = 0x08
SAM_STAT_INTERMEDIATE SAMStat = 0x10
SAM_STAT_INTERMEDIATE_CONDITION_MET SAMStat = 0x14
SAM_STAT_RESERVATION_CONFLICT SAMStat = 0x18
SAM_STAT_COMMAND_TERMINATED SAMStat = 0x22
SAM_STAT_TASK_SET_FULL SAMStat = 0x28
SAM_STAT_ACA_ACTIVE SAMStat = 0x30
SAM_STAT_TASK_ABORTED SAMStat = 0x40
SAM_STAT_GOOD byte = 0x00
SAM_STAT_CHECK_CONDITION byte = 0x02
SAM_STAT_CONDITION_MET byte = 0x04
SAM_STAT_BUSY byte = 0x08
SAM_STAT_INTERMEDIATE byte = 0x10
SAM_STAT_INTERMEDIATE_CONDITION_MET byte = 0x14
SAM_STAT_RESERVATION_CONFLICT byte = 0x18
SAM_STAT_COMMAND_TERMINATED byte = 0x22
SAM_STAT_TASK_SET_FULL byte = 0x28
SAM_STAT_ACA_ACTIVE byte = 0x30
SAM_STAT_TASK_ABORTED byte = 0x40
)
type SAMStat struct {
Stat byte
Err error
}
var (
SAMStatGood = SAMStat{SAM_STAT_GOOD, nil}
SAMStatCheckCondition = SAMStat{SAM_STAT_CHECK_CONDITION, errors.New("check condition")}
SAMStatConditionMet = SAMStat{SAM_STAT_CONDITION_MET, errors.New("condition met")}
SAMStatBusy = SAMStat{SAM_STAT_BUSY, errors.New("busy")}
SAMStatIntermediate = SAMStat{SAM_STAT_INTERMEDIATE, errors.New("intermediate")}
SAMStatIntermediateConditionMet = SAMStat{SAM_STAT_INTERMEDIATE_CONDITION_MET, errors.New("intermediate condition met")}
SAMStatReservationConflict = SAMStat{SAM_STAT_RESERVATION_CONFLICT, errors.New("reservation conflict")}
SAMStatCommandTerminated = SAMStat{SAM_STAT_COMMAND_TERMINATED, errors.New("command terminated")}
SAMStatTaskSetFull = SAMStat{SAM_STAT_TASK_SET_FULL, errors.New("task set full")}
SAMStatAcaActive = SAMStat{SAM_STAT_ACA_ACTIVE, errors.New("aca active")}
SAMStatTaskAborted = SAMStat{SAM_STAT_TASK_ABORTED, errors.New("task aborted")}
)
var (
@@ -59,7 +79,7 @@ var (
TYPE_PT SCSIDeviceType = 0xff
)
type CommandFunc func(host int, cmd *SCSICommand) error
type CommandFunc func(host int, cmd *SCSICommand) SAMStat
type SCSIServiceAction struct {
ServiceAction uint32
@@ -92,3 +112,33 @@ func NewSCSIDeviceOperation(fn CommandFunc, sa *SCSIServiceAction, pr uint8) SCS
PRConflictBits: pr,
}
}
func BuildSenseData(cmd *SCSICommand, key byte, asc SCSISubError) {
senseBuffer := cmd.SenseBuffer
if cmd.Device.Attrs.SenseFormat {
// descriptor format
// current, not deferred
senseBuffer.WriteByte(0x72)
senseBuffer.WriteByte(key)
senseBuffer.WriteByte((byte(asc) >> 8) & 0xff)
senseBuffer.WriteByte(byte(asc) & 0xff)
cmd.SenseLength = 8
} else {
// fixed format
var length uint32 = 0xa
// current, not deferred
senseBuffer.WriteByte(0x70)
senseBuffer.WriteByte(0x00)
senseBuffer.WriteByte(key)
for i := 0; i < 4; i++ {
senseBuffer.WriteByte(0x00)
}
senseBuffer.WriteByte(byte(length))
for i := 0; i < 4; i++ {
senseBuffer.WriteByte(0x00)
}
senseBuffer.WriteByte((byte(asc) >> 8) & 0xff)
senseBuffer.WriteByte(byte(asc) & 0xff)
cmd.SenseLength = length + 8
}
}