Capstone: Verifying a MAC
Put the module together: one UVM bench, one plan, and five faulty receive MACs that each fall to a named check.
You Will Be Able To
- Draw the testbench map of a MAC: sequence, driver, monitor, scoreboard and coverage.
- Turn the receive rules of the module into a plan of checks, stimulus and coverage bins.
- Explain what a reference model is and why each kind of mismatch gets its own report ID.
- Use a coverage report to find the frame that exposes a hidden fault.
- Lesson
- P11.47
- Time
- 45 min
- Runs on
- Verilator with UVM
- Check
- 6 questions
Six receive MACs look the same from outside. One is correct. A bench has to tell which, and say what is wrong with the others.
| MAC | What it gets wrong | Basic sequence | After closing coverage |
|---|---|---|---|
| correct | nothing | no report | no report |
| A | drops frames for the groups on its list | RX_MISSING on frame 4 | caught already |
| B | takes a frame of 63 octets | RX_UNEXPECTED on frame 7 | caught already |
| C | ignores RX_ER | RX_STATUS on frame 12 | caught already |
| D | hands over the pad | RX_DATA on frame 8 | caught already |
| E | checks the FCS before the size | no report | RX_STATUS on frame 16 |
Bench runs: one UVM bench on six receive MACs. Each report ID names the check that failed. MAC E passes until a coverage hole is closed.
The Testbench Map
- Sequence
- Driver
- DUT
- Monitor
- Scoreboard
- Neutral
- Transaction / TLM
- Data
- Analysis
- Stimulus
A sequence builds line_frame items. The driver passes each one to the interface.
- Pins
A small model in the interface turns a frame into preamble, SFD and nibbles on the MII.
- Observation
A second model rebuilds the frame from the pins and notes the MAC's answer. The monitor publishes both as one item.
- Checking
The scoreboard predicts the answer and compares. Coverage counts which kinds of frame have been seen.
Read the diagram as text
- Sequence: which frames, in what order
- Sequencer and driver: hands over line_frame items
- Interface: driver model: preamble, SFD, nibbles
- The MAC: design under test
- Interface: monitor model: rebuilds the frame, waits for the answer
- Monitor: publishes mac_rx_item
- Scoreboard: reference model and compare
- Coverage: bins of the plan
- Sequence → Sequencer and driver
- Sequencer and driver → Interface: driver model
- Interface: driver model → The MAC: MII
- The MAC → Interface: monitor model: indication
- Interface: monitor model → Monitor
- Monitor → Scoreboard
- Monitor → Coverage
One agent on the line side. The driver and the monitor never talk to each other: the monitor trusts only the pins.
The bench is a UVM environment, as in the UVM track. Only the items are new: a line_frame going in and a mac_rx_item coming out.
The line side is an MII (P11.13): four bits a clock, low nibble first, with RX_DV and RX_ER.
The client side is a model. The MAC gives one indication for a frame, as a one-clock event, like the MA_DATA.indication of P11.7. A real core streams the octets over a bus.
The Verification Plan
A plan is a table. Each row names a feature, the check that guards it, the frames that provoke it and the bin that proves they ran.
| Feature | Lesson | Check | Stimulus | Coverage |
|---|---|---|---|---|
| Fragments | P11.8 | no indication | 63 octets with a good FCS | size.fragment, cross.fragment_with_good_fcs |
| Address filter | P11.4 | indication or none | station, broadcast, groups on and off the list, one neighbour per address bit | to.* |
| Size limit | P11.8, P11.9 | status | 1,518 and 1,519 octets; tagged 1,522 and 1,523 | size.at_limit, size.over_limit, cross.tag_at_1522 |
| FCS, extra nibble, RX_ER | P11.5, P11.8, P11.13 | status | one flipped bit; an extra nibble with and without it; RX_ER | damage.*, both extra-nibble crosses |
| Order of the checks | P11.8 | status, or none | two things wrong in one frame | cross.over_limit_and_bad_fcs, cross.other_station_and_bad_fcs |
| Length and pad | P11.2, P11.8 | status and octets | lengths on both sides of 46 and of 1,500 | type.*, cross.short_length_and_pad, cross.length_and_wrong_size |
| MAC Control | P11.10 | no indication | PAUSE and one other opcode | type.mac_control, cross.control_other_opcode |
| Data | P11.7 | every octet | long frames with random data | size.middle, size.at_limit |
| Transmit: pad, FCS, gap, pause timer | P11.2, P11.5, P11.6, P11.10 | a second agent | not in this bench | none |
The plan for the receive side. This bench MAC only receives, so the last row is a plan row and nothing more.
This bench follows the receive procedure of IEEE Std 802.3-2022, 4.2.9. It drops excess bits before checking the FCS. Clause 3.4 instead lists non-octet frames as invalid; the bench follows the procedure, as discussed in P11.8.
Every row points back to a lesson. A capstone bench adds nothing new to the rules: it makes them meet.
The interesting rows are the ones where two rules meet. A frame can be too long and damaged. Which status wins is the order of P11.8.
The Agent: Driver and Monitor
A sequence calls make() to build a frame: header, data and FCS. Then it may damage it: flip a bit, add a nibble, raise RX_ER.
The driver passes frames to the interface. Its model sends the gap, seven octets of preamble, the SFD and the octets.
The monitor side works from the pins alone. It hunts for the SFD, packs nibbles into octets and waits three clocks for the MAC's answer.
| Field of mac_rx_item | Meaning |
|---|---|
| oct | the whole octets, from the destination address to the FCS |
| extra_nibble | one nibble was left over after the last whole octet |
| rx_er | RX_ER was high at some point during the frame |
| indicated | the MAC reported the frame to its client |
| status | receiveOK, frameTooLong, frameCheckError, alignmentError or lengthError |
| data | the octets the MAC handed over |
One item for each frame: what was on the line, then what the MAC did. The first three fields are facts; the last three are the answer to check.
The monitor decides nothing. It does not check the FCS or the address. That keeps it reusable, and keeps every verdict in one place.
The Scoreboard and Its Reference Model
A reference model is a second description of the design. It is written from the standard, not from the RTL.
For a receive MAC it answers three questions for each frame: is there an indication, with which status, and with which octets?
| The model says | The MAC did | Report ID |
|---|---|---|
| no indication | an indication | RX_UNEXPECTED |
| an indication | nothing | RX_MISSING |
| a status | another status | RX_STATUS |
| receiveOK and these octets | receiveOK and other octets | RX_DATA |
Four ways to differ, one uvm_error ID each. At most one report for a frame: the first row that applies.
The ID matters. RX_UNEXPECTED sends you to the fragment check, the filter or the control sublayer. RX_DATA sends you to the pad logic or the buffer.
The page example uses a stub MAC that knows one rule, so its model is one line. The model of a full MAC is the job of P11.47.1.
Coverage Closes the Plan
A passing run proves little if the right frames never ran. Coverage counts them.
The model looks only at the line: size, destination, Length/Type and damage. It never looks at the MAC's answer.
| Group | Bins | After the basic sequence |
|---|---|---|
| size | fragment, 64, middle, at_limit, over_limit | all hit |
| to | station, broadcast, listed_group, pause_address, other_group, other_station | all hit |
| type | short_length, length, 1501_to_1535, type, tag, mac_control | holes: 1501_to_1535, tag |
| damage | bad_fcs, extra_nibble, rx_er | all hit |
| cross | nine pairs, such as over_limit_and_bad_fcs | holes: 5 of 9 |
Bench run: 22 of 29 bins after fifteen frames. Every single bin of size and damage is hit; most of the holes are pairs.
After the basic sequence the report lists 7 holes. Most are crosses: two properties in one frame.
The closing sequence sends six more frames, one for each hole or pair of holes. Coverage then reads 29 of 29.
Five Faulty MACs
| MAC | Frame | What was sent | The MAC said | The model said | Report |
|---|---|---|---|---|---|
| A | 4 | 118 octets to a group on the list | no indication | receiveOK | RX_MISSING |
| B | 7 | 63 octets, FCS good | receiveOK | no indication | RX_UNEXPECTED |
| C | 12 | RX_ER during one octet, FCS good | receiveOK | frameCheckError | RX_STATUS |
| D | 8 | length 20, data field of 46 | receiveOK, 60 octets | receiveOK, 34 octets | RX_DATA |
| E | 16 | 1519 octets with a flipped bit | frameCheckError | frameTooLong | RX_STATUS |
Bench runs. Each MAC is caught on the first frame it gets wrong, by the check that its fault belongs to.
MACs A to D fall to the basic sequence. Each fault sits in one row of the plan, and one frame of that row is enough.
MAC E passes all fifteen frames. It has both checks; only their order is wrong. Frame 14 is too long with a good FCS, and frame 10 is damaged at a legal size.
The coverage report names the missing frame: cross.over_limit_and_bad_fcs. Frame 16 fills that bin, and E answers frameCheckError where the model expects frameTooLong.
That is the working loop of verification: run, read the holes, add stimulus, run again.
Try It
The file eth_env.svh holds the agent: interface, items, driver, monitor, coverage and environment. The program adds a stub MAC, a scoreboard for it and two sequences.
The stub reports every frame of 64 octets or more as good. Read the log: frame 5 is for another station and frame 10 has a flipped bit, yet both come back receiveOK.
The scoreboard stays silent, because its model is the stub's own rule. A scoreboard is only as good as its model.
Now break the stub: change MIN = 64 to MIN = 63. Frame 7 gets an indication, and the run ends with one RX_UNEXPECTED error.
Then start mac_closing_seq after the basic one, and wait for 21 frames. The holes close.
frame 1: 64 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> receiveOK, 60 octets frame 2: 318 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> receiveOK, 314 octets frame 3: 64 octets, DA ff-ff-ff-ff-ff-ff, Length/Type 0806 -> receiveOK, 60 octets frame 4: 118 octets, DA 01-00-5e-00-00-01, Length/Type 0800 -> receiveOK, 114 octets frame 5: 64 octets, DA 02-00-00-00-00-77, Length/Type 0800 -> receiveOK, 60 octets frame 6: 64 octets, DA 01-00-5e-00-00-77, Length/Type 0800 -> receiveOK, 60 octets frame 7: 63 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> no indication frame 8: 64 octets, DA 02-00-00-00-00-01, Length/Type 0014 -> receiveOK, 60 octets frame 9: 119 octets, DA 02-00-00-00-00-01, Length/Type 0064 -> receiveOK, 115 octets frame 10: 98 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> receiveOK, 94 octets frame 11: 98 octets, DA 02-00-00-00-00-01, Length/Type 0800, extra nibble -> receiveOK, 94 octets frame 12: 98 octets, DA 02-00-00-00-00-01, Length/Type 0800, RX_ER -> receiveOK, 94 octets frame 13: 1518 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> receiveOK, 1514 octets frame 14: 1519 octets, DA 02-00-00-00-00-01, Length/Type 0800 -> receiveOK, 1515 octets frame 15: 64 octets, DA 01-80-c2-00-00-01, Length/Type 8808 -> receiveOK, 60 octets scoreboard: 15 frames, 0 reports coverage: 22 of 29 bins holes: type.1501_to_1535, type.tag, cross.over_limit_and_bad_fcs, cross.bad_fcs_and_extra_nibble, cross.other_station_and_bad_fcs, cross.control_other_opcode, cross.tag_at_1522 UVM_ERROR : 0Read included file: eth_env.svh
// eth_env.svh: the frame agent of the capstone (P11.47). A bench model, not a product: the line side is an MII
// (four bits a clock, low nibble first, P11.13) and the client side is the MA_DATA.indication primitive of
// P11.7 as a one-clock event.
typedef enum bit [2:0] { RECEIVE_OK = 0, FRAME_TOO_LONG = 2, FRAME_CHECK_ERROR = 3, ALIGNMENT_ERROR = 4, LENGTH_ERROR = 5 } mac_status_e;
localparam bit [47:0] MAC_PAUSE_DA = 48'h0180c2000001;
// The FCS of oct[0 .. len-1] (P11.5). The first FCS octet on the wire is bits 7:0.
function automatic bit [31:0] eth_fcs(input bit [7:0] oct [$], input int len);
bit [31:0] c = 32'hffffffff;
for (int i = 0; i < len; i++) begin
c ^= {24'h0, oct[i]};
repeat (8) c = c[0] ? (c >> 1) ^ 32'hedb88320 : c >> 1;
end
return ~c;
endfunction
// What this MAC is set up to receive.
class mac_cfg extends uvm_object;
`uvm_object_utils(mac_cfg)
bit [47:0] station; // its own address
bit [47:0] group [2]; // the two group addresses on its list
function new(string name = "mac_cfg"); super.new(name); endfunction
endclass
// One frame for the line driver: the octets from the destination address to the FCS, and what happens to them.
class line_frame extends uvm_sequence_item;
`uvm_object_utils(line_frame)
bit [7:0] oct [$];
bit extra_nibble; // one more nibble follows the last octet
int er_octet = -1; // RX_ER is high during this octet (-1: never)
int gap = 12; // idle octet times before the preamble (4 or more)
function new(string name = "line_frame"); super.new(name); endfunction
// Header, n_data random data octets, then the FCS. No pad is added: n_data is what goes on the wire.
function void make(bit [47:0] da, bit [47:0] sa, bit [15:0] lt, int n_data);
oct.delete();
for (int i = 5; i >= 0; i--) oct.push_back(da[8*i +: 8]);
for (int i = 5; i >= 0; i--) oct.push_back(sa[8*i +: 8]);
oct.push_back(lt[15:8]); oct.push_back(lt[7:0]);
repeat (n_data) oct.push_back(8'($urandom));
seal();
endfunction
// Append the FCS of everything so far.
function void seal();
bit [31:0] f = eth_fcs(oct, oct.size());
for (int i = 0; i < 4; i++) oct.push_back(f[8*i +: 8]);
endfunction
// Replace the last four octets by the FCS of the ones before them.
function void reseal();
repeat (4) void'(oct.pop_back());
seal();
endfunction
endclass
// What the interface's models share with the classes. The octets live in this object, not in the interface:
// this simulator re-checks every interface signal a class can reach, and large arrays there made each clock slow.
virtual class mac_listener;
pure virtual function void frame_seen(); // a frame and the MAC's answer are complete
endclass
class mac_store;
line_frame todo [$]; // frames waiting for the line, oldest first
bit [7:0] oct [0:2303]; // the frame the monitor rebuilt
bit [7:0] ind [0:2047]; // the octets of the MAC's last indication
bit [7:0] data [0:2047]; // the monitor's copy of them
mac_listener listener;
endclass
// tick changes once in every MII clock period. One simulator event a clock keeps a UVM run short, so every
// block here runs on any change of tick. A real MII has RX_CLK, sampled on its rising edge (P11.13).
interface mac_if (input logic tick);
mac_store store = new;
// PHY to MAC
logic rx_dv = 0, rx_er = 0;
logic [3:0] rxd = 0;
// MAC to client: one clock of ind_valid for each frame the MAC reports; the octets are in store.ind
logic ind_valid = 0;
logic [2:0] ind_status = 0;
logic [11:0] ind_len = 0; // octets handed over (0 unless the status is receiveOK)
// Bus functional model, driver side: take the next frame of store.todo and send its gap, seven preamble
// octets, the SFD, and the octets low nibble first.
line_frame cur;
int d_state = 0, d_i = 0; // 0 idle, 1 gap, 2 preamble, 3 octets, 4 extra nibble, 5 end
bit d_high = 0;
always @(tick) begin
case (d_state)
0: if (store.todo.size() != 0) begin cur = store.todo.pop_front(); d_i = 2 * cur.gap; d_state = 1; end
1: begin d_i--; if (d_i <= 0) begin d_i = 0; d_state = 2; end end
2: begin
rx_dv <= 1; rx_er <= 0; rxd <= (d_i == 15) ? 4'hd : 4'h5;
d_i++;
if (d_i == 16) begin d_i = 0; d_high = 0; d_state = (cur.oct.size() > 0) ? 3 : (cur.extra_nibble ? 4 : 5); end
end
3: begin
rx_er <= (d_i == cur.er_octet);
rxd <= d_high ? cur.oct[d_i][7:4] : cur.oct[d_i][3:0];
if (d_high) begin d_i++; if (d_i == cur.oct.size()) d_state = cur.extra_nibble ? 4 : 5; end
d_high = !d_high;
end
4: begin rx_er <= 0; rxd <= 4'ha; d_state = 5; end
default: begin rx_dv <= 0; rx_er <= 0; rxd <= 0; d_state = 0; end
endcase
end
// Bus functional model, monitor side: rebuild each frame, wait three clocks for the MAC's answer, then
// tell the listener.
int mon_n = 0, mon_len = 0;
bit mon_extra = 0, mon_er = 0, mon_ind = 0;
bit [2:0] mon_status = 0;
int m_state = 0, m_wait = 0; // 0 idle, 1 preamble, 2 frame, 3 no SFD
bit [3:0] m_last = 0, m_low = 0;
bit m_have = 0;
always @(tick) begin
if (m_wait != 0) begin
if (ind_valid && !mon_ind) begin
mon_ind = 1; mon_status = ind_status; mon_len = int'(ind_len);
for (int i = 0; i < mon_len; i++) store.data[i] = store.ind[i];
end
m_wait--;
if (m_wait == 0 && store.listener != null) store.listener.frame_seen();
end
else if (rx_dv) begin
if (m_state == 0) begin m_state = 1; m_last = 0; m_have = 0; mon_n = 0; mon_er = 0; end
if (rx_er) mon_er = 1;
if (m_state == 1) begin
if (m_last == 4'h5 && rxd == 4'hd) m_state = 2;
else if (rxd != 4'h5) m_state = 3;
m_last = rxd;
end
else if (m_state == 2) begin
if (!m_have) begin m_low = rxd; m_have = 1; end
else begin
if (mon_n < 2304) begin store.oct[mon_n] = {rxd, m_low}; mon_n++; end
m_have = 0;
end
end
end
else if (m_state != 0) begin
if (m_state == 2) begin mon_extra = m_have; mon_ind = 0; mon_len = 0; m_wait = 3; end
m_state = 0;
end
end
endinterface
// One frame as the receive monitor saw it on the line, with the MAC's answer.
class mac_rx_item extends uvm_sequence_item;
`uvm_object_utils(mac_rx_item)
int unsigned index; // 1 for the first frame of the run
bit [7:0] oct [$]; // whole octets from the destination address to the FCS
bit extra_nibble; // a nibble was left over after the last whole octet
bit rx_er; // RX_ER was high at some point while RX_DV was high
bit indicated; // the MAC reported this frame to its client
mac_status_e status; // valid when indicated
bit [7:0] data [$]; // the octets it handed over (none unless receiveOK)
function new(string name = "mac_rx_item"); super.new(name); endfunction
function string status_name();
case (status)
RECEIVE_OK: return "receiveOK";
FRAME_TOO_LONG: return "frameTooLong";
FRAME_CHECK_ERROR: return "frameCheckError";
ALIGNMENT_ERROR: return "alignmentError";
LENGTH_ERROR: return "lengthError";
default: return "?";
endcase
endfunction
function string convert2string();
string s;
s = $sformatf("frame %0d: %0d octets", index, oct.size());
if (oct.size() >= 14) s = {s, $sformatf(", DA %02x-%02x-%02x-%02x-%02x-%02x, Length/Type %02x%02x", oct[0], oct[1], oct[2], oct[3], oct[4], oct[5], oct[12], oct[13])};
if (extra_nibble) s = {s, ", extra nibble"};
if (rx_er) s = {s, ", RX_ER"};
if (!indicated) s = {s, " -> no indication"};
else if (status == RECEIVE_OK) s = {s, $sformatf(" -> receiveOK, %0d octets", data.size())};
else s = {s, " -> ", status_name()};
return s;
endfunction
endclass
// The line driver queues each frame for the interface's model, which plays them out in order. A sequence
// therefore finishes before its last frame is on the line: a test waits for the monitor's count.
class line_driver extends uvm_driver #(line_frame);
`uvm_component_utils(line_driver)
virtual mac_if vif;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
task run_phase(uvm_phase phase);
line_frame f;
forever begin
seq_item_port.get(f);
vif.store.todo.push_back(f);
end
endtask
endclass
// The receive monitor publishes one item for each frame the interface rebuilt, with the MAC's answer.
// The MAC answers within two clocks of the end of a frame, or not at all.
typedef class mac_rx_monitor;
class mac_rx_hook extends mac_listener;
mac_rx_monitor mon;
virtual function void frame_seen(); mon.publish(); endfunction
endclass
class mac_rx_monitor extends uvm_monitor;
`uvm_component_utils(mac_rx_monitor)
virtual mac_if vif;
uvm_analysis_port #(mac_rx_item) ap;
int unsigned count; // frames published so far
function new(string name, uvm_component parent); super.new(name, parent); ap = new("ap", this); endfunction
function void start_of_simulation_phase(uvm_phase phase);
mac_rx_hook hook = new;
hook.mon = this;
vif.store.listener = hook;
endfunction
function void publish();
mac_rx_item t = mac_rx_item::type_id::create("t");
for (int i = 0; i < vif.mon_n; i++) t.oct.push_back(vif.store.oct[i]);
t.extra_nibble = vif.mon_extra;
t.rx_er = vif.mon_er;
t.indicated = vif.mon_ind;
t.status = mac_status_e'(vif.mon_status);
for (int i = 0; i < vif.mon_len; i++) t.data.push_back(vif.store.data[i]);
count++;
t.index = count;
ap.write(t);
endfunction
endclass
// A coverage model in a class: one counter for each bin of the plan (see the lesson for why not a covergroup).
// It looks only at what was on the line, never at the MAC's answer.
class mac_coverage extends uvm_subscriber #(mac_rx_item);
`uvm_component_utils(mac_coverage)
mac_cfg cfg;
int unsigned hits [string];
string names [$];
function new(string name, uvm_component parent);
super.new(name, parent);
names = '{"size.fragment", "size.64", "size.middle", "size.at_limit", "size.over_limit",
"to.station", "to.broadcast", "to.listed_group", "to.pause_address", "to.other_group", "to.other_station",
"type.short_length", "type.length", "type.1501_to_1535", "type.type", "type.tag", "type.mac_control",
"damage.bad_fcs", "damage.extra_nibble", "damage.rx_er",
"cross.over_limit_and_bad_fcs", "cross.bad_fcs_and_extra_nibble", "cross.good_fcs_and_extra_nibble",
"cross.fragment_with_good_fcs", "cross.other_station_and_bad_fcs", "cross.short_length_and_pad",
"cross.length_and_wrong_size", "cross.control_other_opcode", "cross.tag_at_1522"};
foreach (names[i]) hits[names[i]] = 0;
endfunction
function void hit(string name);
if (!hits.exists(name)) `uvm_fatal("COV", {"no such bin: ", name})
hits[name]++;
endfunction
function void write(mac_rx_item t);
int n = t.oct.size(), limit, field;
bit [47:0] da;
bit [15:0] lt;
bit good, mine;
if (n < 18) begin hit("size.fragment"); return; end
da = {t.oct[0], t.oct[1], t.oct[2], t.oct[3], t.oct[4], t.oct[5]};
lt = {t.oct[12], t.oct[13]};
limit = (lt == 16'h8100) ? 1522 : 1518;
field = n - 18;
good = (eth_fcs(t.oct, n - 4) == {t.oct[n-1], t.oct[n-2], t.oct[n-3], t.oct[n-4]});
mine = 1;
if (n < 64) hit("size.fragment");
else if (n == 64) hit("size.64");
else if (n < limit) hit("size.middle");
else if (n == limit) hit("size.at_limit");
else hit("size.over_limit");
if (da == cfg.station) hit("to.station");
else if (da == 48'hffffffffffff) hit("to.broadcast");
else if (da == cfg.group[0] || da == cfg.group[1]) hit("to.listed_group");
else if (da == MAC_PAUSE_DA) hit("to.pause_address");
else if (da[40]) begin mine = 0; hit("to.other_group"); end
else begin mine = 0; hit("to.other_station"); end
if (lt < 16'd46) hit("type.short_length");
else if (lt <= 16'd1500) hit("type.length");
else if (lt < 16'd1536) hit("type.1501_to_1535");
else if (lt == 16'h8100) hit("type.tag");
else if (lt == 16'h8808) hit("type.mac_control");
else hit("type.type");
if (!good) hit("damage.bad_fcs");
if (t.extra_nibble) hit("damage.extra_nibble");
if (t.rx_er) hit("damage.rx_er");
if (mine && n > limit && !good) hit("cross.over_limit_and_bad_fcs");
if (mine && n >= 64 && n <= limit && !good && t.extra_nibble) hit("cross.bad_fcs_and_extra_nibble");
if (mine && n >= 64 && n <= limit && good && t.extra_nibble) hit("cross.good_fcs_and_extra_nibble");
if (mine && n < 64 && good) hit("cross.fragment_with_good_fcs");
if (!mine && n >= 64 && !good) hit("cross.other_station_and_bad_fcs");
if (mine && good && lt < 16'd46 && field == 46) hit("cross.short_length_and_pad");
if (mine && good && lt >= 16'd46 && lt <= 16'd1500 && field != int'(lt) && n <= limit) hit("cross.length_and_wrong_size");
if (mine && good && n >= 64 && lt == 16'h8808 && {t.oct[14], t.oct[15]} != 16'h0001) hit("cross.control_other_opcode");
if (mine && good && lt == 16'h8100 && n == 1522) hit("cross.tag_at_1522");
endfunction
function int covered();
int c = 0;
foreach (names[i]) if (hits[names[i]] != 0) c++;
return c;
endfunction
function string holes();
string s = "";
foreach (names[i]) if (hits[names[i]] == 0) begin
if (s != "") s = {s, ", "};
s = {s, names[i]};
end
if (s == "") s = "none";
return s;
endfunction
endclass
typedef class mac_rx_scoreboard;
// One MAC with its bench: sequencer, line driver, receive monitor and your scoreboard.
class mac_env extends uvm_env;
`uvm_component_utils(mac_env)
mac_cfg cfg;
virtual mac_if vif;
uvm_sequencer #(line_frame) line_sqr;
line_driver line_drv;
mac_rx_monitor rx_mon;
mac_rx_scoreboard sb;
function new(string name, uvm_component parent); super.new(name, parent); endfunction
function void build_phase(uvm_phase phase);
if (!uvm_config_db #(virtual mac_if)::get(this, "", "vif", vif)) `uvm_fatal("NOVIF", "no interface")
if (!uvm_config_db #(mac_cfg)::get(this, "", "cfg", cfg)) `uvm_fatal("NOCFG", "no configuration")
line_sqr = uvm_sequencer #(line_frame)::type_id::create("line_sqr", this);
line_drv = line_driver::type_id::create("line_drv", this);
rx_mon = mac_rx_monitor::type_id::create("rx_mon", this);
sb = mac_rx_scoreboard::type_id::create("sb", this);
line_drv.vif = vif;
rx_mon.vif = vif;
sb.cfg = cfg;
endfunction
function void connect_phase(uvm_phase phase);
line_drv.seq_item_port.connect(line_sqr.seq_item_export);
rx_mon.ap.connect(sb.analysis_export);
endfunction
endclass
Check Yourself
Common Mistakes
Wrong Let the monitor decide whether a frame is good.
Then the rule lives in two places, and a wrong monitor hides a wrong MAC.
Fix The monitor reports facts. Only the scoreboard's model decides.
Wrong Raise one generic error for every mismatch.
The person who reads the log cannot tell a filter fault from a pad fault.
Fix Give each kind of mismatch its own ID, and report the first one that applies.
Wrong Call the bench done when every test passes.
MAC E passed fifteen frames. The frame that breaks it was never sent.
Fix Read the coverage holes, and close the crosses before you trust a pass.
Wrong Write the reference model by reading the RTL.
A model copied from the design repeats its mistakes and agrees with them.
Fix Write it from the standard and the plan, in the order the standard gives.
Remember
- The map: sequence, driver, interface models, MAC, monitor, then scoreboard and coverage.
- A plan row is a feature, a check, a stimulus and a coverage bin.
- The monitor reports facts; only the reference model decides.
- Four ways to differ, four report IDs: unexpected, missing, status, data.
- Coverage holes point at the frames that have not run. Crosses hide the hard faults.