Worked System: A Small Network Node
A small chip on 100 Mb/s Ethernet cannot process every frame the wire can carry. It must hold a burst, drop the rest and count what it dropped. This page sizes it on the review board.
You Will Be Able To
- Work out frames a second and bytes a second for the smallest and largest Ethernet frames.
- Size a receive pool for both floods, and say why small chained buffers beat one size.
- Place the clock domains and the reset order that a PHY on the board imposes.
- Lesson
- S11.12
- Time
- 30 min
- Runs on
- Your browser
- Check
- 5 questions
The node works on the bench. On the factory network, a flood of tiny frames arrives, and the node stops answering for a second.
Most of its SRAM is still free. What ran out?
Before You Start
You need Design Reviews: "Design This SoC" and the two worked systems before this one.
You need DMA and High-Speed I/O Subsystems: a PHY, a controller and the path to memory.
It helps to have read Reset Domain Crossing: a reset released on a clock that is not running does nothing.
| Question | |
|---|---|
| 1 | How many of the smallest frames can arrive in a second at 100 Mb/s? |
| 2 | Why must a receive pool be sized for two floods, not one? |
| 3 | Why do chained small buffers need less SRAM than one size for every frame? |
| 4 | Why must the PHY leave reset before the MAC? |
| 5 | The blackout is 1 ms. What does the lab print last? |
The Idea: The Wire Is Faster Than the Core
A network node is a small chip on a network: a sensor gateway, a controller in a factory. Here it speaks Ethernet at 100 Mb/s.
The first idea is line-rate arithmetic. Small frames give the most frames in a second. Large frames give the most bytes. The design must survive both.
The second idea is buffers for both floods. Each frame needs a record that points to its buffer, and its bytes need room. Small frames use up records; large ones use up bytes.
The third idea is that events and clocks come from outside. Frames arrive whenever the network sends them. Even the clocks of the interface come from the PHY on the board.
New Words
| Word | Meaning |
|---|---|
| Network node | A device on a network that sends and receives data, here a small chip on Ethernet. |
| Ethernet frame | The unit of data on Ethernet: addresses, a type, the data and a check sequence. It is 64 to 1518 bytes long. |
| Preamble and SFD | Eight bytes sent before every frame, so that the receiver can lock on. SFD is short for start frame delimiter. |
| Interpacket gap | The quiet time between two frames on the wire: 96 bit times, or 12 bytes. |
| Line rate | The rate of the wire itself: here 100 million bits a second, or 12.5 million bytes. |
| Ethernet MAC | The block that builds and checks frames and moves their bytes to and from memory. MAC is short for media access control. |
| MII | Media independent interface: the wires between the MAC and the PHY. At 100 Mb/s it moves four bits on each clock. |
| Descriptor | A small record in memory with a buffer's address and length. It also says who owns the buffer now: the core or the MAC. |
| Receive ring | A ring of descriptors that the MAC fills in order and the core empties in order. |
| Blackout of the core | The longest time the core leaves the receive ring alone. Frames that arrive meanwhile must have buffers ready. |
| Interrupt coalescing | One request for several frames: after a set count, or a set time after the first waiting frame. |
| Address filter | Hardware in the MAC that drops frames meant for other nodes before they reach memory. |
One Picture: The Board, Filled for a Node
- File
- Processor
- Memory
- Clock / reset
- Control / FSM
- Power
- Debug
- Report
- 1. Requirements
Bursts come at full line rate. The core processes far fewer frames. The buffers bridge the two.
- 2. Block diagram
The MAC moves every byte by DMA. The filter keeps frames for other nodes out of memory.
- 3. Memory map
Descriptors and buffers live in SRAM. 50,800 bytes fit in the 64 KiB of ap_soc.
- 4. Clocks and resets
Three clock domains. The MAC side of the MII has no clock until the PHY is out of reset.
- 5. Interrupts
One request for 16 frames, or 100 µs after the first waiting one, whichever comes first.
- 6. Power modes
To wake on a frame, the parts that see the frame must stay awake.
- 7. Debug
A dropped frame must leave a count. Loopback tests the MAC without a cable.
- 8. Risks
Each is listed with a test: a flood on the bench, a reset with the PHY held, a stress of the rings.
Read the diagram as text
- Requirements: 100 Mb/s Ethernet both ways; no loss in a 2 ms burst at line rate; 2000 frames a second to process
- Block diagram: core, Ethernet MAC with an address filter and DMA, PHY on the board through MII, SRAM, timer
- Memory map: ap_soc map; MAC registers at 1000_8000; SRAM of 64 KiB for rings, buffers and stack
- Clocks and resets: MII clocks of 25 MHz from the PHY; core and bus 50 MHz; release the PHY, then the MAC
- Interrupts: receive requests coalesced: at most 9900 a second, not 148,809; transmit done; link change
- Power modes: run; idle with the link up; a sleep that keeps the MAC filter and the PHY powered
- Debug: counters: received, dropped for no buffer, bad check sequence; a loopback mode; JTAG
- Risks: a flood longer than 2 ms drops frames; the PHY clock at reset; who owns each descriptor
- Requirements → Block diagram: what to build
- Block diagram → Memory map: what to place
- Memory map → Clocks and resets: what to time
- Clocks and resets → Interrupts: what to count
- Interrupts → Power modes: when to wake
- Power modes → Debug: what to see
- Debug → Risks: what is thin
- Risks → Requirements: change and run again
The eight columns of S11.4, filled for a network node. Its buffers come from two floods, not from one stream.
The Smallest Example, Worked by Hand
No simulator yet. On the wire, each frame comes with 8 bytes in front and a gap of 12 bytes after it. At 100 Mb/s, one byte takes 80 ns.
| Frame | Bytes on the wire | Time | Frames a second |
|---|---|---|---|
| Smallest, 64 bytes | 8 + 64 + 12 = 84 | 84 × 80 ns = 6720 ns | 148,809 |
| Largest, 1518 bytes | 8 + 1518 + 12 = 1538 | 1538 × 80 ns = 123,040 ns | 8127 |
Now the blackout of 2 ms. Count the frames that start inside it, for each flood.
| Flood | Frames | One 1536-byte buffer each | Chained buffers of 128 bytes |
|---|---|---|---|
| Smallest frames | 2,000,000 ÷ 6720, rounded up: 298 | 298 × 1536 = 457,728 bytes | 298 frames × 1 = 298 buffers |
| Largest frames | 2,000,000 ÷ 123,040, rounded up: 17 | 17 × 1536 = 26,112 bytes | 17 frames × 12 = 204 buffers |
One size for every frame must cover the first row: 457,728 bytes, seven times the SRAM. Chained buffers need the larger count of the last column: 298 buffers of 128 bytes, or 38,144 bytes.
The Rules
Rule 1: Count the wire, not the frame.
Add the preamble and the gap. A 64-byte frame takes 84 bytes of wire time.
Rule 2: Size for both floods.
Small frames set the number of descriptors. Large frames set the bytes. A pool must cover both.
Rule 3: Chain small buffers.
A frame takes as many small buffers as it needs. Neither flood wastes much room.
Rule 4: Absorb a burst, drop and count the rest.
No small core keeps up with 148,809 frames a second. Buffers hold the burst; a counter records every drop.
Rule 5: Coalesce requests, and know the cost.
One request for many frames saves the core, and adds up to the timeout to the latency of a frame.
Rule 6: A clock from outside sets the reset order.
The MII clocks come from the PHY. Release the PHY, wait for its clocks, then release the MAC side of the MII.
Sources for These Rules
Eight bytes of preamble and SFD, frames of 64 to 1518 bytes: IEEE Std 802.3-2022, clause 3.1.1. The gap of 96 bit times: clause 4.4.2, Table 4-2. MII clocks of 25 MHz at 100 Mb/s, driven by the PHY: clause 22.2.2.
A driver hands the network controller a descriptor with a buffer's address and length. DMA moves the frame, and an interrupt reports it. Source: Patterson and Hennessy, Computer Organization and Design, ARM edition, section 6.9 (online), pages 553.e4 and 553.e5. The same pages warn that buffers must be ready before resources run out.
A reset released on a clock that is not running: Reset Domain Crossing. Chained buffers, coalescing, address filters and the drop counter are common practice, not checked against a source.
The blackout, the buffer sizes, the coalescing settings and the processing rate are exercise values.
Now Run It: The Sizing Sheet
The lab at the end of this page is the sizing sheet of the node. Its blackout and irq rows come from runs of frames arriving back to back.
wire min_frame=6720 ns max_frame=123040 ns mii_clock=25000000 Hz
rate min_frames=148809/s max_frames=8127/s line=12500000 B/s
bus dma_words=6250000/s (both ways) bus_clock=50000000 Hz load=12%
blackout 2000 us: min frames=298 max frames=17
pool one_size: 298 x 1536 = 457728 B chained 128 B: min=298 max=204 -> 298 buffers = 38144 B
irq per_frame=148809/s coalesced: min frames=9900/s max frames=8000/s
memory rx=38144 tx=6144 descriptors=2416 stack=4096 total=50800 -> sram=65536 BRule 1, in the first two rows: 6720 ns or 123,040 ns on the wire. That is 148,809 or 8127 frames a second. The MII clock is 25 MHz.
The bus row. At line rate both ways, the DMA moves 6,250,000 words a second. That is 12 percent of a 50 MHz bus: not the problem.
Rule 2, in the blackout and pool rows. One size for every frame would need 457,728 bytes. Chained buffers of 128 bytes need 38,144.
Rule 5, in the irq row. With one request for every frame, the core would see 148,809 requests a second. Coalescing cuts that to 9900.
Look at why. At 100 µs, a flood of small frames brings only about 15 frames. So the timeout fires before the count of 16 is reached.
For large frames, coalescing hardly helps: 8000 a second, about one for each frame. A frame of 123 µs outlasts the timeout of 100 µs.
The memory row. Pool, transmit buffers, descriptors and stack come to 50,800 bytes. The 64 KiB of ap_soc holds them.
This lab leaves things out. No frame is built, no MAC or PHY is modelled, and no software runs. Frames are times on a line, counted by a loop.
The Rest of the Board
| Entry | Choice | Reason |
|---|---|---|
| MAC registers | 1000_8000, 4 KiB | The first page of the expansion reserve. The rings and buffers live in SRAM. |
| SRAM | 8000_0000, 64 KiB | 50,800 bytes, with 22 percent spare. |
| MII receive and transmit clocks | 25 MHz, from the PHY | The MAC side of the MII runs on them: two domains of their own. |
| Core and bus | 50 MHz | The DMA load is 12 percent of it. |
| Crossings | a FIFO with two clocks in each direction | Bytes cross from the MII clocks into the bus clock, as in S5.3. |
| Reset order | PHY first; wait for its clocks; then the MAC side of the MII | A synchronizer on a stopped clock never releases its reset. |
| Source 7 | receive, coalesced | At most 9900 a second in a flood of small frames. |
| Source 8 | transmit done and link change | Rare; one source with a cause register. |
| Entry | Choice | Reason |
|---|---|---|
| Run and idle | idle keeps the link up and the core asleep between requests | The PHY keeps the link; the core wakes on a request. |
| Sleep with wake on a frame | MAC filter and PHY stay powered; the rest is off | Only the parts that see a frame can recognise one. This is common practice, not checked. |
| Counters | received, dropped for no buffer, bad check sequence | The hook: a drop counter would have shown the flood at once. |
| Loopback | the MAC sends its own frames back to itself | Bring-up without a cable or a PHY. |
| Risk: long flood | more than 2 ms of small frames | Frames are dropped and counted. Test with a flood on the bench. |
| Risk: descriptor ownership | the core and the MAC must never both own one | Stress the rings with random frame sizes and a slow core. |
Why It Is Built This Way
| Choice | The alternative | What it buys, and what it costs |
|---|---|---|
| Chained buffers of 128 bytes | One 1536-byte buffer per descriptor | 38,144 bytes in place of 457,728. The cost: a frame may span 12 buffers, and software must follow the chain. |
| Drop and count beyond 2 ms | Buffers for any flood | A small SRAM. The cost: under a long flood, frames are lost, as Ethernet allows. |
| An address filter in the MAC | Software checks every address | Frames for other nodes never reach memory or the core. |
| Coalescing at 16 frames or 100 µs | One request per frame | 9900 requests in place of 148,809. The cost: up to 100 µs more latency for a lone frame. |
The Trap: A Pool Sized in Bytes Only
This is the hook. The receive pool was sized for large frames: 17 buffers of 1536 bytes, plus some spare. It had plenty of bytes.
A flood of small frames needs 298 descriptors in 2 ms. The ring ran out of descriptors while most of its bytes sat empty. Rule 2 explains it.
The second trap is the reset order. The MAC was released with the core, before the PHY. Its MII side never left reset, because its clock had not started.
The third trap is a timeout that fires first. The designer expected one request per 16 frames, and counted 148,809 ÷ 16. The timeout fired after about 15.
At Scale
This section looks ahead, to network chips that run at 10 Gb/s and more.
Many queues
Fast controllers keep several receive rings and spread frames over several cores by a hash of their addresses.
The arithmetic scales
At 10 Gb/s the smallest frames come a hundred times faster. The same sums decide descriptors, bytes and requests.
Memory moves closer
Large chips write frames into a cache instead of DRAM, so the core finds them quickly.
Try It
Run the lab. Find the two floods in the blackout row, and the buffers they need in the pool row.
Set SMALL_B to 256, then to 64. Which flood decides the pool each time?
Set COALESCE_US to 50. Which line of the irq row changes most?
Names Printed by the Lab
| Name | Meaning |
|---|---|
| min_frame, max_frame | The time on the wire of the smallest and the largest frame, with preamble and gap. |
| min_frames, max_frames, line | Frames each second when every frame is smallest or largest; bytes each second on the wire. |
| dma_words, load | Words of 4 bytes that the DMA moves each second, both ways at line rate; their share of the bus clock. |
| blackout | Frames that start during the longest time the core leaves the ring alone. |
| one_size, chained | The receive pool with one 1536-byte buffer per frame, or with small buffers chained per frame. |
| per_frame, coalesced | Receive requests each second with one per frame, or with coalescing, counted over 10 ms. |
| rx, tx, descriptors, stack | Bytes of SRAM for the receive pool, four transmit buffers, 8-byte descriptors and the stack. |
wire min_frame=6720 ns max_frame=123040 ns mii_clock=25000000 Hz rate min_frames=148809/s max_frames=8127/s line=12500000 B/s bus dma_words=6250000/s (both ways) bus_clock=50000000 Hz load=12% blackout 2000 us: min frames=298 max frames=17 pool one_size: 298 x 1536 = 457728 B chained 128 B: min=298 max=204 -> 298 buffers = 38144 B irq per_frame=148809/s coalesced: min frames=9900/s max frames=8000/s memory rx=38144 tx=6144 descriptors=2416 stack=4096 total=50800 -> sram=65536 BCheck Yourself
Common Mistakes
Wrong Divide the line rate by the frame size alone.
The preamble and the gap also take wire time.
Fix Use 8 + frame + 12 bytes for each frame.
Wrong Size the receive pool in bytes only.
A flood of small frames runs out of descriptors first.
Fix Size descriptors for small frames and bytes for large frames.
Wrong Release the MAC with the rest of the chip.
Its MII side runs on a clock that the PHY has not started.
Fix Release the PHY, wait for its clocks, then release the MAC side.
Remember
- On the wire, every frame carries 8 bytes in front and a 12-byte gap after it.
- Small frames set the descriptors; large frames set the bytes. Size for both floods.
- Chained small buffers cover both floods with little waste. Beyond the burst, drop and count.
- The PHY drives the MII clocks, so it leaves reset first.