* [PATCH v3 0/1] s390x: css: pong, channel subsystem test device @ 2020-05-18 16:43 Pierre Morel 2020-05-18 16:43 ` [PATCH v3 1/1] " Pierre Morel 0 siblings, 1 reply; 3+ messages in thread From: Pierre Morel @ 2020-05-18 16:43 UTC (permalink / raw) To: qemu-s390x; +Cc: thuth, frankja, david, cohuck, qemu-devel, pasic, borntraeger This patch series presents a device to test the channel subsystem. Currently the pong device does the following: - on PONG_WRITE requests: read the CCW buffer, expect a string with an integer in the buffer. store the integer in a variable initialy initialized to zero. - on PONG_READ requests: Store the value of the variable + 1 as a string in a buffer send back the buffer - defines a Control Unit property of type CCW_PONG_CU_TYPE for the guest to recognize the PONG device when using a SENSE_ID command. Pierre Morel (1): s390x: css: pong, channel subsystem test device default-configs/s390x-softmmu.mak | 1 + hw/s390x/Kconfig | 3 + hw/s390x/Makefile.objs | 1 + hw/s390x/ccw-pong.c | 134 ++++++++++++++++++++++++++++++ include/hw/s390x/pong.h | 48 +++++++++++ 5 files changed, 187 insertions(+) create mode 100644 hw/s390x/ccw-pong.c create mode 100644 include/hw/s390x/pong.h -- 2.25.1 Changelog: from v2 to v3 - rebase to devel - use device_class_set_props() from v1 to v2 - use ccw_dstream_xxx_buf (Connie) - adding a cu_type property - testing the ccw.count - conditional compiling for TEST_DEVICES (Connie, Thomas) - suppress the device categorie (Connie ?) - adding write callback and some funny protocol ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/1] s390x: css: pong, channel subsystem test device 2020-05-18 16:43 [PATCH v3 0/1] s390x: css: pong, channel subsystem test device Pierre Morel @ 2020-05-18 16:43 ` Pierre Morel 0 siblings, 0 replies; 3+ messages in thread From: Pierre Morel @ 2020-05-18 16:43 UTC (permalink / raw) To: qemu-s390x; +Cc: thuth, frankja, david, cohuck, qemu-devel, pasic, borntraeger This is a test device for channel subsystem. Most of the CSS instructions are handled by the common code. The PONG_READ and PONG_WRITE CCW commands allow to test the SSCH instruction with both read and write commands. It is also possible to define the Control Unit type with the cu_type property. Currently only the kvm-unit-test css test uses the PONG device. Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> --- default-configs/s390x-softmmu.mak | 1 + hw/s390x/Kconfig | 3 + hw/s390x/Makefile.objs | 1 + hw/s390x/ccw-pong.c | 134 ++++++++++++++++++++++++++++++ include/hw/s390x/pong.h | 48 +++++++++++ 5 files changed, 187 insertions(+) create mode 100644 hw/s390x/ccw-pong.c create mode 100644 include/hw/s390x/pong.h diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak index f2287a133f..72711912cd 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -7,6 +7,7 @@ #CONFIG_VFIO_CCW=n #CONFIG_VIRTIO_PCI=n #CONFIG_WDT_DIAG288=n +#CONFIG_CCW_TESTDEV=n # Boards: # diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 5e7d8a2bae..041ede333e 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -10,3 +10,6 @@ config S390_CCW_VIRTIO select SCLPCONSOLE select VIRTIO_CCW select MSI_NONBROKEN + +config CCW_TESTDEV + default y if TEST_DEVICES diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs index 568bab9711..f839e28fb6 100644 --- a/hw/s390x/Makefile.objs +++ b/hw/s390x/Makefile.objs @@ -35,3 +35,4 @@ obj-$(CONFIG_KVM) += pv.o obj-y += s390-ccw.o obj-y += ap-device.o obj-y += ap-bridge.o +obj-y += ccw-pong.o diff --git a/hw/s390x/ccw-pong.c b/hw/s390x/ccw-pong.c new file mode 100644 index 0000000000..292124721d --- /dev/null +++ b/hw/s390x/ccw-pong.c @@ -0,0 +1,134 @@ +/* + * CCW PING-PONG + * + * Copyright 2019 IBM Corp. + * Author(s): Pierre Morel <pmorel@linux.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "cpu.h" +#include "exec/address-spaces.h" +#include "hw/s390x/css.h" +#include "hw/s390x/css-bridge.h" +#include "hw/qdev-properties.h" +#include "hw/s390x/pong.h" + +#define PONG_BUF_SIZE 0x1000 +static char buf[PONG_BUF_SIZE]; + +static int pong_ccw_cb(SubchDev *sch, CCW1 ccw) +{ + int rc = 0; + static int value; + int len; + + len = (ccw.count > PONG_BUF_SIZE) ? PONG_BUF_SIZE : ccw.count; + switch (ccw.cmd_code) { + case PONG_WRITE: + rc = ccw_dstream_read_buf(&sch->cds, buf, len); + value = atol(buf); + break; + case PONG_READ: + sprintf(buf, "%08x", value + 1); + rc = ccw_dstream_write_buf(&sch->cds, buf, len); + break; + default: + rc = -ENOSYS; + break; + } + + sch->curr_status.scsw.count = ccw_dstream_residual_count(&sch->cds); + + if (rc == -EIO) { + /* I/O error, specific devices generate specific conditions */ + SCHIB *schib = &sch->curr_status; + + sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK; + sch->sense_data[0] = 0x40; /* intervention-req */ + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; + } + return rc; +} + +static void pong_ccw_realize(DeviceState *ds, Error **errp) +{ + uint16_t chpid; + CcwPONGDevice *dev = CCW_PONG(ds); + CcwDevice *cdev = CCW_DEVICE(ds); + CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev); + SubchDev *sch; + Error *err = NULL; + + sch = css_create_sch(cdev->devno, errp); + if (!sch) { + return; + } + + sch->driver_data = dev; + cdev->sch = sch; + chpid = css_find_free_chpid(sch->cssid); + + if (chpid > MAX_CHPID) { + error_setg(&err, "No available chpid to use."); + goto out_err; + } + + sch->id.reserved = 0xff; + sch->id.cu_type = dev->cu_type; + css_sch_build_virtual_schib(sch, (uint8_t)chpid, CCW_PONG_CHPID_TYPE); + sch->do_subchannel_work = do_subchannel_work_virtual; + sch->ccw_cb = pong_ccw_cb; + + cdk->realize(cdev, &err); + if (err) { + goto out_err; + } + + css_reset_sch(sch); + return; + +out_err: + error_propagate(errp, err); + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); + cdev->sch = NULL; + g_free(sch); +} + +static Property pong_ccw_properties[] = { + DEFINE_PROP_UINT16("cu_type", CcwPONGDevice, cu_type, CCW_PONG_CU_TYPE), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pong_ccw_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, pong_ccw_properties); + dc->bus_type = TYPE_VIRTUAL_CSS_BUS; + dc->realize = pong_ccw_realize; + dc->hotpluggable = false; +} + +static const TypeInfo pong_ccw_info = { + .name = TYPE_CCW_PONG, + .parent = TYPE_CCW_DEVICE, + .instance_size = sizeof(CcwPONGDevice), + .class_init = pong_ccw_class_init, + .class_size = sizeof(CcwPONGClass), +}; + +static void pong_ccw_register(void) +{ + type_register_static(&pong_ccw_info); +} + +type_init(pong_ccw_register) diff --git a/include/hw/s390x/pong.h b/include/hw/s390x/pong.h new file mode 100644 index 0000000000..b14af7ca86 --- /dev/null +++ b/include/hw/s390x/pong.h @@ -0,0 +1,48 @@ +/* + * ccw-attached PONG definitions + * + * Copyright 2019 IBM Corp. + * Author(s): Pierre Morel <pmorel@linux.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#ifndef HW_S390X_PONG_CCW_H +#define HW_S390X_PONG_CCW_H + +#include "hw/sysbus.h" +#include "hw/s390x/css.h" +#include "hw/s390x/ccw-device.h" + +#define CCW_PONG_CU_TYPE 0xc0ca +#define CCW_PONG_CHPID_TYPE 0xd0 + +#define TYPE_CCW_PONG "ccw-pong" + +/* Local Channel Commands */ +#define PONG_WRITE 0x21 /* Write */ +#define PONG_READ 0x22 /* Read buffer */ + +#define CCW_PONG(obj) \ + OBJECT_CHECK(CcwPONGDevice, (obj), TYPE_CCW_PONG) +#define CCW_PONG_CLASS(klass) \ + OBJECT_CLASS_CHECK(CcwPONGClass, (klass), TYPE_CCW_PONG) +#define CCW_PONG_GET_CLASS(obj) \ + OBJECT_GET_CLASS(CcwPONGClass, (obj), TYPE_CCW_PONG) + +typedef struct CcwPONGDevice { + CcwDevice parent_obj; + uint16_t cu_type; +} CcwPONGDevice; + +typedef struct CcwPONGClass { + CCWDeviceClass parent_class; + + void (*init)(CcwPONGDevice *, Error **); + int (*read_payload)(CcwPONGDevice *); + int (*write_payload)(CcwPONGDevice *, uint8_t); +} CcwPONGClass; + +#endif -- 2.25.1 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v3 0/1] s390x: css: pong, channel subsystem test device @ 2020-02-20 11:59 Pierre Morel 2020-02-20 11:59 ` [PATCH v3 1/1] " Pierre Morel 0 siblings, 1 reply; 3+ messages in thread From: Pierre Morel @ 2020-02-20 11:59 UTC (permalink / raw) To: qemu-s390x; +Cc: thuth, frankja, david, cohuck, qemu-devel, pasic This patch series presents a device to test the channel subsystem. Currently it only does the following: - answer to WRITE requests by incrementing an integer stored as string in the data of a PONG_WRITE CCW command. - send back the same buffer, with the incremented integer when receiving a PONG_READ CCW command. - defines a Control Unit property. Pierre Morel (1): s390x: css: pong, channel subsystem test device default-configs/s390x-softmmu.mak | 1 + hw/s390x/Kconfig | 3 + hw/s390x/Makefile.objs | 1 + hw/s390x/ccw-pong.c | 140 ++++++++++++++++++++++++++++++ include/hw/s390x/pong.h | 54 ++++++++++++ 5 files changed, 199 insertions(+) create mode 100644 hw/s390x/ccw-pong.c create mode 100644 include/hw/s390x/pong.h -- 2.17.0 Changelog: v2 to v3: - use device_class_set_props() instead to access the properties directly v1 to v2: - use ccw_dstream_xxx_buf (Connie) - adding a cu_type property - testing the ccw.count - conditional compiling for TEST_DEVICES (Connie, Thomas) - suppress the device categorie (Connie ?) - adding write callback and some funny protocol ^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v3 1/1] s390x: css: pong, channel subsystem test device 2020-02-20 11:59 [PATCH v3 0/1] " Pierre Morel @ 2020-02-20 11:59 ` Pierre Morel 0 siblings, 0 replies; 3+ messages in thread From: Pierre Morel @ 2020-02-20 11:59 UTC (permalink / raw) To: qemu-s390x; +Cc: thuth, frankja, david, cohuck, qemu-devel, pasic This is a test device for channel subsystem. Most of the CSS instructions are handled by the common code. The PONG_READ and PONG_WRITE CCW commands allow to test the SSCH instruction with both read and write commands. It is also possible to define the Control Unit type with the cu_type property. Currently only the kvm-unit-test css test uses the PONG device. Signed-off-by: Pierre Morel <pmorel@linux.ibm.com> --- default-configs/s390x-softmmu.mak | 1 + hw/s390x/Kconfig | 3 + hw/s390x/Makefile.objs | 1 + hw/s390x/ccw-pong.c | 140 ++++++++++++++++++++++++++++++ include/hw/s390x/pong.h | 54 ++++++++++++ 5 files changed, 199 insertions(+) create mode 100644 hw/s390x/ccw-pong.c create mode 100644 include/hw/s390x/pong.h diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-softmmu.mak index f2287a133f..72711912cd 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -7,6 +7,7 @@ #CONFIG_VFIO_CCW=n #CONFIG_VIRTIO_PCI=n #CONFIG_WDT_DIAG288=n +#CONFIG_CCW_TESTDEV=n # Boards: # diff --git a/hw/s390x/Kconfig b/hw/s390x/Kconfig index 5e7d8a2bae..041ede333e 100644 --- a/hw/s390x/Kconfig +++ b/hw/s390x/Kconfig @@ -10,3 +10,6 @@ config S390_CCW_VIRTIO select SCLPCONSOLE select VIRTIO_CCW select MSI_NONBROKEN + +config CCW_TESTDEV + default y if TEST_DEVICES diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs index e02ed80b68..e74d0efd9d 100644 --- a/hw/s390x/Makefile.objs +++ b/hw/s390x/Makefile.objs @@ -34,3 +34,4 @@ obj-$(CONFIG_KVM) += s390-stattrib-kvm.o obj-y += s390-ccw.o obj-y += ap-device.o obj-y += ap-bridge.o +obj-y += ccw-pong.o diff --git a/hw/s390x/ccw-pong.c b/hw/s390x/ccw-pong.c new file mode 100644 index 0000000000..28177eddae --- /dev/null +++ b/hw/s390x/ccw-pong.c @@ -0,0 +1,140 @@ +/* + * CCW PING-PONG + * + * Copyright 2019 IBM Corp. + * Author(s): Pierre Morel <pmorel@linux.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "cpu.h" +#include "exec/address-spaces.h" +#include "hw/s390x/css.h" +#include "hw/s390x/css-bridge.h" +#include "hw/qdev-properties.h" +#include "hw/s390x/pong.h" + +#define PONG_BUF_SIZE 0x1000 +static char buf[PONG_BUF_SIZE]; + +static int pong_ccw_cb(SubchDev *sch, CCW1 ccw) +{ + int rc = 0; + static int value; + int len; + + len = (ccw.count > PONG_BUF_SIZE) ? PONG_BUF_SIZE : ccw.count; + switch (ccw.cmd_code) { + case PONG_WRITE: + rc = ccw_dstream_read_buf(&sch->cds, buf, len); + value = atol(buf); + break; + case PONG_READ: + sprintf(buf, "%08x", value + 1); + rc = ccw_dstream_write_buf(&sch->cds, buf, len); + break; + default: + rc = -ENOSYS; + break; + } + + sch->curr_status.scsw.count = ccw_dstream_residual_count(&sch->cds); + + if (rc == -EIO) { + /* I/O error, specific devices generate specific conditions */ + SCHIB *schib = &sch->curr_status; + + sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_CHECK; + sch->sense_data[0] = 0x40; /* intervention-req */ + schib->scsw.ctrl &= ~SCSW_ACTL_START_PEND; + schib->scsw.ctrl &= ~SCSW_CTRL_MASK_STCTL; + schib->scsw.ctrl |= SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; + } + return rc; +} + +static void pong_ccw_realize(DeviceState *ds, Error **errp) +{ + uint16_t chpid; + CcwPONGDevice *dev = CCW_PONG(ds); + CcwDevice *cdev = CCW_DEVICE(ds); + CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev); + SubchDev *sch; + Error *err = NULL; + + sch = css_create_sch(cdev->devno, errp); + if (!sch) { + return; + } + + sch->driver_data = dev; + cdev->sch = sch; + chpid = css_find_free_chpid(sch->cssid); + + if (chpid > MAX_CHPID) { + error_setg(&err, "No available chpid to use."); + goto out_err; + } + + sch->id.reserved = 0xff; + sch->id.cu_type = dev->cu_type; + sch->id.cu_model = dev->cu_model; + sch->id.dev_type = dev->dev_type; + sch->id.dev_model = dev->dev_model; + css_sch_build_virtual_schib(sch, (uint8_t)chpid, CCW_PONG_CHPID_TYPE); + sch->do_subchannel_work = do_subchannel_work_virtual; + sch->ccw_cb = pong_ccw_cb; + + cdk->realize(cdev, &err); + if (err) { + goto out_err; + } + + css_reset_sch(sch); + return; + +out_err: + error_propagate(errp, err); + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); + cdev->sch = NULL; + g_free(sch); +} + +static Property pong_ccw_properties[] = { + DEFINE_PROP_UINT16("cu_type", CcwPONGDevice, cu_type, CCW_PONG_CU_TYPE), + DEFINE_PROP_UINT8("cu_model", CcwPONGDevice, cu_model, CCW_PONG_CU_MODEL), + DEFINE_PROP_UINT16("dev_type", CcwPONGDevice, dev_type, CCW_PONG_DEV_TYPE), + DEFINE_PROP_UINT8("dev_model", CcwPONGDevice, dev_model, CCW_PONG_DEV_MODEL), + DEFINE_PROP_END_OF_LIST(), +}; + +static void pong_ccw_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + device_class_set_props(dc, pong_ccw_properties); + dc->bus_type = TYPE_VIRTUAL_CSS_BUS; + dc->realize = pong_ccw_realize; + dc->hotpluggable = false; +} + +static const TypeInfo pong_ccw_info = { + .name = TYPE_CCW_PONG, + .parent = TYPE_CCW_DEVICE, + .instance_size = sizeof(CcwPONGDevice), + .class_init = pong_ccw_class_init, + .class_size = sizeof(CcwPONGClass), +}; + +static void pong_ccw_register(void) +{ + type_register_static(&pong_ccw_info); +} + +type_init(pong_ccw_register) diff --git a/include/hw/s390x/pong.h b/include/hw/s390x/pong.h new file mode 100644 index 0000000000..1e60aef24e --- /dev/null +++ b/include/hw/s390x/pong.h @@ -0,0 +1,54 @@ +/* + * ccw-attached PONG definitions + * + * Copyright 2019 IBM Corp. + * Author(s): Pierre Morel <pmorel@linux.ibm.com> + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#ifndef HW_S390X_PONG_CCW_H +#define HW_S390X_PONG_CCW_H + +#include "hw/sysbus.h" +#include "hw/s390x/css.h" +#include "hw/s390x/ccw-device.h" + +#define CCW_PONG_CU_TYPE 0xc0ca +#define CCW_PONG_CU_MODEL 0xa7 +#define CCW_PONG_DEV_TYPE 0xcafe +#define CCW_PONG_DEV_MODEL 0xe5 +#define CCW_PONG_CHPID_TYPE 0xd0 + +#define TYPE_CCW_PONG "ccw-pong" + +/* Local Channel Commands */ +#define PONG_WRITE 0x21 /* Write */ +#define PONG_READ 0x22 /* Read buffer */ + +#define CCW_PONG(obj) \ + OBJECT_CHECK(CcwPONGDevice, (obj), TYPE_CCW_PONG) +#define CCW_PONG_CLASS(klass) \ + OBJECT_CLASS_CHECK(CcwPONGClass, (klass), TYPE_CCW_PONG) +#define CCW_PONG_GET_CLASS(obj) \ + OBJECT_GET_CLASS(CcwPONGClass, (obj), TYPE_CCW_PONG) + +typedef struct CcwPONGDevice { + CcwDevice parent_obj; + uint16_t cu_type; + uint8_t cu_model; + uint16_t dev_type; + uint8_t dev_model; +} CcwPONGDevice; + +typedef struct CcwPONGClass { + CCWDeviceClass parent_class; + + void (*init)(CcwPONGDevice *, Error **); + int (*read_payload)(CcwPONGDevice *); + int (*write_payload)(CcwPONGDevice *, uint8_t); +} CcwPONGClass; + +#endif -- 2.17.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-05-18 16:59 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-05-18 16:43 [PATCH v3 0/1] s390x: css: pong, channel subsystem test device Pierre Morel 2020-05-18 16:43 ` [PATCH v3 1/1] " Pierre Morel -- strict thread matches above, loose matches on Subject: below -- 2020-02-20 11:59 [PATCH v3 0/1] " Pierre Morel 2020-02-20 11:59 ` [PATCH v3 1/1] " Pierre Morel
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).