[SeaBIOS] [PATCH 14/17] pvscsi: Handle pvscsi drives directly via 'struct disk_op_s' requests

Kevin O'Connor kevin at koconnor.net
Tue Jul 7 21:26:18 CEST 2015


Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/block.c       |  3 ++-
 src/hw/blockcmd.c |  4 ----
 src/hw/pvscsi.c   | 31 ++++++++++++-------------------
 src/hw/pvscsi.h   |  2 +-
 4 files changed, 15 insertions(+), 25 deletions(-)

diff --git a/src/block.c b/src/block.c
index 422e2a2..8e5bdad 100644
--- a/src/block.c
+++ b/src/block.c
@@ -14,6 +14,7 @@
 #include "hw/lsi-scsi.h" // lsi_scsi_process_op
 #include "hw/megasas.h" // megasas_process_op
 #include "hw/pci.h" // pci_bdf_to_bus
+#include "hw/pvscsi.h" // pvscsi_process_op
 #include "hw/rtc.h" // rtc_read
 #include "hw/usb-msc.h" // usb_process_op
 #include "hw/usb-uas.h" // uas_process_op
@@ -538,7 +539,7 @@ process_op_32(struct disk_op_s *op)
     case DTYPE_VIRTIO_SCSI:
         return virtio_scsi_process_op(op);
     case DTYPE_PVSCSI:
-        return scsi_process_op(op);
+        return pvscsi_process_op(op);
     default:
         return process_op_both(op);
     }
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c
index 684f420..4b4798b 100644
--- a/src/hw/blockcmd.c
+++ b/src/hw/blockcmd.c
@@ -9,7 +9,6 @@
 #include "block.h" // struct disk_op_s
 #include "blockcmd.h" // struct cdb_request_sense
 #include "byteorder.h" // be32_to_cpu
-#include "pvscsi.h" // pvscsi_cmd_data
 #include "output.h" // dprintf
 #include "std/disk.h" // DISK_RET_EPARAM
 #include "string.h" // memset
@@ -21,9 +20,6 @@ cdb_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
 {
     u8 type = GET_GLOBALFLAT(op->drive_gf->type);
     switch (type) {
-    case DTYPE_PVSCSI:
-        if (!MODESEGMENT)
-            return pvscsi_cmd_data(op, cdbcmd, blocksize);
     default:
         return DISK_RET_EPARAM;
     }
diff --git a/src/hw/pvscsi.c b/src/hw/pvscsi.c
index 67d1d94..4e98b5d 100644
--- a/src/hw/pvscsi.c
+++ b/src/hw/pvscsi.c
@@ -206,10 +206,13 @@ pvscsi_get_rsp(struct PVSCSIRingsState *s,
     return status;
 }
 
-static int
-pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op,
-           void *cdbcmd, u16 target, u16 lun, u16 blocksize)
+int
+pvscsi_process_op(struct disk_op_s *op)
 {
+    if (!CONFIG_PVSCSI)
+        return DISK_RET_EBADTRACK;
+    struct pvscsi_lun_s *plun =
+        container_of(op->drive_gf, struct pvscsi_lun_s, drive);
     struct pvscsi_ring_dsc_s *ring_dsc = plun->ring_dsc;
     struct PVSCSIRingsState *s = ring_dsc->ring_state;
     u32 req_entries = s->reqNumEntriesLog2;
@@ -225,17 +228,19 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op,
     }
 
     req = ring_dsc->ring_reqs + (s->reqProdIdx & MASK(req_entries));
+    int blocksize = scsi_fill_cmd(op, req->cdb, 16);
+    if (blocksize < 0)
+        return default_process_op(op);
     req->bus = 0;
-    req->target = target;
+    req->target = plun->target;
     memset(req->lun, 0, sizeof(req->lun));
-    req->lun[1] = lun;
+    req->lun[1] = plun->lun;
     req->senseLen = 0;
     req->senseAddr = 0;
     req->cdbLen = 16;
     req->vcpuHint = 0;
-    memcpy(req->cdb, cdbcmd, 16);
     req->tag = SIMPLE_QUEUE_TAG;
-    req->flags = cdb_is_read(cdbcmd, blocksize) ?
+    req->flags = cdb_is_read(req->cdb, blocksize) ?
         PVSCSI_FLAG_CMD_DIR_TOHOST : PVSCSI_FLAG_CMD_DIR_TODEVICE;
     req->dataLen = op->count * blocksize;
     req->dataAddr = (u32)op->buf_fl;
@@ -250,18 +255,6 @@ pvscsi_cmd(struct pvscsi_lun_s *plun, struct disk_op_s *op,
     return status == 0 ? DISK_RET_SUCCESS : DISK_RET_EBADTRACK;
 }
 
-int
-pvscsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
-{
-    if (!CONFIG_PVSCSI)
-        return DISK_RET_EBADTRACK;
-
-    struct pvscsi_lun_s *plun =
-        container_of(op->drive_gf, struct pvscsi_lun_s, drive);
-
-    return pvscsi_cmd(plun, op, cdbcmd, plun->target, plun->lun, blocksize);
-}
-
 static int
 pvscsi_add_lun(struct pci_device *pci, void *iobase,
                struct pvscsi_ring_dsc_s *ring_dsc, u8 target, u8 lun)
diff --git a/src/hw/pvscsi.h b/src/hw/pvscsi.h
index fde9f0b..5af7dcb 100644
--- a/src/hw/pvscsi.h
+++ b/src/hw/pvscsi.h
@@ -2,7 +2,7 @@
 #define _PVSCSI_H_
 
 struct disk_op_s;
-int pvscsi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize);
+int pvscsi_process_op(struct disk_op_s *op);
 void pvscsi_setup(void);
 
 #endif /* _PVSCSI_H_ */
-- 
1.9.3




More information about the SeaBIOS mailing list