Blame SOURCES/kvm-vfio-ccw-Add-support-for-the-CRW-region-and-IRQ.patch

902636
From 58edd0fba4d9e98edfeb16139467d6035a1f4e61 Mon Sep 17 00:00:00 2001
902636
From: Cornelia Huck <cohuck@redhat.com>
902636
Date: Tue, 23 Jun 2020 09:25:42 -0400
902636
Subject: [PATCH 08/12] vfio-ccw: Add support for the CRW region and IRQ
902636
902636
RH-Author: Cornelia Huck <cohuck@redhat.com>
902636
Message-id: <20200623092543.358315-9-cohuck@redhat.com>
902636
Patchwork-id: 97698
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH 8/9] vfio-ccw: Add support for the CRW region and IRQ
902636
Bugzilla: 1660916
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
RH-Acked-by: Thomas Huth <thuth@redhat.com>
902636
902636
From: Farhan Ali <alifm@linux.ibm.com>
902636
902636
The crw region can be used to obtain information about
902636
Channel Report Words (CRW) from vfio-ccw driver.
902636
902636
Currently only channel-path related CRWs are passed to
902636
QEMU from vfio-ccw driver.
902636
902636
Signed-off-by: Farhan Ali <alifm@linux.ibm.com>
902636
Signed-off-by: Eric Farman <farman@linux.ibm.com>
902636
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
902636
Message-Id: <20200505125757.98209-7-farman@linux.ibm.com>
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
(cherry picked from commit f030532f2ad6eeb200034915e9c6357cce81b538)
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 hw/vfio/ccw.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
902636
 1 file changed, 73 insertions(+)
902636
902636
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
902636
index 94a0d9840d..b72a505893 100644
902636
--- a/hw/vfio/ccw.c
902636
+++ b/hw/vfio/ccw.c
902636
@@ -44,7 +44,11 @@ struct VFIOCCWDevice {
902636
     uint64_t schib_region_size;
902636
     uint64_t schib_region_offset;
902636
     struct ccw_schib_region *schib_region;
902636
+    uint64_t crw_region_size;
902636
+    uint64_t crw_region_offset;
902636
+    struct ccw_crw_region *crw_region;
902636
     EventNotifier io_notifier;
902636
+    EventNotifier crw_notifier;
902636
     bool force_orb_pfch;
902636
     bool warned_orb_pfch;
902636
 };
902636
@@ -254,6 +258,44 @@ static void vfio_ccw_reset(DeviceState *dev)
902636
     ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);
902636
 }
902636
 
902636
+static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev)
902636
+{
902636
+    struct ccw_crw_region *region = vcdev->crw_region;
902636
+    CRW crw;
902636
+    int size;
902636
+
902636
+    /* Keep reading CRWs as long as data is returned */
902636
+    do {
902636
+        memset(region, 0, sizeof(*region));
902636
+        size = pread(vcdev->vdev.fd, region, vcdev->crw_region_size,
902636
+                     vcdev->crw_region_offset);
902636
+
902636
+        if (size == -1) {
902636
+            error_report("vfio-ccw: Read crw region failed with errno=%d",
902636
+                         errno);
902636
+            break;
902636
+        }
902636
+
902636
+        if (region->crw == 0) {
902636
+            /* No more CRWs to queue */
902636
+            break;
902636
+        }
902636
+
902636
+        memcpy(&crw, &region->crw, sizeof(CRW));
902636
+
902636
+        css_crw_add_to_queue(crw);
902636
+    } while (1);
902636
+}
902636
+
902636
+static void vfio_ccw_crw_notifier_handler(void *opaque)
902636
+{
902636
+    VFIOCCWDevice *vcdev = opaque;
902636
+
902636
+    while (event_notifier_test_and_clear(&vcdev->crw_notifier)) {
902636
+        vfio_ccw_crw_read(vcdev);
902636
+    }
902636
+}
902636
+
902636
 static void vfio_ccw_io_notifier_handler(void *opaque)
902636
 {
902636
     VFIOCCWDevice *vcdev = opaque;
902636
@@ -340,6 +382,10 @@ static void vfio_ccw_register_irq_notifier(VFIOCCWDevice *vcdev,
902636
         notifier = &vcdev->io_notifier;
902636
         fd_read = vfio_ccw_io_notifier_handler;
902636
         break;
902636
+    case VFIO_CCW_CRW_IRQ_INDEX:
902636
+        notifier = &vcdev->crw_notifier;
902636
+        fd_read = vfio_ccw_crw_notifier_handler;
902636
+        break;
902636
     default:
902636
         error_setg(errp, "vfio: Unsupported device irq(%d)", irq);
902636
         return;
902636
@@ -391,6 +437,9 @@ static void vfio_ccw_unregister_irq_notifier(VFIOCCWDevice *vcdev,
902636
     case VFIO_CCW_IO_IRQ_INDEX:
902636
         notifier = &vcdev->io_notifier;
902636
         break;
902636
+    case VFIO_CCW_CRW_IRQ_INDEX:
902636
+        notifier = &vcdev->crw_notifier;
902636
+        break;
902636
     default:
902636
         error_report("vfio: Unsupported device irq(%d)", irq);
902636
         return;
902636
@@ -468,10 +517,24 @@ static void vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
902636
         vcdev->schib_region = g_malloc(info->size);
902636
     }
902636
 
902636
+    ret = vfio_get_dev_region_info(vdev, VFIO_REGION_TYPE_CCW,
902636
+                                   VFIO_REGION_SUBTYPE_CCW_CRW, &info;;
902636
+
902636
+    if (!ret) {
902636
+        vcdev->crw_region_size = info->size;
902636
+        if (sizeof(*vcdev->crw_region) != vcdev->crw_region_size) {
902636
+            error_setg(errp, "vfio: Unexpected size of the CRW region");
902636
+            goto out_err;
902636
+        }
902636
+        vcdev->crw_region_offset = info->offset;
902636
+        vcdev->crw_region = g_malloc(info->size);
902636
+    }
902636
+
902636
     g_free(info);
902636
     return;
902636
 
902636
 out_err:
902636
+    g_free(vcdev->crw_region);
902636
     g_free(vcdev->schib_region);
902636
     g_free(vcdev->async_cmd_region);
902636
     g_free(vcdev->io_region);
902636
@@ -481,6 +544,7 @@ out_err:
902636
 
902636
 static void vfio_ccw_put_region(VFIOCCWDevice *vcdev)
902636
 {
902636
+    g_free(vcdev->crw_region);
902636
     g_free(vcdev->schib_region);
902636
     g_free(vcdev->async_cmd_region);
902636
     g_free(vcdev->io_region);
902636
@@ -596,6 +660,14 @@ static void vfio_ccw_realize(DeviceState *dev, Error **errp)
902636
         goto out_notifier_err;
902636
     }
902636
 
902636
+    if (vcdev->crw_region) {
902636
+        vfio_ccw_register_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX, &err;;
902636
+        if (err) {
902636
+            vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
902636
+            goto out_notifier_err;
902636
+        }
902636
+    }
902636
+
902636
     return;
902636
 
902636
 out_notifier_err:
902636
@@ -620,6 +692,7 @@ static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
902636
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
902636
     VFIOGroup *group = vcdev->vdev.group;
902636
 
902636
+    vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_CRW_IRQ_INDEX);
902636
     vfio_ccw_unregister_irq_notifier(vcdev, VFIO_CCW_IO_IRQ_INDEX);
902636
     vfio_ccw_put_region(vcdev);
902636
     vfio_ccw_put_device(vcdev);
902636
-- 
902636
2.27.0
902636