qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 07/10] scsi: add scatter/gather functionality
Date: Thu,  4 Aug 2011 19:14:45 +0200	[thread overview]
Message-ID: <1312478089-806-8-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1312478089-806-1-git-send-email-pbonzini@redhat.com>

Scatter/gather functionality uses the newly added DMA helpers.  The
device can choose between doing DMA itself, or calling scsi_req_data
as usual, which will use the newly added DMA helpers to map the
destination area(s) piecewise and copy to/from them.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/esp.c         |    2 +-
 hw/lsi53c895a.c  |    2 +-
 hw/scsi-bus.c    |   34 +++++++++++++++++++++++++++++++---
 hw/scsi.h        |    4 +++-
 hw/spapr_vscsi.c |    2 +-
 hw/usb-msd.c     |    2 +-
 6 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/hw/esp.c b/hw/esp.c
index 5d29071..2d098ea 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -245,7 +245,7 @@ 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, buf, NULL);
-    datalen = scsi_req_enqueue(s->current_req);
+    datalen = scsi_req_enqueue(s->current_req, NULL);
     s->ti_size = datalen;
     if (datalen != 0) {
         s->rregs[ESP_RSTAT] = STAT_TC;
diff --git a/hw/lsi53c895a.c b/hw/lsi53c895a.c
index a0c2419..ee7f67c 100644
--- a/hw/lsi53c895a.c
+++ b/hw/lsi53c895a.c
@@ -785,7 +785,7 @@ static void lsi_do_command(LSIState *s)
     s->current->req = scsi_req_new(dev, s->current->tag, s->current_lun, buf,
                                    s->current);
 
-    n = scsi_req_enqueue(s->current->req);
+    n = scsi_req_enqueue(s->current->req, NULL);
     if (n) {
         if (n > 0) {
             lsi_set_phase(s, PHASE_DI);
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index b49d02d..5876f78 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -5,6 +5,7 @@
 #include "qdev.h"
 #include "blockdev.h"
 #include "trace.h"
+#include "dma.h"
 
 static char *scsibus_get_fw_dev_path(DeviceState *dev);
 static int scsi_req_parse(SCSICommand *cmd, SCSIDevice *dev, uint8_t *buf);
@@ -521,7 +522,7 @@ void scsi_req_build_sense(SCSIRequest *req, SCSISense sense)
     req->sense_len = 18;
 }
 
-int32_t scsi_req_enqueue(SCSIRequest *req)
+int32_t scsi_req_enqueue(SCSIRequest *req, QEMUSGList *sg)
 {
     int32_t rc;
 
@@ -529,6 +530,7 @@ int32_t scsi_req_enqueue(SCSIRequest *req)
     scsi_req_ref(req);
     req->enqueued = true;
     QTAILQ_INSERT_TAIL(&req->dev->requests, req, next);
+    req->sg = sg;
 
     scsi_req_ref(req);
     rc = req->ops->send_command(req, req->cmd.buf);
@@ -1039,15 +1041,41 @@ void scsi_req_continue(SCSIRequest *req)
     }
 }
 
+static void scsi_dma_cb(void *opaque, int ret)
+{
+    SCSIRequest *req = opaque;
+    assert(ret == 0);
+    assert(req->dma_started);
+    req->resid = qemu_sglist_get_resid(req->sg);
+    scsi_req_continue(req);
+}
+
 /* Called by the devices when data is ready for the HBA.  The HBA should
    start a DMA operation to read or fill the device's data buffer.
    Once it completes, calling scsi_req_continue will restart I/O.  */
 void scsi_req_data(SCSIRequest *req, int len)
 {
+    uint8_t *buf;
     trace_scsi_req_data(req->dev->id, req->lun, req->tag, len);
     assert(req->cmd.mode != SCSI_XFER_NONE);
-    req->resid -= len;
-    req->bus->ops->transfer_data(req, len);
+    if (!req->sg) {
+        req->resid -= len;
+        req->bus->ops->transfer_data(req, len);
+        return;
+    }
+
+    /* If the device calls scsi_req_data and the HBA specified a
+     * scatter/gather list, the transfer has to happen in a single
+     * step.  */
+    assert(!req->dma_started);
+    req->dma_started = true;
+
+    buf = scsi_req_get_buf(req);
+    if (req->cmd.mode == SCSI_XFER_FROM_DEV) {
+        req->aiocb = dma_buf_read(buf, len, req->sg, scsi_dma_cb, req);
+    } else {
+        req->aiocb = dma_buf_write(buf, len, req->sg, scsi_dma_cb, req);
+    }
 }
 
 void scsi_req_print(SCSIRequest *req)
diff --git a/hw/scsi.h b/hw/scsi.h
index 76d4df2..febb6fd 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -50,6 +50,8 @@ struct SCSIRequest {
     size_t            resid;
     SCSICommand       cmd;
     BlockDriverAIOCB  *aiocb;
+    QEMUSGList        *sg;
+    bool              dma_started;
     uint8_t sense[SCSI_SENSE_BUF_SIZE];
     uint32_t sense_len;
     bool enqueued;
@@ -174,7 +176,7 @@ 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,
                           uint8_t *buf, void *hba_private);
-int32_t scsi_req_enqueue(SCSIRequest *req);
+int32_t scsi_req_enqueue(SCSIRequest *req, QEMUSGList *qsg);
 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 128b5a6..3a6d35f 100644
--- a/hw/spapr_vscsi.c
+++ b/hw/spapr_vscsi.c
@@ -601,7 +601,7 @@ static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req)
 
     req->lun = lun;
     req->sreq = scsi_req_new(sdev, req->qtag, lun, srp->cmd.cdb, req);
