From patchwork Thu Nov 26 14:33:53 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 39540 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE9561007D1 for ; Fri, 27 Nov 2009 02:39:16 +1100 (EST) Received: from localhost ([127.0.0.1]:33549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDgR6-0001VZ-SV for incoming@patchwork.ozlabs.org; Thu, 26 Nov 2009 10:39:12 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NDfR3-0006sv-34 for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:35:05 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NDfQr-0006ig-Vf for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:34:57 -0500 Received: from [199.232.76.173] (port=56158 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NDfQo-0006i1-FF for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:34:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34919) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NDfQn-0000Fl-RO for qemu-devel@nongnu.org; Thu, 26 Nov 2009 09:34:50 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAQEYnAj008426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 26 Nov 2009 09:34:49 -0500 Received: from zweiblum.home.kraxel.org (vpn2-8-164.ams2.redhat.com [10.36.8.164]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id nAQEYdKO007191; Thu, 26 Nov 2009 09:34:42 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 2556C7010B; Thu, 26 Nov 2009 15:34:17 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 26 Nov 2009 15:33:53 +0100 Message-Id: <1259246056-5389-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1259246056-5389-1-git-send-email-kraxel@redhat.com> References: <1259246056-5389-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 07/30] scsi: add scsi-defs.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Largely based on 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 --- 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 #include #include -#include - -#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