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.

Five questions this page answers
Question
1How many of the smallest frames can arrive in a second at 100 Mb/s?
2Why must a receive pool be sized for two floods, not one?
3Why do chained small buffers need less SRAM than one size for every frame?
4Why must the PHY leave reset before the MAC?
5The 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

New words on this page
WordMeaning
Network nodeA device on a network that sends and receives data, here a small chip on Ethernet.
Ethernet frameThe unit of data on Ethernet: addresses, a type, the data and a check sequence. It is 64 to 1518 bytes long.
Preamble and SFDEight bytes sent before every frame, so that the receiver can lock on. SFD is short for start frame delimiter.
Interpacket gapThe quiet time between two frames on the wire: 96 bit times, or 12 bytes.
Line rateThe rate of the wire itself: here 100 million bits a second, or 12.5 million bytes.
Ethernet MACThe block that builds and checks frames and moves their bytes to and from memory. MAC is short for media access control.
MIIMedia independent interface: the wires between the MAC and the PHY. At 100 Mb/s it moves four bits on each clock.
DescriptorA 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 ringA ring of descriptors that the MAC fills in order and the core empties in order.
Blackout of the coreThe longest time the core leaves the receive ring alone. Frames that arrive meanwhile must have buffers ready.
Interrupt coalescingOne request for several frames: after a set count, or a set time after the first waiting frame.
Address filterHardware in the MAC that drops frames meant for other nodes before they reach memory.

One Picture: The Board, Filled for a Node

The Board of the Network NodeStep through the board. Here the hard columns are memory and the clocks that arrive from outside the chip.
  • File
  • Processor
  • Memory
  • Clock / reset
  • Control / FSM
  • Power
  • Debug
  • Report
The Board of the Network NodeStep through the board. Here the hard columns are memory and the clocks that arrive from outside the chip. component Requirements 100 Mb/s Ethernetboth ways; no loss in a2 ms burst at linerate; 2000 frames asecond to process component Block diagram core, Ethernet MACwith an address filterand DMA, PHY on theboard through MII,SRAM, timer component Memory map ap_soc map; MACregisters at1000_8000; SRAMof 64 KiB for rings,buffers and stack component Clocks and resets MII clocks of 25 MHzfrom the PHY; coreand bus 50 MHz;release the PHY, thenthe MAC component Interrupts receive requestscoalesced: at most9900 a second, not148,809; transmitdone; link change component Power modes run; idle with the linkup; a sleep that keepsthe MAC filter andthe PHY powered component Debug counters: received,dropped for nobuffer, bad checksequence; a loopbackmode; JTAG component Risks a flood longer than 2ms drops frames; thePHY clock at reset;who owns eachdescriptor what to buildwhat to placewhat to timewhat to countwhen to wakewhat to seewhat is thinchange and run again
  1. component Requirements100 Mb/s Ethernet both ways; no loss in a 2 ms burst at line rate; 2000 frames a second to process
    • what to build → Block diagram
  2. component Block diagramcore, Ethernet MAC with an address filter and DMA, PHY on the board through MII, SRAM, timer
    • what to place → Memory map
  3. component Memory mapap_soc map; MAC registers at 1000_8000; SRAM of 64 KiB for rings, buffers and stack
    • what to time → Clocks and resets
  4. component Clocks and resetsMII clocks of 25 MHz from the PHY; core and bus 50 MHz; release the PHY, then the MAC
    • what to count → Interrupts
  5. component Interruptsreceive requests coalesced: at most 9900 a second, not 148,809; transmit done; link change
    • when to wake → Power modes
  6. component Power modesrun; idle with the link up; a sleep that keeps the MAC filter and the PHY powered
    • what to see → Debug
  7. component Debugcounters: received, dropped for no buffer, bad check sequence; a loopback mode; JTAG
    • what is thin → Risks
  8. component Risksa flood longer than 2 ms drops frames; the PHY clock at reset; who owns each descriptor
    • change and run again → Requirements
  1. 1. Requirements

    Bursts come at full line rate. The core processes far fewer frames. The buffers bridge the two.

  2. 2. Block diagram

    The MAC moves every byte by DMA. The filter keeps frames for other nodes out of memory.

  3. 3. Memory map

    Descriptors and buffers live in SRAM. 50,800 bytes fit in the 64 KiB of ap_soc.

  4. 4. Clocks and resets

    Three clock domains. The MAC side of the MII has no clock until the PHY is out of reset.

  5. 5. Interrupts

    One request for 16 frames, or 100 µs after the first waiting one, whichever comes first.

  6. 6. Power modes

    To wake on a frame, the parts that see the frame must stay awake.

  7. 7. Debug

    A dropped frame must leave a count. Loopback tests the MAC without a cable.

  8. 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.

