morpheus_network::driver::traits

Trait NetworkDriver

Source
pub trait NetworkDriver {
    // Required methods
    fn mac_address(&self) -> MacAddress;
    fn can_transmit(&self) -> bool;
    fn can_receive(&self) -> bool;
    fn transmit(&mut self, frame: &[u8]) -> Result<(), TxError>;
    fn receive(&mut self, buffer: &mut [u8]) -> Result<Option<usize>, RxError>;
    fn refill_rx_queue(&mut self);
    fn collect_tx_completions(&mut self);

    // Provided method
    fn link_up(&self) -> bool { ... }
}
Expand description

Core network device interface.

All NIC drivers must implement this trait. Higher layers (smoltcp adapter, state machines) use this interface.

Required Methods§

Source

fn mac_address(&self) -> MacAddress

Get MAC address.

Source

fn can_transmit(&self) -> bool

Check if device can accept a TX frame.

Returns true if transmit() will succeed.

Source

fn can_receive(&self) -> bool

Check if device has a received frame ready.

Returns true if receive() will return Ok(Some(_)).

Source

fn transmit(&mut self, frame: &[u8]) -> Result<(), TxError>

Transmit an Ethernet frame.

§Arguments
  • frame: Complete Ethernet frame (no VirtIO header)
§Returns
  • Ok(()): Frame queued (fire-and-forget)
  • Err(TxError::QueueFull): No space, try again later
§Contract
  • MUST return immediately (no completion wait)
Source

fn receive(&mut self, buffer: &mut [u8]) -> Result<Option<usize>, RxError>

Receive an Ethernet frame.

§Arguments
  • buffer: Buffer to copy frame into
§Returns
  • Ok(Some(len)): Frame received, len bytes copied
  • Ok(None): No frame available (normal)
  • Err(RxError): Receive error
§Contract
  • MUST return immediately (no blocking)
Source

fn refill_rx_queue(&mut self)

Refill RX queue with available buffers.

Called in main loop Phase 1.

Source

fn collect_tx_completions(&mut self)

Collect TX completions.

Called in main loop Phase 5.

Provided Methods§

Get link status.

Implementors§