pub trait NetDriverOps<'a>: BaseDriverOps {
    // Required methods
    fn mac_address(&self) -> EthernetAddress;
    fn can_transmit(&self) -> bool;
    fn can_receive(&self) -> bool;
    fn rx_queue_size(&self) -> usize;
    fn tx_queue_size(&self) -> usize;
    fn fill_rx_buffers(
        &mut self,
        buf_pool: &'a NetBufferPool
    ) -> Result<(), DevError>;
    fn prepare_tx_buffer(
        &self,
        tx_buf: &mut NetBuffer<'_>,
        packet_len: usize
    ) -> Result<(), DevError>;
    fn recycle_rx_buffer(
        &mut self,
        rx_buf: Box<NetBuffer<'a>, Global>
    ) -> Result<(), DevError>;
    fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>;
    fn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>;
}
Available on crate feature net only.
Expand description

Operations that require a network device (NIC) driver to implement.

'a indicates the lifetime of the network buffers.

Required Methods§

source

fn mac_address(&self) -> EthernetAddress

The ethernet address of the NIC.

source

fn can_transmit(&self) -> bool

Whether can transmit packets.

source

fn can_receive(&self) -> bool

Whether can receive packets.

source

fn rx_queue_size(&self) -> usize

Size of the receive queue.

source

fn tx_queue_size(&self) -> usize

Size of the transmit queue.

source

fn fill_rx_buffers( &mut self, buf_pool: &'a NetBufferPool ) -> Result<(), DevError>

Fills the receive queue with buffers.

It should be called once when the driver is initialized.

source

fn prepare_tx_buffer( &self, tx_buf: &mut NetBuffer<'_>, packet_len: usize ) -> Result<(), DevError>

Prepares a buffer for transmitting.

e.g., fill the header of the packet.

source

fn recycle_rx_buffer( &mut self, rx_buf: Box<NetBuffer<'a>, Global> ) -> Result<(), DevError>

Gives back the rx_buf to the receive queue for later receiving.

rx_buf should be the same as the one returned by NetDriverOps::receive.

source

fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>

Transmits a packet in the buffer to the network, and blocks until the request completed.

tx_buf should be initialized by NetDriverOps::prepare_tx_buffer.

source

fn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>

Receives a packet from the network and store it in the NetBuffer, returns the buffer.

Before receiving, the driver should have already populated some buffers in the receive queue by NetDriverOps::fill_rx_buffers or NetDriverOps::recycle_rx_buffer.

If currently no incomming packets, returns an error with type DevError::Again.

Implementations on Foreign Types§

source§

impl<'a, H, T, const QS: usize> NetDriverOps<'a> for VirtIoNetDev<'a, H, T, QS>where H: Hal, T: Transport,

source§

fn mac_address(&self) -> EthernetAddress

source§

fn can_transmit(&self) -> bool

source§

fn can_receive(&self) -> bool

source§

fn rx_queue_size(&self) -> usize

source§

fn tx_queue_size(&self) -> usize

source§

fn fill_rx_buffers( &mut self, buf_pool: &'a NetBufferPool ) -> Result<(), DevError>

source§

fn prepare_tx_buffer( &self, tx_buf: &mut NetBuffer<'_>, pkt_len: usize ) -> Result<(), DevError>

source§

fn recycle_rx_buffer( &mut self, rx_buf: Box<NetBuffer<'a>, Global> ) -> Result<(), DevError>

source§

fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>

source§

fn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>

Implementors§