[SLOF] [PATCH v1 08/27] virtio: make virtio_get_qsize 1.0 aware

Alexey Kardashevskiy aik at ozlabs.ru
Thu Jan 14 18:09:26 AEDT 2016


On 01/13/2016 10:16 PM, Nikunj A Dadhania wrote:
> Also return unsigned int

Why?


>
> Signed-off-by: Nikunj A Dadhania <nikunj at linux.vnet.ibm.com>
> ---
>   lib/libvirtio/virtio.c | 15 +++++++++++----
>   lib/libvirtio/virtio.h |  2 +-
>   2 files changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/lib/libvirtio/virtio.c b/lib/libvirtio/virtio.c
> index bcf050b..77676c7 100644
> --- a/lib/libvirtio/virtio.c
> +++ b/lib/libvirtio/virtio.c
> @@ -185,17 +185,24 @@ unsigned long virtio_vring_size(unsigned int qsize)
>    * @param   queue virtio queue number
>    * @return  number of elements
>    */
> -int virtio_get_qsize(struct virtio_device *dev, int queue)
> +unsigned int virtio_get_qsize(struct virtio_device *dev, int queue)
>   {
> -	int size = 0;
> +	unsigned int size = 0;
>
> -	if (dev->type == VIRTIO_TYPE_PCI) {
> +	if (dev->type != VIRTIO_TYPE_PCI)
> +		return 0;
> +	if (dev->is_modern) {
> +		void *addr = dev->common.addr + offset_of(struct virtio_dev_common, q_select);
> +		ci_write_16(addr, cpu_to_le16(queue));
> +		eieio();
> +		size = le16_to_cpu(ci_read_16(addr + 2));


Please add commit log explaining this magic.


> +	}
> +	else {
>   		ci_write_16(dev->base+VIRTIOHDR_QUEUE_SELECT,
>   			    cpu_to_le16(queue));
>   		eieio();
>   		size = le16_to_cpu(ci_read_16(dev->base+VIRTIOHDR_QUEUE_SIZE));
>   	}
> -

Unrelated change.


>   	return size;
>   }
>
> diff --git a/lib/libvirtio/virtio.h b/lib/libvirtio/virtio.h
> index eee3144..537862b 100644
> --- a/lib/libvirtio/virtio.h
> +++ b/lib/libvirtio/virtio.h
> @@ -107,7 +107,7 @@ struct vqs {
>   #define VQ_ALIGN(addr)	(((addr) + 0xfff) & ~0xfff)
>
>   extern unsigned long virtio_vring_size(unsigned int qsize);
> -extern int virtio_get_qsize(struct virtio_device *dev, int queue);
> +extern unsigned int virtio_get_qsize(struct virtio_device *dev, int queue);
>   extern struct vring_desc *virtio_get_vring_desc(struct virtio_device *dev, int queue);
>   extern struct vring_avail *virtio_get_vring_avail(struct virtio_device *dev, int queue);
>   extern struct vring_used *virtio_get_vring_used(struct virtio_device *dev, int queue);
>


-- 
Alexey


More information about the SLOF mailing list