-    n = scsi_req_enqueue(req->sreq);
+    n = scsi_req_enqueue(req->sreq, NULL);
 
     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 8cddf80..167da8a 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -381,7 +381,7 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)
             s->residue = 0;
             s->scsi_len = 0;
             s->req = scsi_req_new(s->scsi_dev, s->tag, 0, cbw.cmd, NULL);
-            scsi_req_enqueue(s->req);
+            scsi_req_enqueue(s->req, NULL);
             /* ??? Should check that USB and SCSI data transfer
                directions match.  */
             if (s->mode != USB_MSDM_CSW && s->residue == 0) {
-- 
1.7.6

  parent reply	other threads:[~2011-08-04 17:15 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-04 17:14 [Qemu-devel] [PATCH 00/10] SCSI scatter/gather support Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 01/10] dma-helpers: allow including from target-independent code Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 02/10] dma-helpers: track position in the QEMUSGList Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 03/10] dma-helpers: rewrite completion/cancellation Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 04/10] dma-helpers: prepare for adding dma_buf_* functions Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 05/10] dma-helpers: add dma_buf_read and dma_buf_write Paolo Bonzini
2011-08-11  7:58   ` Stefan Hajnoczi
2011-08-11 12:10     ` Paolo Bonzini
2011-08-11 13:29       ` Stefan Hajnoczi
2011-08-11 14:24         ` Paolo Bonzini
2011-08-11 14:37           ` Kevin Wolf
2011-08-11 15:05             ` Paolo Bonzini
2011-08-11 15:12               ` Kevin Wolf
2011-08-11 15:27                 ` Paolo Bonzini
2011-08-11 20:06                   ` Stefan Hajnoczi
2011-08-04 17:14 ` [Qemu-devel] [PATCH 06/10] scsi: pass residual amount to command_complete Paolo Bonzini
2011-08-04 17:14 ` Paolo Bonzini [this message]
2011-08-04 17:14 ` [Qemu-devel] [PATCH 08/10] scsi-disk: commonize iovec creation between reads and writes Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 09/10] scsi-disk: lazily allocate bounce buffer Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 10/10] scsi-disk: enable scatter/gather functionality Paolo Bonzini
2011-08-04 17:14 ` [Qemu-devel] [PATCH 11/11] sample pvscsi driver with s/g support Paolo Bonzini
2011-08-11  7:57 ` [Qemu-devel] [PATCH 00/10] SCSI scatter/gather support Stefan Hajnoczi

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=1312478089-806-8-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@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).