aboutsummaryrefslogtreecommitdiff
path: root/hw/scsi-disk.c
diff options
context:
space:
mode:
authorbalrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162>2008-04-26 15:56:05 +0000
committerbalrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162>2008-04-26 15:56:05 +0000
commit47e4ca5abd9679300e78771de923ce9d708467cb (patch)
treefe9342037dd3a77cca6f00f98910faf891321fe8 /hw/scsi-disk.c
parent4a0d8278ca77c5e93a6594556a21ec562f8e0b10 (diff)
Fix scsi-disk sense-key/status confusion (Marcelo Tosatti).
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4260 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'hw/scsi-disk.c')
-rw-r--r--hw/scsi-disk.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 44462d4351..d7fdd37e3c 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -34,6 +34,18 @@ do { fprintf(stderr, "scsi-disk: " fmt , ##args); } while (0)
#define SENSE_HARDWARE_ERROR 4
#define SENSE_ILLEGAL_REQUEST 5
+#define SCSI_OK 0
+#define SCSI_CHECK_COND 0x2
+#define SCSI_COND_MET 0x4
+#define SCSI_BUSY 0x8
+#define SCSI_INTERMEDIATE 0x10
+#define SCSI_INTER_MET 0x14
+#define SCSI_RES_CONFLICT 0x18
+#define SCSI_CMD_TERMINATED 0x22
+#define SCSI_QUEUE_FULL 0x28
+#define SCSI_ACA_ACTIVE 0x30
+#define SCSI_TASK_ABORTED 0x40
+
#define SCSI_DMA_BUF_SIZE 65536
typedef struct SCSIRequest {
@@ -124,7 +136,7 @@ static SCSIRequest *scsi_find_request(SCSIDeviceState *s, uint32_t tag)
}
/* Helper function for command completion. */
-static void scsi_command_complete(SCSIRequest *r, int sense)
+static void scsi_command_complete(SCSIRequest *r, int status, int sense)
{
SCSIDeviceState *s = r->dev;
uint32_t tag;
@@ -132,7 +144,7 @@ static void scsi_command_complete(SCSIRequest *r, int sense)
s->sense = sense;
tag = r->tag;
scsi_remove_request(r);
- s->completion(s->opaque, SCSI_REASON_DONE, tag, sense);
+ s->completion(s->opaque, SCSI_REASON_DONE, tag, status);
}
/* Cancel a pending data transfer. */
@@ -157,7 +169,7 @@ static void scsi_read_complete(void * opaque, int ret)
if (ret) {
DPRINTF("IO error\n");
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return;
}
DPRINTF("Data ready tag=0x%x len=%d\n", r->tag, r->buf_len);
@@ -175,8 +187,7 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
r = scsi_find_request(s, tag);
if (!r) {
BADF("Bad read tag 0x%x\n", tag);
- /* ??? This is the wrong error. */
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return;
}
if (r->sector_count == (uint32_t)-1) {
@@ -187,7 +198,7 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
}
DPRINTF("Read sector_count=%d\n", r->sector_count);
if (r->sector_count == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
return;
}
@@ -199,7 +210,7 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
r->aiocb = bdrv_aio_read(s->bdrv, r->sector, r->dma_buf, n,
scsi_read_complete, r);
if (r->aiocb == NULL)
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
r->sector += n;
r->sector_count -= n;
}
@@ -217,7 +228,7 @@ static void scsi_write_complete(void * opaque, int ret)
r->aiocb = NULL;
if (r->sector_count == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
} else {
len = r->sector_count * 512;
if (len > SCSI_DMA_BUF_SIZE) {
@@ -241,7 +252,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
r = scsi_find_request(s, tag);
if (!r) {
BADF("Bad write tag 0x%x\n", tag);
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
return 1;
}
if (r->aiocb)
@@ -251,7 +262,7 @@ static int scsi_write_data(SCSIDevice *d, uint32_t tag)
r->aiocb = bdrv_aio_write(s->bdrv, r->sector, r->dma_buf, n,
scsi_write_complete, r);
if (r->aiocb == NULL)
- scsi_command_complete(r, SENSE_HARDWARE_ERROR);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_HARDWARE_ERROR);
r->sector += n;
r->sector_count -= n;
} else {
@@ -601,7 +612,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
outbuf[7] = 0;
r->buf_len = 8;
} else {
- scsi_command_complete(r, SENSE_NOT_READY);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_NOT_READY);
return 0;
}
break;
@@ -688,11 +699,11 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
default:
DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]);
fail:
- scsi_command_complete(r, SENSE_ILLEGAL_REQUEST);
+ scsi_command_complete(r, SCSI_CHECK_COND, SENSE_ILLEGAL_REQUEST);
return 0;
}
if (r->sector_count == 0 && r->buf_len == 0) {
- scsi_command_complete(r, SENSE_NO_SENSE);
+ scsi_command_complete(r, SCSI_OK, SENSE_NO_SENSE);
}
len = r->sector_count * 512 + r->buf_len;
if (is_write) {