Skip to main content

E1000Nic

Struct E1000Nic 

Source
pub struct E1000Nic {
    pub(crate) mmio: u64,
    pub(crate) rx: RxRing<LegacyRxDesc>,
    pub(crate) rx_bufs: [DmaRegion; 128],
    pub(crate) rx_ring_phys: u64,
    pub(crate) tx: TxRing<LegacyTxDesc>,
    pub(crate) tx_bufs: [DmaRegion; 128],
    pub(crate) tx_ring_phys: u64,
    pub(crate) mac: [u8; 6],
    pub(crate) link_up: bool,
    pub(crate) stats: E1000Stats,
    pub(crate) tx_since_last_reclaim: u64,
    pub(crate) last_tdh: usize,
}

Fields§

§mmio: u64§rx: RxRing<LegacyRxDesc>§rx_bufs: [DmaRegion; 128]§rx_ring_phys: u64§tx: TxRing<LegacyTxDesc>§tx_bufs: [DmaRegion; 128]§tx_ring_phys: u64§mac: [u8; 6]§link_up: bool§stats: E1000Stats§tx_since_last_reclaim: u64§last_tdh: usize

Last known TDH value for watchdog stall detection.

Implementations§

Source§

impl E1000Nic

Source

pub fn init(mmio_base: u64, alloc: &dyn DmaAllocator) -> Result<Self, NetError>

Source

pub fn mac_address(&self) -> [u8; 6]

Source

pub fn stats(&self) -> &E1000Stats

Source

pub(crate) fn recycle_rx_desc(&mut self, idx: usize)

Recycle an RX descriptor: clear status, restore buffer address, bump tail.

Source

pub fn receive(&mut self, buf: &mut [u8]) -> Result<usize, NetError>

Source

pub fn transmit(&mut self, buf: &[u8]) -> Result<(), NetError>

Source

pub(crate) fn reclaim_completed_tx_buffers(&mut self)

Reclaim TX descriptors that the hardware has completed (DD bit set). No per-packet DMA free is needed because the buffer pool is pre-allocated; we only reset the descriptor for reuse.

Source

pub fn is_transmit_complete(&self) -> bool

Non-blocking: check if the last submitted TX has completed.

Source

pub fn wait_for_transmit(&self)

Blocking spin until the last TX completes.

Source

pub fn tx_is_done(&self, idx: usize) -> bool

Source

pub fn handle_interrupt(&mut self) -> u32

Process a hardware interrupt. Returns the raw ICR value so the kernel adapter can decide what to do (e.g. wake a receive task).

Source

pub fn watchdog_tick(&mut self, alloc: &dyn DmaAllocator) -> bool

Watchdog check: called periodically (e.g. from timer IRQ) to detect and recover from a stalled link. Returns true if a reset was performed.

Stall detection logic:

  • If tx_since_last_reclaim exceeds WATCHDOG_TX_THRESHOLD the software has been submitting without any reclaim happening.
  • If TDH (hardware head) == last_tdh → the hardware has not advanced → stall → reset.
  • If TDH advanced → update last_tdh and reset counter (progress).
  • If TDH == tail (ring empty) → normal idle → reset counter.
Source

pub(crate) fn reinit_hardware(&mut self, _alloc: &dyn DmaAllocator)

Re-initialise hardware without tearing down the DMA rings. Used by the watchdog to recover from a stuck state.

Source

pub(crate) unsafe fn read_mac(base: u64) -> Result<[u8; 6], NetError>

Source

pub(crate) unsafe fn eeprom_read(base: u64, addr: u8) -> Result<u16, NetError>

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.