qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-2.2 v2 0/5] scsi: enable passthrough of vendor-specific commands
@ 2014-07-28 15:08 Paolo Bonzini
  2014-07-28 15:08 ` [Qemu-devel] [PATCH 1/5] scsi-bus: prepare scsi_req_new for introduction of parse_cdb Paolo Bonzini
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Paolo Bonzini @ 2014-07-28 15:08 UTC (permalink / raw)
  To: qemu-devel

Right now scsi-generic is parsing the CDB, in order to compute
the expected number of bytes to be transferred.  This is necessary
if DMA is done by the HBA via scsi_req_data, but it prevents executing
vendor-specific commands via scsi-generic because we don't know how
to parse them.

If DMA is delegated to the SCSI layer via get_sg_list, we know in
advance how many bytes the guest will want to receive and we can pass
the information straight from the guest to SG_IO.  In this case, it is
unnecessary to parse the CDB to get the same information.  scsi-disk needs
it to detect underruns and overruns, but scsi-generic and scsi-block can
just ask the HBA about the transfer direction and size.

This series introduces a new parse_cdb callback in both the device and
the HBA.  The latter is called by scsi_bus_parse_cdb, which devices can
call for passthrough requests in their implementation of parse_cdb.

Paolo

v1->v2: use the "right" CDB size for non-vendor-specific commands,
        as some drivers and/or firmware expect that and complain
        if you pass a READ(10) command in a 16-byte CDB.  Interdiff
        here.

diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index f999bfa..6f4462b 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -57,12 +57,14 @@ int scsi_bus_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf,
                        void *hba_private)
 {
     SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, dev->qdev.parent_bus);
+    int rc;
 
+    assert(cmd->len == 0);
+    rc = scsi_req_parse_cdb(dev, cmd, buf);
     if (bus->info->parse_cdb) {
-        return bus->info->parse_cdb(dev, cmd, buf, hba_private);
-    } else {
-        return scsi_req_parse_cdb(dev, cmd, buf);
+        rc = bus->info->parse_cdb(dev, cmd, buf, hba_private);
     }
+    return rc;
 }
 
 static SCSIRequest *scsi_device_alloc_req(SCSIDevice *s, uint32_t tag, uint32_t lun,
@@ -575,7 +577,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
     const SCSIReqOps *ops;
     SCSIDeviceClass *sc = SCSI_DEVICE_GET_CLASS(d);
     SCSIRequest *req;
-    SCSICommand cmd;
+    SCSICommand cmd = { .len = 0 };
     int ret;
 
     if ((d->unit_attention.key == UNIT_ATTENTION ||
@@ -609,6 +611,7 @@ SCSIRequest *scsi_req_new(SCSIDevice *d, uint32_t tag, uint32_t lun,
         trace_scsi_req_parse_bad(d->id, lun, tag, buf[0]);
         req = scsi_req_alloc(&reqops_invalid_opcode, d, tag, lun, hba_private);
     } else {
+        assert(cmd.len != 0);
         trace_scsi_req_parsed(d->id, lun, tag, buf[0],
                               cmd.mode, cmd.xfer);
         if (cmd.lba != -1) {
@@ -1210,6 +1213,7 @@ int scsi_req_parse_cdb(SCSIDevice *dev, SCSICommand *cmd, uint8_t *buf)
 {
     int rc;
 
+    cmd->lba = -1;
     switch (buf[0] >> 5) {
     case 0:
         cmd->len = 6;
diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c
index e8f4c0c..2dd9255 100644
--- a/hw/scsi/virtio-scsi.c
+++ b/hw/scsi/virtio-scsi.c
@@ -411,9 +411,10 @@ static int virtio_scsi_parse_cdb(SCSIDevice *dev, SCSICommand *cmd,
 {
     VirtIOSCSIReq *req = hba_private;
 
-    cmd->lba = -1;
-    cmd->len = MIN(VIRTIO_SCSI_CDB_SIZE, SCSI_CMD_BUF_SIZE);
-    memcpy(cmd->buf, buf, cmd->len);
+    if (cmd->len == 0) {
+        cmd->len = MIN(VIRTIO_SCSI_CDB_SIZE, SCSI_CMD_BUF_SIZE);
+        memcpy(cmd->buf, buf, cmd->len);
+    }
 
     /* Extract the direction and mode directly from the request, for
      * host device passthrough.

Paolo Bonzini (5):
  scsi-bus: prepare scsi_req_new for introduction of parse_cdb
  scsi-bus: introduce parse_cdb in SCSIDeviceClass and SCSIBusInfo
  scsi-block: extract scsi_block_is_passthrough
  scsi-block, scsi-generic: implement parse_cdb
  virtio-scsi: implement parse_cdb

 hw/scsi/scsi-bus.c     | 74 ++++++++++++++++++++++++++++++++++----------------
 hw/scsi/scsi-disk.c    | 52 +++++++++++++++++++++++++++--------
 hw/scsi/scsi-generic.c |  7 +++++
 hw/scsi/virtio-scsi.c  | 25 +++++++++++++++++
 include/hw/scsi/scsi.h |  7 +++++
 5 files changed, 130 insertions(+), 35 deletions(-)

-- 
1.9.3

^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [Qemu-devel] [PATCH for-2.2 0/5] scsi: enable passthrough of vendor-specific commands
@ 2014-07-16 12:54 Paolo Bonzini
  2014-07-16 12:54 ` [Qemu-devel] [PATCH 1/5] scsi-bus: prepare scsi_req_new for introduction of parse_cdb Paolo Bonzini
  0 siblings, 1 reply; 10+ messages in thread
