virtio_drivers::device::net

Struct VirtIONet

Source
pub struct VirtIONet<H: Hal, T: Transport, const QUEUE_SIZE: usize> { /* private fields */ }
Expand description

Driver for a VirtIO network device.

Unlike VirtIONetRaw, it uses RxBuffers for transmission and reception rather than the raw slices. On initialization, it pre-allocates all receive buffers and puts them all in the receive queue.

The virtio network device is a virtual ethernet card.

It has enhanced rapidly and demonstrates clearly how support for new features are added to an existing device. Empty buffers are placed in one virtqueue for receiving packets, and outgoing packets are enqueued into another for transmission in that order. A third command queue is used to control advanced filtering features.

Implementations§

Source§

impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> VirtIONet<H, T, QUEUE_SIZE>

Source

pub fn new(transport: T, buf_len: usize) -> Result<Self>

Create a new VirtIO-Net driver.

Source

pub fn ack_interrupt(&mut self) -> bool

Acknowledge interrupt.

Source

pub fn disable_interrupts(&mut self)

Disable interrupts.

Source

pub fn enable_interrupts(&mut self)

Enable interrupts.

Source

pub fn mac_address(&self) -> [u8; 6]

Get MAC address.

Source

pub fn can_send(&self) -> bool

Whether can send packet.

Source

pub fn can_recv(&self) -> bool

Whether can receive packet.

Source

pub fn receive(&mut self) -> Result<RxBuffer>

Receives a RxBuffer from network. If currently no data, returns an error with type Error::NotReady.

It will try to pop a buffer that completed data reception in the NIC queue.

Source

pub fn recycle_rx_buffer(&mut self, rx_buf: RxBuffer) -> Result

Gives back the ownership of rx_buf, and recycles it for next use.

It will add the buffer back to the NIC queue.

Source

pub fn new_tx_buffer(&self, buf_len: usize) -> TxBuffer

Allocate a new buffer for transmitting.

Source

pub fn send(&mut self, tx_buf: TxBuffer) -> Result

Sends a TxBuffer to the network, and blocks until the request completed.

Auto Trait Implementations§

§

impl<H, T, const QUEUE_SIZE: usize> Freeze for VirtIONet<H, T, QUEUE_SIZE>
where T: Freeze,

§

impl<H, T, const QUEUE_SIZE: usize> RefUnwindSafe for VirtIONet<H, T, QUEUE_SIZE>
where T: RefUnwindSafe, H: RefUnwindSafe,

§

impl<H, T, const QUEUE_SIZE: usize> Send for VirtIONet<H, T, QUEUE_SIZE>
where T: Send,

§

impl<H, T, const QUEUE_SIZE: usize> Sync for VirtIONet<H, T, QUEUE_SIZE>
where T: Sync,

§

impl<H, T, const QUEUE_SIZE: usize> Unpin for VirtIONet<H, T, QUEUE_SIZE>
where T: Unpin, H: Unpin,

§

impl<H, T, const QUEUE_SIZE: usize> UnwindSafe for VirtIONet<H, T, QUEUE_SIZE>
where T: UnwindSafe, H: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.