qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 07/30] scsi: add scsi-defs.h
Date: Thu, 26 Nov 2009 15:33:53 +0100	[thread overview]
Message-ID: <1259246056-5389-8-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1259246056-5389-1-git-send-email-kraxel@redhat.com>

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>
---
 hw/scsi-defs.h    |  156 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/scsi-disk.c    |   41 ++++++--------
 hw/scsi-generic.c |    8 +---
 3 files changed, 174 insertions(+), 31 deletions(-)
 create mode 100644 hw/scsi-defs.h

diff --git a/hw/scsi-defs.h b/hw/scsi-defs.h
new file mode 100644
index 0000000..1701521
--- /dev/null
+++ b/hw/scsi-defs.h
@@ -0,0 +1,156 @@
+/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+/*
+ * This header file contains public constants and structures used by
+ * the scsi code for linux.
+ */
+
+/*
+ *      SCSI opcodes
+ */
+
+#define TEST_UNIT_READY       0x00
+#define REZERO_UNIT           0x01
+#define REQUEST_SENSE         0x03
+#define FORMAT_UNIT           0x04
+#define READ_BLOCK_LIMITS     0x05
+#define REASSIGN_BLOCKS       0x07
+#define READ_6                0x08
+#define WRITE_6               0x0a
+#define SEEK_6                0x0b
+#define READ_REVERSE          0x0f
+#define WRITE_FILEMARKS       0x10
+#define SPACE                 0x11
+#define INQUIRY               0x12
+#define RECOVER_BUFFERED_DATA 0x14
+#define MODE_SELECT           0x15
+#define RESERVE               0x16
+#define RELEASE               0x17
+#define COPY                  0x18
+#define ERASE                 0x19
+#define MODE_SENSE            0x1a
+#define START_STOP            0x1b
+#define RECEIVE_DIAGNOSTIC    0x1c
+#define SEND_DIAGNOSTIC       0x1d
+#define ALLOW_MEDIUM_REMOVAL  0x1e
+
+#define SET_WINDOW            0x24
+#define READ_CAPACITY         0x25
+#define READ_10               0x28
+#define WRITE_10              0x2a
+#define SEEK_10               0x2b
+#define WRITE_VERIFY          0x2e
+#define VERIFY                0x2f
+#define SEARCH_HIGH           0x30
+#define SEARCH_EQUAL          0x31
+#define SEARCH_LOW            0x32
+#define SET_LIMITS            0x33
+#define PRE_FETCH             0x34
+#define READ_POSITION         0x34
+#define SYNCHRONIZE_CACHE     0x35
+#define LOCK_UNLOCK_CACHE     0x36
+#define READ_DEFECT_DATA      0x37
+#define MEDIUM_SCAN           0x38
+#define COMPARE               0x39
+#define COPY_VERIFY           0x3a
+#define WRITE_BUFFER          0x3b
+#define READ_BUFFER           0x3c
+#define UPDATE_BLOCK          0x3d
+#define READ_LONG             0x3e
+#define WRITE_LONG            0x3f
+#define CHANGE_DEFINITION     0x40
+#define WRITE_SAME            0x41
+#define READ_TOC              0x43
+#define LOG_SELECT            0x4c
+#define LOG_SENSE             0x4d
+#define MODE_SELECT_10        0x55
+#define RESERVE_10            0x56
+#define RELEASE_10            0x57
+#define MODE_SENSE_10         0x5a
+#define PERSISTENT_RESERVE_IN 0x5e
+#define PERSISTENT_RESERVE_OUT 0x5f
+#define MOVE_MEDIUM           0xa5
+#define READ_12               0xa8
+#define WRITE_12              0xaa
+#define WRITE_VERIFY_12       0xae
+#define SEARCH_HIGH_12        0xb0
+#define SEARCH_EQUAL_12       0xb1
+#define SEARCH_LOW_12         0xb2
+#define READ_ELEMENT_STATUS   0xb8
+#define SEND_VOLUME_TAG       0xb6
+#define WRITE_LONG_2          0xea
+
+/* from hw/scsi-generic.c */
+#define REWIND 0x01
+#define REPORT_DENSITY_SUPPORT 0x44
+#define LOAD_UNLOAD 0xa6
+#define SET_CD_SPEED 0xbb
+#define BLANK 0xa1
+
+/*
+ *  Status codes
+ */
+
+#define GOOD                 0x00
+#define CHECK_CONDITION      0x01
+#define CONDITION_GOOD       0x02
+#define BUSY                 0x04
+#define INTERMEDIATE_GOOD    0x08
+#define INTERMEDIATE_C_GOOD  0x0a
+#define RESERVATION_CONFLICT 0x0c
+#define COMMAND_TERMINATED   0x11
+#define QUEUE_FULL           0x14
+
+#define STATUS_MASK          0x3e
+
+/*
+ *  SENSE KEYS
+ */
+
+#define NO_SENSE            0x00
+#define RECOVERED_ERROR     0x01
+#define NOT_READY           0x02
+#define MEDIUM_ERROR        0x03
+#define HARDWARE_ERROR      0x04
+#define ILLEGAL_REQUEST     0x05
+#define UNIT_ATTENTION      0x06
+#define DATA_PROTECT        0x07
+#define BLANK_CHECK         0x08
+#define COPY_ABORTED        0x0a
+#define ABORTED_COMMAND     0x0b
+#define VOLUME_OVERFLOW     0x0d
+#define MISCOMPARE          0x0e
+
+
+/*
+ *  DEVICE TYPES
+ */
+
+#define TYPE_DISK           0x00
+#define TYPE_TAPE           0x01
+#define TYPE_PROCESSOR      0x03    /* HP scanners use this */
+#define TYPE_WORM           0x04    /* Treated as ROM by our system */
+#define TYPE_ROM            0x05
+#define TYPE_SCANNER        0x06
+#define TYPE_MOD            0x07    /* Magneto-optical disk -
+				     * - treated as TYPE_DISK */
+#define TYPE_MEDIUM_CHANGER 0x08
+#define TYPE_ENCLOSURE	    0x0d    /* Enclosure Services Device */
+#define TYPE_NO_LUN         0x7f
+
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 @@ do { fprintf(stderr, "scsi-disk: " fmt , ## __VA_ARGS__); } while (0)
 #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 @@ static void scsi_read_complete(void * opaque, int ret)
     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 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
     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 @@ 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, STATUS_GOOD, SENSE_NO_SENSE);
+        scsi_command_complete(r, GOOD, NO_SENSE);
         return;
     }
 