Two frames on the wire, by hand
FrameBytes on the wireTimeFrames a second
Smallest, 64 bytes8 + 64 + 12 = 8484 × 80 ns = 6720 ns148,809
Largest, 1518 bytes8 + 1518 + 12 = 15381538 × 80 ns = 123,040 ns8127

Now the blackout of 2 ms. Count the frames that start inside it, for each flood.

Two floods in 2 ms, by hand
FloodFramesOne 1536-byte buffer eachChained buffers of 128 bytes
Smallest frames2,000,000 ÷ 6720, rounded up: 298298 × 1536 = 457,728 bytes298 frames × 1 = 298 buffers
Largest frames2,000,000 ÷ 123,040, rounded up: 1717 × 1536 = 26,112 bytes17 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

  1. Rule 1: Count the wire, not the frame.

    Add the preamble and the gap. A 64-byte frame takes 84 bytes of wire time.

  2. Rule 2: Size for both floods.

    Small frames set the number of descriptors. Large frames set the bytes. A pool must cover both.

  3. Rule 3: Chain small buffers.

    A frame takes as many small buffers as it needs. Neither flood wastes much room.

  4. 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.

  5. 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.

  6. 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.

Printed by the lab on Icarus: the sizing sheet of the network node.
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 B

Rule 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

Columns 3 to 5: map, clocks, resets and interrupts
EntryChoiceReason
MAC registers1000_8000, 4 KiBThe first page of the expansion reserve. The rings and buffers live in SRAM.
SRAM8000_0000, 64 KiB50,800 bytes, with 22 percent spare.
MII receive and transmit clocks25 MHz, from the PHYThe MAC side of the MII runs on them: two domains of their own.
Core and bus50 MHzThe DMA load is 12 percent of it.
Crossingsa FIFO with two clocks in each directionBytes cross from the MII clocks into the bus clock, as in S5.3.
Reset orderPHY first; wait for its clocks; then the MAC side of the MIIA synchronizer on a stopped clock never releases its reset.
Source 7receive, coalescedAt most 9900 a second in a flood of small frames.
Source 8transmit done and link changeRare; one source with a cause register.
Columns 6 to 8: power, debug and risks
EntryChoiceReason
Run and idleidle keeps the link up and the core asleep between requestsThe PHY keeps the link; the core wakes on a request.
Sleep with wake on a frameMAC filter and PHY stay powered; the rest is offOnly the parts that see a frame can recognise one. This is common practice, not checked.
Countersreceived, dropped for no buffer, bad check sequenceThe hook: a drop counter would have shown the flood at once.
Loopbackthe MAC sends its own frames back to itselfBring-up without a cable or a PHY.
Risk: long floodmore than 2 ms of small framesFrames are dropped and counted. Test with a flood on the bench.
Risk: descriptor ownershipthe core and the MAC must never both own oneStress the rings with random frame sizes and a slow core.

Why It Is Built This Way

ChoiceThe alternativeWhat it buys, and what it costs
Chained buffers of 128 bytesOne 1536-byte buffer per descriptor38,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 msBuffers for any floodA small SRAM. The cost: under a long flood, frames are lost, as Ethernet allows.
An address filter in the MACSoftware checks every addressFrames for other nodes never reach memory or the core.
Coalescing at 16 frames or 100 µsOne request per frame9900 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 page1 port, 100 Mb/s
A switch chipdozens of ports, 100 Gb/s each

This section looks ahead, to network chips that run at 10 Gb/s and more.

  1. Many queues

    Fast controllers keep several receive rings and spread frames over several cores by a hash of their addresses.

  2. The arithmetic scales

    At 10 Gb/s the smallest frames come a hundred times faster. The same sums decide descriptors, bytes and requests.

  3. 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
NameMeaning
min_frame, max_frameThe time on the wire of the smallest and the largest frame, with preamble and gap.
min_frames, max_frames, lineFrames each second when every frame is smallest or largest; bytes each second on the wire.
dma_words, loadWords of 4 bytes that the DMA moves each second, both ways at line rate; their share of the bus clock.
blackoutFrames that start during the longest time the core leaves the ring alone.
one_size, chainedThe receive pool with one 1536-byte buffer per frame, or with small buffers chained per frame.
per_frame, coalescedReceive requests each second with one per frame, or with coalescing, counted over 10 ms.
rx, tx, descriptors, stackBytes of SRAM for the receive pool, four transmit buffers, 8-byte descriptors and the stack.
RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: 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 B

Check Yourself

