mirror of
https://github.com/allaunthefox/Research-Stack.git
synced 2026-07-31 03:05:21 +00:00
513 lines
20 KiB
Markdown
513 lines
20 KiB
Markdown
# Ethernet Card ASIC Repurposing Report
|
|
|
|
## Hardware Identification
|
|
|
|
**Device**: Realtek RTL8126 5GbE Controller
|
|
- **PCI ID**: 10ec:8126
|
|
- **Subsystem**: Micro-Star International Co., Ltd. [MSI] Device 1462:7e71
|
|
- **Driver**: r8169 (version 7.0.0-1-cachyos)
|
|
- **Firmware**: rtl8126a-3_0.0.5 08/30/24
|
|
- **Interface**: enp14s0
|
|
|
|
## Key Finding: ASIC Address Translation Capabilities Available
|
|
|
|
The Realtek RTL8126 is a **consumer-grade ethernet controller** with fixed-function ASICs. While it does **NOT** contain programmable CPU cores, it **DOES** have DMA engines and checksum units that perform on-the-fly address translation and mathematical operations that could potentially be repurposed.
|
|
|
|
## Hardware Capabilities
|
|
|
|
### Memory Regions
|
|
- **Region 0**: I/O ports at e000 [size=256]
|
|
- **Region 2**: Memory at f5800000 (64-bit, non-prefetchable) [size=64K]
|
|
- **Region 4**: Memory at f5810000 (64-bit, non-prefetchable) [size=16K]
|
|
|
|
### DMA Descriptor Format (from u-boot driver)
|
|
```c
|
|
struct TxDesc {
|
|
u32 status;
|
|
u32 vlan_tag;
|
|
u32 buf_addr; // Lower 32 bits of buffer address
|
|
u32 buf_Haddr; // Upper 32 bits of buffer address (for 64-bit)
|
|
};
|
|
|
|
struct RxDesc {
|
|
u32 status;
|
|
u32 vlan_tag;
|
|
u32 buf_addr; // Lower 32 bits of buffer address
|
|
u32 buf_Haddr; // Upper 32 bits of buffer address (for 64-bit)
|
|
};
|
|
```
|
|
|
|
### Offload Features (Standard Consumer NIC Features)
|
|
- ✅ RX/TX checksumming (IPv4, IPv6) - **Performs mathematical checksum calculations**
|
|
- ✅ TCP segmentation offload (TSO) - **Performs segmentation calculations**
|
|
- ✅ Generic segmentation offload (GSO)
|
|
- ✅ Generic receive offload (GRO)
|
|
- ✅ Scatter-gather I/O - **DMA address translation**
|
|
- ✅ VLAN offload (RX/TX)
|
|
- ✅ High DMA (64-bit)
|
|
- ❌ No PTP hardware clock
|
|
- ❌ No programmable packet processing
|
|
- ❌ No flow steering (ntuple filters)
|
|
- ❌ No receive hashing
|
|
- ❌ No hardware timestamping
|
|
|
|
### Ring Parameters
|
|
- RX ring size: 256
|
|
- TX ring size: 256
|
|
- No advanced features (RX push, TX push, TCP data split, etc.)
|
|
|
|
## ASIC Operations Available for Repurposing
|
|
|
|
### 1. DMA Engine Address Translation
|
|
|
|
The RTL8126 DMA engine performs **on-the-fly address translation** between:
|
|
- **CPU virtual addresses** → **Physical addresses** (via MMU)
|
|
- **Physical addresses** → **Bus addresses** (via IOMMU/host bridge)
|
|
- **Bus addresses** → **Device addresses** (DMA engine)
|
|
|
|
This translation capability is the core of what you're looking for. The DMA engine can:
|
|
- Translate 64-bit addresses to 32-bit addresses (if device limited)
|
|
- Perform scatter-gather operations with multiple address translations
|
|
- Chain descriptors for complex address translation patterns
|
|
|
|
### 2. Checksum Calculation Units
|
|
|
|
The RTL8126 has hardware checksum offload that performs:
|
|
- **IPv4 header checksums** (mathematical operation)
|
|
- **TCP/UDP checksums** (mathematical operation)
|
|
- These are fixed mathematical operations that could potentially be repurposed
|
|
|
|
### 3. TCP Segmentation Offload (TSO)
|
|
|
|
The TSO unit performs:
|
|
- **Packet segmentation calculations**
|
|
- **MSS (Maximum Segment Size) calculations**
|
|
- **TCP header adjustments**
|
|
- These involve mathematical operations on packet sizes and offsets
|
|
|
|
## Potential Repurposing Approaches
|
|
|
|
### Approach 1: DMA Engine as Address Translation Unit
|
|
|
|
**Feasibility**: **Moderate**
|
|
|
|
The DMA engine can be used for address translation, but with limitations:
|
|
- **Pros**:
|
|
- Already performs address translation between physical and bus addresses
|
|
- Can handle scatter-gather lists with multiple translations
|
|
- 64-bit address support (with high DMA capability)
|
|
|
|
- **Cons**:
|
|
- Translation is tied to packet transmission/reception
|
|
- Cannot be used independently of network activity
|
|
- Driver controls the DMA engine, not userspace directly
|
|
- Requires network packets to trigger DMA operations
|
|
|
|
**Implementation challenges**:
|
|
- Would need to inject fake network traffic to trigger DMA operations
|
|
- Cannot bypass the driver's control over DMA descriptors
|
|
- Address translation results are not exposed to userspace
|
|
|
|
### Approach 2: Checksum Unit for Mathematical Operations
|
|
|
|
**Feasibility**: **Low**
|
|
|
|
The checksum units perform specific mathematical operations:
|
|
- **Pros**:
|
|
- Hardware-accelerated checksum calculations
|
|
- Can process data at line rate
|
|
|
|
- **Cons**:
|
|
- Operations are specific to network checksums (not general-purpose)
|
|
- Cannot be controlled independently of packet processing
|
|
- Results are used internally, not exposed for general computation
|
|
|
|
**Implementation challenges**:
|
|
- Checksum operations are tightly coupled to packet processing
|
|
- No interface to feed arbitrary data for checksum calculation
|
|
- Results are not accessible outside the network stack
|
|
|
|
### Approach 3: Direct MMIO Register Access
|
|
|
|
**Feasibility**: **Low** (requires root access)
|
|
|
|
The memory-mapped I/O regions could be accessed directly:
|
|
- **Pros**:
|
|
- Direct access to hardware registers
|
|
- Potential for low-level hardware control
|
|
|
|
- **Cons**:
|
|
- Requires root access to /dev/mem
|
|
- Registers are for control, not computation
|
|
- Risk of destabilizing the system
|
|
- Documentation of register functionality is limited
|
|
|
|
**Implementation challenges**:
|
|
- Need reverse engineering of register functionality
|
|
- No public documentation for RTL8126 register-level programming
|
|
- High risk of hardware damage or system instability
|
|
|
|
## Technical Assessment
|
|
|
|
### Why ASIC Repurposing Is Challenging
|
|
|
|
1. **Fixed-Function Design**: The ASICs are designed for specific network operations, not general computation
|
|
|
|
2. **Driver Mediation**: The r8169 driver controls all ASIC operations; userspace cannot directly access them
|
|
|
|
3. **Coupled Operations**: DMA, checksum, and TSO operations are tightly coupled to packet processing
|
|
|
|
4. **No General-Purpose Interface**: There's no API to use these units for arbitrary computation
|
|
|
|
5. **Result Visibility**: Even if operations could be triggered, results are not exposed to userspace
|
|
|
|
### What Would Be Required for ASIC Repurposing
|
|
|
|
To successfully repurpose the RTL8126 ASICs for address translation:
|
|
|
|
1. **Custom Driver**: Would need to write a custom kernel driver that:
|
|
- Takes userspace requests for address translation
|
|
- Programs DMA descriptors with source/destination addresses
|
|
- Triggers DMA operations without network packets
|
|
- Returns translation results to userspace
|
|
|
|
2. **Hardware Documentation**: Would need detailed RTL8126 register documentation (not publicly available)
|
|
|
|
3. **Bypass Network Stack**: Would need to operate outside the standard network stack
|
|
|
|
4. **Root Privileges**: Would require root access for MMIO register manipulation
|
|
|
|
## Comparison with SmartNICs
|
|
|
|
### What SmartNICs Have (That This Card Lacks)
|
|
|
|
SmartNICs with programmable CPU cores are high-end server hardware:
|
|
|
|
1. **Fully-Programmable Network Processors**
|
|
- Mellanox BlueField
|
|
- Cavium LiquidIO
|
|
- Netronome Agilio-CX
|
|
|
|
2. **FPGA-based SmartNICs**
|
|
- Mellanox InnovaFlex
|
|
- Microsoft Catapult (deployed in Azure)
|
|
|
|
3. **Features Available on SmartNICs**
|
|
- Custom highly-threaded CPUs
|
|
- Hardware-accelerated processing primitives
|
|
- Programmable data plane
|
|
- Low-latency, high-bandwidth data paths between NIC and FPGA
|
|
- Direct FPGA-to-host memory DMA
|
|
- "Bump-in-the-wire" architecture for traffic interception
|
|
- **Exposed APIs for general-purpose computation**
|
|
|
|
### What This Card Has
|
|
|
|
The Realtek RTL8126 is a fixed-function ASIC device:
|
|
- No programmable processing units
|
|
- No custom CPU cores
|
|
- No FPGA or reconfigurable logic
|
|
- Standard DMA engines only (tied to network operations)
|
|
- Fixed-function offload engines (checksum, TSO, GRO)
|
|
- **No API for general-purpose computation**
|
|
|
|
## Potential Alternatives
|
|
|
|
If you need programmable address translation or computation:
|
|
|
|
1. **SmartNIC Hardware**: Acquire a SmartNIC with programmable cores (Mellanox BlueField, Netronome, etc.)
|
|
|
|
2. **DPDK**: Use Data Plane Development Kit for high-performance packet processing on host CPU with direct memory access
|
|
|
|
3. **eBPF/XDP**: Use Linux kernel's eXpress Data Path for programmable packet processing with custom address manipulation
|
|
|
|
4. **FPGA NIC**: Consider FPGA-based network cards for custom packet processing and address translation
|
|
|
|
5. **IOMMU Programming**: Use the system's IOMMU directly for address translation (requires kernel programming)
|
|
|
|
6. **GPU Acceleration**: Use GPU for parallel address translation and computation (CUDA/OpenCL)
|
|
|
|
## UDP-Based Packet Computation Approach
|
|
|
|
### Your UDP Research
|
|
|
|
Your existing UDP research (`golden_crc_udp_reassembly.py`, `msm_udp_phonon_demo.py`) demonstrates:
|
|
- **Invisible Unicode encoding** for bit-level data hiding
|
|
- **Golden ratio-based CRC** for segment validation
|
|
- **UDP segmentation** with error introduction and reassembly
|
|
- **Phonon graph reassembly** for corrupted segment recovery
|
|
|
|
### Feasibility Assessment for Packet Computation
|
|
|
|
Using UDP packets to trigger NIC ASIC operations for computation is **more feasible** than direct ASIC repurposing, but still has significant limitations:
|
|
|
|
#### Available Operations via UDP Packets
|
|
|
|
**1. Checksum Offload Computation**
|
|
- **Feasibility**: **Moderate**
|
|
- **How it works**: NIC computes 16-bit ones-complement checksums on packet data
|
|
- **Visibility**: Checksum results are written back to packet headers
|
|
- **Limitations**:
|
|
- Only computes IP-style checksums (not general-purpose math)
|
|
- Results are 16-bit only
|
|
- Must be part of valid network packet structure
|
|
- RTL8126 supports TX checksum offload but not USO (UDP Segmentation Offload)
|
|
|
|
**2. DMA Address Translation**
|
|
- **Feasibility**: **Low** for computation
|
|
- **How it works**: DMA engine translates addresses between physical and bus address spaces
|
|
- **Visibility**: Translation happens transparently; results not exposed to userspace
|
|
- **Limitations**:
|
|
- Translation is internal to DMA operation
|
|
- No way to read back translated addresses
|
|
- Only works as part of packet transmission/reception
|
|
|
|
**3. TSO/GSO Segmentation**
|
|
- **Feasibility**: **Low** on RTL8126
|
|
- **How it works**: NIC segments large packets into MTU-sized chunks
|
|
- **Visibility**: Segmentation results are the transmitted packets
|
|
- **Limitations**:
|
|
- RTL8126 does NOT support hardware UDP segmentation offload (USO)
|
|
- `tx-udp-segmentation: off [fixed]` - hardware feature not present
|
|
- Only kernel GSO available (software segmentation)
|
|
- Segmentation is packet-oriented, not computation-oriented
|
|
|
|
#### RTL8126-Specific Limitations
|
|
|
|
From `ethtool -k enp14s0`:
|
|
```
|
|
tx-udp_tnl-segmentation: off [fixed]
|
|
tx-udp_tnl-csum-segmentation: off [fixed]
|
|
tx-udp-segmentation: off [fixed] ← Hardware USO not supported
|
|
rx-udp_tunnel-port-offload: off [fixed]
|
|
rx-udp-gro-forwarding: off
|
|
```
|
|
|
|
The RTL8126 **does not support** hardware UDP segmentation offload, which limits computation encoding options.
|
|
|
|
### Potential Computation Encoding Schemes
|
|
|
|
#### Approach 1: Checksum Computation as Hash Function
|
|
|
|
**Idea**: Use checksum offload to compute hash values of data
|
|
|
|
**Implementation**:
|
|
1. Encode data to be hashed into UDP packet payload
|
|
2. Set checksum field to 0
|
|
3. Enable TX checksum offload
|
|
4. NIC computes checksum and fills it in
|
|
5. Receive packet and read checksum value
|
|
|
|
**Feasibility**: **Moderate**
|
|
- **Pros**:
|
|
- Checksum is a form of mathematical computation
|
|
- Results are readable in packet headers
|
|
- Can process data at line rate
|
|
- **Cons**:
|
|
- Only 16-bit output space (limited resolution)
|
|
- Checksum algorithm is fixed (IP-style ones-complement)
|
|
- Cannot control the algorithm
|
|
- Must maintain valid packet structure
|
|
- Loopback required (send to self or another machine)
|
|
|
|
#### Approach 2: Checksum as CRC for Data Validation
|
|
|
|
**Idea**: Extend your golden CRC research to use hardware checksums
|
|
|
|
**Implementation**:
|
|
1. Use your invisible Unicode encoding in UDP payloads
|
|
2. Let NIC compute checksums for validation
|
|
3. Read checksum validation flags on receive
|
|
|
|
**Feasibility**: **Moderate**
|
|
- **Pros**:
|
|
- Leverages your existing encoding scheme
|
|
- Hardware-accelerated validation
|
|
- Checksum validation flags are readable (CHECKSUM_UNNECESSARY, etc.)
|
|
- **Cons**:
|
|
- Validation is pass/fail, not a computational result
|
|
- Cannot extract the actual checksum value for computation
|
|
- Limited to validation use case
|
|
|
|
#### Approach 3: Scatter-Gather DMA for Address Translation
|
|
|
|
**Idea**: Use scatter-gather lists to perform address translation patterns
|
|
|
|
**Implementation**:
|
|
1. Craft scatter-gather descriptors with specific address patterns
|
|
2. Send packets using scatter-gather I/O
|
|
3. DMA engine translates addresses
|
|
4. Results are not directly readable
|
|
|
|
**Feasibility**: **Very Low**
|
|
- **Pros**:
|
|
- DMA engine does perform address translation
|
|
- **Cons**:
|
|
- Translation results are not exposed to userspace
|
|
- Cannot read back translated addresses
|
|
- Scatter-gather is for efficient data transfer, not computation
|
|
- No visibility into translation process
|
|
|
|
### Technical Challenges
|
|
|
|
**1. Loopback Requirement**
|
|
- To receive packets you send, need loopback or second machine
|
|
- Local loopback bypasses NIC hardware
|
|
- Must send to external address and receive back
|
|
|
|
**2. Checksum Algorithm Limitations**
|
|
- Fixed IP-style ones-complement checksum
|
|
- Cannot change algorithm
|
|
- 16-bit result space limits computational usefulness
|
|
- Algorithm designed for error detection, not general computation
|
|
|
|
**3. Packet Structure Constraints**
|
|
- Must maintain valid IP/UDP headers
|
|
- Checksum computed over specific ranges (csum_start to end)
|
|
- Cannot arbitrary control what gets checksummed
|
|
- Headers consume bandwidth overhead
|
|
|
|
**4. Performance Overhead**
|
|
- Each computation requires:
|
|
- Packet construction
|
|
- System call (sendto/recvfrom)
|
|
- NIC processing
|
|
- Packet reception
|
|
- Header parsing
|
|
- High overhead compared to direct computation
|
|
|
|
**5. RTL8126 Hardware Limitations**
|
|
- No UDP segmentation offload (USO)
|
|
- No advanced offload features
|
|
- Limited to basic checksum and DMA operations
|
|
|
|
### Comparison with Your Existing UDP Research
|
|
|
|
Your current approach (`golden_crc_udp_reassembly.py`):
|
|
- Uses software CRC computation (zlib.crc32)
|
|
- Golden ratio-based polynomial
|
|
- Invisible Unicode encoding
|
|
- Software-based segmentation and reassembly
|
|
|
|
**Hardware-accelerated version would**:
|
|
- Replace software CRC with NIC checksum
|
|
- Limited to 16-bit IP-style checksum (not 32-bit CRC)
|
|
- Cannot use golden ratio polynomial
|
|
- Still need software for encoding/decoding
|
|
- Limited benefit for your use case
|
|
|
|
### Conclusion on UDP Packet Computation
|
|
|
|
Using UDP packets to trigger NIC ASIC operations for computation is **theoretically possible** but **practically limited** on the RTL8126:
|
|
|
|
**What works**:
|
|
- Basic checksum computation as a hash function
|
|
- Checksum validation flags for data integrity
|
|
- DMA address translation (but results not readable)
|
|
|
|
**What doesn't work**:
|
|
- Hardware UDP segmentation offload (not supported by RTL8126)
|
|
- General-purpose mathematical operations
|
|
- Reading back DMA translation results
|
|
- Custom checksum algorithms
|
|
- High-performance computation (overhead too high)
|
|
|
|
**For your specific UDP research**:
|
|
- Your software-based CRC approach is actually **better suited** for your needs
|
|
- Hardware checksums are too limited (16-bit, fixed algorithm)
|
|
- Your golden ratio polynomial and invisible encoding require software
|
|
- The NIC's capabilities don't align with your research goals
|
|
|
|
**Recommendation**:
|
|
Continue with your software-based UDP research. The RTL8126's hardware offload capabilities don't provide significant advantages for your use case, and the limitations (16-bit checksums, fixed algorithm, no USO) make it impractical to leverage for packet computation.
|
|
|
|
## NIC Probe Layer — Metaprobe Integration
|
|
|
|
### Lean-Based Abstraction Layer
|
|
|
|
To address the RTL8126 limitations while leveraging the metaprobe stack, a formal Lean abstraction layer has been designed in `0-Core-Formalism/lean/Semantics/Semantics/NICProbe.lean`.
|
|
|
|
**Architecture:**
|
|
|
|
1. **PTOS Manifest Integration**
|
|
- `PTOSMetadata` structure captures NIC hardware state
|
|
- Tier classification: ASIC, FALLBACK, SOFTWARE
|
|
- Module identification (rtl8126, generic_nic)
|
|
- Capability tags for hardware features
|
|
|
|
2. **Software Fallbacks**
|
|
- `softwareAddressTranslation`: Virtual → Physical → Bus address translation
|
|
- `softwareChecksum`: Checksum computation fallback
|
|
- Cost-aware operation selection (hardware vs software)
|
|
|
|
3. **Bind Primitive for NIC Operations**
|
|
- `NICOperation` inductive type: addressTranslate, checksumCompute, packetSegment, dmaTransfer, capabilityProbe
|
|
- `nicBind` function using physical_bind primitive
|
|
- Cost functions in Q16_16 fixed-point
|
|
- Invariant extraction for lawful binding
|
|
|
|
4. **Capability Probing**
|
|
- `NICCapability` structure: txChecksumOffload, rxChecksumOffload, tsoSupport, usoSupport, dma64Bit, scatterGather
|
|
- `rtl8126Capabilities`: Confirmed USO=false, other features available
|
|
- Runtime capability detection and fallback selection
|
|
|
|
**Key Features:**
|
|
|
|
- **Formal Verification**: Theorems proving totality and correctness of operations
|
|
- **Hardware-Native**: All numeric operations use Q16_16 fixed-point (no Float)
|
|
- **Metaprobe Integration**: PTOS manifest structure for hardware metadata
|
|
- **Cost-Aware**: Operations track cost and select optimal hardware/software path
|
|
- **Invariant Preservation**: Bind primitive ensures lawful state transitions
|
|
|
|
**Compilation Status:**
|
|
- Lake build successful (3449 jobs)
|
|
- Build Log: [`out/build_logs/lake_build_20260429.log`](../../out/build_logs/lake_build_20260429.log)
|
|
- NICProbe.lean compiles without errors
|
|
- #eval witnesses verify expected behavior
|
|
- Theorems prove correctness properties
|
|
|
|
**Usage Pattern:**
|
|
|
|
```lean
|
|
-- Probe NIC capabilities
|
|
let state := defaultNICProbeState
|
|
let input := { operation := NICOperation.capabilityProbe, data := [], address := none }
|
|
let bindResult := nicBind input state
|
|
|
|
-- Perform address translation with software fallback
|
|
let translateInput := { operation := NICOperation.addressTranslate, data := [], address := some 0x1000 }
|
|
let translateResult := nicBind translateInput state
|
|
```
|
|
|
|
**Advantages Over Direct Hardware Access:**
|
|
|
|
1. **Formal Correctness**: Lean proofs ensure invariant preservation
|
|
2. **Hardware Abstraction**: Same interface works across different NICs
|
|
3. **Graceful Degradation**: Automatic fallback to software when hardware unavailable
|
|
4. **Cost Tracking**: Quantitative comparison of hardware vs software paths
|
|
5. **Metaprobe Integration**: PTOS manifest provides structured hardware metadata
|
|
|
|
**Limitations Addressed:**
|
|
|
|
- **No USO**: Software segmentation fallback with higher cost (5.0 vs 1.5)
|
|
- **Fixed Checksum**: Software checksum provides custom polynomial support
|
|
- **DMA Translation**: Software address translation when hardware DMA unavailable
|
|
- **Driver Mediation**: Abstraction layer works above driver level
|
|
|
|
This layer provides a formally verified, metaprobe-integrated approach to NIC ASIC abstraction that addresses the RTL8126 limitations while maintaining the project's strict adherence to Lean as source of truth.
|
|
|
|
## Overall Conclusion
|
|
|
|
The Realtek RTL8126 5GbE Controller in your system is a consumer-grade ethernet card with fixed-function ASICs. While it **does** have DMA engines that perform on-the-fly address translation and checksum units that perform mathematical operations, **repurposing these for general-purpose computation is not practical** because:
|
|
|
|
1. The ASIC operations are tightly coupled to network packet processing
|
|
2. There is no userspace API to control these operations independently
|
|
3. The driver mediates all access to the hardware
|
|
4. Results are not exposed outside the network stack
|
|
5. Hardware documentation is not publicly available
|
|
6. The RTL8126 lacks advanced offload features (USO, advanced checksums)
|
|
7. Checksum computation is limited to 16-bit IP-style algorithm
|
|
|
|
**UDP-based packet computation** is marginally more feasible than direct ASIC repurposing, but still limited to basic checksum hashing with significant overhead. For your UDP research, the software-based approach remains superior.
|
|
|
|
To achieve programmable address translation or computation, you would need specialized SmartNIC hardware with exposed programming interfaces, or alternative approaches like DPDK/eBPF on the host CPU, or GPU acceleration.
|