mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-26 21:52:20 +00:00
virtio_ring: separate the logic of reset/enable from virtqueue_resize
The subsequent reset function will reuse these logic. Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com> Acked-by: Jason Wang <jasowang@redhat.com> Message-Id: <20230810123057.43407-9-xuanzhuo@linux.alibaba.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
This commit is contained in:
parent
4d09f24080
commit
ad48d53b5b
@ -2152,6 +2152,43 @@ static int virtqueue_resize_packed(struct virtqueue *_vq, u32 num)
|
|||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int virtqueue_disable_and_recycle(struct virtqueue *_vq,
|
||||||
|
void (*recycle)(struct virtqueue *vq, void *buf))
|
||||||
|
{
|
||||||
|
struct vring_virtqueue *vq = to_vvq(_vq);
|
||||||
|
struct virtio_device *vdev = vq->vq.vdev;
|
||||||
|
void *buf;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (!vq->we_own_ring)
|
||||||
|
return -EPERM;
|
||||||
|
|
||||||
|
if (!vdev->config->disable_vq_and_reset)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
if (!vdev->config->enable_vq_after_reset)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
err = vdev->config->disable_vq_and_reset(_vq);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
while ((buf = virtqueue_detach_unused_buf(_vq)) != NULL)
|
||||||
|
recycle(_vq, buf);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int virtqueue_enable_after_reset(struct virtqueue *_vq)
|
||||||
|
{
|
||||||
|
struct vring_virtqueue *vq = to_vvq(_vq);
|
||||||
|
struct virtio_device *vdev = vq->vq.vdev;
|
||||||
|
|
||||||
|
if (vdev->config->enable_vq_after_reset(_vq))
|
||||||
|
return -EBUSY;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generic functions and exported symbols.
|
* Generic functions and exported symbols.
|
||||||
@ -2702,13 +2739,8 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
|
|||||||
void (*recycle)(struct virtqueue *vq, void *buf))
|
void (*recycle)(struct virtqueue *vq, void *buf))
|
||||||
{
|
{
|
||||||
struct vring_virtqueue *vq = to_vvq(_vq);
|
struct vring_virtqueue *vq = to_vvq(_vq);
|
||||||
struct virtio_device *vdev = vq->vq.vdev;
|
|
||||||
void *buf;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!vq->we_own_ring)
|
|
||||||
return -EPERM;
|
|
||||||
|
|
||||||
if (num > vq->vq.num_max)
|
if (num > vq->vq.num_max)
|
||||||
return -E2BIG;
|
return -E2BIG;
|
||||||
|
|
||||||
@ -2718,28 +2750,16 @@ int virtqueue_resize(struct virtqueue *_vq, u32 num,
|
|||||||
if ((vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num) == num)
|
if ((vq->packed_ring ? vq->packed.vring.num : vq->split.vring.num) == num)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!vdev->config->disable_vq_and_reset)
|
err = virtqueue_disable_and_recycle(_vq, recycle);
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
if (!vdev->config->enable_vq_after_reset)
|
|
||||||
return -ENOENT;
|
|
||||||
|
|
||||||
err = vdev->config->disable_vq_and_reset(_vq);
|
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
while ((buf = virtqueue_detach_unused_buf(_vq)) != NULL)
|
|
||||||
recycle(_vq, buf);
|
|
||||||
|
|
||||||
if (vq->packed_ring)
|
if (vq->packed_ring)
|
||||||
err = virtqueue_resize_packed(_vq, num);
|
err = virtqueue_resize_packed(_vq, num);
|
||||||
else
|
else
|
||||||
err = virtqueue_resize_split(_vq, num);
|
err = virtqueue_resize_split(_vq, num);
|
||||||
|
|
||||||
if (vdev->config->enable_vq_after_reset(_vq))
|
return virtqueue_enable_after_reset(_vq);
|
||||||
return -EBUSY;
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(virtqueue_resize);
|
EXPORT_SYMBOL_GPL(virtqueue_resize);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user