Expand description
§FXMAC Ethernet Driver
A no_std Rust driver for the FXMAC Ethernet controller found on the PhytiumPi (Phytium Pi) board.
This driver supports DMA-based packet transmission and reception, providing a foundation for
network communication in embedded and bare-metal environments.
§Features
- DMA Support: Efficient packet transmission and reception using DMA buffer descriptors.
- PHY Management: Support for PHY initialization, auto-negotiation, and manual speed configuration.
- Interrupt Handling: Built-in interrupt handlers for TX/RX completion and error conditions.
- Multiple PHY Interfaces: Support for SGMII, RGMII, RMII, XGMII, and other interface modes.
- Configurable: Supports jumbo frames, multicast filtering, and various MAC options.
§Target Platform
This driver is designed for the aarch64 architecture, specifically targeting the PhytiumPi board with the Motorcomm YT8521 PHY.
§Quick Start
To use this driver, you need to implement the KernelFunc trait to provide the necessary
kernel functions for address translation and DMA memory allocation.
ⓘ
use fxmac_rs::{KernelFunc, xmac_init, FXmacLwipPortTx, FXmacRecvHandler};
// Implement the KernelFunc trait for your platform
pub struct FXmacDriver;
#[crate_interface::impl_interface]
impl KernelFunc for FXmacDriver {
fn virt_to_phys(addr: usize) -> usize {
// Your implementation
addr
}
fn phys_to_virt(addr: usize) -> usize {
// Your implementation
addr
}
fn dma_alloc_coherent(pages: usize) -> (usize, usize) {
// Your implementation: returns (virtual_addr, physical_addr)
unimplemented!()
}
fn dma_free_coherent(vaddr: usize, pages: usize) {
// Your implementation
}
fn dma_request_irq(irq: usize, handler: fn()) {
// Your implementation
}
}
// Initialize the driver
let hwaddr: [u8; 6] = [0x55, 0x44, 0x33, 0x22, 0x11, 0x00];
let fxmac = xmac_init(&hwaddr);
// Send packets
let mut tx_vec = Vec::new();
tx_vec.push(packet_data.to_vec());
FXmacLwipPortTx(fxmac, tx_vec);
// Receive packets
if let Some(recv_packets) = FXmacRecvHandler(fxmac) {
for packet in recv_packets {
// Process received packet
}
}§Module Structure
- [
fxmac]: Core MAC controller functionality and configuration. - [
fxmac_dma]: DMA buffer descriptor management and packet handling. - [
fxmac_intr]: Interrupt handling and callback management. - [
fxmac_phy]: PHY initialization and management functions.
§Safety and Environment
- This crate targets
no_stdand assumes the platform provides DMA-coherent memory and interrupt routing. - Most APIs interact with memory-mapped registers and should be used with care in the correct execution context.
§Feature Flags
debug: Enable logging via thelogcrate. Without this feature, logging macros become no-ops.
Structs§
- FXmac
- Main FXMAC Ethernet controller instance.
- FXmac
BdRing - FXmac
Config - Hardware configuration for the FXMAC controller.
- FXmac
Lwip Port - FXmac
Netif Buffer - FXmac
Queue - Hardware queue structure for TX/RX operations.
- macb_
dma_ desc - DMA address width 64 bits: word 0: 32 bit address of Data Buffer word 1: control / status, 32-bit word 2: upper 32 bit address of Data Buffer word 3: unused
Enums§
- FXmac
PhyInterface - PHY interface mode definitions.
Constants§
- BD_
ALIGNMENT - Byte alignment of BDs
- FT_
COMPONENT_ IS_ READY - Component is initialized and ready.
- FT_
COMPONENT_ IS_ STARTED - Component is started.
- FXMA
C0_ HOTPLUG_ IRQ_ NUM - FXMAC0 hotplug IRQ number.
- FXMA
C0_ PCLK - FXMAC0 peripheral clock frequency in Hz.
- FXMAC_
BD_ ADDR_ HI_ OFFSET - word 2/addr of BDs
- FXMAC_
BD_ ADDR_ OFFSET - Transmit buffer descriptor status words offset word 0/addr of BDs
- FXMAC_
BD_ NUM_ WORDS - FXMAC_
BD_ STAT_ OFFSET - word 1/status of BDs, 4 bytes
- FXMAC_
DMABD_ MINIMUM_ ALIGNMENT - FXMAC_
HANDLER_ DMARECV - Handler type for DMA receive (RX) interrupts.
- FXMAC_
HANDLER_ DMASEND - Handler type for DMA send (TX) interrupts.
- FXMAC_
HANDLER_ ERROR - Handler type for error interrupts.
- FXMAC_
HANDLER_ LINKCHANGE - Handler type for link status change interrupts.
- FXMAC_
HANDLER_ RESTART - Handler type for TX descriptor queue restart.
- FXMAC_
LINKDOWN - Link status: down.
- FXMAC_
LINKUP - Link status: up.
- FXMAC_
LWIP_ PORT_ CONFIG_ CLOSE_ FCS_ CHECK - FXMAC_
LWIP_ PORT_ CONFIG_ COPY_ ALL_ FRAMES - FXMAC_
LWIP_ PORT_ CONFIG_ JUMBO - FXMAC_
LWIP_ PORT_ CONFIG_ MULTICAST_ ADDRESS_ FILITER - FXMAC_
LWIP_ PORT_ CONFIG_ UNICAST_ ADDRESS_ FILITER - FXMAC_
NEGOTIATING - Link status: negotiating.
- FXMAC_
PHY_ FULL_ DUPLEX - FXMAC_
PHY_ HALF_ DUPLEX - FXMAC_
PHY_ SPEED_ 10G - FXMAC_
PHY_ SPEED_ 10M - FXMAC_
PHY_ SPEED_ 100M - FXMAC_
PHY_ SPEED_ 1000M - FXMAC_
QUEUE_ MAX_ NUM - Maximum number of hardware queues supported.
- FXMAC_
RECV - receive direction
- FXMAC_
RECV_ MAX_ COUNT - FXMAC_
RXBUF_ ADD_ MASK - Mask for address
- FXMAC_
RXBUF_ NEW_ MASK - RX Used bit
- FXMAC_
RXBUF_ WRAP_ MASK - RX Wrap bit, last BD
- FXMAC_
SEND - send direction
- FXMAC_
TXBUF_ USED_ MASK - TX Used bit
- FXMAC_
TXBUF_ WRAP_ MASK - TX Wrap bit, last descriptor
- FXMAX_
MAX_ HARDWARE_ ADDRESS_ LENGTH - FXMAX_
RX_ BDSPACE_ LENGTH - FXMAX_
RX_ PBUFS_ LENGTH - FXMAX_
TX_ BDSPACE_ LENGTH - FXMAX_
TX_ PBUFS_ LENGTH - PAGE_
SIZE - Memory page size in bytes.
- PQ_
QUEUE_ SIZE - ULON
G64_ HI_ MASK - Mask for upper 32 bits of 64-bit address.
- ULON
G64_ LO_ MASK - Mask for lower 32 bits of 64-bit address.
Traits§
- Kernel
Func - Kernel function interface required by the FXMAC Ethernet driver.
Functions§
- FXmac
Alloc DmaPbufs - FXmac
BdRing Alloc - 在BD list中预留待设置的BD
- FXmac
BdRing Clone - 将给定的BD, 克隆到list中的每个BD上
- FXmac
BdRing Create - Create the RxBD ring 创建收包的环形缓冲区
- FXmac
BdRing Free - FXmacBdRingFree, Frees a set of BDs that had been previously retrieved with
- FXmac
BdRing From HwRx - FXmac
BdRing From HwTx - @name: FXmacBdRingFromHwTx @msg: Returns a set of BD(s) that have been processed by hardware. The returned BDs may be examined to determine the outcome of the DMA transaction(s). Once the BDs have been examined, the user must call FXmacBdRingFree() in the same order which they were retrieved here.
- FXmac
BdRing ToHw - 将一组BD排队到之前由FXmacBdRingAlloc分配了的硬件上
- FXmac
GetMac Address - Reads a MAC address from the specified address slot.
- FXmac
Handle DmaTx Error - Handle DMA interrupt error
- FXmac
Handle TxErrors - FXmac
Init Dma - FXmac
Intr Handler - Main interrupt handler for FXMAC controller.
- FXmac
Link Change - FXmac
Lwip Port Tx - Transmits packets through the lwIP-compatible interface.
- FXmac
PhyInit - Initializes the PHY for the FXMAC controller.
- FXmac
PhyRead - Reads data from a PHY register via MDIO.
- FXmac
PhyWrite - Writes data to a PHY register via MDIO.
- FXmac
Process Sent Bds - FXmacProcessSentBds, 释放发送队列q参数
- FXmac
Recv Handler - Handles received packets from the DMA queue.
- FXmac
Send Handler - FXmac
SetMac Address - Sets the MAC address for the specified address slot.
- FXmac
SetQueue Ptr - Sets the start address of the transmit/receive buffer queue.
- FXmac
Sgsend - Transmits packets using scatter-gather DMA.
- FXmac
Start - Starts the Ethernet controller.
- FXmac
Stop - Gracefully stops the Ethernet MAC.
- FXmac_
Delete Hash - Delete 48-bit MAC addresses in hash table. The device must be stopped before calling this function.
- FXmac_
SetHash - Sets a 48-bit MAC address entry in the hash table.
- Reset
Dma - Reset Tx and Rx DMA pointers after FXmacStop
- Setup
RxBds - ethernetif_
input_ to_ recv_ packets - fxmac_
bd_ read - fxmac_
bd_ write - phy_
autoneg_ status - phy_
link_ detect - @name: phy_link_detect @msg: 获取当前link status @note: @param {FXmac} fxmac_p @param {u32} phy_addr @return {} 1 is link up , 0 is link down
- read_
reg - Reads a memory-mapped register via a physical address.
- write_
reg - Writes a value to a memory-mapped register via a physical address.
- xmac_
init - Initializes the FXMAC Ethernet controller.
- xmac_
intr_ handler - Top-level interrupt handler for FXMAC.