scsi: add scsi-defs.h

Largely based on <scsi/scsi.h> from linux.  Added into the tree so we
can use the defines everywhere, not just in scsi-generic.c (which is
linux-specific).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 0a8b8bb..b0eceaf 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -30,14 +30,7 @@
 #include "qemu-common.h"
 #include "block.h"
 #include "scsi.h"
-
-#define SENSE_NO_SENSE        0
-#define SENSE_NOT_READY       2
-#define SENSE_HARDWARE_ERROR  4
-#define SENSE_ILLEGAL_REQUEST 5
-
-#define STATUS_GOOD            0
-#define STATUS_CHECK_CONDITION 2
+#include "scsi-defs.h"
 
 #define SCSI_DMA_BUF_SIZE    131072
 #define SCSI_MAX_INQUIRY_LEN 256
@@ -128,7 +121,7 @@
     if (ret) {
         DPRINTF("IO error\n");
         r->req.bus->complete(r->req.bus, SCSI_REASON_DATA, r->req.tag, 0);
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NO_SENSE);
+        scsi_command_complete(r, CHECK_CONDITION, NO_SENSE);
         return;
     }
     DPRINTF("Data ready tag=0x%x len=%" PRId64 "\n", r->req.tag, r->iov.iov_len);
@@ -147,7 +140,7 @@
     if (!r) {
         BADF("Bad read tag 0x%x\n", tag);
         /* ??? This is the wrong error.  */
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
         return;
     }
     if (r->sector_count == (uint32_t)-1) {
@@ -158,7 +151,7 @@
     }
     DPRINTF("Read sector_count=%d\n", r->sector_count);
     if (r->sector_count == 0) {
-        scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
+        scsi_command_complete(r, GOOD, NO_SENSE);
         return;
     }
 
@@ -171,7 +164,7 @@
     r->req.aiocb = bdrv_aio_readv(s->dinfo->bdrv, r->sector, &r->qiov, n,
                               scsi_read_complete, r);
     if (r->req.aiocb == NULL)
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
     r->sector += n;
     r->sector_count -= n;
 }
@@ -189,8 +182,8 @@
         r->status |= SCSI_REQ_STATUS_RETRY;
         vm_stop(0);
     } else {
-        scsi_command_complete(r, STATUS_CHECK_CONDITION,
-                SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION,
+                HARDWARE_ERROR);
     }
 
     return 1;
@@ -213,7 +206,7 @@
     r->sector += n;
     r->sector_count -= n;
     if (r->sector_count == 0) {
-        scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
+        scsi_command_complete(r, GOOD, NO_SENSE);
     } else {
         len = r->sector_count * 512;
         if (len > SCSI_DMA_BUF_SIZE) {
@@ -236,8 +229,8 @@
         r->req.aiocb = bdrv_aio_writev(s->dinfo->bdrv, r->sector, &r->qiov, n,
                                    scsi_write_complete, r);
         if (r->req.aiocb == NULL)
-            scsi_command_complete(r, STATUS_CHECK_CONDITION,
-                                  SENSE_HARDWARE_ERROR);
+            scsi_command_complete(r, CHECK_CONDITION,
+                                  HARDWARE_ERROR);
     } else {
         /* Invoke completion routine to fetch data from host.  */
         scsi_write_complete(r, 0);
@@ -255,7 +248,7 @@
     r = scsi_find_request(s, tag);
     if (!r) {
         BADF("Bad write tag 0x%x\n", tag);
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
         return 1;
     }
 
@@ -401,7 +394,7 @@
             goto fail;
         memset(outbuf, 0, 4);
         r->iov.iov_len = 4;
-        if (s->sense == SENSE_NOT_READY && len >= 18) {
+        if (s->sense == NOT_READY && len >= 18) {
             memset(outbuf, 0, 18);
             r->iov.iov_len = 18;
             outbuf[7] = 10;
@@ -767,7 +760,7 @@
             r->iov.iov_len = 8;
         } else {
         notready:
-            scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
+            scsi_command_complete(r, CHECK_CONDITION, NOT_READY);
             return 0;
         }
 	break;
@@ -877,7 +870,7 @@
                 /* Protection, exponent and lowest lba field left blank. */
                 r->iov.iov_len = len;
             } else {
-                scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_NOT_READY);
+                scsi_command_complete(r, CHECK_CONDITION, NOT_READY);
                 return 0;
             }
             break;
@@ -898,14 +891,14 @@
     default:
 	DPRINTF("Unknown SCSI command (%2.2x)\n", buf[0]);
     fail:
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_ILLEGAL_REQUEST);
+        scsi_command_complete(r, CHECK_CONDITION, ILLEGAL_REQUEST);
 	return 0;
     illegal_lba:
-        scsi_command_complete(r, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
         return 0;
     }
     if (r->sector_count == 0 && r->iov.iov_len == 0) {
-        scsi_command_complete(r, STATUS_GOOD, SENSE_NO_SENSE);
+        scsi_command_complete(r, GOOD, NO_SENSE);
     }
     len = r->sector_count * 512 + r->iov.iov_len;
     if (is_write) {