Test Patterns, Loopback and Compliance

Test a link the way a lab does: PRBS patterns and checkers, loopback, error counts, eye scans and compliance patterns.

You Will Be Able To

  • Choose a PRBS pattern and predict its period and longest runs.
  • Explain why a free-running PRBS checker counts each wire error once.
  • Choose a loopback point for a test and say what it covers.
  • Read an eye scan and name what each USB compliance pattern is for.
Lesson
P10.15
Time
30 min
Runs on
Your browser
Check
5 questions

A link passes every functional test, yet a lab rejects it. Its checker reported 15 errors where only 5 bits were wrong: it was the wrong kind of checker.

Where a Test Loops the Data BackA pattern generator and a checker sit in the PCS. Loopback points pick how much of the path the test covers.
  • Datapath
  • I/O
  • Channel / handshake
  • Monitor
  • Data
Where a test loops the data backA pattern generator and a checker sit in the PCS. Loopback points pick how much of the path the test covers. datapath PRBS generator datapath PCS encoder, gearbox io PMA serializer, driver channel Channel io Link partner retimed loopback monitor PRBS checker far-end loopbackback over the channelnear-end loopback
  1. datapath PRBS generator
    • PCS
  2. datapath PCSencoder, gearbox
    • PMA
    • near-end loopback → PRBS checker
  3. monitor PRBS checker
  4. io PMAserializer, driver
    • Channel
  5. channel Channel
    • far-end loopback → Link partner
  6. io Link partnerretimed loopback
    • back over the channel → PRBS checker
  1. Generate

    A PRBS generator feeds known data into the transmit path.

  2. Near-end loopback

    The data turns back inside the same chip, before the pins. It tests the logic without a channel. PIPE calls these paths LB0 to LB4 (§8.34).

  3. Through the channel

    The data leaves through the serializer and driver and crosses the channel.

  4. Far-end loopback

    The link partner sends back what it received. USB 3.2 requires this loopback to be retimed, not wired straight from the receiver to the transmitter (§6.8.4).

  5. Check

    The checker compares what returns with the pattern and counts errors. That is a bit error rate test.

Read the diagram as text
  • PRBS generator
  • PCS: encoder, gearbox
  • PMA: serializer, driver
  • Channel
  • Link partner: retimed loopback
  • PRBS checker
  • PRBS generator → PCS
  • PCS → PMA
  • PMA → Channel
  • Channel → Link partner: far-end loopback
  • Link partner → PRBS checker: back over the channel
  • PCS → PRBS checker: near-end loopback

AMD's transceiver example design pairs a PRBS generator and checker per channel and tests in loopback (PG182).

PRBS Patterns

A pseudo-random binary sequence (PRBS) comes from a maximal LFSR. It looks random but repeats exactly, so a checker can predict every bit.

PatternPolynomialRepeats afterLongest runs (ones, zeros)Used by
PRBS7x^7 + x^6 + 1127 bits7, 6the bench eyes of P10.6 and P10.9
PRBS111 + x^9 + x^112,047 bits11, 10USB4 (Table 4-66)
LFSR15x^15 + x^14 + 132,767 bits15, 14USB 3.2 CP12 (Table 6-14)

Bench runs of hs_pkg::prbs_next. An n-bit maximal LFSR repeats after 2^n − 1 bits and holds runs of n ones and n − 1 zeros.

A longer register gives a longer period and longer runs. Longer runs stress the clock recovery and the channel's low frequencies harder.

USB4 requires PRBS31 for its transmitter and receiver compliance tests (§3.1.3, §3.1.4.2). Its period, 2^31 − 1 bits, is about 0.2 s at 10 Gb/s.

Checking a PRBS

A checker must first know where in the sequence the data is. The simplest way: copy the first n received bits into its own register. That is lock.

After lock there are two ways to go on. A free-running checker steps its own register. A self-synchronising checker predicts each bit from the last n received bits, like the descrambler of P10.5.

The bench flipped 5 bits in 20,000. The free-running checker counted 5 errors. The self-synchronising one counted 15: each wrong bit is used twice more, at the two taps.

A free-running checker counts what really went wrong. It must relock if the data ever slips.

AMD's transceivers build both sides in (PG182). TXPRBSSEL and RXPRBSSEL pick the pattern, RXPRBSLOCKED reports lock, RXPRBSERR flags errors and TXPRBSFORCEERR injects one.

Bit Error Rate Test and Loopback

A bit error rate test (BERT) counts errors over a known number of bits.

Bits sentErrors countedMeasured BER
10,00022.00e-4
100,000101.00e-4

Bench runs: PRBS15 with each bit flipped at a true BER of 1e-4 (the library rng). Short runs count few errors, so their estimate scatters.

