virtio: push out code to vp_avq_index()
authorJiri Pirko <jiri@nvidia.com>
Tue, 16 Jul 2024 11:35:46 +0000 (13:35 +0200)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 17 Jul 2024 09:43:21 +0000 (05:43 -0400)
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>
drivers/virtio/virtio_pci_modern.c

index 6d653be..d704947 100644 (file)
@@ -28,6 +28,21 @@ static u64 vp_get_features(struct virtio_device *vdev)
        return vp_modern_get_features(&vp_dev->mdev);
 }
 
+static int vp_avq_index(struct virtio_device *vdev, u16 *index, u16 *num)
+{
+       struct virtio_pci_device *vp_dev = to_vp_device(vdev);
+
+       *num = 0;
+       if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
+               return 0;
+
+       *num = vp_modern_avq_num(&vp_dev->mdev);
+       if (!(*num))
+               return -EINVAL;
+       *index = vp_modern_avq_index(&vp_dev->mdev);
+       return 0;
+}
+
 static bool vp_is_avq(struct virtio_device *vdev, unsigned int index)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
@@ -729,19 +744,15 @@ static bool vp_get_shm_region(struct virtio_device *vdev,
 static int vp_modern_create_avq(struct virtio_device *vdev)
 {
        struct virtio_pci_device *vp_dev = to_vp_device(vdev);
-       struct virtio_pci_admin_vq *avq;
+       struct virtio_pci_admin_vq *avq = &vp_dev->admin_vq;
        struct virtqueue *vq;
-       u16 admin_q_num;
-
-       if (!virtio_has_feature(vdev, VIRTIO_F_ADMIN_VQ))
-               return 0;
+       u16 num;
+       int err;
 
-       admin_q_num = vp_modern_avq_num(&vp_dev->mdev);
-       if (!admin_q_num)
-               return -EINVAL;
+       err = vp_avq_index(vdev, &avq->vq_index, &num);
+       if (err || !num)
+               return err;
 
-       avq = &vp_dev->admin_vq;
-       avq->vq_index = vp_modern_avq_index(&vp_dev->mdev);
        sprintf(avq->name, "avq.%u", avq->vq_index);
        vq = vp_dev->setup_vq(vp_dev, &vp_dev->admin_vq.info, avq->vq_index, NULL,
                              avq->name, NULL, VIRTIO_MSI_NO_VECTOR);