virtio: Replace size return with usedLength in queue_dequeue.

The size was in fact the count of physical entries that were used. That
number must necessarily be the same as the number given when adding to
the queue, so that number isn't really interesting. Consequently none
of the users of that API made use of it.

Return the used length instead, which is the way virtio signals how much
valid data resides in the dequeued buffer. This is for example important
to know the frame length of incoming packets in virtio_net.
This commit is contained in:
Michael Lotz 2018-11-17 00:28:57 +01:00
parent 14b0498cfa
commit 2f211cce6d
4 changed files with 7 additions and 8 deletions

View File

@ -134,7 +134,7 @@ typedef struct {
uint16 (*queue_size)(virtio_queue queue);
void* (*queue_dequeue)(virtio_queue queue, uint16* _size);
void* (*queue_dequeue)(virtio_queue queue, uint32* _usedLength);
} virtio_device_interface;

View File

@ -185,10 +185,10 @@ virtio_queue_size(virtio_queue _queue)
void*
virtio_queue_dequeue(virtio_queue _queue, uint16* _size)
virtio_queue_dequeue(virtio_queue _queue, uint32* _usedLength)
{
VirtioQueue *queue = (VirtioQueue *)_queue;
return queue->Dequeue(_size);
return queue->Dequeue(_usedLength);
}

View File

@ -131,7 +131,7 @@ public:
void EnableInterrupt();
void DisableInterrupt();
void* Dequeue(uint16* _size = NULL);
void* Dequeue(uint32* _usedLength = NULL);
private:
void UpdateAvailable(uint16 index);

View File

@ -246,7 +246,7 @@ VirtioQueue::Interrupt()
void*
VirtioQueue::Dequeue(uint16 *_size)
VirtioQueue::Dequeue(uint32* _usedLength)
{
TRACE("Dequeue() fRingUsedIndex: %u\n", fRingUsedIndex);
@ -257,12 +257,11 @@ VirtioQueue::Dequeue(uint16 *_size)
TRACE("Dequeue() usedIndex: %u\n", usedIndex);
struct vring_used_elem *element = &fRing.used->ring[usedIndex];
uint16 descriptorIndex = element->id;
// uint32 length = element->len;
if (_usedLength != NULL)
*_usedLength = element->len;
void* cookie = fDescriptors[descriptorIndex]->Cookie();
uint16 size = fDescriptors[descriptorIndex]->Size();
if (_size != NULL)
*_size = size;
if (size == 0)
panic("VirtioQueue::Dequeue() size is zero\n");
fDescriptors[descriptorIndex]->Unset();