Skip to main content

NetQueue

Struct NetQueue 

Source
pub struct NetQueue {
Show 16 fields pub qid: u16, pub dev_id: u64, pub ring_id: RingId, ring: Arc<SharedRing>, vas: Vec<u64>, phys: Vec<u64>, header: *mut NetQueueHeader, pub event: Arc<QueueEvent>, pub irq: AtomicU8, pub port: AtomicU64, pub features: AtomicU64, pub alive: AtomicU8, mapped: AtomicBool, mapped_base: AtomicU64, mapped_owner: AtomicU64, pending_rx: SpinLock<Option<NetFrameDesc>>,
}
Expand description

One shared RX/TX queue pair for a network device.

Fields§

§qid: u16§dev_id: u64§ring_id: RingId§ring: Arc<SharedRing>§vas: Vec<u64>

Kernel virtual address of each page, in mapping order.

§phys: Vec<u64>

Physical address of each page, in mapping order.

§header: *mut NetQueueHeader§event: Arc<QueueEvent>§irq: AtomicU8

IRQ vector bound to this queue (0xFF = polling).

§port: AtomicU64

IPC port bound to this queue (0 = none).

§features: AtomicU64

Feature mask negotiated with the device.

§alive: AtomicU8

Serialises queue teardown against the IRQ handler.

§mapped: AtomicBool

True once the region has been mapped into a userspace strate.

§mapped_base: AtomicU64

User virtual base of the mapping, 0 when unmapped.

§mapped_owner: AtomicU64

Task that owns the mapping, 0 when unmapped.

§pending_rx: SpinLock<Option<NetFrameDesc>>

Descriptor popped by a consumer whose buffer was too small. It must be returned before the next descriptor to preserve ordering.

Implementations§

Source§

impl NetQueue

Source

pub fn new( dev_id: u64, qid: u16, feature_mask: u64, mtu: u32, epoch: u32, ) -> Result<Arc<Self>, &'static str>

Allocate and initialise a queue region.

Source

pub fn header(&self) -> &NetQueueHeader

Source

pub fn header_mut_ptr(&self) -> *mut NetQueueHeader

Source

pub fn region(&self) -> &Arc<SharedRing> ⓘ

Source

pub fn try_map(&self, owner: u64) -> bool

Reserve the single userspace mapping for owner. Returns false if another live task owns it. A mapping left behind by a dead task is reclaimed (hot-restart).

Source

pub fn unmap_reservation(&self)

Release the mapping reservation after a failed map.

Source

pub fn set_mapped_base(&self, base: u64)

Record the user base of a successful mapping.

Source

pub fn take_mapped_base(&self) -> u64

Take the user base of the mapping (0 if none).

Source

pub fn phys_pages(&self) -> &[u64]

Source

pub fn is_alive(&self) -> bool

Source

pub fn shutdown(&self)

Mark the queue dead and wake any waiter. The region is released when the last Arc<NetQueue> is dropped.

Source

fn ptr_at(&self, offset: usize) -> Option<*mut u8>

Translate a byte offset in the region to its kernel VA.

Source

pub fn phys_at(&self, offset: usize) -> Option<u64>

Physical address of a byte offset in the region.

Source

pub fn rx_slot_phys(&self, slot: u32) -> Option<u64>

Physical address of an RX slot (for programming DMA).

Source

pub fn tx_slot_phys(&self, slot: u32) -> Option<u64>

Physical address of a TX slot.

Source

pub fn rx_slot_ptr(&self, slot: u32) -> Option<*mut u8>

Kernel VA of an RX slot.

Source

pub fn tx_slot_ptr(&self, slot: u32) -> Option<*mut u8>

Kernel VA of a TX slot.

Source

pub fn push_rx(&self, frame: &[u8]) -> bool

Copy a frame into an RX slot and publish it.

Called from the IRQ/poll path. Returns false if the ring or the slot pool is full.

Source

pub fn pop_rx(&self) -> Option<NetFrameDesc>

Pop one RX descriptor (stack side). A descriptor previously returned with putback_rx is served first to preserve ordering.

Source

pub fn putback_rx(&self, desc: NetFrameDesc)

Put back an RX descriptor whose consumer buffer was too small.

Source

pub fn release_rx(&self, slot: u32)

Release an RX slot after the stack copied its payload.

Source

pub fn alloc_tx(&self) -> Option<(u32, *mut u8)>

Allocate a TX slot and return its kernel VA.

Source

pub fn push_tx(&self, desc: NetFrameDesc) -> bool

Publish a TX descriptor after the stack filled the slot.

Source

pub fn pop_tx(&self) -> Option<NetFrameDesc>

Pop one TX descriptor (kernel/device side).

Source

pub fn release_tx(&self, slot: u32)

Release a transmitted TX slot.

Update the shared link state.

Source

pub fn feature_mask(&self) -> u64

Current feature mask.

Source

pub fn configure(&self, mask: u64, mtu: u32)

Negotiate features and MTU after the driver has probed the device.

Source

pub fn set_features(&self, mask: u64)

Enable features after negotiation.

Trait Implementations§

Source§

impl Drop for NetQueue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl Send for NetQueue

Source§

impl Sync for NetQueue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.