Skip to content

Commit 7e5d9f5

Browse files
Jiri Pirkomstsirkin
authored andcommitted
virtio: push out code to vp_avq_index()
To prepare for the follow-up patch to use the code as an op, push out the code that gets admin virtqueue base index and count to a separate helper. Signed-off-by: Jiri Pirko <jiri@nvidia.com> Message-Id: <20240716113552.80599-8-jiri@resnulli.us> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 4199107 commit 7e5d9f5

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

drivers/virtio/virtio_pci_modern.c

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ static u64 vp_get_features(struct virtio_device *vdev)
2828
return vp_modern_get_features(&vp_dev->mdev);
2929
}
3030

31+
static int vp_avq_index(struct virtio_device *vdev, u16 *index, u16 *num)
32+
{
33+
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
34+
35+
*num = 0;
36+
if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
37+
return 0;
38+
39+
*num = vp_modern_avq_num(&vp_dev->mdev);
40+
if (!(*num))
41+
return -EINVAL;
42+
*index = vp_modern_avq_index(&vp_dev->mdev);
43+
return 0;
44+
}
45+
3146
static bool vp_is_avq(struct virtio_device *vdev, unsigned int index)
3247
{
3348
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
@@ -729,19 +744,15 @@ static bool vp_get_shm_region(struct virtio_device *vdev,
729744
static int vp_modern_create_avq(struct virtio_device *vdev)
730745
{
731746
struct virtio_pci_device *vp_dev = to_vp_device(vdev);
732-
struct virtio_pci_admin_vq *avq;
747+
struct virtio_pci_admin_vq *avq = &vp_dev->admin_vq;
733748
struct virtqueue *vq;
734-
u16 admin_q_num;
735-
736-
if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
737-
return 0;
749+
u16 num;
750+
int err;
738751

739-
admin_q_num = vp_modern_avq_num(&vp_dev->mdev);
740-
if (!admin_q_num)
741-
return -EINVAL;
752+
err = vp_avq_index(vdev, &avq->vq_index, &num);
753+
if (err || !num)
754+
return err;
742755

743-
avq = &vp_dev->admin_vq;
744-
avq->vq_index = vp_modern_avq_index(&vp_dev->mdev);
745756
sprintf(avq->name, "avq.%u", avq->vq_index);
746757
vq = vp_dev->setup_vq(vp_dev, &vp_dev->admin_vq.info, avq->vq_index, NULL,
747758
avq->name, NULL, VIRTIO_MSI_NO_VECTOR);

0 commit comments

Comments
 (0)