On 8/11/26 10:46 AM, [email protected] wrote:
From: Jared Rossi <[email protected]>
Read virtio-pci configuration and configure virt-queue for scsi devices.
Signed-off-by: Jared Rossi <[email protected]>
---
pc-bios/s390-ccw/main.c | 3 ++-
pc-bios/s390-ccw/virtio-pci.c | 30 ++++++++++++++++++++++++++++++
pc-bios/s390-ccw/virtio-scsi.c | 12 +++++++++++-
3 files changed, 43 insertions(+), 2 deletions(-)
diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c
index 63692260a4..50f455324e 100644
--- a/pc-bios/s390-ccw/main.c
+++ b/pc-bios/s390-ccw/main.c
@@ -269,6 +269,7 @@ static bool find_boot_device(void)
}
break;
case S390_IPL_TYPE_PCI:
+ vdev->scsi_device_selected = false;
found = find_fid(iplb.pci.fid);
break;
default:
@@ -329,13 +330,13 @@ static void ipl_pci_device(void)
{
VDev *vdev = virtio_get_device();
vdev->is_cdrom = false;
- vdev->scsi_device_selected = false;
if (virtio_pci_setup_device()) {
return;
}
switch (vdev->dev_type) {
+ case VIRTIO_ID_SCSI:
case VIRTIO_ID_BLOCK:
if (virtio_setup() == 0) {
zipl_load(); /* only return on error */
diff --git a/pc-bios/s390-ccw/virtio-pci.c b/pc-bios/s390-ccw/virtio-pci.c
index 231ab6e04d..277c3ea68d 100644
--- a/pc-bios/s390-ccw/virtio-pci.c
+++ b/pc-bios/s390-ccw/virtio-pci.c
@@ -52,6 +52,10 @@ void virtio_pci_id2type(VDev *vdev, uint16_t device_id)
case 0x1001:
vdev->dev_type = VIRTIO_ID_BLOCK;
break;
+ case 0x1048:
+ case 0x1004:
+ vdev->dev_type = VIRTIO_ID_SCSI;
+ break;
default:
vdev->dev_type = 0;
}
@@ -199,6 +203,26 @@ static int virtio_pci_get_blk_config(void)
return rc;
}
+static int virtio_pci_get_scsi_config(void)
+{
+ VirtioScsiConfig *cfg = &virtio_get_device()->config.scsi;
+ int rc = vpci_read_flex(d_cap.off, d_cap.bar, cfg,
sizeof(VirtioScsiConfig));
+
+ /* all fields of scsi config must be byte swapped */
+ cfg->num_queues = bswap32(cfg->num_queues);
+ cfg->seg_max = bswap32(cfg->seg_max);
+ cfg->max_sectors = bswap32(cfg->max_sectors);
+ cfg->cmd_per_lun = bswap32(cfg->cmd_per_lun);
+ cfg->event_info_size = bswap32(cfg->event_info_size);
+ cfg->sense_size = bswap32(cfg->sense_size);
+ cfg->cdb_size = bswap32(cfg->cdb_size);
+ cfg->max_channel = bswap16(cfg->max_channel);
+ cfg->max_target = bswap16(cfg->max_target);
+ cfg->max_lun = bswap32(cfg->max_lun);
+
+ return rc;
+}
+
static int virtio_pci_negotiate(void)
{
int i, rc;
@@ -330,6 +354,7 @@ bool virtio_pci_is_supported(VDev *vdev)
if (vdev->vendor_id == PCI_VENDOR_VIRTIO) {
switch (vdev->dev_type) {
case VIRTIO_ID_BLOCK:
+ case VIRTIO_ID_SCSI:
return true;
default:
return false;
@@ -384,6 +409,11 @@ int virtio_pci_setup(VDev *vdev)
vdev->cmd_vr_idx = 0;
virtio_pci_get_blk_config();
break;
+ case VIRTIO_ID_SCSI:
+ vdev->nr_vqs = 3;
+ vdev->cmd_vr_idx = 2;
+ virtio_pci_get_scsi_config();
+ break;
default:
puts("Unsupported virtio device");
return -ENODEV;
diff --git a/pc-bios/s390-ccw/virtio-scsi.c b/pc-bios/s390-ccw/virtio-scsi.c
index 9ea00c6fe6..095d7ac430 100644
--- a/pc-bios/s390-ccw/virtio-scsi.c
+++ b/pc-bios/s390-ccw/virtio-scsi.c
@@ -16,6 +16,7 @@
#include "scsi.h"
#include "virtio-scsi.h"
#include "virtio-ccw.h"
+#include "virtio-pci.h"
#include "s390-time.h"
#include "helper.h"
@@ -479,7 +480,16 @@ static int virtio_scsi_setup(VDev *vdev)
int virtio_scsi_setup_device(VDev *vdev)
{
- virtio_ccw_setup(vdev);
+ switch (vdev->ipl_type) {
+ case S390_IPL_TYPE_CCW:
+ virtio_ccw_setup(vdev);
+ break;
+ case S390_IPL_TYPE_PCI:
+ virtio_pci_setup(vdev);
+ break;
Why was/is the return code from virtio_*_setup discarded? Shouldn't we
do -something- if it's nonzero instead of continuing on?
Besides that, this looks good to me.
+ default:
+ return 1;
+ }
if (vdev->config.scsi.sense_size != VIRTIO_SCSI_SENSE_SIZE) {
puts("Config: sense size mismatch");