[SLOF] [PATCH v1 3/3] virtio-scsi: enable virtio 1.0
Thomas Huth
thuth at redhat.com
Thu Feb 11 03:19:11 AEDT 2016
On 10.02.2016 10:05, Nikunj A Dadhania wrote:
> Also add a device file for non-transitional pci device id: 0x1048
>
> Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
> ---
> board-qemu/slof/Makefile | 1 +
> board-qemu/slof/pci-device_1af4_1048.fs | 15 +++++++++++++
> lib/libvirtio/virtio-scsi.c | 39 ++++++++++++++++++++-------------
> 3 files changed, 40 insertions(+), 15 deletions(-)
> create mode 100644 board-qemu/slof/pci-device_1af4_1048.fs
>
> diff --git a/board-qemu/slof/Makefile b/board-qemu/slof/Makefile
> index 44706b1..a000a25 100644
> --- a/board-qemu/slof/Makefile
> +++ b/board-qemu/slof/Makefile
> @@ -70,6 +70,7 @@ VIO_FFS_FILES = \
> $(SLOFBRDDIR)/pci-device_1af4_1001.fs \
> $(SLOFBRDDIR)/pci-device_1af4_1042.fs \
> $(SLOFBRDDIR)/pci-device_1af4_1004.fs \
> + $(SLOFBRDDIR)/pci-device_1af4_1048.fs \
> $(SLOFBRDDIR)/pci-device_1af4_1009.fs \
> $(SLOFBRDDIR)/pci-device_1af4_1050.fs \
> $(SLOFBRDDIR)/vio-hvterm.fs \
> diff --git a/board-qemu/slof/pci-device_1af4_1048.fs b/board-qemu/slof/pci-device_1af4_1048.fs
> new file mode 100644
> index 0000000..055ad89
> --- /dev/null
> +++ b/board-qemu/slof/pci-device_1af4_1048.fs
> @@ -0,0 +1,15 @@
> +\ *****************************************************************************
> +\ * Copyright (c) 2016 IBM Corporation
> +\ * All rights reserved.
> +\ * This program and the accompanying materials
> +\ * are made available under the terms of the BSD License
> +\ * which accompanies this distribution, and is available at
> +\ * http://www.opensource.org/licenses/bsd-license.php
> +\ *
> +\ * Contributors:
> +\ * IBM Corporation - initial implementation
> +\ ****************************************************************************/
> +
> +\ Device ID 1048 is for virtio-scsi non-transitional device.
> +\ Include the driver for virtio-scsi
> +s" pci-device_1af4_1004.fs" included
> diff --git a/lib/libvirtio/virtio-scsi.c b/lib/libvirtio/virtio-scsi.c
> index 47d6b5e..04181b0 100644
> --- a/lib/libvirtio/virtio-scsi.c
> +++ b/lib/libvirtio/virtio-scsi.c
> @@ -15,6 +15,7 @@
> #include <cpu.h>
> #include <helpers.h>
> #include "virtio.h"
> +#include "virtio-internal.h"
> #include "virtio-scsi.h"
>
> int virtioscsi_send(struct virtio_device *dev,
> @@ -27,7 +28,7 @@ int virtioscsi_send(struct virtio_device *dev,
> struct vring_used *vq_used; /* "Used" vring */
>
> volatile uint16_t *current_used_idx;
> - uint16_t last_used_idx;
> + uint16_t last_used_idx, avail_idx;
> int id;
> uint32_t vq_size, time;
>
> @@ -38,35 +39,35 @@ int virtioscsi_send(struct virtio_device *dev,
> vq_avail = virtio_get_vring_avail(dev, vq);
> vq_used = virtio_get_vring_used(dev, vq);
>
> + avail_idx = virtio_modern16_to_cpu(dev, vq_avail->idx);
> +
> last_used_idx = vq_used->idx;
> current_used_idx = &vq_used->idx;
>
> /* Determine descriptor index */
> - id = (vq_avail->idx * 3) % vq_size;
> -
> - virtio_fill_desc(&vq_desc[id], 0, (uint64_t)req, sizeof(*req), VRING_DESC_F_NEXT,
> + id = (avail_idx * 3) % vq_size;
> + virtio_fill_desc(&vq_desc[id], dev->is_modern, (uint64_t)req, sizeof(*req), VRING_DESC_F_NEXT,
> (id + 1) % vq_size);
>
> /* Set up virtqueue descriptor for data */
> if (buf && buf_len) {
> - virtio_fill_desc(&vq_desc[(id + 1) % vq_size], 0,
> + virtio_fill_desc(&vq_desc[(id + 1) % vq_size], dev->is_modern,
> (uint64_t)resp, sizeof(*resp),
> VRING_DESC_F_NEXT | VRING_DESC_F_WRITE,
> (id + 2) % vq_size);
> -
> /* Set up virtqueue descriptor for status */
> - virtio_fill_desc(&vq_desc[(id + 2) % vq_size], 0,
> + virtio_fill_desc(&vq_desc[(id + 2) % vq_size], dev->is_modern,
> (uint64_t)buf, buf_len,
> (is_read ? VRING_DESC_F_WRITE : 0), 0);
> } else {
> - virtio_fill_desc(&vq_desc[(id + 1) % vq_size], 0,
> + virtio_fill_desc(&vq_desc[(id + 1) % vq_size], dev->is_modern,
> (uint64_t)resp, sizeof(*resp),
> VRING_DESC_F_WRITE, 0);
> }
>
> - vq_avail->ring[vq_avail->idx % vq_size] = id;
> + vq_avail->ring[avail_idx % vq_size] = virtio_cpu_to_modern16(dev, id);
> mb();
> - vq_avail->idx += 1;
> + vq_avail->idx = virtio_cpu_to_modern16(dev, avail_idx + 1);
>
> /* Tell HV that the vq is ready */
> virtio_queue_notify(dev, vq);
> @@ -94,9 +95,6 @@ int virtioscsi_init(struct virtio_device *dev)
> int qsize = 0;
> int status = VIRTIO_STAT_ACKNOWLEDGE;
>
> - /* Keep it disabled until the driver is 1.0 capable */
> - dev->is_modern = false;
> -
> /* Reset device */
> // XXX That will clear the virtq base. We need to move
> // initializing it to here anyway
> @@ -111,7 +109,13 @@ int virtioscsi_init(struct virtio_device *dev)
> virtio_set_status(dev, status);
>
> /* Device specific setup - we do not support special features right now */
> - virtio_set_guest_features(dev, 0);
> + if (dev->is_modern) {
> + if (virtio_negotiate_guest_features(dev, VIRTIO_F_VERSION_1))
> + goto dev_error;
> + virtio_get_status(dev, &status);
> + } else {
> + virtio_set_guest_features(dev, 0);
> + }
>
> while(1) {
> qsize = virtio_get_qsize(dev, idx);
> @@ -120,7 +124,7 @@ int virtioscsi_init(struct virtio_device *dev)
> virtio_vring_size(qsize);
>
> vq_avail = virtio_get_vring_avail(dev, idx);
> - vq_avail->flags = VRING_AVAIL_F_NO_INTERRUPT;
> + vq_avail->flags = virtio_cpu_to_modern16(dev, VRING_AVAIL_F_NO_INTERRUPT);
> vq_avail->idx = 0;
> idx++;
> }
> @@ -130,6 +134,11 @@ int virtioscsi_init(struct virtio_device *dev)
> virtio_set_status(dev, status);
>
> return 0;
> +dev_error:
> + printf("%s: failed\n", __func__);
> + status |= VIRTIO_STAT_FAILED;
> + virtio_set_status(dev, status);
> + return -1;
> }
Reviewed-by: Thomas Huth <thuth at redhat.com>
More information about the SLOF
mailing list