virtio_drivers::device::net

Struct VirtIONetRaw

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

Raw driver for a VirtIO network device.

This is a raw version of the VirtIONet driver. It provides non-blocking methods for transmitting and receiving raw slices, without the buffer management. For more higher-level functions such as receive buffer backing, see VirtIONet.

Implementations§

Source§

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

Source

pub fn new(transport: T) -> 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 fill_buffer_header(&self, buffer: &mut [u8]) -> Result<usize>

Fill the header of the buffer with VirtioNetHdr.

If the buffer is not large enough, it returns Error::InvalidParam.

Source

pub unsafe fn transmit_begin(&mut self, tx_buf: &[u8]) -> Result<u16>

Submits a request to transmit a buffer immediately without waiting for the transmission to complete.

It will submit request to the VirtIO net device and return a token identifying the position of the first descriptor in the chain. If there are not enough descriptors to allocate, then it returns Error::QueueFull.

The caller needs to fill the tx_buf with a header by calling fill_buffer_header before transmission. Then it calls poll_transmit with the returned token to check whether the device has finished handling the request. Once it has, the caller must call transmit_complete with the same buffer before reading the result (transmitted length).

§Safety

tx_buf is still borrowed by the underlying VirtIO net device even after this method returns. Thus, it is the caller’s responsibility to guarantee that they are not accessed before the request is completed in order to avoid data races.

Source

pub fn poll_transmit(&mut self) -> Option<u16>

Fetches the token of the next completed transmission request from the used ring and returns it, without removing it from the used ring. If there are no pending completed requests it returns [None].

Source

pub unsafe fn transmit_complete( &mut self, token: u16, tx_buf: &[u8], ) -> Result<usize>

Completes a transmission operation which was started by transmit_begin. Returns number of bytes transmitted.

§Safety

The same buffer must be passed in again as was passed to transmit_begin when it returned the token.

Source

pub unsafe fn receive_begin(&mut self, rx_buf: &mut [u8]) -> Result<u16>

Submits a request to receive a buffer immediately without waiting for the reception to complete.

It will submit request to the VirtIO net device and return a token identifying the position of the first descriptor in the chain. If there are not enough descriptors to allocate, then it returns Error::QueueFull.

The caller can then call poll_receive with the returned token to check whether the device has finished handling the request. Once it has, the caller must call receive_complete with the same buffer before reading the response.

§Safety

rx_buf is still borrowed by the underlying VirtIO net device even after this method returns. Thus, it is the caller’s responsibility to guarantee that they are not accessed before the request is completed in order to avoid data races.

Source

pub fn poll_receive(&self) -> Option<u16>

Fetches the token of the next completed reception request from the used ring and returns it, without removing it from the used ring. If there are no pending completed requests it returns [None].

Source

pub unsafe fn receive_complete( &mut self, token: u16, rx_buf: &mut [u8], ) -> Result<(usize, usize)>

Completes a transmission operation which was started by receive_begin.

After completion, the rx_buf will contain a header followed by the received packet. It returns the length of the header and the length of the packet.

§Safety

The same buffer must be passed in again as was passed to receive_begin when it returned the token.

Source

pub fn send(&mut self, tx_buf: &[u8]) -> Result

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

Source

pub fn receive_wait(&mut self, rx_buf: &mut [u8]) -> Result<(usize, usize)>

Blocks and waits for a packet to be received.

After completion, the rx_buf will contain a header followed by the received packet. It returns the length of the header and the length of the packet.

Trait Implementations§

Source§

impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> Drop for VirtIONetRaw<H, T, QUEUE_SIZE>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<H, T, const QUEUE_SIZE: usize> UnwindSafe for VirtIONetRaw<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.