P10.7 showed how many bits a claim needs. A rate of 1e-12 cannot be counted directly in a short test; it is extrapolated or tested under stress.

The test needs the data to come back. Near-end loopback turns it inside the chip, to test the logic. Far-end loopback asks the link partner to send back what it received, to test the whole path.

USB 3.2 defines the far-end case. The loopback is retimed, at the 10-bit symbol level for Gen 1, and SKPs are still added or removed (§6.8.4). PIPE loops back received symbols when the MAC asks (§8.16).

At Gen 1, USB 3.2 also defines a BERT in loopback. BRST resets the error count and the scrambler, and BDAT carries the scrambled pattern. BERC asks for the count, which comes back in BCNT (§6.8.4.1).

The Eye Scan

An oscilloscope cannot see inside a receiver after its equalizer. An eye scan measures the eye where it matters. The receiver moves its own sampling point and threshold, and counts errors at each.

Threshold-0.4 UI-0.3 UI-0.2 UI-0.1 UI0 UI+0.1 UI+0.2 UI+0.3 UI+0.4 UI
+300 mV323232323224163131
+200 mV323216800101631
+100 mV241600000816
0 mV000000000
-100 mV231500000816
-200 mV313115700101632
-300 mV313131313123163232

Eye scan of the long bench channel's ngspice transient. Each cell counts wrong decisions among 122 symbols at one offset and threshold.

The zeros mark the open eye. It reaches about ±0.4 UI at the 0 mV threshold, matching the 0.82 UI width the eye plot of P10.9 measured.

A real scan counts errors over many bits at each point and draws contours of equal error ratio. AMD's transceivers have eye-scan ports for this (PG182).

USB Compliance Patterns

A compliance test needs patterns that stress one thing at a time. USB 3.2 defines seventeen, CP0 to CP16 (§6.4.4, Table 6-14). CP0 to CP8 run at Gen 1, CP9 to CP16 at Gen 2.

PatternWhat it isOn the line (first 40 bits)Longest runTransitions per 100 bits
CP1D10.201010101010101010101010101010101010101011100
CP2D24.31100110011001100110011001100110011001100249
CP3K28.50011111010110000010100111110101100000101549
CP5K28.70011111000001111100000111110000011111000520

Bench runs: each symbol repeated through the 8b/10b encoder, starting at RD-. USB 3.2 lists CP1 as the Nyquist pattern and CP2 as Nyquist/2 (Table 6-14).

CP0 and CP9 are scrambled data, like real traffic. CP4 is LFPS. CP7 and CP8 repeat 50 to 250 ones then as many zeros, with and without de-emphasis, to stress low frequencies.

At Gen 2, CP10 and CP11 are raw AAh and CCh, and CP12 is the uncoded LFSR15. CP13 to CP16 repeat 64 ones and 64 zeros with each mix of pre-shoot and de-emphasis.

A device steps from one pattern to the next on each ping LFPS, and stops on a reset LFPS (§6.4.4). Unless the table says otherwise, the patterns are not scrambled.

Try It

The checker copies the first 15 bits into its register: that is lock. From then on it steps its own register.

The flipped bit at 3000 is counted once. The checker's register never saw it, so the next bits match again.

