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>
impl<H: Hal, T: Transport, const QUEUE_SIZE: usize> VirtIONetRaw<H, T, QUEUE_SIZE>
Sourcepub fn ack_interrupt(&mut self) -> bool
pub fn ack_interrupt(&mut self) -> bool
Acknowledge interrupt.
Sourcepub fn disable_interrupts(&mut self)
pub fn disable_interrupts(&mut self)
Disable interrupts.
Sourcepub fn enable_interrupts(&mut self)
pub fn enable_interrupts(&mut self)
Enable interrupts.
Sourcepub fn mac_address(&self) -> [u8; 6]
pub fn mac_address(&self) -> [u8; 6]
Get MAC address.
Sourcepub fn fill_buffer_header(&self, buffer: &mut [u8]) -> Result<usize>
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
.
Sourcepub unsafe fn transmit_begin(&mut self, tx_buf: &[u8]) -> Result<u16>
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.
Sourcepub fn poll_transmit(&mut self) -> Option<u16>
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
].
Sourcepub unsafe fn transmit_complete(
&mut self,
token: u16,
tx_buf: &[u8],
) -> Result<usize>
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.
Sourcepub unsafe fn receive_begin(&mut self, rx_buf: &mut [u8]) -> Result<u16>
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.
Sourcepub fn poll_receive(&self) -> Option<u16>
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
].
Sourcepub unsafe fn receive_complete(
&mut self,
token: u16,
rx_buf: &mut [u8],
) -> Result<(usize, usize)>
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.
Sourcepub fn send(&mut self, tx_buf: &[u8]) -> Result
pub fn send(&mut self, tx_buf: &[u8]) -> Result
Sends a packet to the network, and blocks until the request completed.
Sourcepub fn receive_wait(&mut self, rx_buf: &mut [u8]) -> Result<(usize, usize)>
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.