Re: [PATCH v2 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
On Wed, 19 Sep 2012 18:38:38 +0200 Alexander Graf ag...@suse.de wrote: On 04.09.2012, at 17:13, Cornelia Huck wrote: +static u32 virtio_ccw_get_features(struct virtio_device *vdev) +{ + struct virtio_ccw_device *vcdev = to_vc_device(vdev); + struct virtio_feature_desc features; + int ret; + + /* Read the feature bits from the host. */ + /* TODO: Features 32 bits */ + features.index = 0; + vcdev-ccw.cmd_code = CCW_CMD_READ_FEAT; + vcdev-ccw.flags = 0; + vcdev-ccw.count = sizeof(features); + vcdev-ccw.cda = vcdev-area; + ret = ccw_io_helper(vcdev, VIRTIO_CCW_DOING_READ_FEAT); + if (ret) + return 0; + + memcpy(features, (void *)(unsigned long)vcdev-area, + sizeof(features)); + return le32_to_cpu(features.features); The fact that the features are LE is missing from the spec, right? You're right, I thought it was there. Alex -- To unsubscribe from this list: send the line unsubscribe kvm in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
On 04.09.2012, at 17:13, Cornelia Huck wrote: Add a driver for kvm guests that matches virtual ccw devices provided by the host as virtio bridge devices. These virtio-ccw devices use a special set of channel commands in order to perform virtio functions. Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com --- Changes v1-v2: - adapt to improved virtio-ccw channel commands - fix unregistration of online devices - add a missing spinlock initialization --- arch/s390/include/asm/irq.h | 1 + arch/s390/kernel/irq.c| 1 + drivers/s390/kvm/Makefile | 2 +- drivers/s390/kvm/virtio_ccw.c | 790 ++ 4 files changed, 793 insertions(+), 1 deletion(-) create mode 100644 drivers/s390/kvm/virtio_ccw.c diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h index 2b9d418..b4bea53 100644 --- a/arch/s390/include/asm/irq.h +++ b/arch/s390/include/asm/irq.h @@ -31,6 +31,7 @@ enum interruption_class { IOINT_CTC, IOINT_APB, IOINT_CSC, + IOINT_VIR, NMI_NMI, NR_IRQS, }; diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c index dd7630d..2cc7eed 100644 --- a/arch/s390/kernel/irq.c +++ b/arch/s390/kernel/irq.c @@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = { {.name = CTC, .desc = [I/O] CTC }, {.name = APB, .desc = [I/O] AP Bus }, {.name = CSC, .desc = [I/O] CHSC Subchannel }, + {.name = VIR, .desc = [I/O] Virtual I/O Devices }, {.name = NMI, .desc = [NMI] Machine Check }, }; diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile index 0815690..241891a 100644 --- a/drivers/s390/kvm/Makefile +++ b/drivers/s390/kvm/Makefile @@ -6,4 +6,4 @@ # it under the terms of the GNU General Public License (version 2 only) # as published by the Free Software Foundation. -obj-$(CONFIG_S390_GUEST) += kvm_virtio.o +obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c new file mode 100644 index 000..1c9af22 --- /dev/null +++ b/drivers/s390/kvm/virtio_ccw.c @@ -0,0 +1,790 @@ +/* + * ccw based virtio transport + * + * Copyright IBM Corp. 2012 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2 only) + * as published by the Free Software Foundation. + * + *Author(s): Cornelia Huck cornelia.h...@de.ibm.com + */ + +#include linux/kernel_stat.h +#include linux/init.h +#include linux/bootmem.h +#include linux/err.h +#include linux/virtio.h +#include linux/virtio_config.h +#include linux/slab.h +#include linux/virtio_console.h +#include linux/interrupt.h +#include linux/virtio_ring.h +#include linux/pfn.h +#include linux/async.h +#include linux/wait.h +#include linux/list.h +#include linux/bitops.h +#include linux/module.h +#include asm/io.h +#include asm/kvm_para.h +#include asm/setup.h +#include asm/irq.h +#include asm/cio.h +#include asm/ccwdev.h + +/* + * virtio related functions + */ + +struct vq_config_block { + __u16 index; + __u16 num; +} __attribute__ ((packed)); + +#define VIRTIO_CCW_CONFIG_SIZE 0x100 +/* same as PCI config space size, should be enough for all drivers */ + +struct virtio_ccw_device { + struct virtio_device vdev; + __u8 status; + __u8 config[VIRTIO_CCW_CONFIG_SIZE]; + struct ccw_device *cdev; + struct ccw1 ccw; + __u32 area; + __u32 curr_io; + int err; + wait_queue_head_t wait_q; + spinlock_t lock; + struct list_head virtqueues; + unsigned long indicators; /* XXX - works because we're under 64 bit */ + struct vq_config_block *config_block; +}; + +struct vq_info_block { + __u64 queue; + __u32 align; + __u16 index; + __u16 num; +} __attribute__ ((packed)); + +struct virtio_feature_desc { + __u32 features; + __u8 index; +} __attribute__ ((packed)); + +struct virtio_ccw_vq_info { + struct virtqueue *vq; + int num; + int queue_index; + void *queue; + struct vq_info_block *info_block; + struct list_head node; +}; + +#define KVM_VIRTIO_CCW_RING_ALIGN 4096 + +#define CCW_CMD_SET_VQ 0x13 +#define CCW_CMD_VDEV_RESET 0x33 +#define CCW_CMD_SET_IND 0x43 +#define CCW_CMD_READ_FEAT 0x12 +#define CCW_CMD_WRITE_FEAT 0x11 +#define CCW_CMD_READ_CONF 0x22 +#define CCW_CMD_WRITE_CONF 0x21 +#define CCW_CMD_WRITE_STATUS 0x31 +#define CCW_CMD_READ_VQ_CONF 0x32 + +#define VIRTIO_CCW_DOING_SET_VQ 0x0001 +#define VIRTIO_CCW_DOING_RESET 0x0004 +#define VIRTIO_CCW_DOING_READ_FEAT 0x0008 +#define VIRTIO_CCW_DOING_WRITE_FEAT 0x0010 +#define VIRTIO_CCW_DOING_READ_CONFIG 0x0020 +#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x0040 +#define VIRTIO_CCW_DOING_WRITE_STATUS 0x0080 +#define VIRTIO_CCW_DOING_SET_IND 0x0100
[PATCH v2 3/4] s390/kvm: Add a channel I/O based virtio transport driver.
Add a driver for kvm guests that matches virtual ccw devices provided by the host as virtio bridge devices. These virtio-ccw devices use a special set of channel commands in order to perform virtio functions. Signed-off-by: Cornelia Huck cornelia.h...@de.ibm.com --- Changes v1-v2: - adapt to improved virtio-ccw channel commands - fix unregistration of online devices - add a missing spinlock initialization --- arch/s390/include/asm/irq.h | 1 + arch/s390/kernel/irq.c| 1 + drivers/s390/kvm/Makefile | 2 +- drivers/s390/kvm/virtio_ccw.c | 790 ++ 4 files changed, 793 insertions(+), 1 deletion(-) create mode 100644 drivers/s390/kvm/virtio_ccw.c diff --git a/arch/s390/include/asm/irq.h b/arch/s390/include/asm/irq.h index 2b9d418..b4bea53 100644 --- a/arch/s390/include/asm/irq.h +++ b/arch/s390/include/asm/irq.h @@ -31,6 +31,7 @@ enum interruption_class { IOINT_CTC, IOINT_APB, IOINT_CSC, + IOINT_VIR, NMI_NMI, NR_IRQS, }; diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c index dd7630d..2cc7eed 100644 --- a/arch/s390/kernel/irq.c +++ b/arch/s390/kernel/irq.c @@ -56,6 +56,7 @@ static const struct irq_class intrclass_names[] = { {.name = CTC, .desc = [I/O] CTC }, {.name = APB, .desc = [I/O] AP Bus }, {.name = CSC, .desc = [I/O] CHSC Subchannel }, + {.name = VIR, .desc = [I/O] Virtual I/O Devices }, {.name = NMI, .desc = [NMI] Machine Check }, }; diff --git a/drivers/s390/kvm/Makefile b/drivers/s390/kvm/Makefile index 0815690..241891a 100644 --- a/drivers/s390/kvm/Makefile +++ b/drivers/s390/kvm/Makefile @@ -6,4 +6,4 @@ # it under the terms of the GNU General Public License (version 2 only) # as published by the Free Software Foundation. -obj-$(CONFIG_S390_GUEST) += kvm_virtio.o +obj-$(CONFIG_S390_GUEST) += kvm_virtio.o virtio_ccw.o diff --git a/drivers/s390/kvm/virtio_ccw.c b/drivers/s390/kvm/virtio_ccw.c new file mode 100644 index 000..1c9af22 --- /dev/null +++ b/drivers/s390/kvm/virtio_ccw.c @@ -0,0 +1,790 @@ +/* + * ccw based virtio transport + * + * Copyright IBM Corp. 2012 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2 only) + * as published by the Free Software Foundation. + * + *Author(s): Cornelia Huck cornelia.h...@de.ibm.com + */ + +#include linux/kernel_stat.h +#include linux/init.h +#include linux/bootmem.h +#include linux/err.h +#include linux/virtio.h +#include linux/virtio_config.h +#include linux/slab.h +#include linux/virtio_console.h +#include linux/interrupt.h +#include linux/virtio_ring.h +#include linux/pfn.h +#include linux/async.h +#include linux/wait.h +#include linux/list.h +#include linux/bitops.h +#include linux/module.h +#include asm/io.h +#include asm/kvm_para.h +#include asm/setup.h +#include asm/irq.h +#include asm/cio.h +#include asm/ccwdev.h + +/* + * virtio related functions + */ + +struct vq_config_block { + __u16 index; + __u16 num; +} __attribute__ ((packed)); + +#define VIRTIO_CCW_CONFIG_SIZE 0x100 +/* same as PCI config space size, should be enough for all drivers */ + +struct virtio_ccw_device { + struct virtio_device vdev; + __u8 status; + __u8 config[VIRTIO_CCW_CONFIG_SIZE]; + struct ccw_device *cdev; + struct ccw1 ccw; + __u32 area; + __u32 curr_io; + int err; + wait_queue_head_t wait_q; + spinlock_t lock; + struct list_head virtqueues; + unsigned long indicators; /* XXX - works because we're under 64 bit */ + struct vq_config_block *config_block; +}; + +struct vq_info_block { + __u64 queue; + __u32 align; + __u16 index; + __u16 num; +} __attribute__ ((packed)); + +struct virtio_feature_desc { + __u32 features; + __u8 index; +} __attribute__ ((packed)); + +struct virtio_ccw_vq_info { + struct virtqueue *vq; + int num; + int queue_index; + void *queue; + struct vq_info_block *info_block; + struct list_head node; +}; + +#define KVM_VIRTIO_CCW_RING_ALIGN 4096 + +#define CCW_CMD_SET_VQ 0x13 +#define CCW_CMD_VDEV_RESET 0x33 +#define CCW_CMD_SET_IND 0x43 +#define CCW_CMD_READ_FEAT 0x12 +#define CCW_CMD_WRITE_FEAT 0x11 +#define CCW_CMD_READ_CONF 0x22 +#define CCW_CMD_WRITE_CONF 0x21 +#define CCW_CMD_WRITE_STATUS 0x31 +#define CCW_CMD_READ_VQ_CONF 0x32 + +#define VIRTIO_CCW_DOING_SET_VQ 0x0001 +#define VIRTIO_CCW_DOING_RESET 0x0004 +#define VIRTIO_CCW_DOING_READ_FEAT 0x0008 +#define VIRTIO_CCW_DOING_WRITE_FEAT 0x0010 +#define VIRTIO_CCW_DOING_READ_CONFIG 0x0020 +#define VIRTIO_CCW_DOING_WRITE_CONFIG 0x0040 +#define VIRTIO_CCW_DOING_WRITE_STATUS 0x0080 +#define VIRTIO_CCW_DOING_SET_IND 0x0100 +#define VIRTIO_CCW_DOING_READ_VQ_CONF 0x0200 +#define VIRTIO_CCW_INTPARM_MASK 0x + +static struct virtio_ccw_device