From 1aeb125770c4c161394b851b0eff982292702c23 Mon Sep 17 00:00:00 2001 From: Alexey Kardashevskiy Date: Thu, 7 Nov 2019 17:54:58 +1100 Subject: virtio-net: Init queues after features negotiation Every virtio device negotiates virtio protocol features before setting up internal queue descriptors with one exception which is virtio-net. This moves virtio_queue_init_vq() later to have feature negotiation happened sooner. This is going to be used for IOMMU setup later. Signed-off-by: Alexey Kardashevskiy Reviewed-by: Michael Roth --- lib/libvirtio/virtio-net.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/libvirtio/virtio-net.c b/lib/libvirtio/virtio-net.c index 2290b2d..ae67883 100644 --- a/lib/libvirtio/virtio-net.c +++ b/lib/libvirtio/virtio-net.c @@ -84,18 +84,6 @@ static int virtionet_init_pci(struct virtio_net *vnet, struct virtio_device *dev /* Reset device */ virtio_reset_device(vdev); - /* The queue information can be retrieved via the virtio header that - * can be found in the I/O BAR. First queue is the receive queue, - * second the transmit queue, and the forth is the control queue for - * networking options. - * We are only interested in the receive and transmit queue here. */ - if (!virtio_queue_init_vq(vdev, VQ_RX) || - !virtio_queue_init_vq(vdev, VQ_TX)) { - virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER - |VIRTIO_STAT_FAILED); - return -1; - } - /* Acknowledge device. */ virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE); @@ -113,7 +101,7 @@ static int virtionet_init(struct virtio_net *vnet) int status = VIRTIO_STAT_ACKNOWLEDGE | VIRTIO_STAT_DRIVER; struct virtio_device *vdev = &vnet->vdev; net_driver_t *driver = &vnet->driver; - struct vqs *vq_tx = &vdev->vq[VQ_TX], *vq_rx = &vdev->vq[VQ_RX]; + struct vqs *vq_tx, *vq_rx; dprintf("virtionet_init(%02x:%02x:%02x:%02x:%02x:%02x)\n", driver->mac_addr[0], driver->mac_addr[1], @@ -137,6 +125,19 @@ static int virtionet_init(struct virtio_net *vnet) virtio_set_guest_features(vdev, 0); } + /* The queue information can be retrieved via the virtio header that + * can be found in the I/O BAR. First queue is the receive queue, + * second the transmit queue, and the forth is the control queue for + * networking options. + * We are only interested in the receive and transmit queue here. */ + vq_rx = virtio_queue_init_vq(vdev, VQ_RX); + vq_tx = virtio_queue_init_vq(vdev, VQ_TX); + if (!vq_rx || !vq_tx) { + virtio_set_status(vdev, VIRTIO_STAT_ACKNOWLEDGE|VIRTIO_STAT_DRIVER + |VIRTIO_STAT_FAILED); + return -1; + } + /* Allocate memory for one transmit an multiple receive buffers */ vq_rx->buf_mem = SLOF_alloc_mem((BUFFER_ENTRY_SIZE+net_hdr_size) * RX_QUEUE_SIZE); -- cgit v1.1