Move the flip to bit 10. The checker then locks on a wrong copy, and about half of the later bits are counted wrong. Real checkers relock when errors pile up.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: locked after 15 bits error at bit 3000 1 error counted in 6000 bits
Read included file: hs_pkg.sv
`timescale 1ns/1ns
// hs_pkg.sv: shared pure functions, and the bench random generator (read-only).
package hs_pkg;
  // xorshift32 (Marsaglia 2003): a linear generator over GF(2), period 2^32 - 1. A zero state is
  // replaced by 1, because zero maps to itself.
  function automatic [31:0] xs32(input [31:0] s);
    reg [31:0] x;
    x = (s == 32'd0) ? 32'd1 : s;
    x = x ^ (x << 13); x = x ^ (x >> 17); x = x ^ (x << 5);
    return x;
  endfunction
  // A Fibonacci PRBS generator x^n + x^m + 1 (PRBS7: 7,6; PRBS9: 9,5; PRBS15: 15,14; PRBS23: 23,18;
  // PRBS31: 31,28). The output bit is s[n-1]; the next state shifts the feedback into bit 0.
  function automatic [31:0] prbs_next(input [31:0] s, input int n, input int m);
    reg fb;
    fb = s[n-1] ^ s[m-1];
    return ((s << 1) | {31'd0, fb}) & ((n == 32) ? 32'hffffffff : ((32'd1 << n) - 32'd1));
  endfunction
  function automatic int ones(input [63:0] v);
    int n; n = 0;
    for (int i = 0; i < 64; i++) n += v[i];
    return n;
  endfunction
  // GF(16) with x^4 + x + 1, and GF(1024) with x^10 + x^3 + 1: shift-and-add multiply, no tables.
  function automatic [3:0] gf16_mul(input [3:0] a, input [3:0] b);
    reg [3:0] p, x; p = 4'd0; x = a;
    for (int i = 0; i < 4; i++) begin
      if (b[i]) p = p ^ x;
      x = x[3] ? ({x[2:0], 1'b0} ^ 4'b0011) : {x[2:0], 1'b0};
    end
    return p;
  endfunction
  function automatic [3:0] gf16_pow(input int e);   // alpha^e, alpha = x
    reg [3:0] p; int k; p = 4'd1; k = e % 15; if (k < 0) k += 15;
    for (int i = 0; i < k; i++) p = gf16_mul(p, 4'd2);
    return p;
  endfunction
  function automatic int gf16_log(input [3:0] a);   // -1 for 0
    reg [3:0] p; p = 4'd1;
    if (a == 4'd0) return -1;
    for (int i = 0; i < 15; i++) begin if (p == a) return i; p = gf16_mul(p, 4'd2); end
    return -1;
  endfunction
  function automatic [9:0] gf1024_mul(input [9:0] a, input [9:0] b);
    reg [9:0] p, x; p = 10'd0; x = a;
    for (int i = 0; i < 10; i++) begin
      if (b[i]) p = p ^ x;
      x = x[9] ? ({x[8:0], 1'b0} ^ 10'b0000001001) : {x[8:0], 1'b0};
    end
    return p;
  endfunction
  function automatic [9:0] gf1024_pow(input int e);
    reg [9:0] p; int k; p = 10'd1; k = e % 1023; if (k < 0) k += 1023;
    for (int i = 0; i < k; i++) p = gf1024_mul(p, 10'd2);
    return p;
  endfunction
endpackage

// hs_rng: the bench's random numbers. Same seed, same numbers, on every engine.
module hs_rng;
  int unsigned s = 32'h2545f491;
  function automatic void seed(input int unsigned v); s = (v == 0) ? 32'd1 : v; endfunction
  function automatic int unsigned next(); s = hs_pkg::xs32(s); return s; endfunction
  function automatic int below(input int n); s = hs_pkg::xs32(s); return (n <= 0) ? 0 : int'(s % n); endfunction
  function automatic bit bit1(); s = hs_pkg::xs32(s); return s[16]; endfunction
  function automatic bit chance_ppm(input int ppm); s = hs_pkg::xs32(s); return (s % 1000000) < ppm; endfunction
  function automatic [7:0] byte8(); s = hs_pkg::xs32(s); return s[23:16]; endfunction
endmodule

Check Yourself

Predict the outputA self-synchronising PRBS15 checker (taps 15 and 14) receives 6,000 bits with one wire bit flipped at bit 3000. The program prints the error count. What does it print?
`timescale 1ns/1ns
module tb;
  reg [31:0] tx, hist, pred; int errs_free, errs_self, nb; bit b, locked;
  function automatic bit flip_at(input int i); return i == 1000 || i == 5000 || i == 9000 || i == 13000 || i == 17000; endfunction
  initial begin
    // a self-synchronising PRBS15 checker (x^15 + x^14 + 1); one wire bit flipped at bit 3000
    tx = 32'h7fff; hist = 0; errs_self = 0;
    for (int i = 0; i < 6000; i++) begin
      b = tx[14] ^ (i == 3000); tx = hs_pkg::prbs_next(tx, 15, 14);
      if (i >= 15 && b !== (hist[14] ^ hist[13])) errs_self++;
      hist = ((hist << 1) | b) & 32'h7fff;
    end
    $display("%0d", errs_self);
    $finish;
  end
