From patchwork Tue Nov 17 10:17:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 38613 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 DD297B70CF for ; Tue, 17 Nov 2009 21:38:41 +1100 (EST) Received: from localhost ([127.0.0.1]:36006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NALSI-0006Yi-9w for incoming@patchwork.ozlabs.org; Tue, 17 Nov 2009 05:38:38 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NAL8b-0000Lh-BN for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NAL8T-0000FE-Ev for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:13 -0500 Received: from [199.232.76.173] (port=58250 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NAL8S-0000F9-Cp for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17089) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NAL8R-0006wY-SZ for qemu-devel@nongnu.org; Tue, 17 Nov 2009 05:18:08 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nAHAI6sd020163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Nov 2009 05:18:07 -0500 Received: from zweiblum.home.kraxel.org (vpn1-7-195.ams2.redhat.com [10.36.7.195]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id nAHAI1Op001841; Tue, 17 Nov 2009 05:18:02 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 54C9E70066; Tue, 17 Nov 2009 11:17:52 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 17 Nov 2009 11:17:48 +0100 Message-Id: <1258453071-3496-13-git-send-email-kraxel@redhat.com> In-Reply-To: <1258453071-3496-1-git-send-email-kraxel@redhat.com> References: <1258453071-3496-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 12/15] scsi: move sense to SCSIDevice, create SCSISense struct. 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 Signed-off-by: Gerd Hoffmann --- hw/scsi-bus.c | 10 ++++++++++ hw/scsi-disk.c | 8 ++++---- hw/scsi.h | 8 ++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 77409de..493e220 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -113,6 +113,16 @@ void scsi_bus_legacy_handle_cmdline(SCSIBus *bus) } } +void scsi_dev_clear_sense(SCSIDevice *dev) +{ + memset(&dev->sense, 0, sizeof(dev->sense)); +} + +void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key) +{ + dev->sense.key = key; +} + void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun) { req->bus = scsi_bus_from_device(d); diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 2068187..c0c407b 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -59,7 +59,6 @@ struct SCSIDiskState This is the number of 512 byte blocks in a single scsi sector. */ int cluster_size; uint64_t max_lba; - int sense; char drive_serial_str[21]; QEMUBH *bh; }; @@ -112,7 +111,7 @@ static void scsi_command_complete(SCSIDiskReq *r, int status, int sense) uint32_t tag; DPRINTF("Command complete tag=0x%x status=%d sense=%d\n", r->req.tag, status, sense); - s->sense = sense; + scsi_dev_set_sense(&s->qdev, sense); tag = r->req.tag; scsi_remove_request(r); r->req.bus->complete(r->req.bus, SCSI_REASON_DONE, tag, status); @@ -413,7 +412,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 == NOT_READY && len >= 18) { + if (s->qdev.sense.key == NOT_READY && len >= 18) { memset(outbuf, 0, 18); r->iov.iov_len = 18; outbuf[7] = 10; @@ -423,7 +422,8 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, } outbuf[0] = 0xf0; outbuf[1] = 0; - outbuf[2] = s->sense; + outbuf[2] = s->qdev.sense.key; + scsi_dev_clear_sense(&s->qdev); break; case INQUIRY: DPRINTF("Inquiry (len %d)\n", len); diff --git a/hw/scsi.h b/hw/scsi.h index f2d033f..bdba1db 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -24,6 +24,10 @@ enum SCSIXferMode { SCSI_XFER_TO_DEV, /* WRITE, MODE_SELECT, ... */ }; +typedef struct SCSISense { + uint8_t key; +} SCSISense; + typedef struct SCSIRequest { SCSIBus *bus; SCSIDevice *dev; @@ -48,6 +52,7 @@ struct SCSIDevice QTAILQ_HEAD(, SCSIRequest) requests; int blocksize; int type; + struct SCSISense sense; }; /* cdrom.c */ @@ -92,6 +97,9 @@ static inline SCSIBus *scsi_bus_from_device(SCSIDevice *d) SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, DriveInfo *dinfo, int unit); void scsi_bus_legacy_handle_cmdline(SCSIBus *bus); +void scsi_dev_clear_sense(SCSIDevice *dev); +void scsi_dev_set_sense(SCSIDevice *dev, uint8_t key); + void scsi_req_init(SCSIRequest *req, SCSIDevice *d, uint32_t tag, uint32_t lun); int scsi_req_parse(SCSIRequest *req, uint8_t *buf);