{"id":813450,"url":"http://patchwork.ozlabs.org/api/patches/813450/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913132752.8484-2-pasic@linux.vnet.ibm.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170913132752.8484-2-pasic@linux.vnet.ibm.com>","list_archive_url":null,"date":"2017-09-13T13:27:51","name":"[1/2] s390x/ccs: add ccw-tester emulated device","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f0937bbc5adf628cab48aaf93e8ee06fa8e6923a","submitter":{"id":68297,"url":"http://patchwork.ozlabs.org/api/people/68297/?format=json","name":"Halil Pasic","email":"pasic@linux.vnet.ibm.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20170913132752.8484-2-pasic@linux.vnet.ibm.com/mbox/","series":[{"id":2918,"url":"http://patchwork.ozlabs.org/api/series/2918/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=2918","date":"2017-09-13T13:27:52","name":"tests for CCW IDA","version":1,"mbox":"http://patchwork.ozlabs.org/series/2918/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/813450/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/813450/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xsjSl0vcbz9s4s\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed, 13 Sep 2017 23:39:35 +1000 (AEST)","from localhost ([::1]:42587 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1ds7t7-0003EV-1B\n\tfor incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 09:39:33 -0400","from eggs.gnu.org ([2001:4830:134:3::10]:40479)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <pasic@linux.vnet.ibm.com>) id 1ds7iE-00005e-Cr\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 09:28:19 -0400","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <pasic@linux.vnet.ibm.com>) id 1ds7iB-0006NV-4t\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 09:28:18 -0400","from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41114)\n\tby eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <pasic@linux.vnet.ibm.com>)\n\tid 1ds7iA-0006Mr-S0\n\tfor qemu-devel@nongnu.org; Wed, 13 Sep 2017 09:28:15 -0400","from pps.filterd (m0098409.ppops.net [127.0.0.1])\n\tby mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id\n\tv8DDOp95037844\n\tfor <qemu-devel@nongnu.org>; Wed, 13 Sep 2017 09:28:13 -0400","from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109])\n\tby mx0a-001b2d01.pphosted.com with ESMTP id 2cy388yywk-1\n\t(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)\n\tfor <qemu-devel@nongnu.org>; Wed, 13 Sep 2017 09:28:13 -0400","from localhost\n\tby e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use\n\tOnly! Violators will be prosecuted\n\tfor <qemu-devel@nongnu.org> from <pasic@linux.vnet.ibm.com>;\n\tWed, 13 Sep 2017 14:28:10 +0100","from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198)\n\tby e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP\n\tGateway: Authorized Use Only! Violators will be prosecuted; \n\tWed, 13 Sep 2017 14:28:07 +0100","from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com\n\t[9.149.105.59])\n\tby b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with\n\tESMTP id v8DDS7jC6488294; Wed, 13 Sep 2017 13:28:07 GMT","from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 51E0BA4051;\n\tWed, 13 Sep 2017 14:24:17 +0100 (BST)","from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1])\n\tby IMSVA (Postfix) with ESMTP id 1CEB3A4040;\n\tWed, 13 Sep 2017 14:24:17 +0100 (BST)","from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9])\n\tby d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS;\n\tWed, 13 Sep 2017 14:24:17 +0100 (BST)"],"From":"Halil Pasic <pasic@linux.vnet.ibm.com>","To":"Cornelia Huck <cohuck@redhat.com>","Date":"Wed, 13 Sep 2017 15:27:51 +0200","X-Mailer":"git-send-email 2.13.5","In-Reply-To":"<20170913132752.8484-1-pasic@linux.vnet.ibm.com>","References":"<20170913132752.8484-1-pasic@linux.vnet.ibm.com>","X-TM-AS-GCONF":"00","x-cbid":"17091313-0012-0000-0000-00000578B37A","X-IBM-AV-DETECTION":"SAVI=unused REMOTE=unused XFE=unused","x-cbparentid":"17091313-0013-0000-0000-000018F1D015","Message-Id":"<20170913132752.8484-2-pasic@linux.vnet.ibm.com>","X-Proofpoint-Virus-Version":"vendor=fsecure engine=2.50.10432:, ,\n\tdefinitions=2017-09-13_04:, , signatures=0","X-Proofpoint-Spam-Details":"rule=outbound_notspam policy=outbound score=0\n\tspamscore=0 suspectscore=2\n\tmalwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam\n\tadjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000\n\tdefinitions=main-1709130210","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy]","X-Received-From":"148.163.156.1","Subject":"[Qemu-devel] [PATCH 1/2] s390x/ccs: add ccw-tester emulated device","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>,\n\tHalil Pasic <pasic@linux.vnet.ibm.com>,\n\tPierre Morel <pmorel@linux.vnet.ibm.com>, qemu-devel@nongnu.org","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"},"content":"Add a fake device meant for testing the correctness of our css emulation.\n\nWhat we currently have is writing a Fibonacci sequence of uint32_t to the\ndevice via ccw write. The write is going to fail if it ain't a Fibonacci\nand indicate a device exception in scsw together with the proper residual\ncount.\n\nOf course lot's of invalid inputs (besides basic data processing) can be\ntested with that as well.\n\nUsage:\n1) fire up a qemu with something like -device ccw-tester,devno=fe.0.0001\n   on the command line\n2) exercise the device from the guest\n\nSigned-off-by: Halil Pasic <pasic@linux.vnet.ibm.com>\n---\n\nDepends on the series 'add CCW indirect data access support'\n\n---\n hw/s390x/Makefile.objs |   1 +\n hw/s390x/ccw-tester.c  | 179 +++++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 180 insertions(+)\n create mode 100644 hw/s390x/ccw-tester.c","diff":"diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs\nindex 7ee19d3abc..28eb58a3cb 100644\n--- a/hw/s390x/Makefile.objs\n+++ b/hw/s390x/Makefile.objs\n@@ -18,3 +18,4 @@ obj-y += s390-stattrib.o\n obj-$(CONFIG_KVM) += s390-skeys-kvm.o\n obj-$(CONFIG_KVM) += s390-stattrib-kvm.o\n obj-y += s390-ccw.o\n+obj-y += ccw-tester.o\ndiff --git a/hw/s390x/ccw-tester.c b/hw/s390x/ccw-tester.c\nnew file mode 100644\nindex 0000000000..c8017818c4\n--- /dev/null\n+++ b/hw/s390x/ccw-tester.c\n@@ -0,0 +1,179 @@\n+#include \"qemu/osdep.h\"\n+#include \"qapi/error.h\"\n+#include \"qemu/module.h\"\n+#include \"cpu.h\"\n+#include \"hw/s390x/css.h\"\n+#include \"hw/s390x/css-bridge.h\"\n+#include \"hw/s390x/3270-ccw.h\"\n+#include \"exec/address-spaces.h\"\n+#include <error.h>\n+\n+typedef struct CcwTesterDevice {\n+    CcwDevice parent_obj;\n+    uint16_t cu_type;\n+    uint8_t chpid_type;\n+    struct {\n+        uint32_t ring[4];\n+        unsigned int next;\n+    } fib;\n+} CcwTesterDevice;\n+\n+\n+typedef struct CcwTesterClass {\n+    CCWDeviceClass parent_class;\n+    DeviceRealize parent_realize;\n+} CcwTesterClass;\n+\n+#define TYPE_CCW_TESTER \"ccw-tester\"\n+\n+#define CCW_TESTER(obj) \\\n+     OBJECT_CHECK(CcwTesterDevice, (obj), TYPE_CCW_TESTER)\n+#define CCW_TESTER_CLASS(klass) \\\n+     OBJECT_CLASS_CHECK(CcwTesterClass, (klass), TYPE_CCW_TESTER)\n+#define CCW_TESTER_GET_CLASS(obj) \\\n+     OBJECT_GET_CLASS(CcwTesterClass, (obj), TYPE_CCW_TESTER)\n+\n+#define CCW_CMD_READ 0x01U\n+#define CCW_CMD_WRITE 0x02U\n+\n+static unsigned int abs_to_ring(unsigned int i)\n+{\n+    return i & 0x3;\n+}\n+\n+static int  ccw_tester_write_fib(SubchDev *sch, CCW1 ccw)\n+{\n+    CcwTesterDevice *d = sch->driver_data;\n+    bool is_fib = true;\n+    uint32_t sum;\n+    int ret = 0;\n+\n+    ccw_dstream_init(&sch->cds, &ccw, &sch->orb);\n+    d->fib.next = 0;\n+    while (ccw_dstream_avail(&sch->cds) > 0) {\n+        ret = ccw_dstream_read(&sch->cds,\n+                               d->fib.ring[abs_to_ring(d->fib.next)]);\n+        if (ret) {\n+            error(0, -ret, \"fib\");\n+            break;\n+        }\n+        if (d->fib.next > 2) {\n+            sum = (d->fib.ring[abs_to_ring(d->fib.next - 1)]\n+                  + d->fib.ring[abs_to_ring(d->fib.next - 2)]);\n+            is_fib = sum ==  d->fib.ring[abs_to_ring(d->fib.next)];\n+            if (!is_fib) {\n+                break;\n+            }\n+        }\n+        ++(d->fib.next);\n+    }\n+    if (!is_fib) {\n+        sch->curr_status.scsw.ctrl &= ~SCSW_ACTL_START_PEND;\n+        sch->curr_status.scsw.ctrl |= SCSW_STCTL_PRIMARY |\n+                                      SCSW_STCTL_SECONDARY |\n+                                      SCSW_STCTL_ALERT |\n+                                      SCSW_STCTL_STATUS_PEND;\n+        sch->curr_status.scsw.count = ccw_dstream_residual_count(&sch->cds);\n+        sch->curr_status.scsw.cpa = sch->channel_prog + 8;\n+        sch->curr_status.scsw.dstat =  SCSW_DSTAT_UNIT_EXCEP;\n+        return -EIO;\n+    }\n+    return ret;\n+}\n+\n+static int ccw_tester_ccw_cb_impl(SubchDev *sch, CCW1 ccw)\n+{\n+    switch (ccw.cmd_code) {\n+    case CCW_CMD_READ:\n+        break;\n+    case CCW_CMD_WRITE:\n+        return ccw_tester_write_fib(sch, ccw);\n+    default:\n+        return -EINVAL;\n+    }\n+    return 0;\n+}\n+\n+static void ccw_tester_realize(DeviceState *ds, Error **errp)\n+{\n+    uint16_t chpid;\n+    CcwTesterDevice *dev = CCW_TESTER(ds);\n+    CcwTesterClass *ctc = CCW_TESTER_GET_CLASS(dev);\n+    CcwDevice *cdev = CCW_DEVICE(ds);\n+    BusState *qbus = qdev_get_parent_bus(ds);\n+    VirtualCssBus *cbus = VIRTUAL_CSS_BUS(qbus);\n+    SubchDev *sch;\n+    Error *err = NULL;\n+\n+    sch = css_create_sch(cdev->devno, true, cbus->squash_mcss, errp);\n+    if (!sch) {\n+        return;\n+    }\n+\n+    sch->driver_data = dev;\n+    cdev->sch = sch;\n+    chpid = css_find_free_chpid(sch->cssid);\n+\n+    if (chpid > MAX_CHPID) {\n+        error_setg(&err, \"No available chpid to use.\");\n+        goto out_err;\n+    }\n+\n+    sch->id.reserved = 0xff;\n+    sch->id.cu_type = dev->cu_type;\n+    css_sch_build_virtual_schib(sch, (uint8_t)chpid,\n+                                dev->chpid_type);\n+    sch->ccw_cb = ccw_tester_ccw_cb_impl;\n+    sch->do_subchannel_work = do_subchannel_work_virtual;\n+\n+\n+    ctc->parent_realize(ds, &err);\n+    if (err) {\n+        goto out_err;\n+    }\n+\n+    css_generate_sch_crws(sch->cssid, sch->ssid, sch->schid,\n+                          ds->hotplugged, 1);\n+    return;\n+\n+out_err:\n+    error_propagate(errp, err);\n+    css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);\n+    cdev->sch = NULL;\n+    g_free(sch);\n+}\n+\n+static Property ccw_tester_properties[] = {\n+    DEFINE_PROP_UINT16(\"cu_type\", CcwTesterDevice, cu_type,\n+                        0x3831),\n+    DEFINE_PROP_UINT8(\"chpid_type\", CcwTesterDevice, chpid_type,\n+                       0x98),\n+    DEFINE_PROP_END_OF_LIST(),\n+};\n+\n+static void ccw_tester_class_init(ObjectClass *klass, void *data)\n+{\n+    DeviceClass *dc = DEVICE_CLASS(klass);\n+    CcwTesterClass *ctc = CCW_TESTER_CLASS(klass);\n+\n+    dc->props = ccw_tester_properties;\n+    dc->bus_type = TYPE_VIRTUAL_CSS_BUS;\n+    ctc->parent_realize = dc->realize;\n+    dc->realize = ccw_tester_realize;\n+    dc->hotpluggable = false;\n+}\n+\n+static const TypeInfo ccw_tester_info = {\n+    .name = TYPE_CCW_TESTER,\n+    .parent = TYPE_CCW_DEVICE,\n+    .instance_size = sizeof(CcwTesterDevice),\n+    .class_init = ccw_tester_class_init,\n+    .class_size = sizeof(CcwTesterClass),\n+};\n+\n+static void ccw_tester_register(void)\n+{\n+    type_register_static(&ccw_tester_info);\n+}\n+\n+type_init(ccw_tester_register)\n","prefixes":["1/2"]}