From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [RFC PATCH 8/9] scsi: add get_iovec/unmap_iovec to SCSIBusOps
Date: Mon, 6 Jun 2011 18:26:59 +0200 [thread overview]
Message-ID: <1307377620-7538-9-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307377620-7538-1-git-send-email-pbonzini@redhat.com>
This lets scsi-disk avoid a bounce buffer.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi-bus.c | 16 ++++++++++++----
hw/scsi-disk.c | 21 ++++++++++++++++-----
hw/scsi.h | 3 +++
3 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
index 3b545ed..8e888e8 100644
--- a/hw/scsi-bus.c
+++ b/hw/scsi-bus.c
@@ -618,6 +618,8 @@ void scsi_req_unref(SCSIRequest *req)
if (req->dev->info->free_req) {
req->dev->info->free_req(req);
}
+ qemu_iovec_reset(&req->qiov);
+ qemu_iovec_destroy(&req->qiov);
qemu_free(req);
}
}
@@ -634,13 +636,19 @@ void scsi_req_continue(SCSIRequest *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. */
+/* Called by the devices when data is ready for the HBA. Depending on
+ the transfer method it will call either unmap_iovec or transfer_data.
+ Execution of the command resumes when the HBA calls scsi_req_continue;
+ if applicable, the HBA should do so only after completing any DMA
+ operations involving the request buffer. */
void scsi_req_data(SCSIRequest *req, int len)
{
trace_scsi_req_data(req->dev->id, req->lun, req->tag, len);
- req->bus->ops->transfer_data(req, len);
+ if (req->has_sg_list) {
+ req->bus->ops->unmap_iovec(req, len);
+ } else {
+ req->bus->ops->transfer_data(req, len);
+ }
}
void scsi_req_print(SCSIRequest *req)
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 4f5ba1c..e13b633 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -139,12 +139,23 @@ static uint32_t scsi_init_iovec(SCSIDiskReq *r)
{
SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, r->req.dev);
- if (!r->iov.iov_base) {
- r->buflen = SCSI_DMA_BUF_SIZE;
- r->iov.iov_base = qemu_blockalign(s->bs, r->buflen);
+ qemu_iovec_reset(&r->req.qiov);
+ if (r->req.bus->ops->get_iovec) {
+ r->req.bus->ops->get_iovec(&r->req, r->sector_count * 512);
+ }
+ if (r->req.qiov.size) {
+ assert((r->req.qiov.size % 512) == 0);
+ r->req.has_sg_list = true;
+ } else {
+ if (!r->iov.iov_base) {
+ r->buflen = SCSI_DMA_BUF_SIZE;
+ r->iov.iov_base = qemu_blockalign(s->bs, r->buflen);
+ }
+ r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
+ qemu_iovec_destroy(&r->req.qiov);
+ qemu_iovec_init_external(&r->req.qiov, &r->iov, 1);
+ r->req.has_sg_list = false;
}
- r->iov.iov_len = MIN(r->sector_count * 512, r->buflen);
- qemu_iovec_init_external(&r->req.qiov, &r->iov, 1);
return r->req.qiov.size / 512;
}
diff --git a/hw/scsi.h b/hw/scsi.h
index b551b57..9627404 100644
--- a/hw/scsi.h
+++ b/hw/scsi.h
@@ -35,6 +35,7 @@ struct SCSIRequest {
uint32_t tag;
uint32_t lun;
uint32_t status;
+ bool has_sg_list;
struct {
uint8_t buf[SCSI_CMD_BUF_SIZE];
int len;
@@ -82,6 +83,8 @@ struct SCSIBusOps {
void (*transfer_data)(SCSIRequest *req, uint32_t arg);
void (*complete)(SCSIRequest *req, uint32_t arg);
void (*cancel)(SCSIRequest *req);
+ void (*get_iovec)(SCSIRequest *req, uint64_t len);
+ void (*unmap_iovec)(SCSIRequest *req, uint64_t len);
};
struct SCSIBus {
--
1.7.4.4
next prev parent reply other threads:[~2011-06-06 16:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-06 16:26 [Qemu-devel] [RFC PATCH 0/9] scsi: support s/g operation without a bounce buffer Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 1/9] make qbus_reset_all public Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 2/9] pvscsi: first commit Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 3/9] pvscsi: check validity of DMA addresses in advance Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 4/9] scsi: always use get_sense Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 5/9] scsi-disk: lazily allocate bounce buffer Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 6/9] allow switching a qiov between internal and external storage Paolo Bonzini
2011-06-06 16:26 ` [Qemu-devel] [RFC PATCH 7/9] scsi: push qiov to SCSIRequest Paolo Bonzini
2011-06-06 16:26 ` Paolo Bonzini [this message]
2011-06-06 16:27 ` [Qemu-devel] [RFC PATCH 9/9] pvscsi: implement s/g operation without a bounce buffer Paolo Bonzini
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=1307377620-7538-9-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).