pub struct Queue {
pub max_size: u16,
pub size: u16,
pub ready: bool,
pub desc_table_addr: GuestAddress,
pub avail_ring_addr: GuestAddress,
pub used_ring_addr: GuestAddress,
pub next_avail_idx: u16,
pub next_used_idx: u16,
}Expand description
Per-queue setup state and runtime cursor.
The transport mutates size, *_addr, and ready in response to guest
MMIO writes during driver init. The device handler mutates
next_avail_idx as it consumes descriptor heads.
Fields§
§max_size: u16Maximum descriptor count negotiated at boot (the device exposes this
as QueueNumMax).
size: u16Active descriptor count. Bounded by max_size. Set by the driver
writing QueueNum.
ready: booltrue once the driver writes QueueReady = 1.
desc_table_addr: GuestAddressGuest-physical address of the descriptor table.
avail_ring_addr: GuestAddressGuest-physical address of the available ring.
used_ring_addr: GuestAddressGuest-physical address of the used ring.
next_avail_idx: u16Device-side cursor into the available ring.
next_used_idx: u16Device-side cursor into the used ring (the next slot to write to).
Implementations§
Source§impl Queue
impl Queue
Sourcepub fn set_size(&mut self, requested: u16)
pub fn set_size(&mut self, requested: u16)
Set the negotiated descriptor count, clamping to max_size and to a
power of two as the spec requires.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the queue cursors and clear the ready flag. Called when the
driver writes Status = INIT.
Sourcepub fn pop_avail<M: GuestMemory + ?Sized>(
&mut self,
mem: &M,
) -> Result<Option<DescriptorChain>, QueueError>
pub fn pop_avail<M: GuestMemory + ?Sized>( &mut self, mem: &M, ) -> Result<Option<DescriptorChain>, QueueError>
Pop the next descriptor head from the available ring.
Returns Ok(None) if the driver has not made any new descriptors
available since the last call.
§Errors
QueueError for any underlying memory access failure.
Sourcepub fn push_used<M: GuestMemory + ?Sized>(
&mut self,
mem: &M,
head_index: u16,
bytes_written: u32,
) -> Result<(), QueueError>
pub fn push_used<M: GuestMemory + ?Sized>( &mut self, mem: &M, head_index: u16, bytes_written: u32, ) -> Result<(), QueueError>
Push a completed descriptor chain into the used ring.
head_index is the descriptor index returned by pop_avail;
bytes_written is the total bytes the device wrote into device-write
descriptors of the chain (zero for purely device-read chains).
§Errors
QueueError for any underlying memory access failure.