From patchwork Wed Aug 3 08:49:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 108054 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6D277B7199 for ; Wed, 3 Aug 2011 18:50:10 +1000 (EST) Received: from localhost ([::1]:51071 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QoX9T-0006Lo-Nc for incoming@patchwork.ozlabs.org; Wed, 03 Aug 2011 04:50:07 -0400 Received: from eggs.gnu.org ([140.186.70.92]:44626) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QoX8x-0005iL-FG for qemu-devel@nongnu.org; Wed, 03 Aug 2011 04:49:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QoX8v-0003hm-9a for qemu-devel@nongnu.org; Wed, 03 Aug 2011 04:49:34 -0400 Received: from mail-wy0-f173.google.com ([74.125.82.173]:44070) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QoX8u-0003gH-RN for qemu-devel@nongnu.org; Wed, 03 Aug 2011 04:49:33 -0400 Received: by mail-wy0-f173.google.com with SMTP id 20so154406wye.4 for ; Wed, 03 Aug 2011 01:49:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=1HLiNpFfIhAMpqle0xG6g+RkuKUOSuQtpw0mMncwdPA=; b=ozoENGHRwiXeL+ElcXpy5GRHx3VcNHwwanbbJhRyKbJLeCfgZe646goH5SbVqoTIf/ aFqlB5TNRwi6Q0uNnafLyB+ZgGjDhs23BxFyW41Pla1B8cGYnRHq6LncbbWR4OpCNV3R ILqj8YZITht6yZxSA7UaVHiRtTqzXt3+TesXs= Received: by 10.227.55.72 with SMTP id t8mr7941983wbg.68.1312361372314; Wed, 03 Aug 2011 01:49:32 -0700 (PDT) Received: from localhost.localdomain (93-34-199-31.ip51.fastwebnet.it [93.34.199.31]) by mx.google.com with ESMTPS id ff6sm485877wbb.66.2011.08.03.01.49.31 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 03 Aug 2011 01:49:31 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 3 Aug 2011 10:49:10 +0200 Message-Id: <1312361359-15445-8-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.6 In-Reply-To: <1312361359-15445-1-git-send-email-pbonzini@redhat.com> References: <1312361359-15445-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 74.125.82.173 Subject: [Qemu-devel] [PATCH 07/16] scsi: pass cdb already to scsi_req_new X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Right now the CDB is not passed to the SCSIBus until scsi_req_enqueue. Passing it to scsi_req_new will let scsi_req_new dispatch common requests through different reqops. Moving the memcpy to scsi_req_new is a hack that will go away as soon as scsi_req_new will also take care of the parsing. Signed-off-by: Paolo Bonzini --- hw/esp.c | 4 ++-- hw/lsi53c895a.c | 4 ++-- hw/scsi-bus.c | 13 ++++++++----- hw/scsi.h | 4 ++-- hw/spapr_vscsi.c | 4 ++-- hw/usb-msd.c | 4 ++-- 6 files changed, 18 insertions(+), 15 deletions(-) diff --git a/hw/esp.c b/hw/esp.c index 9ddd637..be3a35d 100644 --- a/hw/esp.c +++ b/hw/esp.c @@ -244,8 +244,8 @@ static void do_busid_cmd(ESPState *s, uint8_t *buf, uint8_t busid) DPRINTF("do_busid_cmd: busid 0x%x\n", busid); lun = busid & 7; - s->current_req = scsi_req_new(s->current_dev, 0, lun, NULL); - datalen = scsi_req_enqueue(s->current_req, buf); + s->current_req = scsi_req_new(s->current_dev, 0, lun, buf, NULL); + datalen = scsi_req_enqueue(s->current_req); s->ti_size = datalen; if (datalen != 0) { s->rregs[ESP_RSTAT] = STAT_TC; diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c index e9904c4..dac176a 100644 --- a/hw/lsi53c895a.c +++ b/hw/lsi53c895a.c @@ -782,10 +782,10 @@ static void lsi_do_command(LSIState *s) assert(s->current == NULL); s->current = qemu_mallocz(sizeof(lsi_request)); s->current->tag = s->select_tag; - s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, + s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, buf, s->current); - n = scsi_req_enqueue(s->current->req, buf); + n = scsi_req_enqueue(s->current->req); if (n) { if (n > 0) { lsi_set_phase(s, PHASE_DI); diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index be73f29..9b81b9c 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -153,9 +153,12 @@ SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag, } SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, - void *hba_private) + uint8_t *buf, void *hba_private) { - return d->info->alloc_req(d, tag, lun, hba_private); + SCSIRequest *req; + req = d->info->alloc_req(d, tag, lun, hba_private); + memcpy(req->cmd.buf, buf, 16); + return req; } uint8_t *scsi_req_get_buf(SCSIRequest *req) @@ -189,7 +192,7 @@ void scsi_req_build_sense(SCSIRequest *req, SCSISense sense) req->sense_len = 18; } -int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf) +int32_t scsi_req_enqueue(SCSIRequest *req) { int32_t rc; @@ -199,7 +202,7 @@ int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf) QTAILQ_INSERT_TAIL(&req->dev->requests, req, next); scsi_req_ref(req); - rc = req->ops->send_command(req, buf); + rc = req->ops->send_command(req, req->cmd.buf); scsi_req_unref(req); return rc; } @@ -433,7 +436,7 @@ int scsi_req_parse(SCSIRequest *req, uint8_t *buf) if (rc != 0) return rc; - memcpy(req->cmd.buf, buf, req->cmd.len); + assert(buf == req->cmd.buf); scsi_req_xfer_mode(req); req->cmd.lba = scsi_req_lba(req); trace_scsi_req_parsed(req->dev->id, req->lun, req->tag, buf[0], diff --git a/hw/scsi.h b/hw/scsi.h index 5c0e076..7ed7550 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -154,8 +154,8 @@ int scsi_sense_valid(SCSISense sense); SCSIRequest *scsi_req_alloc(SCSIReqOps *reqops, SCSIDevice *d, uint32_t tag, uint32_t lun, void *hba_private); SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun, - void *hba_private); -int32_t scsi_req_enqueue(SCSIRequest *req, uint8_t *buf); + uint8_t *buf, void *hba_private); +int32_t scsi_req_enqueue(SCSIRequest *req); void scsi_req_free(SCSIRequest *req); SCSIRequest *scsi_req_ref(SCSIRequest *req); void scsi_req_unref(SCSIRequest *req); diff --git a/hw/spapr_vscsi.c b/hw/spapr_vscsi.c index c65308c..d98d1fd 100644 --- a/hw/spapr_vscsi.c +++ b/hw/spapr_vscsi.c @@ -600,8 +600,8 @@ static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req) } req->lun = lun; - req->sreq = scsi_req_new(sdev, req->qtag, lun, req); - n = scsi_req_enqueue(req->sreq, srp->cmd.cdb); + req->sreq = scsi_req_new(sdev, req->qtag, lun, srp->cmd.cdb, req); + n = scsi_req_enqueue(req->sreq); dprintf("VSCSI: Queued command tag 0x%x CMD 0x%x ID %d LUN %d ret: %d\n", req->qtag, srp->cmd.cdb[0], id, lun, n); diff --git a/hw/usb-msd.c b/hw/usb-msd.c index cdeac58..63305b8 100644 --- a/hw/usb-msd.c +++ b/hw/usb-msd.c @@ -380,8 +380,8 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p) s->tag, cbw.flags, cbw.cmd_len, s->data_len); s->residue = 0; s->scsi_len = 0; - s->req = scsi_req_new(s->scsi_dev, s->tag, 0, NULL); - scsi_req_enqueue(s->req, cbw.cmd); + s->req = scsi_req_new(s->scsi_dev, s->tag, 0, cbw.cmd, NULL); + scsi_req_enqueue(s->req); /* ??? Should check that USB and SCSI data transfer directions match. */ if (s->mode != USB_MSDM_CSW && s->residue == 0) {