From: Paolo Bonzini @ 2014-07-16 12:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: TAMUKI Shoichi

Right now scsi-generic is parsing the CDB, in order to compute
the expected number of bytes to be transferred.  This is necessary
if DMA is done by the HBA via scsi_req_data, but it prevents executing
vendor-specific commands via scsi-generic because we don't know how
to parse them.

If DMA is delegated to the SCSI layer via get_sg_list, we know in
advance how many bytes the guest will want to receive and we can pass
the information straight from the guest to SG_IO.  In this case, it is
unnecessary to parse the CDB to get the same information.  scsi-disk needs
it to detect underruns and overruns, but scsi-generic and scsi-block can
just ask the HBA about the transfer direction and size.

This series introduces a new parse_cdb callback in both the device and
the HBA.  The latter is called by scsi_bus_parse_cdb, which devices can
call for passthrough requests in their implementation of parse_cdb.

Tamuki-san, can you please test if these patches are okay for your
usecase?

Paolo

Paolo Bonzini (5):
  scsi-bus: prepare scsi_req_new for introduction of parse_cdb
  scsi-bus: introduce parse_cdb in SCSIDeviceClass and SCSIBusInfo
  scsi-block: extract scsi_block_is_passthrough
  scsi-block, scsi-generic: implement parse_cdb
  virtio-scsi: implement parse_cdb

 hw/scsi/scsi-bus.c     | 68 ++++++++++++++++++++++++++++++++++----------------
 hw/scsi/scsi-disk.c    | 52 +++++++++++++++++++++++++++++---------
 hw/scsi/scsi-generic.c |  7 ++++++
 hw/scsi/virtio-scsi.c  | 24 ++++++++++++++++++
 include/hw/scsi/scsi.h |  7 ++++++
 5 files changed, 124 insertions(+), 34 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-07-29  7:45 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-28 15:08 [Qemu-devel] [PATCH for-2.2 v2 0/5] scsi: enable passthrough of vendor-specific commands Paolo Bonzini
2014-07-28 15:08 ` [Qemu-devel] [PATCH 1/5] scsi-bus: prepare scsi_req_new for introduction of parse_cdb Paolo Bonzini
2014-07-28 15:08 ` [Qemu-devel] [PATCH 2/5] scsi-bus: introduce parse_cdb in SCSIDeviceClass and SCSIBusInfo Paolo Bonzini
2014-07-28 15:08 ` [Qemu-devel] [PATCH 3/5] scsi-block: extract scsi_block_is_passthrough Paolo Bonzini
2014-07-29  6:28   ` Fam Zheng
2014-07-29  7:45     ` Paolo Bonzini
2014-07-28 15:08 ` [Qemu-devel] [PATCH 4/5] scsi-block, scsi-generic: implement parse_cdb Paolo Bonzini
2014-07-28 15:08 ` [Qemu-devel] [PATCH 5/5] virtio-scsi: " Paolo Bonzini
2014-07-29  7:17 ` [Qemu-devel] [PATCH for-2.2 v2 0/5] scsi: enable passthrough of vendor-specific commands Fam Zheng
  -- strict thread matches above, loose matches on Subject: below --
2014-07-16 12:54 [Qemu-devel] [PATCH for-2.2 " Paolo Bonzini
2014-07-16 12:54 ` [Qemu-devel] [PATCH 1/5] scsi-bus: prepare scsi_req_new for introduction of parse_cdb Paolo Bonzini

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).