Trait EthernetAdapterDatapath

Source
pub trait EthernetAdapterDatapath<'a> {
    // Required methods
    fn set_client(&self, client: &'a dyn EthernetAdapterDatapathClient);
    fn enable_receive(&self);
    fn disable_receive(&self);
    fn transmit_frame(
        &self,
        frame_buffer: &'static mut [u8],
        len: u16,
        transmission_identifier: usize,
    ) -> Result<(), (ErrorCode, &'static mut [u8])>;
}
Expand description

Ethernet adapter datapath HIL

Required Methods§

Source

fn set_client(&self, client: &'a dyn EthernetAdapterDatapathClient)

Set the Ethernet adapter client for this peripheral.

Source

fn enable_receive(&self)

Enable reception of Ethernet frames.

Ethernet adapters must not invoke any EthernetAdapterDatapathClient::received_frame client methods before this function is called, and not after EthernetAdapterDatapath::disable_receive is called.

Source

fn disable_receive(&self)

Disable reception of Ethernet frames.

Ethernet adapters must not invoke any EthernetAdapterDatapathClient::received_frame client methods after this function is called, until a subsequent call to EthernetAdapterDatapath::enable_receive.

Source

fn transmit_frame( &self, frame_buffer: &'static mut [u8], len: u16, transmission_identifier: usize, ) -> Result<(), (ErrorCode, &'static mut [u8])>

Transmit an Ethernet frame / enqueue a frame for transmission.

Arguments:

  1. frame: buffer holding the raw Ethernet frame to be transmitted. The frame must be located at offset 0 in this buffer, including the Ethernet header with source and destination address set, but excluding the FCS trailer. The buffer may be larger than the Ethernet frame. The frame length is set in the len argument. The EthernetAdapterDatapath implementation will return this buffer with its original length in a call to EthernetAdapterDatapathClient::transmit_frame_done, or in the return value of this function.

  2. len: the length of the raw frame, including the Ethernet header and excluding the FCS trailer.

    This value imposes a maximum frame size of u16::MAX bytes. While Ethernet II frames do not contain an explicit length parameter (instead using the 16-bit length parameter reserved in IEEE 802.3 as an Ethertype parameter), the largest MTUs for Ethernet frames (including various Jumbo-frame options) are all below 65535 bytes and hence fit into a 16-bit integer value.

  3. transmission_identifier: an opaque identifier of this transmission operation. This value will be identical to the one supplied in the subsequent call to EthernetAdapterDatapathClient::transmit_frame_done, which will be issued once this frame has been transmitted or an asynchronous error occurred during transmission.

Return value: This function will return with Ok(()) when a frame has successfully been enqueued for transmission. In this case, the currently registered client will receive a call to EthernetAdapterDatapathClient::transmit_frame_done containing this function call’s transmission_identifier. In case of a synchronous error when enqueueing a frame for transmission, the following errors may be returned alongside the passed frame_buffer:

  • ErrorCode::FAIL: an internal error occurred. The frame may or may not have been sent, and the Ethernet MAC may or may not be able to send further frames.

  • ErrorCode::BUSY: the Ethernet MAC is currently busy processing another operation and could not enqueue this frame. A client may try again later.

  • ErrorCode::OFF: the Ethernet MAC is not enabled or initialized and cannot send this frame.

  • ErrorCode::NODEVICE: the Ethernet MAC does not have an active link and cannot send this frame.

When this function returns with a synchronous error, it will not also raise a callback for this transmit operation.

Ethernet adapters may or may not support multiple outstanding / pending transmissions. When they do not, they will return Err(ErrorCode::BUSY) when trying to transmit a frame while another transmission is pending or in progress.

Implementors§

impl<'a, const MAX_TX_SLOTS: usize, R: LiteXSoCRegisterConfiguration> EthernetAdapterDatapath<'a> for LiteEth<'a, MAX_TX_SLOTS, R>

impl<'a> EthernetAdapterDatapath<'a> for VirtIONet<'a>