@@ -171,7 +164,7 @@ static void scsi_read_data(SCSIDevice *d, uint32_t tag)
     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 @@ static int scsi_handle_write_error(SCSIDiskReq *r, int error)
         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 @@ static void scsi_write_complete(void * opaque, int ret)
     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 @@ static void scsi_write_request(SCSIDiskReq *r)
         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 @@ 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, STATUS_CHECK_CONDITION, SENSE_HARDWARE_ERROR);
+        scsi_command_complete(r, CHECK_CONDITION, HARDWARE_ERROR);
         return 1;
     }
 
@@ -401,7 +394,7 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
             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 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
             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 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag,
                 /* 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 @@ 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, 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) {
diff --git a/hw/scsi-generic.c b/hw/scsi-generic.c
index a925caa..834d2d8 100644
--- a/hw/scsi-generic.c
+++ b/hw/scsi-generic.c
@@ -34,13 +34,7 @@ do { fprintf(stderr, "scsi-generic: " fmt , ## __VA_ARGS__); } while (0)
 #include <sys/stat.h>
 #include <unistd.h>
 #include <scsi/sg.h>
-#include <scsi/scsi.h>
-
-#define REWIND 0x01
-#define REPORT_DENSITY_SUPPORT 0x44
-#define LOAD_UNLOAD 0xa6
-#define SET_CD_SPEED 0xbb
-#define BLANK 0xa1
+#include "scsi-defs.h"
 
 #define SCSI_SENSE_BUF_SIZE 96
 
-- 
1.6.2.5

  parent reply	other threads:[~2009-11-26 14:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26 14:33 [Qemu-devel] [PATCH 00/30] scsi: data structures and cleanups Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 01/30] scsi: add/fix header protection Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 02/30] scsi: create common SCSIRequest structure Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 03/30] scsi: move request lists to QTAILQ Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 04/30] scsi: move SCSIRequest management to common code Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 05/30] scsi: move scsi command buffer from SCSIGenericReq to SCSIRequest Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 06/30] scsi: move blocksize from SCSIGenericState to SCSIDevice Gerd Hoffmann
2009-11-26 14:33 ` Gerd Hoffmann [this message]
2009-11-26 14:33 ` [Qemu-devel] [PATCH 08/30] scsi: move type " Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 09/30] scsi: add request parsing helpers to common code Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 10/30] scsi: use command defines in scsi-disk.c Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 11/30] scsi: add xfer mode Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 12/30] scsi: move sense to SCSIDevice, create SCSISense struct Gerd Hoffmann
2009-11-26 14:33 ` [Qemu-devel] [PATCH 13/30] scsi: move dinfo to SCSIDevice Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 14/30] scsi: move status to SCSIRequest Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 15/30] scsi: add scsi_req_print() Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 16/30] scsi-disk: restruct emulation: core + TEST_UNIT_READY Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 17/30] scsi-disk: restruct emulation: REQUEST_SENSE Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 18/30] scsi-disk: restruct emulation: INQUIRY Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 19/30] scsi-disk: restruct emulation: RESERVE+RELEASE Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 20/30] scsi-disk: restruct emulation: MODE_SENSE Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 21/30] scsi-disk: restruct emulation: START_STOP Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 22/30] scsi-disk: restruct emulation: ALLOW_MEDIUM_REMOVAL Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 23/30] scsi-disk: restruct emulation: READ_CAPACITY Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 24/30] scsi-disk: restruct emulation: SYNCHRONIZE_CACHE Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 25/30] scsi-disk: restruct emulation: READ_TOC Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 26/30] scsi-disk: restruct emulation: GET_CONFIGURATION Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 27/30] scsi-disk: restruct emulation: SERVICE_ACTION_IN Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 28/30] scsi-disk: restruct emulation: REPORT_LUNS Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 29/30] scsi-disk: restruct emulation: VERIFY Gerd Hoffmann
2009-11-26 14:34 ` [Qemu-devel] [PATCH 30/30] scsi: add read/write 16 commands Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1259246056-5389-8-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).