Predict the outputIn this run the blackout is 1000 µs in place of 2000 µs. What is the last line? Its form is: memory rx=.. tx=6144 descriptors=.. stack=4096 total=.. -> sram=.. B
// The sizing sheet of a small network node on 100 Mb/s Ethernet. Test code: arithmetic, and runs of
// frames arriving back to back. Every number is an exercise value except the frame sizes, the preamble
// and the gap (IEEE 802.3, clauses 3.1.1 and 4.4.2) and the MII clock (clause 22).
module tb;
  // ---- Requirements and the standard ---------------------------------------------------------------------
  parameter int MBPS = 100, MIN_FRAME = 64, MAX_FRAME = 1518;       // line rate; frame sizes in bytes
  localparam int PREAMBLE = 8, GAP = 12;          // bytes on the wire before a frame and after it
  localparam int MII_HZ = 25000000;               // the MII clock at 100 Mb/s: four bits in each cycle
  // ---- Choices of this design ---------------------------------------------------------------------------
  parameter int BLACKOUT_US = 1000;     // the longest time the core leaves the receive ring alone
  parameter int BUF_B = 1536, SMALL_B = 128;   // one buffer that holds any frame; or small buffers chained
  parameter int COALESCE_N = 16, COALESCE_US = 100;   // interrupt after N frames, or US after the first waiting one
  parameter int BUS_HZ = 50000000, TX_BUFS = 4, DESC_B = 8, STACK = 4096;

  function automatic int ceil_div(input longint a, input longint b); return (a + b - 1) / b; endfunction
  function automatic int pow2_at_least(input int n); int s = 1; while (s < n) s = s * 2; return s; endfunction
  function automatic int wire_ns(input int frame); return longint'(PREAMBLE + frame + GAP) * 8 * 1000 / MBPS; endfunction

  // Frames of one size arrive back to back. Count the frames that start inside the blackout, and the
  // interrupts that coalescing raises in ten milliseconds.
  task automatic burst(input int frame, output int frames, output int irq_per_s);
    int t, n, waiting, first, irqs;
    frames = 0;
    for (t = 0; t < BLACKOUT_US * 1000; t += wire_ns(frame)) frames++;
    // Ten milliseconds of arrivals, in steps of 80 ns: a frame is complete at the end of its last byte.
    n = 0; waiting = 0; first = 0; irqs = 0;
    for (t = 0; t < 10000000; t += 80) begin
      if (t >= (n + 1) * wire_ns(frame) - GAP * 8 * 1000 / MBPS) begin n++; if (waiting == 0) first = t; waiting++; end
      if (waiting > 0 && (waiting >= COALESCE_N || t - first >= COALESCE_US * 1000)) begin irqs++; waiting = 0; end
    end
    irq_per_s = irqs * 100;
  endtask

  initial begin
    int min_ns, max_ns, min_rate, max_rate, line, words, load, nmin, nmax, imin, imax, big_pool, chain_min, chain_max, chain, mem;
    min_ns = wire_ns(MIN_FRAME); max_ns = wire_ns(MAX_FRAME);
    min_rate = 1000000000 / min_ns; max_rate = 1000000000 / max_ns;
    $display("wire      min_frame=%0d ns  max_frame=%0d ns  mii_clock=%0d Hz", min_ns, max_ns, MII_HZ);
    $display("rate      min_frames=%0d/s  max_frames=%0d/s  line=%0d B/s", min_rate, max_rate, MBPS * 1000000 / 8);
    // The bus: the DMA moves every byte of both directions in words of 4 bytes.
    line = MBPS * 1000000 / 8;
    words = 2 * line / 4;
    load = longint'(words) * 100 / BUS_HZ;
    $display("bus       dma_words=%0d/s (both ways)  bus_clock=%0d Hz  load=%0d%%", words, BUS_HZ, load);
    burst(MIN_FRAME, nmin, imin);
    burst(MAX_FRAME, nmax, imax);
    $display("blackout  %0d us: min frames=%0d  max frames=%0d", BLACKOUT_US, nmin, nmax);
    big_pool = nmin * BUF_B;
    chain_min = nmin * ceil_div(MIN_FRAME, SMALL_B);
    chain_max = nmax * ceil_div(MAX_FRAME, SMALL_B);
    chain = chain_min > chain_max ? chain_min : chain_max;
    $display("pool      one_size: %0d x %0d = %0d B   chained %0d B: min=%0d max=%0d -> %0d buffers = %0d B", nmin, BUF_B, big_pool,
      SMALL_B, chain_min, chain_max, chain, chain * SMALL_B);
    $display("irq       per_frame=%0d/s  coalesced: min frames=%0d/s  max frames=%0d/s", min_rate, imin, imax);
    mem = chain * SMALL_B + TX_BUFS * BUF_B + (chain + TX_BUFS) * DESC_B + STACK;
    $display("memory    rx=%0d tx=%0d descriptors=%0d stack=%0d total=%0d -> sram=%0d B", chain * SMALL_B, TX_BUFS * BUF_B,
      (chain + TX_BUFS) * DESC_B, STACK, mem, pow2_at_least(mem));
  end
endmodule
ConceptHow many of the smallest frames can arrive in a second at 100 Mb/s?
ConceptWhy must the receive pool be sized for two floods?
ConceptWhy do chained buffers of 128 bytes need less SRAM?
ConceptWhy must the PHY leave reset before the MAC?

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.

Practice

Report a problem with this page