[dpdk-dev] [PATCH v9 3/8] net/virtio: add packed virtqueue helpers

Tiwei Bie tiwei.bie at intel.com
Thu Oct 25 11:23:53 CEST 2018


On Wed, Oct 24, 2018 at 04:32:31PM +0200, Jens Freimann wrote:
> Add helper functions to set/clear and check descriptor flags.
> 
> Signed-off-by: Jens Freimann <jfreimann at redhat.com>
> ---
>  drivers/net/virtio/virtio_ring.h | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/drivers/net/virtio/virtio_ring.h b/drivers/net/virtio/virtio_ring.h
> index f84ab5e34..629d3477a 100644
> --- a/drivers/net/virtio/virtio_ring.h
> +++ b/drivers/net/virtio/virtio_ring.h
> @@ -77,6 +77,8 @@ struct vring_packed_desc_event {
>  
>  struct vring {
>  	unsigned int num;
> +	unsigned int avail_wrap_counter;
> +	unsigned int used_wrap_counter;

Above fields should be defined in struct virtqueue.

>  	union {
>  		struct vring_desc_packed *desc_packed;
>  		struct vring_desc *desc;
> @@ -91,6 +93,30 @@ struct vring {
>  	};
>  };
>  
> +static inline void
> +_set_desc_avail(struct vring_desc_packed *desc, int wrap_counter)
> +{
> +	desc->flags |= VRING_DESC_F_AVAIL(wrap_counter) |
> +		       VRING_DESC_F_USED(!wrap_counter);
> +}
> +
> +static inline void
> +set_desc_avail(struct vring *vr, struct vring_desc_packed *desc)
> +{
> +	_set_desc_avail(desc, vr->avail_wrap_counter);
> +}
> +
> +static inline int
> +desc_is_used(struct vring_desc_packed *desc, struct vring *vr)
> +{
> +	uint16_t used, flags;
> +
> +	flags = desc->flags;
> +	used = !!(flags & VRING_DESC_F_USED(1));
> +
> +	return used == vr->used_wrap_counter;
> +}
> +
>  /* The standard layout for the ring is a continuous chunk of memory which
>   * looks like this.  We assume num is a power of 2.
>   *
> -- 
> 2.17.1
> 


More information about the dev mailing list