endmodule
Read included file: hs_pkg.sv
`timescale 1ns/1ns
// hs_pkg.sv: shared pure functions, and the bench random generator (read-only).
package hs_pkg;
  // xorshift32 (Marsaglia 2003): a linear generator over GF(2), period 2^32 - 1. A zero state is
  // replaced by 1, because zero maps to itself.
  function automatic [31:0] xs32(input [31:0] s);
    reg [31:0] x;
    x = (s == 32'd0) ? 32'd1 : s;
    x = x ^ (x << 13); x = x ^ (x >> 17); x = x ^ (x << 5);
    return x;
  endfunction
  // A Fibonacci PRBS generator x^n + x^m + 1 (PRBS7: 7,6; PRBS9: 9,5; PRBS15: 15,14; PRBS23: 23,18;
  // PRBS31: 31,28). The output bit is s[n-1]; the next state shifts the feedback into bit 0.
  function automatic [31:0] prbs_next(input [31:0] s, input int n, input int m);
    reg fb;
    fb = s[n-1] ^ s[m-1];
    return ((s << 1) | {31'd0, fb}) & ((n == 32) ? 32'hffffffff : ((32'd1 << n) - 32'd1));
  endfunction
  function automatic int ones(input [63:0] v);
    int n; n = 0;
    for (int i = 0; i < 64; i++) n += v[i];
    return n;
  endfunction
  // GF(16) with x^4 + x + 1, and GF(1024) with x^10 + x^3 + 1: shift-and-add multiply, no tables.
  function automatic [3:0] gf16_mul(input [3:0] a, input [3:0] b);
    reg [3:0] p, x; p = 4'd0; x = a;
    for (int i = 0; i < 4; i++) begin
      if (b[i]) p = p ^ x;
      x = x[3] ? ({x[2:0], 1'b0} ^ 4'b0011) : {x[2:0], 1'b0};
    end
    return p;
  endfunction
  function automatic [3:0] gf16_pow(input int e);   // alpha^e, alpha = x
    reg [3:0] p; int k; p = 4'd1; k = e % 15; if (k < 0) k += 15;
    for (int i = 0; i < k; i++) p = gf16_mul(p, 4'd2);
    return p;
  endfunction
  function automatic int gf16_log(input [3:0] a);   // -1 for 0
    reg [3:0] p; p = 4'd1;
    if (a == 4'd0) return -1;
    for (int i = 0; i < 15; i++) begin if (p == a) return i; p = gf16_mul(p, 4'd2); end
    return -1;
  endfunction
  function automatic [9:0] gf1024_mul(input [9:0] a, input [9:0] b);
    reg [9:0] p, x; p = 10'd0; x = a;
    for (int i = 0; i < 10; i++) begin
      if (b[i]) p = p ^ x;
      x = x[9] ? ({x[8:0], 1'b0} ^ 10'b0000001001) : {x[8:0], 1'b0};
    end
    return p;
  endfunction
  function automatic [9:0] gf1024_pow(input int e);
    reg [9:0] p; int k; p = 10'd1; k = e % 1023; if (k < 0) k += 1023;
    for (int i = 0; i < k; i++) p = gf1024_mul(p, 10'd2);
    return p;
  endfunction
endpackage

// hs_rng: the bench's random numbers. Same seed, same numbers, on every engine.
module hs_rng;
  int unsigned s = 32'h2545f491;
  function automatic void seed(input int unsigned v); s = (v == 0) ? 32'd1 : v; endfunction
  function automatic int unsigned next(); s = hs_pkg::xs32(s); return s; endfunction
  function automatic int below(input int n); s = hs_pkg::xs32(s); return (n <= 0) ? 0 : int'(s % n); endfunction
  function automatic bit bit1(); s = hs_pkg::xs32(s); return s[16]; endfunction
  function automatic bit chance_ppm(input int ppm); s = hs_pkg::xs32(s); return (s % 1000000) < ppm; endfunction
  function automatic [7:0] byte8(); s = hs_pkg::xs32(s); return s[23:16]; endfunction
endmodule
ConceptA test must cover the channel and the partner's receiver. Which loopback does it need?
ConceptWhat does USB 3.2's CP1, D10.2 repeated, test?
ConceptWhy does an eye scan measure inside the receiver instead of at the pins?
ConceptA BER test counts 10 errors in 100,000 bits. What is the measured BER?

Common Mistakes

Wrong Count errors with a self-synchronising PRBS checker.

Each wrong bit enters its prediction register and spoils two more checks; 5 flipped bits counted as 15.

Fix Lock once, then let the checker run on its own register, and relock only when errors pile up.

Wrong Test only with a short PRBS7 pattern.

Its longest run is 7 bits, so it never shows the low-frequency stress of long runs that real or longer patterns have.

Fix Test with the pattern the standard names, such as PRBS31 for USB4, and with the long-run compliance patterns.

Wrong Loop the receiver straight to the transmitter for a far-end test.

USB 3.2 forbids it: the loopback must be retimed, so the received jitter is not passed back unfiltered.

Fix Loop back after the clock recovery and the symbol level, as USB 3.2 §6.8.4 requires.

Wrong Report a BER from a test that counted two errors.

With so few errors the estimate scatters: the bench counted 2 in 10,000 bits at a true 1e-4.

Fix Count enough errors, or report an upper bound at a stated confidence, as P10.7 shows.

Remember

  • A PRBS from an n-bit maximal LFSR repeats after 2^n − 1 bits and has runs of up to n bits.
  • A free-running checker counts each wire error once; a self-synchronising one multiplies it.
  • Near-end loopback tests the logic; far-end loopback tests the channel and the partner too.
  • An eye scan moves the receiver's own sampling point and threshold and counts errors.
  • USB defines compliance patterns CP0 to CP16, each stressing one property of the link.

Practice

Report a problem with this page