scsi: Rename scsi_*_length() to scsi_*_xfer(), add scsi_cdb_length()
scsi_cdb_length() does not return the length of the cdb, but the transfersize encoded in the cdb. So rename it to scsi_cdb_xfer() and also rename all other related functions to end with _xfer. We can then add a new scsi_cdb_length() which actually does return the length of the cdb. With that DEBUG_SCSI can now display the correct CDB buffer. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
98001e7b08
commit
1894df0281
@ -826,7 +826,7 @@ static int ata_passthrough_xfer_unit(SCSIDevice *dev, uint8_t *buf)
|
|||||||
return xfer_unit;
|
return xfer_unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ata_passthrough_12_xfer_size(SCSIDevice *dev, uint8_t *buf)
|
static int ata_passthrough_12_xfer(SCSIDevice *dev, uint8_t *buf)
|
||||||
{
|
{
|
||||||
int length = buf[2] & 0x3;
|
int length = buf[2] & 0x3;
|
||||||
int xfer;
|
int xfer;
|
||||||
@ -849,7 +849,7 @@ static int ata_passthrough_12_xfer_size(SCSIDevice *dev, uint8_t *buf)
|
|||||||
return xfer * unit;
|
return xfer * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ata_passthrough_16_xfer_size(SCSIDevice *dev, uint8_t *buf)
|
static int ata_passthrough_16_xfer(SCSIDevice *dev, uint8_t *buf)
|
||||||
{
|
{
|
||||||
int extend = buf[1] & 0x1;
|
int extend = buf[1] & 0x1;
|
||||||
int length = buf[2] & 0x3;
|
int length = buf[2] & 0x3;
|
||||||
@ -875,16 +875,16 @@ static int ata_passthrough_16_xfer_size(SCSIDevice *dev, uint8_t *buf)
|
|||||||
return xfer * unit;
|
return xfer * unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t scsi_data_cdb_length(uint8_t *buf)
|
uint32_t scsi_data_cdb_xfer(uint8_t *buf)
|
||||||
{
|
{
|
||||||
if ((buf[0] >> 5) == 0 && buf[4] == 0) {
|
if ((buf[0] >> 5) == 0 && buf[4] == 0) {
|
||||||
return 256;
|
return 256;
|
||||||
} else {
|
} else {
|
||||||
return scsi_cdb_length(buf);
|
return scsi_cdb_xfer(buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t scsi_cdb_length(uint8_t *buf)
|
uint32_t scsi_cdb_xfer(uint8_t *buf)
|
||||||
{
|
{
|
||||||
switch (buf[0] >> 5) {
|
switch (buf[0] >> 5) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -905,9 +905,9 @@ uint32_t scsi_cdb_length(uint8_t *buf)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
static int scsi_req_xfer(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
||||||
{
|
{
|
||||||
cmd->xfer = scsi_cdb_length(buf);
|
cmd->xfer = scsi_cdb_xfer(buf);
|
||||||
switch (buf[0]) {
|
switch (buf[0]) {
|
||||||
case TEST_UNIT_READY:
|
case TEST_UNIT_READY:
|
||||||
case REWIND:
|
case REWIND:
|
||||||
@ -1038,17 +1038,17 @@ static int scsi_req_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
|||||||
/* BLANK command of MMC */
|
/* BLANK command of MMC */
|
||||||
cmd->xfer = 0;
|
cmd->xfer = 0;
|
||||||
} else {
|
} else {
|
||||||
cmd->xfer = ata_passthrough_12_xfer_size(dev, buf);
|
cmd->xfer = ata_passthrough_12_xfer(dev, buf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ATA_PASSTHROUGH_16:
|
case ATA_PASSTHROUGH_16:
|
||||||
cmd->xfer = ata_passthrough_16_xfer_size(dev, buf);
|
cmd->xfer = ata_passthrough_16_xfer(dev, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scsi_req_stream_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
static int scsi_req_stream_xfer(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
||||||
{
|
{
|
||||||
switch (buf[0]) {
|
switch (buf[0]) {
|
||||||
/* stream commands */
|
/* stream commands */
|
||||||
@ -1103,12 +1103,12 @@ static int scsi_req_stream_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *bu
|
|||||||
break;
|
break;
|
||||||
/* generic commands */
|
/* generic commands */
|
||||||
default:
|
default:
|
||||||
return scsi_req_length(cmd, dev, buf);
|
return scsi_req_xfer(cmd, dev, buf);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int scsi_req_medium_changer_length(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
static int scsi_req_medium_changer_xfer(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf)
|
||||||
{
|
{
|
||||||
switch (buf[0]) {
|
switch (buf[0]) {
|
||||||
/* medium changer commands */
|
/* medium changer commands */
|
||||||
@ -1125,7 +1125,7 @@ static int scsi_req_medium_changer_length(SCSICommand *cmd, SCSIDevice *dev, uin
|
|||||||
|
|
||||||
/* generic commands */
|
/* generic commands */
|
||||||
default:
|
default:
|
||||||
return scsi_req_length(cmd, dev, buf);
|
return scsi_req_xfer(cmd, dev, buf);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1214,38 +1214,45 @@ static uint64_t scsi_cmd_lba(SCSICommand *cmd)
|
|||||||
return lba;
|
return lba;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int scsi_cdb_length(uint8_t *buf) {
|
||||||
|
int cdb_len;
|
||||||
|
|
||||||
|
switch (buf[0] >> 5) {
|
||||||
|
case 0:
|
||||||
|
cdb_len = 6;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
cdb_len = 10;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
cdb_len = 16;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
cdb_len = 12;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
cdb_len = -1;
|
||||||
|
}
|
||||||
|
return cdb_len;
|
||||||
|
}
|
||||||
|
|
||||||
int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf)
|
int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
cmd->lba = -1;
|
cmd->lba = -1;
|
||||||
switch (buf[0] >> 5) {
|
cmd->len = scsi_cdb_length(buf);
|
||||||
case 0:
|
|
||||||
cmd->len = 6;
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
cmd->len = 10;
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
cmd->len = 16;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
cmd->len = 12;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (dev->type) {
|
switch (dev->type) {
|
||||||
case TYPE_TAPE:
|
case TYPE_TAPE:
|
||||||
rc = scsi_req_stream_length(cmd, dev, buf);
|
rc = scsi_req_stream_xfer(cmd, dev, buf);
|
||||||
break;
|
break;
|
||||||
case TYPE_MEDIUM_CHANGER:
|
case TYPE_MEDIUM_CHANGER:
|
||||||
rc = scsi_req_medium_changer_length(cmd, dev, buf);
|
rc = scsi_req_medium_changer_xfer(cmd, dev, buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rc = scsi_req_length(cmd, dev, buf);
|
rc = scsi_req_xfer(cmd, dev, buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1666,7 +1666,7 @@ static void scsi_disk_emulate_write_same(SCSIDiskReq *r, uint8_t *inbuf)
|
|||||||
{
|
{
|
||||||
SCSIRequest *req = &r->req;
|
SCSIRequest *req = &r->req;
|
||||||
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
|
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, req->dev);
|
||||||
uint32_t nb_sectors = scsi_data_cdb_length(r->req.cmd.buf);
|
uint32_t nb_sectors = scsi_data_cdb_xfer(r->req.cmd.buf);
|
||||||
WriteSameCBData *data;
|
WriteSameCBData *data;
|
||||||
uint8_t *buf;
|
uint8_t *buf;
|
||||||
int i;
|
int i;
|
||||||
@ -2061,7 +2061,7 @@ static int32_t scsi_disk_dma_command(SCSIRequest *req, uint8_t *buf)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = scsi_data_cdb_length(r->req.cmd.buf);
|
len = scsi_data_cdb_xfer(r->req.cmd.buf);
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case READ_6:
|
case READ_6:
|
||||||
case READ_10:
|
case READ_10:
|
||||||
@ -2396,7 +2396,7 @@ static SCSIRequest *scsi_new_request(SCSIDevice *d, uint32_t tag, uint32_t lun,
|
|||||||
DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]);
|
DPRINTF("Command: lun=%d tag=0x%x data=0x%02x", lun, tag, buf[0]);
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for (i = 1; i < req->cmd.len; i++) {
|
for (i = 1; i < scsi_cdb_length(buf); i++) {
|
||||||
printf(" 0x%02x", buf[i]);
|
printf(" 0x%02x", buf[i]);
|
||||||
}
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -239,8 +239,9 @@ extern const struct SCSISense sense_code_SPACE_ALLOC_FAILED;
|
|||||||
|
|
||||||
#define SENSE_CODE(x) sense_code_ ## x
|
#define SENSE_CODE(x) sense_code_ ## x
|
||||||
|
|
||||||
uint32_t scsi_data_cdb_length(uint8_t *buf);
|
uint32_t scsi_data_cdb_xfer(uint8_t *buf);
|
||||||
uint32_t scsi_cdb_length(uint8_t *buf);
|
uint32_t scsi_cdb_xfer(uint8_t *buf);
|
||||||
|
int scsi_cdb_length(uint8_t *buf);
|
||||||
int scsi_sense_valid(SCSISense sense);
|
int scsi_sense_valid(SCSISense sense);
|
||||||
int scsi_build_sense(uint8_t *in_buf, int in_len,
|
int scsi_build_sense(uint8_t *in_buf, int in_len,
|
||||||
uint8_t *buf, int len, bool fixed);
|
uint8_t *buf, int len, bool fixed);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user