From 055cae669be38bec3ec522333a855bc2e8ae8738 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Tue, 17 Nov 2026 17:17:08 -0800 Subject: [PATCH 1/7] additional software tests --- docs/ucie_bringup.md | 356 ++++++++++++++++++++++ software/Makefile | 6 +- software/phytest-clocks.c | 145 +++++++++ software/phytest-loopback.c | 493 +++++++++++++++++++++++++++++++ software/phytest-two-chip.c | 107 +++++++ software/phytest.h | 330 +++++++++++++++++++++ software/ucie-digital-loopback.c | 4 + software/ucie.h | 243 ++++++++++++--- test/src/IrisSpec.scala | 103 ++++++- test/src/Utils.scala | 16 +- ucie | 2 +- 11 files changed, 1756 insertions(+), 49 deletions(-) create mode 100644 docs/ucie_bringup.md create mode 100644 software/phytest-clocks.c create mode 100644 software/phytest-loopback.c create mode 100644 software/phytest-two-chip.c create mode 100644 software/phytest.h diff --git a/docs/ucie_bringup.md b/docs/ucie_bringup.md new file mode 100644 index 0000000..7154daa --- /dev/null +++ b/docs/ucie_bringup.md @@ -0,0 +1,356 @@ +# UCIe bring-up on Iris + +Iris has two UCIe links. This page covers what's specific to Iris: where the links sit in the +address map, how software reaches them, which clocks come in on bumps, and how bumps map to links. + +How to clock, reset and bring up PhyTest, the IP's link tester, is in the UCIe IP's own guide: +[`ucie/docs/phytest_bringup.md`](../ucie/docs/phytest_bringup.md). Read section 3 of that guide +("The register port, and how not to hang it") before touching a link. + +File citations are `file:line` from the repository root. `ucie/...` is the UCIe submodule. +`IrisSpec.scala` is being edited, so its line numbers are for the working tree on 2026-11-10. + +--- + +## 1. The two links + +Both links are chiplet-router ports (`src/Iris.scala:553-578`). Their `UcieTLParams` are identical +apart from `address` and `moduleId`: +- `numLanes` = 16 +- `managerWhere` = SBUS +- `includeDefaultModels` = true +- `sim` follows the config + +`UcieComplexPort` puts both `UcieChipletLink`s inside one module, `UcieComplex` (instance +`d2d_ports`), so physical design can harden them together (`src/UcieComplex.scala:15-67`). +`moduleId` 1 gives the second link its own module names, `UcieTL_1` and `UcieChipletLink_1` +(`ucie/scala/src/tilelink/TileLink.scala:95-106`). + +| | Link 0 | Link 1 | +|---|---|---| +| IrisTop IO | `c2c_ucie0` | `c2c_ucie1` | +| Chiplet-router port (and `program_router` `port` argument) | 0 | 1 | +| `UcieTLParams.address` (`base`) | `0x200000` | `0x208000` | +| PhyTest and lane registers (`UcieTLRegs`, PHY test clock) | `0x200000`–`0x203BFF` | `0x208000`–`0x20BBFF` | +| Controller controls and UCIe spec registers (`UcieController`, TX sideband clock) | `0x203C00`–`0x207FFF` | `0x20BC00`–`0x20FFFF` | +| Clock and reset registers (`UcieClkRegs`, chip clock) | `0x210000`–`0x210FFF` | `0x218000`–`0x218FFF` | +| Module (`moduleId`) | `UcieTL` (0) | `UcieTL_1` (1) | + +The windows come from `UcieTLRegs.regionSize` = 0x3C00, `UcieController.ctrlBase`/`specBase` = +0x3C00/0x4000 with a 0x4000 spec region, and `UcieClkRegs.offset` = 0x10000 with a 0x1000 region +(`ucie/scala/src/tilelink/TileLink.scala:225,269,993,1695-1704`; +`ucie/scala/src/uciedigital/regs/UcieRegParams.scala:49-50,127-160`). The two links' windows don't +overlap. + +Everything outside the windows is unmapped. That includes `0x211000`–`0x217FFF` and `0x219000` +upwards. Iris removed the error device from every bus (`src/Iris.scala:268-280`), so an access to +an unmapped address doesn't return an error. **It hangs** (inference: nothing on the bus can answer +it). + +### Registers you'll touch first + +Offsets come from `software/ucie.h`, regenerated for IrisConfig in the working tree. Regenerate it +whenever the `ucie` submodule moves; the header is the authority. + +| Register | Offset | Link 0 | Link 1 | Safe before `ucieRst` = 0? | +|---|---|---|---|---| +| `UCIE_MAIN_CLK_SEL` | `0x10000` | `0x210000` | `0x218000` | yes | +| `UCIE_PHY_TEST_CLK_BYPASS_EN` | `0x10038` | `0x210038` | `0x218038` | yes | +| `UCIE_CLK_EN` / `UCIE_RX_CLK_EN` | `0x10048` / `0x10050` | `0x210048` / `0x210050` | `0x218048` / `0x218050` | yes | +| `UCIE_CLK_CFG_BUSY` | `0x10088` | `0x210088` | `0x218088` | yes | +| `UCIE_CLK_CFG_UNGATE_REQ` | `0x100A0` | `0x2100A0` | `0x2180A0` | yes | +| `UCIE_PLL_LOCK_OBSERVED` | `0x100A8` | `0x2100A8` | `0x2180A8` | yes | +| `UCIE_UCIE_RST` (reset value 1) | `0x100B0` | `0x2100B0` | `0x2180B0` | yes | +| `UCIE_PHY_TEST_CLK_EN` | `0x100D8` | `0x2100D8` | `0x2180D8` | yes | +| `UCIE_TX_TEST_STATE` | `0x128` | `0x200128` | `0x208128` | **no**: needs `ucieRst` = 0 and a running PHY test clock | +| `UCIE_RX_IDLE_WORDS_OBSERVED` | `0x3C8` | `0x2003C8` | `0x2083C8` | no | +| `UCIE_TX_TEST_FIFO_UNDERFLOW` / `UCIE_RX_TEST_FIFO_OVERFLOW` | `0x3868` / `0x3870` | `0x203868` / `0x203870` | `0x20B868` / `0x20B870` | no | + +Other Iris addresses that bring-up programs use (`software/router.h`; `src/Iris.scala:555`): +- the chiplet-router table at `0x4000`, 32 bytes per entry, 4 entries; +- the chip ID register at `0x4080`. + +--- + +## 2. How software reaches the registers + +Each link's register port hangs off the **control bus**, through `TLFragmenter(cbus)`, a `TLBuffer` +and a `TLWidthWidget(cbus.beatBytes)` (`src/Iris.scala:102-114`). +- The router can't attach the port itself: it takes a bare register node, and the port is a + crossbar in front of three blocks (`ucie/scala/src/tilelink/TileLink.scala:2635-2643`). +- The link's chip clock is the `d2d` clock group. That group is combined into `uncore` with `cbus`, + `sbus`, `pbus` and the other buses, all at 500 MHz (`src/Iris.scala:391-406,453-457`). So the + port needs no clock crossing. + +There are three ways in: + +1. **The cores.** C programs include `software/ucie.h`. Every helper takes `base`, `0x200000` or + `0x208000`, and uses `reg_write64`/`reg_read64` (`software/mmio.h`). +2. **TSI over serial TileLink.** + - IrisTop's `serial_tl` port is a `DecoupledExternalSyncPhitIO`: 16-bit phits on the tapeout + config, 32-bit with `sim` (`src/Iris.scala:320-354`). It's clocked by `serial_tl.clock_in` + from outside. + - Its client side masters the front bus (`SerialTLClientParams` defaults `masterWhere` to FBUS: + `testchipip/src/main/scala/serdes/PeripheryTLSerial.scala:47-52`). From there a request goes + FBUS → SBUS → CBUS → the UCIe register port. + - Its manager side serves off-chip memory at `0x8000_0000`, 4 GiB, on the memory bus. + - The host-side `TSIToTileLink` issues a single 8-byte Get or Put only for an 8-byte-aligned, + two-word request (`testchipip/src/main/scala/tsi/TSIToTileLink.scala:78-92`). Use exactly that + for UCIe registers. +3. **JTAG.** + - `WithJtagDTM` and `WithDebugSBA` give a debug module with system-bus access + (`src/Iris.scala:414-421`). The access width is 64 bits, because the base config uses + `DefaultDebugModuleParams(64)` (`rocket-chip/src/main/scala/subsystem/Configs.scala:59`). + - The bus master is on the front bus (`debug[0]` in the NoC map, `src/Iris.scala:497`). Use + 64-bit accesses, such as OpenOCD `write_memory`/`read_memory` with width 64. + - Abstract commands through a halted hart also work, as long as the control bus isn't wedged. + +**Use 64-bit accesses.** +- Writes to fields wider than 32 bits (`txctl_N_tile`, `clkPhaseSel`, seeds, packet counts, + `txDataChunkIn0/1`, `sbTxPacket`) are ignored silently unless the whole field is in the byte mask + (`rocket-chip/src/main/scala/regmapper/RegMapper.scala:146`). +- A 32-bit read of a 64-bit counter returns half of it. + +**Hang hazards, and recovery on Iris.** +- These hang a request forever: + - an access to a link's PhyTest or controller window while that domain is in reset (`ucieRst` = 1 + is the power-on state) or unclocked; + - an access to an unmapped address; + - an access to a remote address (the off-chip range at `0x8_0000_0000`, `src/Iris.scala:320`) + while the link isn't carrying TileLink. +- A hung access to a UCIe register sits on the control bus. That's inferred from the bus structure. + It blocks: + - both links' registers; + - the router table and chip ID; + - the clock divider; + - CLINT, PLIC and the boot ROM; + - the debug module's hart-facing ROM; + - the periphery bus with the UART. +- TSI and JTAG system-bus access can still reach memory. +- IrisTop doesn't consume the debug module's `ndreset` (`src/Iris.scala:130-149`), so JTAG can't + reset the chip. **Only `reset` recovers.** Plan the bench so you can drive Iris's reset pin from + the host. +- Rules: + - Only one agent touches a link at a time. Halt the cores before poking UCIe registers from TSI + or JTAG. + - Never access a link's `0x0000`–`0x7FFF` window until that link's `UcieClkRegs` checks pass + (`phytest_bringup.md`, sections 3 and 4). + +--- + +## 3. Clocks that come from bumps + +Each link has its own set of PHY clock bumps, all under `c2c_uciek.phy`. The bump bundle is +`UcieBumpsIO` (`ucie/scala/src/tilelink/TileLink.scala:121-170`); its PHY part is `PhyBumpsIO` +(`ucie/scala/src/phy/Phy.scala:172-194`). The Iris comment at `src/Iris.scala:558-562` notes the +per-link bypass bumps. + +| Bump (per link) | What it feeds | When it must be driven | Harness (`test/src/IrisSpec.scala:203-208`) | +|---|---|---|---| +| `phy.bypassClk` | The analog bypass input: ESD, then a clock receiver, then the clocking tile (`Phy.scala:405-411,457-461`). It's the UCIe main clock while `mainClkSel` = 3 (reset). It can also be the source the PHY test and sideband dividers divide (source 2). ≤ 16 GHz. | Always for the reset clocking. It sets the TX line rate: lane rate = 2 × bypass ÷ `txClkDiv`. | 8000 MHz (16 GT/s at the reset ÷1) | +| `phy.digitalBypassClk` | The PHY test clock while `phyTestClkBypassEn` = 1 (reset). That clock runs the PhyTest register block, PhyTest itself and every RX AFE controller. | **Before any access to the link's PhyTest window**, unless software first moves the PHY test clock onto a PLL. It must be faster than every packet clock in use (`phytest_bringup.md` §1.3). | 500 MHz. This **equals** the 16 GT/s packet clock (8 GHz/16), so there's no margin; the UCIe repo's own harness uses 800 MHz. | +| `phy.sidebandBypassClk` | The TX sideband clock while `sbClkBypassEn` = 1 (reset). That clock runs the UCIe controller, its registers, and every sideband serializer. | Before any access to the controller window, or any sideband use. | 800 MHz | +| `phy.refClk` | The 100 MHz reference for PLL8 (×80) and PLL12 (×120). | Only when a PLL is used. | 100 MHz | +| `phy.rxClkP`, `phy.rxClkN`, `phy.sbRxClk` | Forwarded clocks from the partner (or the same link, looped back). | n/a | Looped back or ringed (section 4) | + +Chip-level clock pins are separate from the UCIe ones: +- `clock` feeds every SoC clock group through the programmable `TLClockDivider` (`src/Iris.scala:88-94,118-128`). That includes the UCIe chip clock, through the `uncore` group. +- `serial_tl.clock_in` clocks the serial TileLink port. +- `jtag.TCK` clocks JTAG. +- `clock_tap` is an output tapping an SoC clock (`src/CanHaveClockTap.scala`). It isn't a UCIe clock. + +**Bench notes for Iris:** +- To run the link at the reset clocking, supply `bypassClk`, `digitalBypassClk` and + `sidebandBypassClk` on every link you bring up. Moving onto the PLLs needs `refClk` instead, and + is done through `UcieClkRegs`, which is safe while the link is still in reset. +- Run `digitalBypassClk` faster than the packet clock. With the harness's 8 GHz bypass at ÷1, the + packet clock is 500 MHz, so 800 MHz suits up to 24 GT/s. Otherwise switch the PHY test clock to + PLL8 ÷8 (1 GHz). +- Bring up first at ÷4 (4 GT/s off an 8 GHz bypass), not on a slow bypass clock + (`phytest_bringup.md` §1.2 and step 5). +- PhyTest never needs the sideband clock, but an unclocked sideband domain wedges the bus if + anything touches the controller window (`0x203C00`/`0x20BC00` and up). + +--- + +## 4. Bump and link mapping + +- `c2c_ucie0` is `system.d2d_port_ios(0)`, chiplet-router port 0: the `UcieTL` at `0x200000`. +- `c2c_ucie1` is `system.d2d_port_ios(1)`, port 1: the `UcieTL_1` at `0x208000`. + +Port order is the order of `ChipletRoutingParams.ports` (`src/Iris.scala:170-175,554-578`; +`testchipip/src/main/scala/soc/OffchipRouter.scala:250-333`). + +Each `c2c_uciek` has two parts: +- `phy`: `txData[16]`, `txValid`, `txTrack`, `txClkP`, `txClkN`, `rxData[16]`, `rxValid`, + `rxTrack`, `rxClkP`, `rxClkN`, `sbTxClk`, `sbTxData`, `sbRxClk`, `sbRxData`, plus the four clock + inputs of section 3. +- `debug`: the observation outputs `txClk`, `rxClk`, `rxData`, `clkMux` and `txData` + (`ucie/scala/src/phytest/PhyTest.scala:547-553`). Every one is off until software enables its + driver. + +Chisel flattens the names with underscores, for example `c2c_ucie0_phy_bypassClk`. + +**Lane order on the bumps** is PHY lane order: `txData[i]`/`rxData[i]` are data lanes 0-15. Valid, +track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scala:572-585,633-639`). + +**Harness connectivity** (`test/src/IrisSpec.scala`, `connectRingLink` and the code around it): +- **One chip:** each link is looped onto itself by `UcieBumpsIO.loopback`. TX data, valid, track, + the forwarded clock and the sideband all go to the same link's RX. A test on link `k` exercises + `k`'s TX and `k`'s RX together, and `run_lfsr(base_k, n)` is self-consistent there. +- **N chips:** a ring. Chip `i`'s `c2c_ucie1` connects to chip `i+1`'s `c2c_ucie0`, through + `UcieBumpsIO.connect`: data, valid, track, forwarded clock and sideband both ways. With two chips, + chip 0 link 1 ↔ chip 1 link 0 and chip 1 link 1 ↔ chip 0 link 0. Each die's TX then lands on the + *other* die, so its RX has to be armed before the other die transmits + (`phytest_bringup.md` step 7, topology B). + +**Routing.** `program_router(entry, chip_id, port)` sends a chip ID to port 0 or 1 +(`software/router.h`). In a two-chip ring both ports reach the other chip, so either works. + +--- + +## 5. Building and running bring-up programs + +- **Toolchain.** Install `riscv64-unknown-elf-gcc`, and set `RISCV` for the simulator build + (`test/src/Utils.scala`). +- **Build every program.** `make -C software`, as listed in `PROGRAMS` in `software/Makefile`. They + link against `htif_nano.specs`, so `printf` and the exit code go over HTIF and need a host + serving it: SimTSI in simulation, the lab TSI host on silicon. +- **Regenerate `software/ucie.h`.** Either `make -C software ucie.h` or + `./mill runMain edu.berkeley.cs.iris.GenUcieHeader software/ucie.h` (`src/GenUcieHeader.scala`). + It uses mill, so don't run it while another mill build is running in the same checkout. + `GenUcieHeader` refuses to emit a header if the two links' register layouts ever differ + (`src/GenUcieHeader.scala:28-48`). +- **Run in simulation (VCS).** `./mill test.testOnly edu.berkeley.cs.iris.IrisSpec -- -z ""`. + `Utils.simulateTopWithBinaries` builds the harness, compiles VCS and runs the binaries. `fast` + mode preloads through `FastRAM` and `+loadmem`, and `debug = true` dumps FSDB. +- **Run on silicon.** + - The TSI host loads the ELF into off-chip memory over `serial_tl`. + - The chip boots from the boot ROM at `0x10000` and the boot-address register + (`src/Iris.scala:424-444`). + - The host services HTIF. + - The bench-side procedure isn't in this repository. +- **Existing UCIe programs, and what they exercise.** + - `software/ucie-loopback.c` runs `setup_ucie` on both links, puts both mainbands in TileLink + mode, and does remote reads and writes through the router. It tests the TileLink path, not + PhyTest, and needs both links working. + - `software/ucie-digital-loopback.c` runs `setup_ucie_digital` on both links, which first lines + each RX's words up with its own TX's through PhyTest (`align_rx_words`, + `ucie/docs/phytest_bringup.md` §8.4) and prints the RX UI delay that set, then trains the UCIe + controller. + It spins forever if link training never completes. On the harness both links hold their RX + lanes back 20 UI, train, and carry remote reads and writes. + - Neither is a first-silicon program. + - The PhyTest programs `software/phytest-loopback.c`, `phytest-clocks.c` and `phytest-two-chip.c` + (shared helpers in `software/phytest.h`) are described in section 7. + +--- + +## 6. Iris-specific bring-up notes + +- **One link at a time.** The two links share the chip clock, the chip reset and the control bus. + Their clocking, resets and `UcieClkRegs` are separate, but a hang on either link's registers + blocks both (section 2). +- **Per link, the order is:** + 1. Ping `UcieClkRegs` (base + `0x10000`). + 2. Configure clocks if not on the bypass pins. + 3. Check that `UCIE_CLK_METER_PHY_TEST` and `UCIE_CLK_METER_SB` read nonzero, then write + `ucieRst` = 0. + 4. A single read of `UCIE_TX_TEST_STATE`. + 5. `setup_ucie`, then the overrides in `phytest_bringup.md` step 4. + 6. Set the rate and phase, and check `UCIE_CLK_METER_TX_DIV` and `_RX_DIV`. + 7. Run the on-chip loopback lane. + 8. Run the mainband LFSR, after an injected error has shown the counters count. + 9. Check the sideband with the sideband tester (`phytest_bringup.md` step 10). + 10. Run gated-clock bursts at the UCIe controller's postamble (step 11). + 11. Hand the link to the UCIe controller (step 12): `setup_ucie_digital` on a link looped back + onto itself; by hand between two chips, since `align_rx_words` can't measure across them. +- **Lessons from Kodiak, the previous chip** (`phytest_bringup.md` steps 4-9), as the generated + helpers now apply them: + - Link tests run with the observation pad drivers off: `setup_ucie` leaves them off, and + `enable_debug_drivers` turns them on for a scope. + - Every lane has its own LFSR seed, out of reset and from `seed_lfsrs`. + - `run_lfsr` waits until the packet count stops climbing, not for a fixed number of reads, and + says when it comes back short. + - Iris's RX front end is not Kodiak's, so Kodiak's hand-over and vref settings don't carry over; + those defaults will change with the AFE's own controller. +- **Physical design and lab checks this page can't settle:** + - IrisConfig emits the UCIe behavioral models (`includeDefaultModels = true`, + `src/Iris.scala:567,574`). Confirm the PD flow replaces the analog ones with the macros. + - `digitalBypassClk`, `sidebandBypassClk` and `refClk` have no ESD cell in the UCIe RTL + (`ucie/scala/src/phy/Phy.scala:405-411,432-433,459`). Confirm the pad ring provides one. + - Confirm with analog what termination `zen` = 1 with `zctl` = 0 gives (`phytest_bringup.md` + step 4). + +--- + +## 7. Simulation tests and bring-up programs + +The PhyTest bring-up programs in `software/` are the same programs in +simulation and in the lab. They run on the core, reach both UCIe links over +the SoC bus at their real MMIO bases, and go through the real register map, +clock-domain crossings, clocking tile and lane models. Each check prints +what it expected and what it read rather than stopping, and the program exits +nonzero if any check failed. + +| Program | Topology | What it covers | +|---|---|---| +| `phytest-loopback.c` | each link's bumps looped back onto itself (the single-chip harness, or a loopback board) | on both links: the clock meters against the board clocks; LFSR run with distinct per-lane seeds; injected errors counted exactly once under `rxPauseCounters`; `rxSelfSync` with every RX seed wrong; valid moved onto track at both ends; gated-clock bursts the UCIe way, at the reset values (no preamble, a packet of postamble, the clock parked high and low in turn, then always low), with the forwarded clock centred (`PT_CENTRED_DELAY_TAPS` in `phytest.h`, 29 on the harness; the trained code on silicon) and put back after, after realigning the RX dividers behind the parked clock and one 40 UI training gap, with `rxBurstMode` (and the RX seeing no words while the clock is parked); manual pattern into the capture SRAM, and `rxCaptureStart` past the first lap; error-triggered capture with twin lanes; `rxStartMode` immediate; track counters, ones/zeros/even ones; the loopback lane and its two FIFO flags; per-lane fixed and inverted sources, clean when the RX expects them and every bit wrong, half on each edge, when it does not; one injected error found by lane, UI and class; the observation bumps (on for that test alone) with the TX debug lane; the sideband tester | +| `phytest-clocks.c` | UCIe0 looped back | the TX divider at /1, /2, /4 off the bypass pin; the PHY test clock onto PLL8 /8; the main clock onto PLL8 and PLL12; a PHY test clock too slow for the link, which has to set both the TX FIFO underflow flag and the RX overflow flag (below), with the two packet clocks metering the same, and the recovery; the TX queue capped at 8 words, below its reset value of 16, with the PHY test clock at twice the packet clock (at equal rates 8 runs the queue dry and 10 is the least that holds); the sideband clock onto PLL8 /10; every clock meter after every move, and no PLL lock lost | +| `phytest-two-chip.c` | two chips, UCIe1 of each wired to UCIe0 of the other (the two-chip ring, or two chips on a package) | an LFSR run each way; that each RX hears only the TX it is wired to; `rxManualCheck` scoring the partner's manual pattern against this chip's TX pattern SRAM, with one reference word deliberately wrong | + +**A slow PHY test clock starves this die's TX and overflows its RX.** Where the +next data word of a run isn't queued in time, `TxClkGater` at the PHY end sends +an idle word instead (`ucie/scala/src/tilelink/TileLink.scala:2716-2779`), so +the receiving RX gets an idle word in the middle of the run, or with the clock +gated, the burst split in two. With the clock running, the RX still takes a +word every packet clock, more than a slow PHY test clock drains. On a +looped-back link that means `UCIE_TX_TEST_FIFO_UNDERFLOW` and +`UCIE_RX_TEST_FIFO_OVERFLOW` both set. Between two dies, the RX overflow shows +on the die with the slower PHY test clock, whichever one is sending. + +`setup_ucie` leaves the observation drivers off, so a program that wants a scope on them calls +`enable_debug_drivers(base, 1)` first; `phytest-loopback.c` does it for one test. + +`phytest.h` holds the helpers they share. Every wait is bounded in core +cycles (`PT_TIMEOUT`), because a bound counted in MMIO reads is far too short +on silicon next to a slow divided clock. + +### How the two-chip program keeps in step + +Each chip arms the RX it is about to be sent to, says so to its partner as a +sideband packet on that link, and only starts its own TX once the partner has +said the same of the RX that TX feeds. Both chips run the same binary and +need nothing else in common: not a host, not a shared clock, not matching +code timing. Run it on both chips at once in the lab. + +### Running them in simulation + +```bash +export RISCV= +export PATH=$RISCV/bin:$PATH +make -C software phytest-loopback.riscv phytest-clocks.riscv phytest-two-chip.riscv +./mill test.testOnly edu.berkeley.cs.iris.IrisSpec -- -z "should run phytest" +``` + +VCS compiles its own C with the host `gcc`; GCC 14 rejects it +(`rmapats.c: implicit declaration of function`), so put a GCC 13 or older +first on `PATH` for the sim. + +The tests: + +| Test | Config | Notes | +|---|---|---| +| `should run phytest loopback test` | `IrisConfig(sim = true)` | also checks that every observation bump of both links toggled, from `DebugBumpMonitor` in the harness, while the program had them on | +| `should run phytest loopback test on the tapeout config` | `IrisConfig(sim = false)`, serial TL at 100 MHz | the netlist's configuration | +| `should run phytest clocks test` | `IrisConfig(sim = true)` | | +| `should run phytest two-chip test` | two chips, `IrisConfig(sim = true)` | | + +### What simulation does not show + +- The lanes are the behavioral models (`includeDefaultModels`): a shift + register per lane, so nothing about a code, a termination or a delay setting + makes a lane fail. The AMS models in `ucie/verilog` are the tier for that. +- The harness clocks are fixed: an 8 GHz main bypass clock, a 500 MHz PHY test + bypass clock, an 800 MHz sideband bypass clock and a 100 MHz PLL reference. +- The observation bumps are only checked for toggling, not for what they carry. diff --git a/software/Makefile b/software/Makefile index 573ca08..55f5e46 100644 --- a/software/Makefile +++ b/software/Makefile @@ -36,7 +36,7 @@ VEC_ARCHFLAGS = -march=rv64gcv_zfh_zvfh -mabi=$(ABI) CFLAGS = -std=gnu99 -O2 -fno-common -fno-builtin-printf -Wall -specs=htif_nano.specs -Iinclude LDFLAGS = -specs=htif_nano.specs -PROGRAMS = hello hello0 hello1 router ring-hello ucie-loopback ucie-digital-loopback tacit-always tacit-dma ucie-vec-memcpy +PROGRAMS = hello hello0 hello1 router ring-hello ucie-loopback ucie-digital-loopback tacit-always tacit-dma ucie-vec-memcpy phytest-loopback phytest-clocks phytest-two-chip .DEFAULT_GOAL := default @@ -53,6 +53,10 @@ PROGRAMS = hello hello0 hello1 router ring-hello ucie-loopback ucie-digital-loop %.riscv: %.o $(GCC) $(LDFLAGS) $< -o $@ +# The PhyTest programs share their helpers through a header. Not ucie.h, +# which is phony: naming it would regenerate it on every build. +phytest-loopback.o phytest-clocks.o phytest-two-chip.o: phytest.h + ucie-vec-memcpy.o: ucie-vec-memcpy.c $(GCC) $(CFLAGS) $(VEC_ARCHFLAGS) -c $< -o $@ diff --git a/software/phytest-clocks.c b/software/phytest-clocks.c new file mode 100644 index 0000000..ef6e69e --- /dev/null +++ b/software/phytest-clocks.c @@ -0,0 +1,145 @@ +// PhyTest across the clock configurations bring-up moves through, on UCIe0 +// with its bumps looped back: the TX divider, each PLL under the main clock, +// the PHY test and sideband clocks off a PLL, and a PHY test clock too slow +// for the link, which the crossing flags have to report. +// +// Every move ends in `pt_setup`, which restarts the block on its new clocks, +// as bring-up does. + +#include "phytest.h" + +#define N_PACKETS 64 + +// `MainClkSel`, `PhyTestClkSrcSel` and the divider codes, from the clocking +// tile's interface. +#define MAIN_PLL8 0 +#define MAIN_PLL12 1 +#define MAIN_BYPASS 3 +#define TX_DIV1 0 +#define TX_DIV2 1 +#define TX_DIV4 2 +#define SRC_PLL8 0 +#define SRC_PLL12 1 +#define PHY_TEST_DIV8 4 +#define SB_DIV10 2 + +static void move_main_clk(uintptr_t base, uint64_t sel, uint64_t div) { + set_main_clk(base, sel, div); + pt_wait_clk_cfg(base); + pt_setup(base); +} + +// The packet clocks, TX and looped-back RX, from the clock meters. +static void check_packet_clocks(uintptr_t base, uint64_t mhz) { + pt_check_meter(base, UCIE_CLK_METER_TX_DIV, mhz, "TX divided"); + pt_check_meter(base, UCIE_CLK_METER_RX_DIV, mhz, "RX divided"); +} + +static void test_sideband_on_pll(uintptr_t base) { + // 800 MHz, /10 off PLL8. + pt_wr(base, UCIE_SB_CLK_SRC_SEL, SRC_PLL8); + pt_wr(base, UCIE_SB_CLK_DIV, SB_DIV10); + pt_wr(base, UCIE_SB_CLK_BYPASS_EN, 0); + apply_clk_cfg(base); + pt_wait_clk_cfg(base); + pt_setup(base); + const uint64_t packet = 0x5a5a00000000c10cULL; + pt_sb_send(base, packet); + uint64_t got; + if (pt_sb_recv(base, &got)) PT_CHECK_EQ("sideband packet off PLL8", got, packet); +} + +int main(void) { + const uintptr_t base = UCIE0_REG_BASE; + + pt_begin("ucie0", "bypass clock /1"); + pt_setup(base); + pt_check_meter(base, UCIE_CLK_METER_PHY_TEST, 500, "PHY test on its bypass pin"); + pt_check_meter(base, UCIE_CLK_METER_SB, 800, "sideband on its bypass pin"); + check_packet_clocks(base, 500); + pt_lfsr_check(base, N_PACKETS, "bypass /1"); + + pt_begin("ucie0", "bypass clock /2"); + move_main_clk(base, MAIN_BYPASS, TX_DIV2); + check_packet_clocks(base, 250); + pt_lfsr_check(base, N_PACKETS, "bypass /2"); + + pt_begin("ucie0", "bypass clock /4"); + move_main_clk(base, MAIN_BYPASS, TX_DIV4); + check_packet_clocks(base, 125); + pt_lfsr_check(base, N_PACKETS, "bypass /4"); + + // Both PLLs up, and the PHY test clock onto PLL8 /8, 1 GHz. The apply + // holds the PHY test clock's gate shut until PLL8 has locked. + pt_begin("ucie0", "PHY test clock onto PLL8 /8"); + use_internal_clk(base, SRC_PLL8, PHY_TEST_DIV8); + pt_wait_clk_cfg(base); + pt_wait_eq(base, UCIE_PLL_LOCK_OBSERVED, 3, "both PLLs to lock"); + pt_setup(base); + pt_check_meter(base, UCIE_CLK_METER_PHY_TEST, 1000, "PHY test on PLL8 /8"); + pt_lfsr_check(base, N_PACKETS, "PHY test clock on PLL8, main on bypass"); + + pt_begin("ucie0", "main clock onto PLL8 /1"); + move_main_clk(base, MAIN_PLL8, TX_DIV1); + check_packet_clocks(base, 500); + pt_lfsr_check(base, N_PACKETS, "main on PLL8 /1"); + + // The TX queue capped tighter than its reset value of 16, for the lowest + // latency, with the PHY test clock at twice the packet clock. The closer + // the two clocks, the more room a cap needs: at equal rates 8 runs the + // queue dry and 10 is the least that holds. + pt_begin("ucie0", "TX queue capped at 8 words"); + pt_wr(base, UCIE_TX_QUEUE_LIMIT, 8); + pt_lfsr_check(base, N_PACKETS, "TX queue capped at 8 words"); + pt_wr(base, UCIE_TX_QUEUE_LIMIT, 16); + + pt_begin("ucie0", "main clock onto PLL12 /1"); + move_main_clk(base, MAIN_PLL12, TX_DIV1); + check_packet_clocks(base, 750); + pt_lfsr_check(base, N_PACKETS, "main on PLL12 /1"); + + // The PHY test clock back onto its bypass pin, which the harness runs at + // 500 MHz, under 12 GHz lanes that move a word every 1.33 ns: the TX queue + // runs dry partway through the run, and its flag has to say so. The PHY end + // fills every word the queue does not have with an idle one, the forwarded + // clock running, so the looped-back RX still takes a word every packet + // clock, more than the PHY test clock can drain: its queue overflows too, + // and the two packet clocks meter the same. + pt_begin("ucie0", "PHY test clock too slow for the link"); + pt_wr(base, UCIE_PHY_TEST_CLK_BYPASS_EN, 1); + apply_clk_cfg(base); + pt_wait_clk_cfg(base); + pt_setup(base); + pt_set_seeds(base, pt_seed, pt_seed); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_wr(base, UCIE_TX_EXECUTE, 1); + pt_wait_eq(base, UCIE_TX_TEST_STATE, UCIE_TX_TEST_STATE_DONE, + "TX run to finish"); + pt_wait_cycles(1024); + PT_CHECK_EQ("TX test FIFO underflow with a slow PHY test clock", + pt_rd(base, UCIE_TX_TEST_FIFO_UNDERFLOW), 1); + PT_CHECK_EQ("RX test FIFO overflow with a slow PHY test clock", + pt_rd(base, UCIE_RX_TEST_FIFO_OVERFLOW), 1); + { + uint64_t tx = pt_meter_mhz(base, UCIE_CLK_METER_TX_DIV, PT_CHIP_MHZ); + uint64_t rx = pt_meter_mhz(base, UCIE_CLK_METER_RX_DIV, PT_CHIP_MHZ); + PT_CHECK(rx * 50 >= tx * 49 && rx * 50 <= tx * 51, + "RX packet clock %lu MHz, TX %lu MHz", rx, tx); + } + + // And back: a datapath reset on a fast enough clock clears both. + pt_begin("ucie0", "PHY test clock back onto PLL8 /8"); + pt_wr(base, UCIE_PHY_TEST_CLK_BYPASS_EN, 0); + apply_clk_cfg(base); + pt_wait_clk_cfg(base); + move_main_clk(base, MAIN_PLL8, TX_DIV1); + pt_lfsr_check(base, N_PACKETS, "after the slow PHY test clock"); + + pt_begin("ucie0", "sideband clock onto PLL8 /10"); + test_sideband_on_pll(base); + pt_check_meter(base, UCIE_CLK_METER_SB, 800, "sideband on PLL8 /10"); + PT_CHECK_EQ("PLL lock lost", pt_rd(base, UCIE_PLL_LOCK_LOST), 0); + + pt_finish("phytest-clocks"); + return 0; +} diff --git a/software/phytest-loopback.c b/software/phytest-loopback.c new file mode 100644 index 0000000..a13aad2 --- /dev/null +++ b/software/phytest-loopback.c @@ -0,0 +1,493 @@ +// PhyTest over every UCIe port, with each port's bumps looped back onto +// itself: the single-chip harness in simulation, or a loopback board. +// +// Each test leaves the registers it changed as `setup_ucie` left them, so +// they run in any order and any subset. + +#include "phytest.h" + +#define N_PACKETS 64 + +static uint64_t zero(int lane) { return 0; } + +// ===== LFSR ===== + +// At the TX queue's reset cap of 16 words, which on the Iris harness, with the +// PHY test clock at the packet clock, is where a cap has the least room. +static void test_lfsr(uintptr_t base) { + PT_CHECK_EQ("TX queue cap reset value", pt_rd(base, UCIE_TX_QUEUE_LIMIT), 16); + pt_set_seeds(base, pt_seed, pt_seed); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_go(base, N_PACKETS); + pt_check_errors(base, PT_MAINBAND_MASK, zero, "LFSR run"); + pt_check_fifo_flags(base, "LFSR run"); +} + +// One injected error on a data lane and one on track, counted exactly once +// each. Infinite, and read under `rxPauseCounters`, as a lab run would be. +static int inject_lane; +static uint64_t one_on_injected(int lane) { + return lane == inject_lane || lane == UCIE_TRACK_LANE; +} + +static void test_inject(uintptr_t base) { + pt_set_seeds(base, pt_seed, pt_seed); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, 0); + // A strobe before the run hits its first packet. + inject_lane = 3; + pt_wr(base, UCIE_TX_INJECT_LANE, inject_lane); + pt_wr(base, UCIE_TX_INJECT_ERROR, 1); + pt_go(base, 0); + pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, 16, "RX packets"); + pt_wr(base, UCIE_TX_INJECT_LANE, UCIE_TRACK_LANE); + pt_wr(base, UCIE_TX_INJECT_ERROR, 1); + uint64_t r = pt_rd(base, UCIE_RX_PACKETS_RECEIVED); + pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, r + 16, "RX packets"); + pt_wr(base, UCIE_RX_PAUSE_COUNTERS, 1); + pt_wait_cycles(64); + pt_check_errors(base, PT_MAINBAND_MASK, one_on_injected, "injected errors"); + pt_wr(base, UCIE_RX_PAUSE_COUNTERS, 0); + pt_wr(base, UCIE_TX_INJECT_LANE, 0); + reset_fsms(base); +} + +// Scored against its own history with the RX seeds wrong on every lane. +static uint64_t wrong_seed(int lane) { return pt_seed(lane + 7); } + +static void test_self_sync(uintptr_t base) { + pt_set_seeds(base, pt_seed, wrong_seed); + pt_wr(base, UCIE_RX_SELF_SYNC, 1); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_go(base, N_PACKETS); + pt_check_errors(base, PT_MAINBAND_MASK, zero, "self-synchronized run"); + // The early count is still the seeded check, so it sees the wrong seeds. + PT_CHECK(pt_errors_early(base, 0) > 0, + "seeded early count read clean against the wrong seed"); + pt_wr(base, UCIE_RX_SELF_SYNC, 0); +} + +// Valid moved onto track at both ends, the workaround for a broken valid +// lane. Track then carries valid and is scored against it. +static void test_valid_on_track(uintptr_t base) { + pt_set_seeds(base, pt_seed, pt_seed); + pt_wr(base, UCIE_TX_VALID_LANE_SEL, UCIE_TRACK_VALID_LANE_SEL); + pt_wr(base, UCIE_RX_VALID_LANE_SEL, UCIE_TRACK_VALID_LANE_SEL); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_go(base, N_PACKETS); + pt_check_errors(base, PT_MAINBAND_MASK, zero, "valid on track"); + pt_wr(base, UCIE_TX_VALID_LANE_SEL, UCIE_DEFAULT_VALID_LANE_SEL); + pt_wr(base, UCIE_RX_VALID_LANE_SEL, UCIE_DEFAULT_VALID_LANE_SEL); +} + +// Bursts with the forwarded clock gated between them, the way the UCIe +// controller parks it. The RX lanes only deserialize while clock edges +// arrive, so this is the real receiver stopping and restarting. +// UCIe's clock gating at the reset values: no preamble and a packet of +// postamble, parked high and low in turn, then always low. A packet is enough +// once the RX dividers have been realigned behind the parked clock and one 40 +// UI gap has moved the RX word boundary so that every burst ends 23 UI into +// an RX word (ucie/docs/phytest_bringup.md, section 8). With no preamble, the +// first edge after a park has to sample the burst's first data UI, so the +// forwarded clock is centred for this test and put back after it. +static void test_gated_bursts(uintptr_t base) { + const uint64_t n = 24; + const uint64_t phase = pt_rd(base, UCIE_CLK_PHASE_SEL); + PT_CHECK_EQ("preamble reset value", pt_rd(base, UCIE_TX_CLK_PREAMBLE), 0); + PT_CHECK_EQ("postamble reset value", pt_rd(base, UCIE_TX_CLK_POSTAMBLE), + 32 / UCIE_CLK_POSTAMBLE_UI); + PT_CHECK_EQ("park alternation reset value", + pt_rd(base, UCIE_TX_CLK_PARK_ALTERNATE), 1); + pt_set_seeds(base, pt_seed, pt_seed); + pt_wr(base, UCIE_RX_BURST_MODE, 1); + for (int alternate = 1; alternate >= 0; alternate--) { + pt_wr(base, UCIE_TX_CLK_PARK_ALTERNATE, alternate); + // Gated only after `pt_arm`: its RX datapath reset needs clock edges to + // release. Then the dividers realigned behind the parked clock, so the + // next burst's first edge samples its first data UI. + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, 1); + pt_wr(base, UCIE_TX_CLK_GATE, 1); + pt_wait_cycles(256); + set_clk_en(base, 0); + set_rx_clk_en(base, 0); + set_global_delay(base, PT_CENTRED_DELAY_TAPS); + reset_dividers(base); + set_clk_en(base, 1); + set_rx_clk_en(base, 1); + pt_wr(base, UCIE_TX_CLK_POSTAMBLE, 40 / UCIE_CLK_POSTAMBLE_UI); + pt_go(base, 1); + pt_wr(base, UCIE_TX_CLK_POSTAMBLE, 32 / UCIE_CLK_POSTAMBLE_UI); + + // The bursts. A clock that runs or parks for whole packets moves no word + // boundary, so the FSMs can reset on a running clock in between. + pt_wr(base, UCIE_TX_CLK_GATE, 0); + pt_wr(base, UCIE_TX_BURST_PACKETS, 6); + pt_wr(base, UCIE_TX_IDLE_PACKETS, 10); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, n); + pt_wr(base, UCIE_TX_CLK_GATE, 1); + pt_wait_cycles(256); + uint64_t w0 = pt_rd(base, UCIE_RX_IDLE_WORDS_OBSERVED); + pt_wait_cycles(1024); + PT_CHECK_EQ("idle words with the clock parked", + pt_rd(base, UCIE_RX_IDLE_WORDS_OBSERVED), w0); + pt_go(base, n); + const char *what = + alternate ? "gated bursts, parking high and low" : "gated bursts"; + pt_check_errors(base, PT_MAINBAND_MASK, zero, what); + pt_check_fifo_flags(base, what); + pt_wr(base, UCIE_TX_CLK_GATE, 0); + pt_wr(base, UCIE_TX_BURST_PACKETS, 0); + pt_wr(base, UCIE_TX_IDLE_PACKETS, 0); + } + pt_wr(base, UCIE_TX_CLK_PARK_ALTERNATE, 1); + pt_wr(base, UCIE_RX_BURST_MODE, 0); + set_clk_en(base, 0); + set_rx_clk_en(base, 0); + pt_wr(base, UCIE_CLK_PHASE_SEL, phase); + reset_dividers(base); + set_clk_en(base, 1); + set_rx_clk_en(base, 1); + reset_fsms(base); +} + +// ===== Manual patterns and the capture SRAM ===== + +#define PERIOD 5 +static const int checked_lanes[] = {0, 9, UCIE_TRACK_LANE - 3, UCIE_VALID_LANE, + UCIE_TRACK_LANE}; +#define N_CHECKED (sizeof(checked_lanes) / sizeof(checked_lanes[0])) + +static void check_capture(uintptr_t base, int first, const char *what) { + for (unsigned i = 0; i < N_CHECKED; i++) { + int lane = checked_lanes[i]; + for (int e = 0; e < UCIE_SRAM_PACKETS; e++) { + uint32_t got = pt_captured(base, lane, e); + uint32_t want = pt_pattern_word((first + e) % PERIOD, lane); + PT_CHECK(got == want, "%s: lane %d entry %d read 0x%x, sent 0x%x", what, + lane, e, got, want); + } + } +} + +static void test_manual_capture(uintptr_t base) { + reset_fsms(base); + pt_load_pattern(base, PERIOD, pt_pattern_word); + pt_arm(base, UCIE_TX_TEST_MODE_MANUAL, UCIE_SRAM_PACKETS); + pt_go(base, UCIE_SRAM_PACKETS); + check_capture(base, 0, "manual capture"); + + // From packet `start` on, past the first lap of the SRAM. + const int start = UCIE_SRAM_PACKETS + 7; + pt_wr(base, UCIE_RX_CAPTURE_START, start); + pt_arm(base, UCIE_TX_TEST_MODE_MANUAL, start + UCIE_SRAM_PACKETS); + pt_go(base, start + UCIE_SRAM_PACKETS); + check_capture(base, start, "capture start"); + pt_wr(base, UCIE_RX_CAPTURE_START, 0); + pt_wr(base, UCIE_TX_MANUAL_REPEAT_PERIOD, 0); +} + +// An error-triggered capture: two lanes carry the same stream, so one shows +// what the other should have received, and the SRAM has to hold exactly the +// one flipped bit. +#define TWIN 0 +#define VICTIM 1 +static uint64_t twin_seed(int lane) { + return pt_seed(lane == VICTIM ? TWIN : lane); +} +static uint64_t one_on_victim(int lane) { return lane == VICTIM; } + +static void test_error_capture(uintptr_t base) { + const uint64_t post = 4; + pt_set_seeds(base, twin_seed, twin_seed); + pt_wr(base, UCIE_RX_CAPTURE_MODE, UCIE_CAPTURE_MODE_ERROR); + pt_wr(base, UCIE_RX_CAPTURE_POST_TRIGGER, post); + pt_wr(base, UCIE_RX_TRIGGER_LANE_MASK, PT_ALL_LANES_MASK); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, 0); + pt_go(base, 0); + pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, 2 * UCIE_SRAM_PACKETS, + "RX packets"); + PT_CHECK_EQ("triggered before any error", + pt_rd(base, UCIE_RX_CAPTURE_TRIGGERED), 0); + // Read before the strobe: the injected packet can arrive before a read + // issued after it returns. + uint64_t r = pt_rd(base, UCIE_RX_PACKETS_RECEIVED); + pt_wr(base, UCIE_TX_INJECT_LANE, VICTIM); + pt_wr(base, UCIE_TX_INJECT_ERROR, 1); + pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, r + 2 * UCIE_SRAM_PACKETS, + "RX packets"); + pt_wr(base, UCIE_RX_PAUSE_COUNTERS, 1); + if (pt_wait_eq(base, UCIE_RX_CAPTURE_TRIGGERED, 1, "capture trigger")) { + uint64_t t = pt_rd(base, UCIE_RX_CAPTURE_TRIGGER_PACKET); + PT_CHECK(t >= r, "trigger packet %lu is before the injection at %lu", t, r); + for (int e = 0; e < UCIE_SRAM_PACKETS; e++) { + uint32_t diff = pt_captured(base, TWIN, e) ^ pt_captured(base, VICTIM, e); + uint32_t want = (uint64_t)e == t % UCIE_SRAM_PACKETS ? 1 : 0; + PT_CHECK(diff == want, "entry %d: twin lanes differ by 0x%x, expected 0x%x", + e, diff, want); + } + } + pt_check_errors(base, PT_MAINBAND_MASK, one_on_victim, "error capture run"); + pt_wr(base, UCIE_RX_PAUSE_COUNTERS, 0); + pt_wr(base, UCIE_RX_CAPTURE_MODE, UCIE_CAPTURE_MODE_FIRST); + pt_wr(base, UCIE_RX_CAPTURE_POST_TRIGGER, 0); + pt_wr(base, UCIE_RX_TRIGGER_LANE_MASK, 0); + pt_wr(base, UCIE_TX_INJECT_LANE, 0); + reset_fsms(base); +} + +// The RX starting on whatever arrives, with nothing on valid. +static void test_immediate_start(uintptr_t base) { + pt_wr(base, UCIE_RX_DATA_MODE, UCIE_DATA_MODE_INFINITE); + reset_fsms(base); + pt_wait_cycles(512); + PT_CHECK_EQ("packets with the TX idle", pt_rd(base, UCIE_RX_PACKETS_RECEIVED), + 0); + pt_wr(base, UCIE_RX_START_MODE, UCIE_RX_START_MODE_IMMEDIATE); + pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, 8, "immediate-start packets"); + pt_wr(base, UCIE_RX_START_MODE, UCIE_RX_START_MODE_VALID); + reset_fsms(base); +} + +// ===== Track ===== + +static void count_track(uintptr_t base, uint64_t word, uint64_t *ones, + uint64_t *zeros, uint64_t *even) { + pt_wr(base, UCIE_TX_TRACK_WORD, word); + pt_wait_cycles(256); + pt_wr(base, UCIE_TRACK_CNT_RST, 1); + pt_wait_cycles(2048); + pt_wr(base, UCIE_TRACK_CNT_HOLD, 1); + pt_wait_cycles(64); + *ones = pt_rd(base, UCIE_TRACK_ONES); + *zeros = pt_rd(base, UCIE_TRACK_ZEROS); + *even = pt_rd(base, UCIE_TRACK_ONES_EVEN); + pt_wr(base, UCIE_TRACK_CNT_HOLD, 0); +} + +static void test_track(uintptr_t base) { + uint64_t ones, zeros, even; + pt_wr(base, UCIE_TX_TRACK_CLK, 1); + // Sixteen ones in a row: half on even UIs whatever the RX word boundary. + count_track(base, 0x0000ffffULL, &ones, &zeros, &even); + PT_CHECK(ones > 0 && ones == zeros && 2 * even == ones, + "track 0x0000ffff: ones %lu zeros %lu even ones %lu", ones, zeros, + even); + // A clock: every one on an even UI, or every one on an odd UI. + count_track(base, UCIE_DEFAULT_TRACK, &ones, &zeros, &even); + PT_CHECK(ones > 0 && ones == zeros && (even == ones || even == 0), + "track clock: ones %lu zeros %lu even ones %lu", ones, zeros, even); + printf("[%s] track clock lands on %s UIs\n", pt_port, + even == ones ? "even" : "odd"); + pt_wr(base, UCIE_TX_TRACK_CLK, 0); + pt_wr(base, UCIE_TX_TRACK_WORD, 0); +} + +// ===== Loopback lane, debug lane, sideband ===== + +static uint32_t loopback_word(int row, int lane) { + // Bit 0 set on the first row: the RX frames on the first one. + if (lane == UCIE_LOOPBACK_LANE) return ((uint32_t)(row + 1) * 0x9e3779b9u) | 1; + return 0; +} + +static void test_loopback_lane(uintptr_t base) { + const int n = 2 * UCIE_SRAM_PACKETS; + reset_fsms(base); + pt_load_pattern(base, PERIOD, loopback_word); + pt_wr(base, UCIE_TEST_TARGET, UCIE_TEST_TARGET_LOOPBACK); + // Every target change needs a datapath reset; `reset_fsms` does one. + pt_wr(base, UCIE_TX_TEST_MODE, UCIE_TX_TEST_MODE_MANUAL); + pt_wr(base, UCIE_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); + pt_wr(base, UCIE_RX_DATA_MODE, UCIE_DATA_MODE_FINITE); + pt_wr(base, UCIE_TX_PACKETS_TO_SEND, n); + pt_wr(base, UCIE_RX_PACKETS_TO_RECEIVE, n); + reset_fsms(base); + pt_wait_cycles(256); + pt_go(base, n); + for (int e = 0; e < UCIE_SRAM_PACKETS; e++) { + uint32_t got = pt_captured(base, UCIE_LOOPBACK_LANE, e); + uint32_t want = loopback_word(e % PERIOD, UCIE_LOOPBACK_LANE); + PT_CHECK(got == want, "loopback lane entry %d read 0x%x, sent 0x%x", e, got, + want); + } + PT_CHECK_EQ("loopback RX FIFO overflow", + pt_rd(base, UCIE_LOOPBACK_RX_FIFO_OVERFLOW), 0); + PT_CHECK_EQ("loopback TX FIFO underflow", + pt_rd(base, UCIE_LOOPBACK_TX_FIFO_UNDERFLOW), 0); + pt_wr(base, UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); + pt_wr(base, UCIE_TX_MANUAL_REPEAT_PERIOD, 0); + reset_fsms(base); +} + +// The observation bumps, which `setup_ucie` leaves off: on for this test +// alone, with something on each -- the TX data debug lane running, the clock +// mux on the TX divided clock, and traffic on the RX lane `rxData` watches. +// The simulation harness checks every bump moved; on the bench, this is when +// to look with a scope. The debug lane only drives a bump, so from here all +// that can be checked is that it runs to completion without starving. +static void test_observation(uintptr_t base) { + enable_debug_drivers(base, 1); + pt_wr(base, UCIE_DEBUG_CLK_MUX_SEL, 1); + pt_wr(base, UCIE_DEBUG_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); + pt_wr(base, UCIE_DEBUG_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); + pt_wr(base, UCIE_DEBUG_TX_PACKETS_TO_SEND, N_PACKETS); + pt_wr(base, UCIE_DEBUG_TX_FSM_RST, 1); + pt_wr(base, UCIE_DEBUG_TX_EXECUTE, 1); + pt_wait_eq(base, UCIE_DEBUG_TX_TEST_STATE, UCIE_TX_TEST_STATE_DONE, + "debug TX run"); + PT_CHECK_EQ("debug TX packets sent", pt_rd(base, UCIE_DEBUG_TX_PACKETS_SENT), + N_PACKETS); + PT_CHECK_EQ("debug TX FIFO underflow", + pt_rd(base, UCIE_TX_DEBUG_FIFO_UNDERFLOW), 0); + pt_wr(base, UCIE_DEBUG_TX_FSM_RST, 1); + pt_lfsr_check(base, N_PACKETS, "LFSR run with the observation drivers on"); + pt_wr(base, UCIE_DEBUG_CLK_MUX_SEL, 0); + enable_debug_drivers(base, 0); +} + +// ===== Per-lane sources and error diagnostics ===== + +#define FIXED_LANE 5 +#define INVERTED_LANE 7 + +static void set_lane_sources(uintptr_t base, int tx, int rx, uint64_t fixed, + uint64_t inverted, uint64_t word) { + if (tx) { + pt_wr(base, UCIE_TX_LANE_FIXED, fixed); + pt_wr(base, UCIE_TX_LANE_INVERT, inverted); + pt_wr(base, UCIE_TX_FIXED_WORD, word); + } + if (rx) { + pt_wr(base, UCIE_RX_LANE_FIXED, fixed); + pt_wr(base, UCIE_RX_LANE_INVERT, inverted); + pt_wr(base, UCIE_RX_FIXED_WORD, word); + } +} + +static uint64_t err_class_sum(uintptr_t base, int rise) { + return rise ? pt_rd(base, UCIE_RX_ERR_RISE_ONE) + + pt_rd(base, UCIE_RX_ERR_RISE_ZERO) + : pt_rd(base, UCIE_RX_ERR_FALL_ONE) + + pt_rd(base, UCIE_RX_ERR_FALL_ZERO); +} + +static uint64_t err_positions(uintptr_t base, int lane) { + pt_wr(base, UCIE_RX_ERR_POS_LANE, lane); + return pt_rd(base, UCIE_RX_ERR_POS_MASK); +} + +// Victims and aggressors: one lane held at a static level, one inverted, +// clean when the RX expects the same; then the inverted lane read as its +// plain stream, which gets every bit wrong, half on each sampling edge. +static void test_lane_sources(uintptr_t base) { + const uint64_t fixed = 1ULL << FIXED_LANE; + const uint64_t inverted = (1ULL << INVERTED_LANE) | (1ULL << UCIE_TRACK_LANE); + set_lane_sources(base, 1, 1, fixed, inverted, 0); + pt_lfsr_check(base, N_PACKETS, "fixed and inverted lanes, RX matching"); + PT_CHECK_EQ("lanes flagged errored", pt_rd(base, UCIE_RX_LANE_ERRORED), 0); + + set_lane_sources(base, 0, 1, fixed, 1ULL << UCIE_TRACK_LANE, 0); + pt_wr(base, UCIE_RX_ERR_CLASS_LANE, INVERTED_LANE); + pt_set_seeds(base, pt_seed, pt_seed); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_go(base, N_PACKETS); + PT_CHECK_EQ("errors on the inverted lane read plain", + pt_errors(base, INVERTED_LANE), 32 * N_PACKETS); + PT_CHECK_EQ("those errors on rising-edge UIs", err_class_sum(base, 1), + 16 * N_PACKETS); + PT_CHECK_EQ("those errors on falling-edge UIs", err_class_sum(base, 0), + 16 * N_PACKETS); + PT_CHECK_EQ("lanes flagged errored", pt_rd(base, UCIE_RX_LANE_ERRORED), + 1ULL << INVERTED_LANE); + PT_CHECK_EQ("error positions on the inverted lane", + err_positions(base, INVERTED_LANE), 0xffffffffULL); + set_lane_sources(base, 1, 1, 0, 0, 0); + pt_wr(base, UCIE_RX_ERR_CLASS_LANE, 0); +} + +// One injected error, found by lane, by UI and as exactly one classified +// error. Which edge it lands on depends on where the RX framed. +static void test_error_location(uintptr_t base) { + const int lane = 3; + pt_set_seeds(base, pt_seed, pt_seed); + pt_wr(base, UCIE_RX_ERR_CLASS_LANE, lane); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_wr(base, UCIE_TX_INJECT_LANE, lane); + pt_wr(base, UCIE_TX_INJECT_ERROR, 1); + pt_go(base, N_PACKETS); + PT_CHECK_EQ("injected error count", pt_errors(base, lane), 1); + PT_CHECK_EQ("lanes flagged errored", pt_rd(base, UCIE_RX_LANE_ERRORED), + 1ULL << lane); + // Bit 0 of the packet, the bit injection flips. + PT_CHECK_EQ("error positions", err_positions(base, lane), 1); + PT_CHECK_EQ("classified errors", + err_class_sum(base, 1) + err_class_sum(base, 0), 1); + pt_wr(base, UCIE_RX_ERR_CLASS_LANE, 0); + pt_wr(base, UCIE_TX_INJECT_LANE, 0); +} + +// The clock meters, which read the harness's clocks: an 8 GHz main clock +// (500 MHz packet clocks), and the PHY test and sideband clocks on their +// bypass pins at 500 and 800 MHz. +static void test_meters(uintptr_t base) { + pt_check_meter(base, UCIE_CLK_METER_PHY_TEST, 500, "PHY test"); + pt_check_meter(base, UCIE_CLK_METER_SB, 800, "sideband"); + pt_check_meter(base, UCIE_CLK_METER_TX_DIV, 500, "TX divided"); + pt_check_meter(base, UCIE_CLK_METER_RX_DIV, 500, "RX divided"); + PT_CHECK_EQ("controller RX FIFO overflow", + pt_rd(base, UCIE_CONTROLLER_RX_FIFO_OVERFLOW), 0); + PT_CHECK_EQ("PLL lock lost", pt_rd(base, UCIE_PLL_LOCK_LOST), 0); +} + +static void test_sideband(uintptr_t base) { + const uint64_t packets[] = {0x0123456789abcdefULL, 0xfedcba9876543210ULL}; + pt_sb_reset(base); + for (int i = 0; i < 2; i++) pt_sb_send(base, packets[i]); + for (int i = 0; i < 2; i++) { + uint64_t got; + if (pt_sb_recv(base, &got)) PT_CHECK_EQ("sideband packet", got, packets[i]); + } + pt_wait_cycles(64); + PT_CHECK_EQ("sideband RX empty", pt_rd(base, UCIE_SB_RX_VALID), 0); + PT_CHECK_EQ("sideband RX overflow", pt_rd(base, UCIE_SB_RX_OVERFLOW), 0); +} + +typedef struct { + const char *name; + void (*fn)(uintptr_t); +} test_t; + +static const test_t tests[] = { + {"clock meters", test_meters}, + {"LFSR run", test_lfsr}, + {"error injection", test_inject}, + {"self-synchronized check", test_self_sync}, + {"valid moved onto track", test_valid_on_track}, + {"gated-clock bursts", test_gated_bursts}, + {"manual pattern and capture", test_manual_capture}, + {"error-triggered capture", test_error_capture}, + {"immediate start", test_immediate_start}, + {"track counters", test_track}, + {"loopback lane", test_loopback_lane}, + {"per-lane pattern sources", test_lane_sources}, + {"error location and class", test_error_location}, + {"observation bumps and the TX debug lane", test_observation}, + {"sideband", test_sideband}, +}; + +int main(void) { + const struct { + const char *name; + uintptr_t base; + } ports[] = {{"ucie0", UCIE0_REG_BASE}, {"ucie1", UCIE1_REG_BASE}}; + + for (int p = 0; p < 2; p++) { + pt_begin(ports[p].name, "setup"); + pt_setup(ports[p].base); + for (unsigned t = 0; t < sizeof(tests) / sizeof(tests[0]); t++) { + pt_begin(ports[p].name, tests[t].name); + tests[t].fn(ports[p].base); + } + } + pt_finish("phytest-loopback"); + return 0; +} diff --git a/software/phytest-two-chip.c b/software/phytest-two-chip.c new file mode 100644 index 0000000..d13f529 --- /dev/null +++ b/software/phytest-two-chip.c @@ -0,0 +1,107 @@ +// PhyTest between two chips, each running this program, with UCIe1 of each +// wired to UCIe0 of the other: the two-chip ring in simulation, or two +// chips on a package. +// +// Each direction is tested in its own phase. A chip only starts a TX once +// the partner has said, over the sideband of the same link, that the RX it +// feeds is armed, so the two programs need nothing else to keep in step: +// not a shared clock, not a host, not matching code timing. +// +// my UCIe1 TX --> partner UCIe0 RX my UCIe0 sideband --> partner UCIe1 +// my UCIe0 TX --> partner UCIe1 RX my UCIe1 sideband --> partner UCIe0 + +#include "phytest.h" + +#define N_PACKETS 64 +#define PERIOD 5 +#define N_MANUAL (8 * PERIOD) + +#define ARMED(phase) (0x5054000041524d00ULL | (phase)) + +// Tells the partner, on the sideband of `rx`'s link, that `rx` is armed, and +// waits on the sideband of `tx`'s link for the partner to say the same of +// the RX that `tx` feeds. +static int handshake(uintptr_t rx, uintptr_t tx, uint64_t phase) { + pt_sb_send(rx, ARMED(phase)); + uint64_t got; + if (!pt_sb_recv(tx, &got)) return 0; + PT_CHECK_EQ("partner's armed message", got, ARMED(phase)); + return got == ARMED(phase); +} + +// One direction: an LFSR run from `tx` here to the partner, while `rx` here +// takes the partner's run the same way round. +static void lfsr_phase(uintptr_t tx, uintptr_t rx, uintptr_t idle_rx, + uint64_t phase, const char *what) { + pt_set_seeds(tx, pt_seed, pt_seed); + pt_set_seeds(rx, pt_seed, pt_seed); + pt_arm(rx, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + pt_arm(tx, UCIE_TX_TEST_MODE_LFSR, N_PACKETS); + if (!handshake(rx, tx, phase)) return; + pt_wr(tx, UCIE_TX_EXECUTE, 1); + pt_wait_eq(tx, UCIE_TX_TEST_STATE, UCIE_TX_TEST_STATE_DONE, "TX run"); + pt_wait_ge(rx, UCIE_RX_PACKETS_RECEIVED, N_PACKETS, "RX packets"); + PT_CHECK_EQ("RX packets received", pt_rd(rx, UCIE_RX_PACKETS_RECEIVED), + N_PACKETS); + pt_check_errors(rx, PT_MAINBAND_MASK, pt_zero, what); + pt_check_fifo_flags(rx, what); + pt_check_fifo_flags(tx, what); + // The other link carried nothing this phase, so its RX framed nothing: + // each RX hears only the TX it is wired to. + PT_CHECK_EQ("packets on the link with no traffic", + pt_rd(idle_rx, UCIE_RX_PACKETS_RECEIVED), 0); +} + +// The reference the RX scores against: the partner's pattern, with one word +// wrong by two bits on purpose, so the check has to find exactly those. +#define WRONG_ROW 3 +#define WRONG_LANE 2 +static uint32_t reference_word(int row, int lane) { + uint32_t w = pt_pattern_word(row, lane); + return row == WRONG_ROW && lane == WRONG_LANE ? w ^ 0x5 : w; +} +static uint64_t manual_errors(int lane) { + return lane == WRONG_LANE ? 2 * (N_MANUAL / PERIOD) : 0; +} + +// A manual pattern from UCIe1 here, scored by the partner's UCIe0 against +// the copy in its own TX pattern SRAM. +static void manual_check_phase(uintptr_t tx, uintptr_t rx, uint64_t phase) { + reset_fsms(tx); + reset_fsms(rx); + pt_load_pattern(tx, PERIOD, pt_pattern_word); + pt_load_pattern(rx, PERIOD, reference_word); + pt_wr(rx, UCIE_RX_MANUAL_CHECK, 1); + pt_arm(rx, UCIE_TX_TEST_MODE_MANUAL, N_MANUAL); + pt_arm(tx, UCIE_TX_TEST_MODE_MANUAL, N_MANUAL); + if (handshake(rx, tx, phase)) { + pt_wr(tx, UCIE_TX_EXECUTE, 1); + pt_wait_eq(tx, UCIE_TX_TEST_STATE, UCIE_TX_TEST_STATE_DONE, "TX run"); + pt_wait_ge(rx, UCIE_RX_PACKETS_RECEIVED, N_MANUAL, "RX packets"); + pt_wait_cycles(256); + pt_check_errors(rx, PT_MAINBAND_MASK, manual_errors, "manual pattern check"); + } + pt_wr(rx, UCIE_RX_MANUAL_CHECK, 0); + pt_wr(rx, UCIE_TX_MANUAL_REPEAT_PERIOD, 0); + pt_wr(tx, UCIE_TX_MANUAL_REPEAT_PERIOD, 0); +} + +int main(void) { + const uintptr_t u0 = UCIE0_REG_BASE, u1 = UCIE1_REG_BASE; + + pt_begin("both", "setup"); + pt_setup(u0); + pt_setup(u1); + + pt_begin("ucie1->partner ucie0", "LFSR"); + lfsr_phase(u1, u0, u1, 1, "LFSR into ucie0"); + + pt_begin("ucie0->partner ucie1", "LFSR"); + lfsr_phase(u0, u1, u0, 2, "LFSR into ucie1"); + + pt_begin("ucie1->partner ucie0", "manual pattern check"); + manual_check_phase(u1, u0, 3); + + pt_finish("phytest-two-chip"); + return 0; +} diff --git a/software/phytest.h b/software/phytest.h new file mode 100644 index 0000000..6a64837 --- /dev/null +++ b/software/phytest.h @@ -0,0 +1,330 @@ +// PhyTest bring-up helpers, on top of the generated ucie.h. +// +// Written for the lab as much as for simulation: every wait is bounded, and +// every check prints what it expected and what it read instead of stopping, +// so one run reports everything that is wrong. A program calls +// `pt_finish()` at the end, which exits nonzero if any check failed. + +#ifndef __PHYTEST_H__ +#define __PHYTEST_H__ + +#include +#include +#include +#include +#include "mmio.h" +#include "ucie.h" + +#define UCIE0_REG_BASE 0x200000UL +#define UCIE1_REG_BASE 0x208000UL + +// Lane groups of four lanes each in the TX pattern SRAM. +#define PT_LANE_GROUPS ((UCIE_NUM_TEST_LANES + 3) / 4) +// The mainband lanes a run scores: the data lanes, valid and track. The +// loopback lane is only scored with `UCIE_TEST_TARGET_LOOPBACK`. +#define PT_MAINBAND_LANES (UCIE_TRACK_LANE + 1) +#define PT_ALL_LANES_MASK ((1ULL << UCIE_NUM_TEST_LANES) - 1) + +// Bounds on every wait, in core cycles. Generous: on silicon an MMIO read is +// quick next to a slow divided clock, so a bound counted in reads is not. +#define PT_TIMEOUT 2000000ULL + +// The chip clock the UCIe clock register block runs on, in MHz: the rate the +// clock meters count against. 500 MHz on Iris out of reset. +#ifndef PT_CHIP_MHZ +#define PT_CHIP_MHZ 500ULL +#endif + +// Global delay taps that centre the forwarded clock on the data of a +// looped-back link at 16 GT/s on the Iris harness, as the UCIe repo's tests +// and `setup_ucie_digital` use. Out of reset the line is at its longest, which +// is fine for a free-running clock but samples a gated burst's first data UI +// with no edge. On silicon, override it with the code mainband training finds. +#ifndef PT_CENTRED_DELAY_TAPS +#define PT_CENTRED_DELAY_TAPS 29ULL +#endif + +static int pt_failures = 0; +static const char *pt_port = ""; + +#define PT_CHECK(cond, ...) \ + do { \ + if (!(cond)) { \ + printf("FAIL [%s] %s:%d: ", pt_port, __FILE__, __LINE__); \ + printf(__VA_ARGS__); \ + printf("\n"); \ + pt_failures++; \ + } \ + } while (0) + +#define PT_CHECK_EQ(what, got, want) \ + do { \ + uint64_t _g = (got), _w = (want); \ + PT_CHECK(_g == _w, "%s: read 0x%lx, expected 0x%lx", (what), _g, _w); \ + } while (0) + +static inline uint64_t pt_rd(uintptr_t base, uint64_t reg) { + return reg_read64(base + reg); +} + +static inline void pt_wr(uintptr_t base, uint64_t reg, uint64_t v) { + reg_write64(base + reg, v); +} + +static inline void pt_wait_cycles(uint64_t n) { + uint64_t start = rdcycle(); + while (rdcycle() - start < n) { + } +} + +// Polls `reg` until it reads at least `want`. Returns whether it got there. +static inline int pt_wait_ge(uintptr_t base, uint64_t reg, uint64_t want, + const char *what) { + uint64_t start = rdcycle(); + uint64_t v; + while ((v = pt_rd(base, reg)) < want) { + if (rdcycle() - start > PT_TIMEOUT) { + PT_CHECK(0, "timed out waiting for %s: read %lu, wanted %lu", what, v, + want); + return 0; + } + } + return 1; +} + +static inline int pt_wait_eq(uintptr_t base, uint64_t reg, uint64_t want, + const char *what) { + uint64_t start = rdcycle(); + uint64_t v; + while ((v = pt_rd(base, reg)) != want) { + if (rdcycle() - start > PT_TIMEOUT) { + PT_CHECK(0, "timed out waiting for %s: read 0x%lx, wanted 0x%lx", what, + v, want); + return 0; + } + } + return 1; +} + +// Waits for the RX to hand over `n` more idle words than it had: the RX +// datapath is out of reset, and a forwarded clock is arriving. The counter is +// 32 bits and free running, so the difference is taken modulo that. +static inline int pt_wait_idle_words(uintptr_t base, uint32_t n) { + uint32_t w0 = (uint32_t)pt_rd(base, UCIE_RX_IDLE_WORDS_OBSERVED); + uint64_t start = rdcycle(); + while ((uint32_t)((uint32_t)pt_rd(base, UCIE_RX_IDLE_WORDS_OBSERVED) - w0) < + n) { + if (rdcycle() - start > PT_TIMEOUT) { + PT_CHECK(0, "no idle words arriving: RX datapath held, or no clock"); + return 0; + } + } + return 1; +} + +// Waits for the clocking block to finish an apply. +static inline int pt_wait_clk_cfg(uintptr_t base) { + return pt_wait_eq(base, UCIE_CLK_CFG_BUSY, 0, "clock config apply"); +} + +// ===== Seeds ===== + +// Distinct per lane, so a lane scored against another lane's reference, or +// two lanes swapped anywhere between the TX and the RX, reads as errors. +static inline uint64_t pt_seed(int lane) { + return UCIE_TRAIN_LFSR_SEED + (uint64_t)lane * 0x1111ULL; +} + +static inline void pt_set_seeds(uintptr_t base, uint64_t (*tx)(int), + uint64_t (*rx)(int)) { + for (int lane = 0; lane < UCIE_NUM_TEST_LANES; lane++) { + pt_wr(base, UCIE_TX_LFSR_SEED + lane * UCIE_TX_LFSR_SEED_WIDTH, tx(lane)); + pt_wr(base, UCIE_RX_LFSR_SEED + lane * UCIE_RX_LFSR_SEED_WIDTH, rx(lane)); + } +} + +// ===== Error counts ===== + +static inline uint64_t pt_errors(uintptr_t base, int lane) { + return pt_rd(base, UCIE_RX_BIT_ERRORS + lane * UCIE_RX_BIT_ERRORS_WIDTH); +} + +static inline uint64_t pt_errors_early(uintptr_t base, int lane) { + return pt_rd(base, + UCIE_RX_BIT_ERRORS_EARLY + lane * UCIE_RX_BIT_ERRORS_EARLY_WIDTH); +} + +// Checks the nominal count of every lane in `mask` against `want(lane)`. +static inline void pt_check_errors(uintptr_t base, uint64_t mask, + uint64_t (*want)(int), const char *what) { + for (int lane = 0; lane < UCIE_NUM_TEST_LANES; lane++) { + if (!((mask >> lane) & 1)) continue; + uint64_t got = pt_errors(base, lane), w = want ? want(lane) : 0; + PT_CHECK(got == w, "%s: lane %d counted %lu errors, expected %lu", what, + lane, got, w); + } +} + +#define PT_MAINBAND_MASK ((1ULL << PT_MAINBAND_LANES) - 1) + +// The crossings between the PHY test clock and the lane clocks. Either flag +// set means words were dropped, which reads like bit errors. +static inline void pt_check_fifo_flags(uintptr_t base, const char *what) { + PT_CHECK(pt_rd(base, UCIE_TX_TEST_FIFO_UNDERFLOW) == 0, + "%s: TX test FIFO underflowed", what); + PT_CHECK(pt_rd(base, UCIE_RX_TEST_FIFO_OVERFLOW) == 0, + "%s: RX test FIFO overflowed", what); +} + +// ===== Clock meters ===== + +// MHz of one of the clock meters (`UCIE_CLK_METER_*`), given the chip clock +// the meters count against. A meter in the clock register block answers +// whatever state the rest of the link is in, so this is safe before the +// PhyTest registers are. +static inline uint64_t pt_meter_mhz(uintptr_t base, uint64_t reg, + uint64_t chip_mhz) { + pt_wait_cycles(4 * UCIE_CLK_METER_WINDOW_CYCLES); + return pt_rd(base, reg) * chip_mhz / UCIE_CLK_METER_WINDOW_CYCLES; +} + +// Checks a meter reads `mhz` to within 2%. +static inline void pt_check_meter(uintptr_t base, uint64_t reg, uint64_t mhz, + const char *what) { + uint64_t got = pt_meter_mhz(base, reg, PT_CHIP_MHZ); + PT_CHECK(got * 50 >= mhz * 49 && got * 50 <= mhz * 51, + "%s clock meter reads %lu MHz, expected %lu MHz", what, got, mhz); +} + +// ===== Runs ===== + +// Programs a finite mainband run of `n` packets each way and resets both +// FSMs, which reseeds the LFSRs. Starts nothing: options that need the RX +// datapath reset to have released first (`txClkGate`) go in between this +// and `pt_go`. +static inline void pt_arm(uintptr_t base, uint64_t mode, uint64_t n) { + pt_wr(base, UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); + pt_wr(base, UCIE_TX_TEST_MODE, mode); + pt_wr(base, UCIE_TX_DATA_MODE, + n ? UCIE_DATA_MODE_FINITE : UCIE_DATA_MODE_INFINITE); + pt_wr(base, UCIE_RX_DATA_MODE, + n ? UCIE_DATA_MODE_FINITE : UCIE_DATA_MODE_INFINITE); + pt_wr(base, UCIE_TX_PACKETS_TO_SEND, n); + pt_wr(base, UCIE_RX_PACKETS_TO_RECEIVE, n); + reset_fsms(base); + pt_wait_idle_words(base, 4); +} + +// Starts the TX, and for a finite run waits for both ends to finish. +static inline int pt_go(uintptr_t base, uint64_t n) { + pt_wr(base, UCIE_TX_EXECUTE, 1); + if (!n) return 1; + int ok = pt_wait_eq(base, UCIE_TX_TEST_STATE, UCIE_TX_TEST_STATE_DONE, + "TX run to finish"); + ok &= pt_wait_ge(base, UCIE_RX_PACKETS_RECEIVED, n, "RX packets"); + PT_CHECK_EQ("TX packets sent", pt_rd(base, UCIE_TX_PACKETS_SENT), n); + PT_CHECK_EQ("RX packets received", pt_rd(base, UCIE_RX_PACKETS_RECEIVED), n); + return ok; +} + +static inline uint64_t pt_zero(int lane) { return 0; } + +// A finite LFSR run with distinct seeds, expected clean on every mainband +// lane and with no words dropped at either crossing. +static inline void pt_lfsr_check(uintptr_t base, uint64_t n, const char *what) { + pt_set_seeds(base, pt_seed, pt_seed); + pt_arm(base, UCIE_TX_TEST_MODE_LFSR, n); + pt_go(base, n); + pt_check_errors(base, PT_MAINBAND_MASK, pt_zero, what); + pt_check_fifo_flags(base, what); +} + +// ===== Pattern SRAM and capture SRAM ===== + +static inline void pt_write_chunk(uintptr_t base, int group, int row, + const uint32_t w[4]) { + pt_wr(base, UCIE_TX_DATA_LANE_GROUP, group); + pt_wr(base, UCIE_TX_DATA_OFFSET, row); + pt_wr(base, UCIE_TX_DATA_CHUNK_IN0, ((uint64_t)w[1] << 32) | w[0]); + pt_wr(base, UCIE_TX_DATA_CHUNK_IN1, ((uint64_t)w[3] << 32) | w[2]); + pt_wr(base, UCIE_TX_WRITE_CHUNK, 1); +} + +// Loads `rows` rows of `word(row, lane)` into the TX pattern SRAM and sets +// the repeat period. The TX FSM has to be idle: it only takes writes there. +static inline void pt_load_pattern(uintptr_t base, int rows, + uint32_t (*word)(int, int)) { + for (int r = 0; r < rows; r++) { + for (int g = 0; g < PT_LANE_GROUPS; g++) { + uint32_t w[4]; + for (int i = 0; i < 4; i++) { + int lane = 4 * g + i; + w[i] = lane < UCIE_NUM_TEST_LANES ? word(r, lane) : 0; + } + pt_write_chunk(base, g, r, w); + } + } + pt_wr(base, UCIE_TX_MANUAL_REPEAT_PERIOD, rows); +} + +static inline uint32_t pt_captured(uintptr_t base, int lane, int entry) { + pt_wr(base, UCIE_RX_DATA_LANE, lane); + pt_wr(base, UCIE_RX_DATA_OFFSET, entry); + return (uint32_t)pt_rd(base, UCIE_RX_DATA_CHUNK); +} + +// A manual pattern word: distinct per row and lane, with the framing +// waveform on valid. A mainband run reads the loopback lane as zero, so its +// slot is zero too, which a loopback-lane run overrides. +static inline uint32_t pt_pattern_word(int row, int lane) { + if (lane == UCIE_VALID_LANE) return (uint32_t)UCIE_DEFAULT_VALID; + if (lane == UCIE_LOOPBACK_LANE) return 0; + return (uint32_t)(row + 1) * 0x9e3779b9u + 7u * (uint32_t)lane; +} + +// ===== Sideband ===== + +static inline void pt_sb_reset(uintptr_t base) { + pt_wr(base, UCIE_SIDEBAND_MODE, UCIE_BAND_MODE_MANUAL); + pt_wr(base, UCIE_SB_RX_RST, 1); + pt_wait_cycles(64); +} + +static inline int pt_sb_send(uintptr_t base, uint64_t packet) { + if (!pt_wait_eq(base, UCIE_SB_TX_BUSY, 0, "sideband TX idle")) return 0; + pt_wr(base, UCIE_SB_TX_PACKET, packet); + pt_wr(base, UCIE_SB_TX_SEND, 1); + return 1; +} + +// Waits for a sideband packet and pops it. Returns 0 on a timeout. +static inline int pt_sb_recv(uintptr_t base, uint64_t *packet) { + if (!pt_wait_eq(base, UCIE_SB_RX_VALID, 1, "sideband packet")) return 0; + *packet = pt_rd(base, UCIE_SB_RX_PACKET); + pt_wr(base, UCIE_SB_RX_POP, 1); + return 1; +} + +// ===== Setup ===== + +// `setup_ucie` with the sideband receiver cleared, so that a program starts +// from a known state on both bands. +static inline void pt_setup(uintptr_t base) { + setup_ucie(base); + pt_sb_reset(base); +} + +static inline void pt_begin(const char *port, const char *test) { + pt_port = port; + printf("[%s] %s (cycle %lu)\n", port, test, rdcycle()); +} + +static inline void pt_finish(const char *program) { + if (pt_failures) { + printf("%s: %d check(s) FAILED\n", program, pt_failures); + exit(1); + } + printf("%s: all checks passed\n", program); +} + +#endif diff --git a/software/ucie-digital-loopback.c b/software/ucie-digital-loopback.c index 379ca75..e6b5c7e 100644 --- a/software/ucie-digital-loopback.c +++ b/software/ucie-digital-loopback.c @@ -53,8 +53,12 @@ int main(void) { printf("Setting up UCIe0 (digital controller)\n"); setup_ucie_digital(UCIE0_REG_BASE); + printf("UCIe0 RX lanes held back %ld UI to align words\n", + reg_read64(UCIE0_REG_BASE + UCIE_RX_UI_DELAY)); printf("Setting up UCIe1 (digital controller)\n"); setup_ucie_digital(UCIE1_REG_BASE); + printf("UCIe1 RX lanes held back %ld UI to align words\n", + reg_read64(UCIE1_REG_BASE + UCIE_RX_UI_DELAY)); printf("Testing UCIe at port 0\n"); program_router(0, 1, 0); diff --git a/software/ucie.h b/software/ucie.h index 4f3afc5..0502196 100644 --- a/software/ucie.h +++ b/software/ucie.h @@ -107,6 +107,60 @@ #define UCIE_SB_RX_OVERFLOW 0x37a0ULL #define UCIE_SB_RX_RST 0x37a8ULL #define UCIE_SB_TL_RX_OVERFLOW 0x37b0ULL +#define UCIE_RX_START_MODE 0x37b8ULL +#define UCIE_RX_BURST_MODE 0x37c0ULL +#define UCIE_RX_SELF_SYNC 0x37c8ULL +#define UCIE_RX_MONITOR 0x37d0ULL +#define UCIE_RX_CAPTURE_MODE 0x37d8ULL +#define UCIE_RX_CAPTURE_POST_TRIGGER 0x37e0ULL +#define UCIE_RX_TRIGGER_LANE_MASK 0x37e8ULL +#define UCIE_RX_CAPTURE_TRIGGERED 0x37f0ULL +#define UCIE_RX_CAPTURE_TRIGGER_PACKET 0x37f8ULL +#define UCIE_TX_BURST_PACKETS 0x3800ULL +#define UCIE_TX_IDLE_PACKETS 0x3808ULL +#define UCIE_TX_CLK_GATE 0x3810ULL +#define UCIE_TX_CLK_PREAMBLE 0x3818ULL +#define UCIE_TX_CLK_POSTAMBLE 0x3820ULL +#define UCIE_TX_TRACK_CLK 0x3828ULL +#define UCIE_TX_INJECT_ERROR 0x3830ULL +#define UCIE_TX_INJECT_LANE 0x3838ULL +#define UCIE_TRACK_ONES 0x3840ULL +#define UCIE_TRACK_ZEROS 0x3848ULL +#define UCIE_TRACK_CNT_RST 0x3850ULL +#define UCIE_TRACK_CNT_HOLD 0x3858ULL +#define UCIE_TX_CLK_DIRECT 0x3860ULL +#define UCIE_TX_TEST_FIFO_UNDERFLOW 0x3868ULL +#define UCIE_RX_TEST_FIFO_OVERFLOW 0x3870ULL +#define UCIE_LOOPBACK_RX_FIFO_OVERFLOW 0x3878ULL +#define UCIE_TX_TRACK_WORD 0x3880ULL +#define UCIE_RX_CAPTURE_START 0x3888ULL +#define UCIE_LOOPBACK_TX_FIFO_UNDERFLOW 0x3890ULL +#define UCIE_TX_DEBUG_FIFO_UNDERFLOW 0x3898ULL +#define UCIE_TRACK_ONES_EVEN 0x38a0ULL +#define UCIE_RX_MANUAL_CHECK 0x38a8ULL +#define UCIE_TX_LANE_FIXED 0x38b0ULL +#define UCIE_TX_LANE_INVERT 0x38b8ULL +#define UCIE_TX_FIXED_WORD 0x38c0ULL +#define UCIE_RX_LANE_FIXED 0x38c8ULL +#define UCIE_RX_LANE_INVERT 0x38d0ULL +#define UCIE_RX_FIXED_WORD 0x38d8ULL +#define UCIE_RX_LANE_ERRORED 0x38e0ULL +#define UCIE_RX_ERR_POS_LANE 0x38e8ULL +#define UCIE_RX_ERR_POS_MASK 0x38f0ULL +#define UCIE_RX_ERR_CLASS_LANE 0x38f8ULL +#define UCIE_RX_ERR_RISE_ONE 0x3900ULL +#define UCIE_RX_ERR_RISE_ZERO 0x3908ULL +#define UCIE_RX_ERR_FALL_ONE 0x3910ULL +#define UCIE_RX_ERR_FALL_ZERO 0x3918ULL +#define UCIE_CONTROLLER_RX_FIFO_OVERFLOW 0x3920ULL +#define UCIE_TX_QUEUE_LIMIT 0x3928ULL +#define UCIE_TX_CLK_PARK_ALTERNATE 0x3930ULL +#define UCIE_RX_FRAME_OFFSET 0x3938ULL +#define UCIE_TX_UI_DELAY 0x3940ULL +#define UCIE_TX_UI_DELAY_WIDTH 0x8ULL +#define UCIE_RX_UI_DELAY 0x39e0ULL +#define UCIE_RX_UI_DELAY_WIDTH 0x8ULL +#define UCIE_RX_VALID_START_THRESHOLD 0x3a70ULL #define UCIE_PCIE_EXT_CAP_ID 0x4000ULL #define UCIE_DVSEC_VENDOR_ID 0x4004ULL #define UCIE_DVSEC_ID 0x4008ULL @@ -185,6 +239,7 @@ #define UCIE_UCIE_LINK_RESET 0x3c00ULL #define UCIE_UCIE_PWR_GOOD 0x3c08ULL #define UCIE_UCIE_RETRY_TRAINING_AMT 0x3c10ULL +#define UCIE_UCIE_CONTROLLER_RST 0x3c18ULL #define UCIE_MAIN_CLK_SEL 0x10000ULL #define UCIE_PLL8_EN 0x10008ULL #define UCIE_PLL12_EN 0x10010ULL @@ -220,6 +275,11 @@ #define UCIE_MANUAL_CLKS_READY 0x10100ULL #define UCIE_MANUAL_CLKS_READY_FREQ_SEL 0x10108ULL #define UCIE_MANUAL_CLKS_UNGATED 0x10110ULL +#define UCIE_CLK_METER_PHY_TEST 0x10118ULL +#define UCIE_CLK_METER_SB 0x10120ULL +#define UCIE_CLK_METER_TX_DIV 0x10128ULL +#define UCIE_CLK_METER_RX_DIV 0x10130ULL +#define UCIE_PLL_LOCK_LOST 0x10138ULL #define UCIE_RATE_CFG 0x10180ULL #define UCIE_RATE_CFG_WIDTH 0x8ULL @@ -237,21 +297,38 @@ #define UCIE_CONTROLLER_SEL_UCIE 0x1ULL #define UCIE_BAND_MODE_MANUAL 0x0ULL #define UCIE_BAND_MODE_TL 0x1ULL +#define UCIE_RX_START_MODE_VALID 0x0ULL +#define UCIE_RX_START_MODE_IMMEDIATE 0x1ULL +#define UCIE_CAPTURE_MODE_FIRST 0x0ULL +#define UCIE_CAPTURE_MODE_ERROR 0x1ULL #define UCIE_DEFAULT_CLK_P 0x55555555ULL #define UCIE_DEFAULT_CLK_N 0xaaaaaaaaULL #define UCIE_DEFAULT_VALID 0xf0f0f0fULL #define UCIE_DEFAULT_TRACK 0x55555555ULL #define UCIE_ENABLE_DRIVER_CTL 0x3ffeULL #define UCIE_ENABLE_TX_CTL 0x3fffff000000000ULL +#define UCIE_DISABLE_DRIVER_CTL 0x1ULL +#define UCIE_DISABLE_TX_CTL 0xf000000000ULL +#define UCIE_TX_CTL_DELAY_MASK 0xffffffffULL #define UCIE_TX_CTL_DELAY_LSB 0x0ULL #define UCIE_TX_CTL_ENP_LSB 0x31ULL #define UCIE_TX_CTL_ENN_LSB 0x28ULL #define UCIE_TX_CTL_ENP_EQ_LSB 0x24ULL #define UCIE_TX_CTL_ENN_EQ_LSB 0x20ULL #define UCIE_TRAIN_LFSR_SEED 0x123456789abcdefULL +#define UCIE_LFSR_SEED_LANE_STEP 0x1111ULL #define UCIE_TRAIN_DATA_LANES 0x10ULL #define UCIE_TRAIN_VALID_LANE 0x10ULL #define UCIE_TRAIN_SCORE_LANES 0x11ULL +#define UCIE_NUM_TEST_LANES 0x13ULL +#define UCIE_VALID_LANE 0x10ULL +#define UCIE_TRACK_LANE 0x11ULL +#define UCIE_LOOPBACK_LANE 0x12ULL +#define UCIE_DEFAULT_VALID_LANE_SEL 0x10ULL +#define UCIE_TRACK_VALID_LANE_SEL 0x11ULL +#define UCIE_SRAM_PACKETS 0x40ULL +#define UCIE_CLK_POSTAMBLE_UI 0x2ULL +#define UCIE_CLK_METER_WINDOW_CYCLES 0x400ULL #define UCIE_RATE_CFG_MAIN_CLK_SEL_LSB 0x5ULL #define UCIE_RATE_CFG_TX_CLK_DIV_LSB 0x3ULL #define UCIE_TRAIN_EYE_FINE_POINTS 0x4ULL @@ -306,11 +383,17 @@ static inline void set_clk_manual(uintptr_t base, uint64_t en) { } static inline void apply_clk_cfg(uintptr_t base) { reg_write64(base + UCIE_CLK_CFG_APPLY, 0x1ULL); - for (int w = 0; w < 256; w++) { + { uint64_t busy; - busy = reg_read64(base + UCIE_CLK_CFG_BUSY); - if (busy == 0) { - break; + busy = 0x1ULL; + for (int w = 0; w < 65536; w++) { + busy = reg_read64(base + UCIE_CLK_CFG_BUSY); + if (busy == 0) { + break; + } + } + if (busy != 0) { + printf("apply_clk_cfg: the apply never finished; a PLL it waits on may not be locking (see clkMeter* and pllLockObserved)\n"); } } } @@ -355,10 +438,14 @@ static inline void set_rx_clk_en(uintptr_t base, uint64_t en) { reg_write64(base + UCIE_RX_CLK_EN, en); } static inline void set_global_delay(uintptr_t base, uint64_t taps) { - reg_write64(base + UCIE_CLK_PHASE_SEL, ((0x1ULL << taps) - 0x1ULL)); + reg_write64(base + UCIE_CLK_PHASE_SEL, ((taps >= 64) ? ~0x0ULL : ((0x1ULL << taps) - 0x1ULL))); } static inline void set_tx_delay(uintptr_t base, uint64_t lane, uint64_t taps) { - write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, (UCIE_ENABLE_TX_CTL | (((0x1ULL << taps) - 0x1ULL) << UCIE_TX_CTL_DELAY_LSB))); + { + uint64_t tile; + tile = reg_read64(base + UCIE_TXCTL + lane * UCIE_TXCTL_WIDTH + UCIE_TXCTL_TILE_OFS); + write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, ((tile & ~UCIE_TX_CTL_DELAY_MASK) | ((((0x1ULL << taps) - 0x1ULL) << UCIE_TX_CTL_DELAY_LSB) & UCIE_TX_CTL_DELAY_MASK))); + } } static inline void set_rx_vref(uintptr_t base, uint64_t lane, uint64_t code) { @@ -368,6 +455,12 @@ static inline void set_rx_delay(uintptr_t base, uint64_t lane, uint64_t taps) { write_rxctl(base, lane, UCIE_RXCTL_DCTRL_OFS, ((0x1ULL << taps) - 0x1ULL)); } +static inline void enable_debug_drivers(uintptr_t base, uint64_t en) { + for (int i = 0; i < 4; i++) { + reg_write64(base + UCIE_DEBUG_DRIVERCTL + 8 * i, (en ? UCIE_ENABLE_DRIVER_CTL : UCIE_DISABLE_DRIVER_CTL)); + } + reg_write64(base + UCIE_DEBUG_TXCTL_TILE, (en ? UCIE_ENABLE_TX_CTL : UCIE_DISABLE_TX_CTL)); +} static inline void setup_ucie(uintptr_t base) { reset_ucie(base); for (int lane = 0; lane < 21; lane++) { @@ -379,10 +472,7 @@ static inline void setup_ucie(uintptr_t base) { reg_write64(base + UCIE_TX_CLK_N, UCIE_DEFAULT_CLK_N); reg_write64(base + UCIE_TX_VALID, UCIE_DEFAULT_VALID); reg_write64(base + UCIE_RX_LFSR_VALID, UCIE_DEFAULT_VALID); - for (int i = 0; i < 4; i++) { - reg_write64(base + UCIE_DEBUG_DRIVERCTL + 8 * i, UCIE_ENABLE_DRIVER_CTL); - } - reg_write64(base + UCIE_DEBUG_TXCTL_TILE, UCIE_ENABLE_TX_CTL); + enable_debug_drivers(base, 0x0ULL); set_clk_en(base, 0x0ULL); set_rx_clk_en(base, 0x0ULL); reset_dividers(base); @@ -394,6 +484,92 @@ static inline void setup_ucie(uintptr_t base) { reset_fsms(base); } +static inline void seed_lfsrs(uintptr_t base) { + for (int i = 0; i < 19; i++) { + reg_write64(base + UCIE_TX_LFSR_SEED + i * UCIE_TX_LFSR_SEED_WIDTH, (UCIE_TRAIN_LFSR_SEED + i * UCIE_LFSR_SEED_LANE_STEP)); + reg_write64(base + UCIE_RX_LFSR_SEED + i * UCIE_RX_LFSR_SEED_WIDTH, (UCIE_TRAIN_LFSR_SEED + i * UCIE_LFSR_SEED_LANE_STEP)); + } +} + +static inline void run_lfsr(uintptr_t base, uint64_t packets) { + reset_fsms(base); + { + uint64_t settle_w; + settle_w = 0x0ULL; + for (int s = 0; s < 4096; s++) { + settle_w = reg_read64(base + UCIE_RX_IDLE_WORDS_OBSERVED); + if (settle_w >= 4) { + break; + } + } + if (settle_w < 4) { + printf("run_lfsr: the RX is handing over no words; no forwarded clock is arriving (see clkMeterRxDiv)\n"); + } + } + reg_write64(base + UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); + reg_write64(base + UCIE_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); + reg_write64(base + UCIE_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); + reg_write64(base + UCIE_RX_DATA_MODE, UCIE_DATA_MODE_FINITE); + reg_write64(base + UCIE_RX_PACKETS_TO_RECEIVE, packets); + reg_write64(base + UCIE_TX_PACKETS_TO_SEND, packets); + reg_write64(base + UCIE_TX_EXECUTE, 0x1ULL); + { + uint64_t r; + uint64_t prev; + uint64_t stalls; + r = 0x0ULL; + prev = ~0x0ULL; + stalls = 0x0ULL; + for (int w = 0; w < 1024; w++) { + r = reg_read64(base + UCIE_RX_PACKETS_RECEIVED); + if (r >= packets) { + break; + } + if (r != prev || r == 0) { + stalls = 0x0ULL; + } + if (r == prev && r != 0) { + stalls = stalls + 0x1ULL; + } + prev = r; + if (stalls >= 32) { + break; + } + } + if (r < packets) { + printf("run_lfsr: the receiver stopped short of the packets asked for\n"); + } + } +} + +static inline void align_rx_words(uintptr_t base) { + reg_write64(base + UCIE_CONTROLLER_SEL, UCIE_CONTROLLER_SEL_PHYTEST); + reg_write64(base + UCIE_MAINBAND_MODE, UCIE_BAND_MODE_MANUAL); + reg_write64(base + UCIE_TX_CLK_P, UCIE_DEFAULT_CLK_P); + reg_write64(base + UCIE_TX_CLK_N, UCIE_DEFAULT_CLK_N); + reg_write64(base + UCIE_TX_VALID, UCIE_DEFAULT_VALID); + reg_write64(base + UCIE_RX_LFSR_VALID, UCIE_DEFAULT_VALID); + for (int lane = 0; lane < 18; lane++) { + reg_write64(base + UCIE_RX_UI_DELAY + lane * UCIE_RX_UI_DELAY_WIDTH, 0x0ULL); + } + seed_lfsrs(base); + run_lfsr(base, 0x4ULL); + { + uint64_t received; + uint64_t offset; + received = reg_read64(base + UCIE_RX_PACKETS_RECEIVED); + offset = reg_read64(base + UCIE_RX_FRAME_OFFSET); + if (received == 0) { + printf("align_rx_words: the RX framed nothing, so rxUiDelay stays at 0\n"); + } + if (received != 0) { + for (int lane = 0; lane < 18; lane++) { + reg_write64(base + UCIE_RX_UI_DELAY + lane * UCIE_RX_UI_DELAY_WIDTH, (32 - offset) % 32); + } + } + } +} + static inline void setup_ucie_digital(uintptr_t base) { reg_write64(base + UCIE_UCIE_RST, 0x0ULL); set_clk_en(base, 0x0ULL); @@ -409,8 +585,11 @@ static inline void setup_ucie_digital(uintptr_t base) { write_rxctl(base, lane, UCIE_RXCTL_ZEN_OFS, 0x1ULL); write_rxctl(base, lane, UCIE_RXCTL_ZCTL_OFS, 0x0ULL); } + align_rx_words(base); + reg_write64(base + UCIE_TX_CLK_POSTAMBLE, 0x20ULL); reg_write64(base + UCIE_CONTROLLER_SEL, UCIE_CONTROLLER_SEL_UCIE); reset_datapath(base); + reg_write64(base + UCIE_UCIE_CONTROLLER_RST, 0x0ULL); { uint64_t linkControl; linkControl = reg_read64(base + UCIE_RAW_FORMAT_ENABLE); @@ -418,43 +597,17 @@ static inline void setup_ucie_digital(uintptr_t base) { } reg_write64(base + UCIE_UNCORR_ERR_MASK, 0x0ULL); reg_write64(base + UCIE_CORR_ERR_MASK, 0x0ULL); - while (1) { + { uint64_t linkStatus; - linkStatus = reg_read64(base + UCIE_RAW_FORMAT_ENABLED); - if ((linkStatus >> 0xfULL) & 0x1ULL) { - break; + linkStatus = 0x0ULL; + for (int w = 0; w < 16777216; w++) { + linkStatus = reg_read64(base + UCIE_RAW_FORMAT_ENABLED); + if ((linkStatus >> 0xfULL) & 0x1ULL) { + break; + } } - } -} - -static inline void seed_lfsrs(uintptr_t base) { - for (int i = 0; i < 19; i++) { - reg_write64(base + UCIE_TX_LFSR_SEED + i * UCIE_TX_LFSR_SEED_WIDTH, UCIE_TRAIN_LFSR_SEED); - reg_write64(base + UCIE_RX_LFSR_SEED + i * UCIE_RX_LFSR_SEED_WIDTH, UCIE_TRAIN_LFSR_SEED); - } -} - -static inline void run_lfsr(uintptr_t base, uint64_t packets) { - reset_fsms(base); - for (int s = 0; s < 64; s++) { - uint64_t settle_w; - settle_w = reg_read64(base + UCIE_RX_IDLE_WORDS_OBSERVED); - if (settle_w >= 4) { - break; - } - } - reg_write64(base + UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); - reg_write64(base + UCIE_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); - reg_write64(base + UCIE_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); - reg_write64(base + UCIE_RX_DATA_MODE, UCIE_DATA_MODE_FINITE); - reg_write64(base + UCIE_RX_PACKETS_TO_RECEIVE, packets); - reg_write64(base + UCIE_TX_PACKETS_TO_SEND, packets); - reg_write64(base + UCIE_TX_EXECUTE, 0x1ULL); - for (int w = 0; w < 16; w++) { - uint64_t r; - r = reg_read64(base + UCIE_RX_PACKETS_RECEIVED); - if (r >= packets) { - break; + if (((linkStatus >> 0xfULL) & 0x1ULL) == 0) { + printf("setup_ucie_digital: link training never brought the link up\n"); } } } diff --git a/test/src/IrisSpec.scala b/test/src/IrisSpec.scala index 4c07a58..3e5cc8a 100644 --- a/test/src/IrisSpec.scala +++ b/test/src/IrisSpec.scala @@ -62,6 +62,37 @@ class ClockSourceAtFreqMHz(val freqMHz: Double) ) } +/** Counts the transitions on a UCIe link's observation bumps and reports them + * when the simulation ends, so that a test can tell the bumps bring-up puts + * a scope on are driven at the chip's pins. + */ +class DebugBumpMonitor(name: String) + extends BlackBox(Map("NAME" -> StringParam(name))) + with HasBlackBoxInline { + val io = IO(new Bundle { + val txClk = Input(Bool()) + val rxClk = Input(Bool()) + val rxData = Input(Bool()) + val clkMux = Input(Bool()) + val txData = Input(Bool()) + }) + setInline( + "DebugBumpMonitor.sv", + """module DebugBumpMonitor #(parameter NAME = "") ( + | input txClk, input rxClk, input rxData, input clkMux, input txData); + | longint unsigned n_txClk = 0, n_rxClk = 0, n_rxData = 0, n_clkMux = 0, n_txData = 0; + | always @(txClk) n_txClk++; + | always @(rxClk) n_rxClk++; + | always @(rxData) n_rxData++; + | always @(clkMux) n_clkMux++; + | always @(txData) n_txData++; + | final $display("Debug bumps %s: txClk %0d rxClk %0d rxData %0d clkMux %0d txData %0d", + | NAME, n_txClk, n_rxClk, n_rxData, n_clkMux, n_txData); + |endmodule + |""".stripMargin + ) +} + class SimTop( nChips: Int, binaryPaths: Seq[Path], @@ -242,11 +273,17 @@ class TestHarness( // The PHY bumps carry a single-ended mainband bypass clock; the PLL // reference pair and its RDAC bias are no longer bumps. - Seq(chiptop.c2c_ucie0, chiptop.c2c_ucie1).foreach { ucie => + Seq(chiptop.c2c_ucie0, chiptop.c2c_ucie1).zipWithIndex.foreach { case (ucie, i) => ucie.phy.bypassClk := ucieBypassClock ucie.phy.digitalBypassClk := ucieDigitalBypassClock ucie.phy.sidebandBypassClk := ucieSidebandBypassClock ucie.phy.refClk := ucieRefClock + val monitor = Module(new DebugBumpMonitor(s"chip$chipId.ucie$i")) + monitor.io.txClk := ucie.debug.txClk + monitor.io.rxClk := ucie.debug.rxClk + monitor.io.rxData := ucie.debug.rxData + monitor.io.clkMux := ucie.debug.clkMux + monitor.io.txData := ucie.debug.txData } Seq(chiptop.c2c_ucie0, chiptop.c2c_ucie1) @@ -479,6 +516,70 @@ class IrisSpec extends AnyFunSpec { ) } + // PhyTest from software on the core, through the SoC bus and the UCIe + // register map, over the behavioral lanes and clocking tile: the same + // programs bring-up runs on the chip. See docs/ucie_bringup.md. + // `setup_ucie` turns every observation driver on, and the program runs the + // TX debug lane and traffic on every RX lane, so every bump of both links + // has to have moved: the scope points bring-up relies on reach the pins. + def checkDebugBumps(simLog: String): Unit = + for (link <- Seq("chip0.ucie0", "chip0.ucie1")) { + val counts = Utils.debugBumpCounts(simLog, link) + assert(counts.keySet == Set("txClk", "rxClk", "rxData", "clkMux", "txData")) + for ((bump, n) <- counts) { + assert(n > 64, s"$link debug bump $bump only moved $n times") + } + } + + it("should run phytest loopback test") { + implicit val p = new IrisConfig(sim = true) + checkDebugBumps( + Utils.simulateTopWithBinaries( + Utils.buildRoot / "Iris_should_run_phytest_loopback_test", + nChips = 1, + binaryPaths = Seq(Utils.root / "software/phytest-loopback.riscv"), + fast = true + ) + ) + } + + it("should run phytest loopback test on the tapeout config") { + // The configuration that is taped out (16b serial TL, no TL monitors), + // with the serial TL on a 100 MHz external clock. + implicit val p = new IrisConfig(sim = false) + checkDebugBumps( + Utils.simulateTopWithBinaries( + Utils.buildRoot / "Iris_should_run_phytest_loopback_test_on_the_tapeout_config", + nChips = 1, + binaryPaths = Seq(Utils.root / "software/phytest-loopback.riscv"), + fast = true, + serialTLFreqMHz = Some(100) + ) + ) + } + + it("should run phytest clocks test") { + implicit val p = new IrisConfig(sim = true) + Utils.simulateTopWithBinaries( + Utils.buildRoot / "Iris_should_run_phytest_clocks_test", + nChips = 1, + binaryPaths = Seq(Utils.root / "software/phytest-clocks.riscv"), + fast = true + ) + } + + it("should run phytest two-chip test") { + implicit val p = new IrisConfig(sim = true) + // Both chips run the one binary; the ring wires UCIe1 of each to UCIe0 + // of the other. + Utils.simulateTopWithBinaries( + Utils.buildRoot / "Iris_should_run_phytest_two_chip_test", + nChips = 2, + binaryPaths = Seq(Utils.root / "software/phytest-two-chip.riscv"), + fast = true + ) + } + it("should run tacit always trace workload") { implicit val p = new IrisConfig(sim = true) val workDir = Utils.buildRoot / "Iris_should_run_tacit_always_trace" diff --git a/test/src/Utils.scala b/test/src/Utils.scala index 673492e..b175103 100644 --- a/test/src/Utils.scala +++ b/test/src/Utils.scala @@ -117,7 +117,7 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d debug: Boolean = false, serialTLFreqMHz: Option[Double] = None, memTrafficMonitor: Boolean = false - )(implicit p: Parameters) = { + )(implicit p: Parameters): String = { binaryPaths.zipWithIndex.foreach { case (path, i) => assert( os.exists(path), @@ -178,5 +178,19 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d s"simulation log reports \"$f\"" ) + s"; see ${simDir / "simulation.log"}" ) + simLog + } + + /** The transition counts `DebugBumpMonitor` reported for one link, by bump + * name. + */ + def debugBumpCounts(simLog: String, link: String): Map[String, BigInt] = { + val line = simLog.linesIterator + .find(_.startsWith(s"Debug bumps $link:")) + .getOrElse(throw new AssertionError(s"no debug bump report for $link")) + "(\\w+) (\\d+)".r + .findAllMatchIn(line.stripPrefix(s"Debug bumps $link:")) + .map(m => m.group(1) -> BigInt(m.group(2))) + .toMap } } diff --git a/ucie b/ucie index ed92e20..2bfc229 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit ed92e2098ad9780544258a7a46e6dc9b029e09e4 +Subproject commit 2bfc229ae3c06deade780a5634df2fa4097aa973 From 041e034425f6d6c8b089b2a2b53fecbcfbbed3a6 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 18 Nov 2026 20:45:55 -0800 Subject: [PATCH 2/7] bump submodule and docs --- docs/ucie_bringup.md | 8 ++++---- ucie | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/ucie_bringup.md b/docs/ucie_bringup.md index 7154daa..6f1de87 100644 --- a/docs/ucie_bringup.md +++ b/docs/ucie_bringup.md @@ -38,7 +38,7 @@ apart from `address` and `moduleId`: The windows come from `UcieTLRegs.regionSize` = 0x3C00, `UcieController.ctrlBase`/`specBase` = 0x3C00/0x4000 with a 0x4000 spec region, and `UcieClkRegs.offset` = 0x10000 with a 0x1000 region -(`ucie/scala/src/tilelink/TileLink.scala:225,269,993,1695-1704`; +(`ucie/scala/src/tilelink/TileLink.scala:225,269,972,1674-1683`; `ucie/scala/src/uciedigital/regs/UcieRegParams.scala:49-50,127-160`). The two links' windows don't overlap. @@ -77,7 +77,7 @@ Other Iris addresses that bring-up programs use (`software/router.h`; `src/Iris. Each link's register port hangs off the **control bus**, through `TLFragmenter(cbus)`, a `TLBuffer` and a `TLWidthWidget(cbus.beatBytes)` (`src/Iris.scala:102-114`). - The router can't attach the port itself: it takes a bare register node, and the port is a - crossbar in front of three blocks (`ucie/scala/src/tilelink/TileLink.scala:2635-2643`). + crossbar in front of three blocks (`ucie/scala/src/tilelink/TileLink.scala:2616-2624`). - The link's chip clock is the `d2d` clock group. That group is combined into `uncore` with `cbus`, `sbus`, `pbus` and the other buses, all at 500 MHz (`src/Iris.scala:391-406,453-457`). So the port needs no clock crossing. @@ -192,7 +192,7 @@ Each `c2c_uciek` has two parts: Chisel flattens the names with underscores, for example `c2c_ucie0_phy_bypassClk`. **Lane order on the bumps** is PHY lane order: `txData[i]`/`rxData[i]` are data lanes 0-15. Valid, -track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scala:572-585,633-639`). +track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scala:586-599,647-653`). **Harness connectivity** (`test/src/IrisSpec.scala`, `connectRingLink` and the code around it): - **One chip:** each link is looped onto itself by `UcieBumpsIO.loopback`. TX data, valid, track, @@ -301,7 +301,7 @@ nonzero if any check failed. **A slow PHY test clock starves this die's TX and overflows its RX.** Where the next data word of a run isn't queued in time, `TxClkGater` at the PHY end sends -an idle word instead (`ucie/scala/src/tilelink/TileLink.scala:2716-2779`), so +an idle word instead (`ucie/scala/src/tilelink/TileLink.scala:2697-2762`), so the receiving RX gets an idle word in the middle of the run, or with the clock gated, the burst split in two. With the clock running, the RX still takes a word every packet clock, more than a slow PHY test clock drains. On a diff --git a/ucie b/ucie index 2bfc229..eb0754e 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit 2bfc229ae3c06deade780a5634df2fa4097aa973 +Subproject commit eb0754e0ce77b7f6345d93f68fc5cd3e286c2b40 From 7cb074213ef8566c4d848204df0363847cbb1a28 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 25 Nov 2026 08:40:44 -0800 Subject: [PATCH 3/7] Update ucie submodule --- ucie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucie b/ucie index eb0754e..62f031d 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit eb0754e0ce77b7f6345d93f68fc5cd3e286c2b40 +Subproject commit 62f031dd8bca56ea4f1d3911b2031e1acd0c889d From 7a5c7bab050315b270314c7f872f7faa7c6f51fd Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 25 Nov 2026 09:37:30 -0800 Subject: [PATCH 4/7] PHY test updates --- docs/ucie_bringup.md | 321 +++++++++++++++--------------------- software/phytest-clocks.c | 59 ++++--- software/phytest-loopback.c | 60 +++---- software/phytest-two-chip.c | 18 +- software/phytest.h | 46 +++--- software/ucie.h | 54 +++--- test/src/IrisSpec.scala | 18 +- test/src/Utils.scala | 7 +- ucie | 2 +- 9 files changed, 276 insertions(+), 309 deletions(-) diff --git a/docs/ucie_bringup.md b/docs/ucie_bringup.md index 6f1de87..2ff0c39 100644 --- a/docs/ucie_bringup.md +++ b/docs/ucie_bringup.md @@ -1,30 +1,20 @@ # UCIe bring-up on Iris -Iris has two UCIe links. This page covers what's specific to Iris: where the links sit in the -address map, how software reaches them, which clocks come in on bumps, and how bumps map to links. +Iris has two UCIe links. This page covers what's specific to Iris: the links' address map, how +software reaches them, which clocks come in on bumps, and how bumps map to links. How to clock, reset and bring up PhyTest, the IP's link tester, is in the UCIe IP's own guide: -[`ucie/docs/phytest_bringup.md`](../ucie/docs/phytest_bringup.md). Read section 3 of that guide +[`ucie/docs/phytest_bringup.md`](../ucie/docs/phytest_bringup.md). Read its section 3 ("The register port, and how not to hang it") before touching a link. -File citations are `file:line` from the repository root. `ucie/...` is the UCIe submodule. -`IrisSpec.scala` is being edited, so its line numbers are for the working tree on 2026-11-10. +Paths are from the repository root. `ucie/...` is the UCIe submodule. --- ## 1. The two links -Both links are chiplet-router ports (`src/Iris.scala:553-578`). Their `UcieTLParams` are identical -apart from `address` and `moduleId`: -- `numLanes` = 16 -- `managerWhere` = SBUS -- `includeDefaultModels` = true -- `sim` follows the config - -`UcieComplexPort` puts both `UcieChipletLink`s inside one module, `UcieComplex` (instance -`d2d_ports`), so physical design can harden them together (`src/UcieComplex.scala:15-67`). -`moduleId` 1 gives the second link its own module names, `UcieTL_1` and `UcieChipletLink_1` -(`ucie/scala/src/tilelink/TileLink.scala:95-106`). +Both links are chiplet-router ports with 16 lanes (`src/Iris.scala`). Their +`UcieTLParams` differ only in `address` and `moduleId`. | | Link 0 | Link 1 | |---|---|---| @@ -36,21 +26,14 @@ apart from `address` and `moduleId`: | Clock and reset registers (`UcieClkRegs`, chip clock) | `0x210000`–`0x210FFF` | `0x218000`–`0x218FFF` | | Module (`moduleId`) | `UcieTL` (0) | `UcieTL_1` (1) | -The windows come from `UcieTLRegs.regionSize` = 0x3C00, `UcieController.ctrlBase`/`specBase` = -0x3C00/0x4000 with a 0x4000 spec region, and `UcieClkRegs.offset` = 0x10000 with a 0x1000 region -(`ucie/scala/src/tilelink/TileLink.scala:225,269,972,1674-1683`; -`ucie/scala/src/uciedigital/regs/UcieRegParams.scala:49-50,127-160`). The two links' windows don't -overlap. - -Everything outside the windows is unmapped. That includes `0x211000`–`0x217FFF` and `0x219000` -upwards. Iris removed the error device from every bus (`src/Iris.scala:268-280`), so an access to -an unmapped address doesn't return an error. **It hangs** (inference: nothing on the bus can answer -it). +Everything outside these windows is unmapped, including `0x211000`–`0x217FFF` and `0x219000` up. +Iris removed the error device from every bus, so an unmapped access +gets no error response. **It hangs** (inference: nothing on the bus can answer it). ### Registers you'll touch first -Offsets come from `software/ucie.h`, regenerated for IrisConfig in the working tree. Regenerate it -whenever the `ucie` submodule moves; the header is the authority. +Offsets come from `software/ucie.h`, which is the authority. Regenerate it whenever the `ucie` +submodule moves (section 5). | Register | Offset | Link 0 | Link 1 | Safe before `ucieRst` = 0? | |---|---|---|---|---| @@ -60,55 +43,45 @@ whenever the `ucie` submodule moves; the header is the authority. | `UCIE_CLK_CFG_BUSY` | `0x10088` | `0x210088` | `0x218088` | yes | | `UCIE_CLK_CFG_UNGATE_REQ` | `0x100A0` | `0x2100A0` | `0x2180A0` | yes | | `UCIE_PLL_LOCK_OBSERVED` | `0x100A8` | `0x2100A8` | `0x2180A8` | yes | -| `UCIE_UCIE_RST` (reset value 1) | `0x100B0` | `0x2100B0` | `0x2180B0` | yes | +| `UCIE_RST` (reset value 1) | `0x100B0` | `0x2100B0` | `0x2180B0` | yes | | `UCIE_PHY_TEST_CLK_EN` | `0x100D8` | `0x2100D8` | `0x2180D8` | yes | | `UCIE_TX_TEST_STATE` | `0x128` | `0x200128` | `0x208128` | **no**: needs `ucieRst` = 0 and a running PHY test clock | | `UCIE_RX_IDLE_WORDS_OBSERVED` | `0x3C8` | `0x2003C8` | `0x2083C8` | no | | `UCIE_TX_TEST_FIFO_UNDERFLOW` / `UCIE_RX_TEST_FIFO_OVERFLOW` | `0x3868` / `0x3870` | `0x203868` / `0x203870` | `0x20B868` / `0x20B870` | no | -Other Iris addresses that bring-up programs use (`software/router.h`; `src/Iris.scala:555`): -- the chiplet-router table at `0x4000`, 32 bytes per entry, 4 entries; -- the chip ID register at `0x4080`. +Other Iris addresses that bring-up programs use (`software/router.h`): the +chiplet-router table at `0x4000` (32 bytes per entry, 4 entries), and the chip ID register at +`0x4080`. --- ## 2. How software reaches the registers -Each link's register port hangs off the **control bus**, through `TLFragmenter(cbus)`, a `TLBuffer` -and a `TLWidthWidget(cbus.beatBytes)` (`src/Iris.scala:102-114`). -- The router can't attach the port itself: it takes a bare register node, and the port is a - crossbar in front of three blocks (`ucie/scala/src/tilelink/TileLink.scala:2616-2624`). -- The link's chip clock is the `d2d` clock group. That group is combined into `uncore` with `cbus`, - `sbus`, `pbus` and the other buses, all at 500 MHz (`src/Iris.scala:391-406,453-457`). So the - port needs no clock crossing. +Each link's register port is on the SoC's **control bus** (CBUS), coupled there in +`src/Iris.scala`. It does not go through the chiplet router. `ChipletRoutingKey.controlBusWhere` +only names which bus that is. The link's chip clock is the `uncore` clock, shared with every bus at +500 MHz. There are three ways in: -1. **The cores.** C programs include `software/ucie.h`. Every helper takes `base`, `0x200000` or - `0x208000`, and uses `reg_write64`/`reg_read64` (`software/mmio.h`). +1. **The cores.** C programs include `software/ucie.h`. Every helper takes `base` (`0x200000` or + `0x208000`) and uses `reg_write64`/`reg_read64` (`software/mmio.h`). 2. **TSI over serial TileLink.** - - IrisTop's `serial_tl` port is a `DecoupledExternalSyncPhitIO`: 16-bit phits on the tapeout - config, 32-bit with `sim` (`src/Iris.scala:320-354`). It's clocked by `serial_tl.clock_in` - from outside. - - Its client side masters the front bus (`SerialTLClientParams` defaults `masterWhere` to FBUS: - `testchipip/src/main/scala/serdes/PeripheryTLSerial.scala:47-52`). From there a request goes - FBUS → SBUS → CBUS → the UCIe register port. - - Its manager side serves off-chip memory at `0x8000_0000`, 4 GiB, on the memory bus. + - IrisTop's `serial_tl` port carries 16-bit phits on the tapeout config, 32-bit with `sim`. + `serial_tl.clock_in` clocks it from outside. + - Its requests enter at the front bus and reach the UCIe port through FBUS → SBUS → CBUS. Its + manager side serves off-chip memory at `0x8000_0000`, 4 GiB. - The host-side `TSIToTileLink` issues a single 8-byte Get or Put only for an 8-byte-aligned, - two-word request (`testchipip/src/main/scala/tsi/TSIToTileLink.scala:78-92`). Use exactly that + two-word request (`TSIToTileLink` in testchipip). Use exactly that for UCIe registers. 3. **JTAG.** - - `WithJtagDTM` and `WithDebugSBA` give a debug module with system-bus access - (`src/Iris.scala:414-421`). The access width is 64 bits, because the base config uses - `DefaultDebugModuleParams(64)` (`rocket-chip/src/main/scala/subsystem/Configs.scala:59`). - - The bus master is on the front bus (`debug[0]` in the NoC map, `src/Iris.scala:497`). Use - 64-bit accesses, such as OpenOCD `write_memory`/`read_memory` with width 64. - - Abstract commands through a halted hart also work, as long as the control bus isn't wedged. + - The debug module has system-bus access (`WithJtagDTM`, `WithDebugSBA`), 64 bits wide. + - Use 64-bit accesses, such as OpenOCD `write_memory`/`read_memory` with width 64. + - Abstract commands through a halted hart also work, unless the control bus is wedged. **Use 64-bit accesses.** - Writes to fields wider than 32 bits (`txctl_N_tile`, `clkPhaseSel`, seeds, packet counts, - `txDataChunkIn0/1`, `sbTxPacket`) are ignored silently unless the whole field is in the byte mask - (`rocket-chip/src/main/scala/regmapper/RegMapper.scala:146`). + `txDataChunkIn0/1`, `sbTxPacket`) are silently ignored unless the whole field is in the byte mask. - A 32-bit read of a 64-bit counter returns half of it. **Hang hazards, and recovery on Iris.** @@ -116,20 +89,15 @@ There are three ways in: - an access to a link's PhyTest or controller window while that domain is in reset (`ucieRst` = 1 is the power-on state) or unclocked; - an access to an unmapped address; - - an access to a remote address (the off-chip range at `0x8_0000_0000`, `src/Iris.scala:320`) + - an access to a remote address (the off-chip range at `0x8_0000_0000`) while the link isn't carrying TileLink. -- A hung access to a UCIe register sits on the control bus. That's inferred from the bus structure. - It blocks: - - both links' registers; - - the router table and chip ID; - - the clock divider; - - CLINT, PLIC and the boot ROM; - - the debug module's hart-facing ROM; - - the periphery bus with the UART. -- TSI and JTAG system-bus access can still reach memory. -- IrisTop doesn't consume the debug module's `ndreset` (`src/Iris.scala:130-149`), so JTAG can't - reset the chip. **Only `reset` recovers.** Plan the bench so you can drive Iris's reset pin from - the host. +- A hung UCIe access blocks the control bus (inferred from the bus structure): both links' + registers, the router table and chip ID, the clock divider, CLINT, PLIC, the boot ROM, the debug + module's hart-facing ROM, and the periphery bus with the UART. TSI and JTAG system-bus access can + still reach memory. +- JTAG can't reset the chip: IrisTop doesn't use the debug module's `ndreset`. + **Only `reset` recovers.** Set up the bench so the host can drive + Iris's reset pin. - Rules: - Only one agent touches a link at a time. Halt the cores before poking UCIe registers from TSI or JTAG. @@ -140,35 +108,32 @@ There are three ways in: ## 3. Clocks that come from bumps -Each link has its own set of PHY clock bumps, all under `c2c_uciek.phy`. The bump bundle is -`UcieBumpsIO` (`ucie/scala/src/tilelink/TileLink.scala:121-170`); its PHY part is `PhyBumpsIO` -(`ucie/scala/src/phy/Phy.scala:172-194`). The Iris comment at `src/Iris.scala:558-562` notes the -per-link bypass bumps. +Each link has its own PHY clock bumps, under `c2c_uciek.phy`. -| Bump (per link) | What it feeds | When it must be driven | Harness (`test/src/IrisSpec.scala:203-208`) | +| Bump (per link) | What it feeds | When it must be driven | Harness (`IrisSpec`) | |---|---|---|---| -| `phy.bypassClk` | The analog bypass input: ESD, then a clock receiver, then the clocking tile (`Phy.scala:405-411,457-461`). It's the UCIe main clock while `mainClkSel` = 3 (reset). It can also be the source the PHY test and sideband dividers divide (source 2). ≤ 16 GHz. | Always for the reset clocking. It sets the TX line rate: lane rate = 2 × bypass ÷ `txClkDiv`. | 8000 MHz (16 GT/s at the reset ÷1) | -| `phy.digitalBypassClk` | The PHY test clock while `phyTestClkBypassEn` = 1 (reset). That clock runs the PhyTest register block, PhyTest itself and every RX AFE controller. | **Before any access to the link's PhyTest window**, unless software first moves the PHY test clock onto a PLL. It must be faster than every packet clock in use (`phytest_bringup.md` §1.3). | 500 MHz. This **equals** the 16 GT/s packet clock (8 GHz/16), so there's no margin; the UCIe repo's own harness uses 800 MHz. | -| `phy.sidebandBypassClk` | The TX sideband clock while `sbClkBypassEn` = 1 (reset). That clock runs the UCIe controller, its registers, and every sideband serializer. | Before any access to the controller window, or any sideband use. | 800 MHz | +| `phy.bypassClk` | The UCIe main clock while `mainClkSel` = 3 (reset). Also source 2 for the PHY test and sideband dividers. ≤ 16 GHz. | Always, for the reset clocking. Sets the TX line rate: lane rate = 2 × bypass ÷ `txClkDiv`. | 8000 MHz (16 GT/s at the reset ÷1) | +| `phy.digitalBypassClk` | The PHY test clock while `phyTestClkBypassEn` = 1 (reset). Runs the PhyTest register block, PhyTest and every RX AFE controller. | **Before any access to the link's PhyTest window**, unless software first moves the PHY test clock onto a PLL. Must be faster than every packet clock in use (`phytest_bringup.md` §1.3). | 500 MHz. This **equals** the 16 GT/s packet clock (8 GHz/16): no margin. The UCIe repo's own harness uses 800 MHz. | +| `phy.sidebandBypassClk` | The TX sideband clock while `sbClkBypassEn` = 1 (reset). Runs the UCIe controller, its registers and every sideband serializer. | Before any access to the controller window, or any sideband use. | 800 MHz | | `phy.refClk` | The 100 MHz reference for PLL8 (×80) and PLL12 (×120). | Only when a PLL is used. | 100 MHz | | `phy.rxClkP`, `phy.rxClkN`, `phy.sbRxClk` | Forwarded clocks from the partner (or the same link, looped back). | n/a | Looped back or ringed (section 4) | Chip-level clock pins are separate from the UCIe ones: -- `clock` feeds every SoC clock group through the programmable `TLClockDivider` (`src/Iris.scala:88-94,118-128`). That includes the UCIe chip clock, through the `uncore` group. +- `clock` feeds every SoC clock group through the programmable `TLClockDivider`, including the + UCIe chip clock. - `serial_tl.clock_in` clocks the serial TileLink port. - `jtag.TCK` clocks JTAG. -- `clock_tap` is an output tapping an SoC clock (`src/CanHaveClockTap.scala`). It isn't a UCIe clock. +- `clock_tap` is an output tapping an SoC clock, not a UCIe clock. **Bench notes for Iris:** -- To run the link at the reset clocking, supply `bypassClk`, `digitalBypassClk` and - `sidebandBypassClk` on every link you bring up. Moving onto the PLLs needs `refClk` instead, and - is done through `UcieClkRegs`, which is safe while the link is still in reset. -- Run `digitalBypassClk` faster than the packet clock. With the harness's 8 GHz bypass at ÷1, the - packet clock is 500 MHz, so 800 MHz suits up to 24 GT/s. Otherwise switch the PHY test clock to - PLL8 ÷8 (1 GHz). +- At the reset clocking, supply `bypassClk`, `digitalBypassClk` and `sidebandBypassClk` on every + link you bring up. The PLLs need `refClk` instead. Software moves onto them through + `UcieClkRegs`, which is safe while the link is still in reset. +- With an 8 GHz bypass at ÷1 the packet clock is 500 MHz, so an 800 MHz `digitalBypassClk` covers + up to 24 GT/s. Otherwise switch the PHY test clock to PLL8 ÷8 (1 GHz). - Bring up first at ÷4 (4 GT/s off an 8 GHz bypass), not on a slow bypass clock (`phytest_bringup.md` §1.2 and step 5). -- PhyTest never needs the sideband clock, but an unclocked sideband domain wedges the bus if +- PhyTest never needs the sideband clock. But an unclocked sideband domain wedges the bus if anything touches the controller window (`0x203C00`/`0x20BC00` and up). --- @@ -178,31 +143,28 @@ Chip-level clock pins are separate from the UCIe ones: - `c2c_ucie0` is `system.d2d_port_ios(0)`, chiplet-router port 0: the `UcieTL` at `0x200000`. - `c2c_ucie1` is `system.d2d_port_ios(1)`, port 1: the `UcieTL_1` at `0x208000`. -Port order is the order of `ChipletRoutingParams.ports` (`src/Iris.scala:170-175,554-578`; -`testchipip/src/main/scala/soc/OffchipRouter.scala:250-333`). +Port order is the order of `ChipletRoutingParams.ports`. Each `c2c_uciek` has two parts: - `phy`: `txData[16]`, `txValid`, `txTrack`, `txClkP`, `txClkN`, `rxData[16]`, `rxValid`, `rxTrack`, `rxClkP`, `rxClkN`, `sbTxClk`, `sbTxData`, `sbRxClk`, `sbRxData`, plus the four clock inputs of section 3. -- `debug`: the observation outputs `txClk`, `rxClk`, `rxData`, `clkMux` and `txData` - (`ucie/scala/src/phytest/PhyTest.scala:547-553`). Every one is off until software enables its - driver. +- `debug`: the observation outputs `txClk`, `rxClk`, `rxData`, `clkMux` and `txData`. Each is off + until software enables its driver. Chisel flattens the names with underscores, for example `c2c_ucie0_phy_bypassClk`. **Lane order on the bumps** is PHY lane order: `txData[i]`/`rxData[i]` are data lanes 0-15. Valid, -track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scala:586-599,647-653`). +track and the forwarded clock have their own bumps. **Harness connectivity** (`test/src/IrisSpec.scala`, `connectRingLink` and the code around it): -- **One chip:** each link is looped onto itself by `UcieBumpsIO.loopback`. TX data, valid, track, - the forwarded clock and the sideband all go to the same link's RX. A test on link `k` exercises - `k`'s TX and `k`'s RX together, and `run_lfsr(base_k, n)` is self-consistent there. -- **N chips:** a ring. Chip `i`'s `c2c_ucie1` connects to chip `i+1`'s `c2c_ucie0`, through - `UcieBumpsIO.connect`: data, valid, track, forwarded clock and sideband both ways. With two chips, - chip 0 link 1 ↔ chip 1 link 0 and chip 1 link 1 ↔ chip 0 link 0. Each die's TX then lands on the - *other* die, so its RX has to be armed before the other die transmits - (`phytest_bringup.md` step 7, topology B). +- **One chip:** each link loops onto itself (`UcieBumpsIO.loopback`): TX data, valid, track, the + forwarded clock and the sideband go to the same link's RX. `run_lfsr(base_k, n)` is + self-consistent there. +- **N chips:** a ring. Chip `i`'s `c2c_ucie1` connects to chip `i+1`'s `c2c_ucie0`, all signals, + both ways (`UcieBumpsIO.connect`). With two chips, chip 0 link 1 ↔ chip 1 link 0 and chip 1 + link 1 ↔ chip 0 link 0. Each die's TX goes to the *other* die, so its RX must be armed before the + other die transmits (`phytest_bringup.md` step 7, topology B). **Routing.** `program_router(entry, chip_id, port)` sends a chip ID to port 0 or 1 (`software/router.h`). In a two-chip ring both ports reach the other chip, so either works. @@ -213,36 +175,31 @@ track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scal - **Toolchain.** Install `riscv64-unknown-elf-gcc`, and set `RISCV` for the simulator build (`test/src/Utils.scala`). -- **Build every program.** `make -C software`, as listed in `PROGRAMS` in `software/Makefile`. They - link against `htif_nano.specs`, so `printf` and the exit code go over HTIF and need a host - serving it: SimTSI in simulation, the lab TSI host on silicon. -- **Regenerate `software/ucie.h`.** Either `make -C software ucie.h` or - `./mill runMain edu.berkeley.cs.iris.GenUcieHeader software/ucie.h` (`src/GenUcieHeader.scala`). - It uses mill, so don't run it while another mill build is running in the same checkout. - `GenUcieHeader` refuses to emit a header if the two links' register layouts ever differ - (`src/GenUcieHeader.scala:28-48`). -- **Run in simulation (VCS).** `./mill test.testOnly edu.berkeley.cs.iris.IrisSpec -- -z ""`. - `Utils.simulateTopWithBinaries` builds the harness, compiles VCS and runs the binaries. `fast` - mode preloads through `FastRAM` and `+loadmem`, and `debug = true` dumps FSDB. -- **Run on silicon.** - - The TSI host loads the ELF into off-chip memory over `serial_tl`. - - The chip boots from the boot ROM at `0x10000` and the boot-address register - (`src/Iris.scala:424-444`). - - The host services HTIF. - - The bench-side procedure isn't in this repository. -- **Existing UCIe programs, and what they exercise.** +- **Build every program** (`PROGRAMS` in `software/Makefile`): `make -C software`. They link + against `htif_nano.specs`, so `printf` and the exit code go over HTIF and need a host serving + it: SimTSI in simulation, the lab TSI host on silicon. +- **Regenerate `software/ucie.h`:** `make -C software ucie.h` or + `./mill runMain edu.berkeley.cs.iris.GenUcieHeader software/ucie.h`. + It uses mill, so don't run it during another mill build in the same checkout. It refuses to emit + a header if the two links' register layouts differ. +- **Run in simulation (VCS):** `./mill test.testOnly edu.berkeley.cs.iris.IrisSpec -- -z ""`. + `Utils.simulateTopWithBinaries` builds the harness, compiles VCS and runs the binaries. + `debug = true` dumps FSDB. +- **Run on silicon.** The TSI host loads the ELF into off-chip memory over `serial_tl`. The chip + boots from the boot ROM at `0x10000` and the boot-address register. + The host services HTIF. The bench-side procedure isn't in this repository. +- **Existing UCIe programs:** - `software/ucie-loopback.c` runs `setup_ucie` on both links, puts both mainbands in TileLink mode, and does remote reads and writes through the router. It tests the TileLink path, not PhyTest, and needs both links working. - - `software/ucie-digital-loopback.c` runs `setup_ucie_digital` on both links, which first lines - each RX's words up with its own TX's through PhyTest (`align_rx_words`, - `ucie/docs/phytest_bringup.md` §8.4) and prints the RX UI delay that set, then trains the UCIe - controller. - It spins forever if link training never completes. On the harness both links hold their RX - lanes back 20 UI, train, and carry remote reads and writes. + - `software/ucie-digital-loopback.c` runs `setup_ucie_digital` on both links. That aligns each + RX's words to its own TX's through PhyTest (`align_rx_words`, `ucie/docs/phytest_bringup.md` + §8.4), prints the RX UI delay it set, then trains the UCIe controller. It spins forever if + link training never completes. On the harness both links delay their RX lanes 20 UI, train, + and carry remote reads and writes. - Neither is a first-silicon program. - The PhyTest programs `software/phytest-loopback.c`, `phytest-clocks.c` and `phytest-two-chip.c` - (shared helpers in `software/phytest.h`) are described in section 7. + (shared helpers in `software/phytest.h`) are in section 7. --- @@ -257,7 +214,8 @@ track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scal 3. Check that `UCIE_CLK_METER_PHY_TEST` and `UCIE_CLK_METER_SB` read nonzero, then write `ucieRst` = 0. 4. A single read of `UCIE_TX_TEST_STATE`. - 5. `setup_ucie`, then the overrides in `phytest_bringup.md` step 4. + 5. `setup_ucie`, which turns on the TX and RX clocks (`UCIE_CLK_EN`, `UCIE_RX_CLK_EN`), then + the overrides in `phytest_bringup.md` step 4. 6. Set the rate and phase, and check `UCIE_CLK_METER_TX_DIV` and `_RX_DIV`. 7. Run the on-chip loopback lane. 8. Run the mainband LFSR, after an injected error has shown the counters count. @@ -265,20 +223,16 @@ track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scal 10. Run gated-clock bursts at the UCIe controller's postamble (step 11). 11. Hand the link to the UCIe controller (step 12): `setup_ucie_digital` on a link looped back onto itself; by hand between two chips, since `align_rx_words` can't measure across them. -- **Lessons from Kodiak, the previous chip** (`phytest_bringup.md` steps 4-9), as the generated - helpers now apply them: - - Link tests run with the observation pad drivers off: `setup_ucie` leaves them off, and - `enable_debug_drivers` turns them on for a scope. - - Every lane has its own LFSR seed, out of reset and from `seed_lfsrs`. - - `run_lfsr` waits until the packet count stops climbing, not for a fixed number of reads, and - says when it comes back short. - - Iris's RX front end is not Kodiak's, so Kodiak's hand-over and vref settings don't carry over; - those defaults will change with the AFE's own controller. +- **Lessons from Kodiak, the previous chip** (`phytest_bringup.md` steps 4-9). The generated + helpers already apply them: observation pad drivers off during link tests (`setup_ucie` leaves + them off; `enable_debug_drivers` turns them on for a scope), a distinct LFSR seed per lane + (`seed_lfsrs`), and `run_lfsr` waiting until the packet count stops climbing. Kodiak's RX + hand-over and vref settings don't apply: Iris's RX front end is different. - **Physical design and lab checks this page can't settle:** - - IrisConfig emits the UCIe behavioral models (`includeDefaultModels = true`, - `src/Iris.scala:567,574`). Confirm the PD flow replaces the analog ones with the macros. - - `digitalBypassClk`, `sidebandBypassClk` and `refClk` have no ESD cell in the UCIe RTL - (`ucie/scala/src/phy/Phy.scala:405-411,432-433,459`). Confirm the pad ring provides one. + - IrisConfig emits the UCIe behavioral models (`includeDefaultModels = true`). Confirm the PD + flow replaces the analog ones with the macros. + - `digitalBypassClk`, `sidebandBypassClk` and `refClk` have no ESD cell in the UCIe RTL. + Confirm the pad ring provides one. - Confirm with analog what termination `zen` = 1 with `zctl` = 0 gives (`phytest_bringup.md` step 4). @@ -286,43 +240,37 @@ track and the forwarded clock have their own bumps (`ucie/scala/src/phy/Phy.scal ## 7. Simulation tests and bring-up programs -The PhyTest bring-up programs in `software/` are the same programs in -simulation and in the lab. They run on the core, reach both UCIe links over -the SoC bus at their real MMIO bases, and go through the real register map, -clock-domain crossings, clocking tile and lane models. Each check prints -what it expected and what it read rather than stopping, and the program exits -nonzero if any check failed. +The PhyTest bring-up programs in `software/` are the same in simulation and in the lab. They run +on the core and reach both links at their real MMIO bases. Each check prints what it expected and +what it read instead of stopping. The program exits nonzero if any check failed. | Program | Topology | What it covers | |---|---|---| -| `phytest-loopback.c` | each link's bumps looped back onto itself (the single-chip harness, or a loopback board) | on both links: the clock meters against the board clocks; LFSR run with distinct per-lane seeds; injected errors counted exactly once under `rxPauseCounters`; `rxSelfSync` with every RX seed wrong; valid moved onto track at both ends; gated-clock bursts the UCIe way, at the reset values (no preamble, a packet of postamble, the clock parked high and low in turn, then always low), with the forwarded clock centred (`PT_CENTRED_DELAY_TAPS` in `phytest.h`, 29 on the harness; the trained code on silicon) and put back after, after realigning the RX dividers behind the parked clock and one 40 UI training gap, with `rxBurstMode` (and the RX seeing no words while the clock is parked); manual pattern into the capture SRAM, and `rxCaptureStart` past the first lap; error-triggered capture with twin lanes; `rxStartMode` immediate; track counters, ones/zeros/even ones; the loopback lane and its two FIFO flags; per-lane fixed and inverted sources, clean when the RX expects them and every bit wrong, half on each edge, when it does not; one injected error found by lane, UI and class; the observation bumps (on for that test alone) with the TX debug lane; the sideband tester | -| `phytest-clocks.c` | UCIe0 looped back | the TX divider at /1, /2, /4 off the bypass pin; the PHY test clock onto PLL8 /8; the main clock onto PLL8 and PLL12; a PHY test clock too slow for the link, which has to set both the TX FIFO underflow flag and the RX overflow flag (below), with the two packet clocks metering the same, and the recovery; the TX queue capped at 8 words, below its reset value of 16, with the PHY test clock at twice the packet clock (at equal rates 8 runs the queue dry and 10 is the least that holds); the sideband clock onto PLL8 /10; every clock meter after every move, and no PLL lock lost | -| `phytest-two-chip.c` | two chips, UCIe1 of each wired to UCIe0 of the other (the two-chip ring, or two chips on a package) | an LFSR run each way; that each RX hears only the TX it is wired to; `rxManualCheck` scoring the partner's manual pattern against this chip's TX pattern SRAM, with one reference word deliberately wrong | - -**A slow PHY test clock starves this die's TX and overflows its RX.** Where the -next data word of a run isn't queued in time, `TxClkGater` at the PHY end sends -an idle word instead (`ucie/scala/src/tilelink/TileLink.scala:2697-2762`), so -the receiving RX gets an idle word in the middle of the run, or with the clock -gated, the burst split in two. With the clock running, the RX still takes a -word every packet clock, more than a slow PHY test clock drains. On a -looped-back link that means `UCIE_TX_TEST_FIFO_UNDERFLOW` and -`UCIE_RX_TEST_FIFO_OVERFLOW` both set. Between two dies, the RX overflow shows -on the die with the slower PHY test clock, whichever one is sending. - -`setup_ucie` leaves the observation drivers off, so a program that wants a scope on them calls -`enable_debug_drivers(base, 1)` first; `phytest-loopback.c` does it for one test. - -`phytest.h` holds the helpers they share. Every wait is bounded in core -cycles (`PT_TIMEOUT`), because a bound counted in MMIO reads is far too short -on silicon next to a slow divided clock. +| `phytest-loopback.c` | each link looped back onto itself (the single-chip harness, or a loopback board) | On both links: clock meters against the board clocks; LFSR run with distinct per-lane seeds; injected errors counted exactly once; `rxSelfSync` with every RX seed wrong; valid moved onto track at both ends; gated-clock bursts the UCIe way after the training in `phytest_bringup.md` §8.3, parking alternately and always low, with the forwarded clock centred (`PT_CENTRED_DELAY_TAPS` in `phytest.h`: 29 on the harness, the trained code on silicon); no RX words while parked; manual pattern into the capture SRAM; error-triggered capture; `rxStartMode` immediate; track counters; the loopback lane and its FIFO flags; per-lane fixed and inverted sources; one injected error found by lane, UI and class; the observation bumps (on for that test only) and the TX debug lane; the sideband tester | +| `phytest-clocks.c` | UCIe0 looped back | TX divider at /1, /2, /4 off the bypass pin; PHY test clock onto PLL8 /8, stopping the program (instead of hanging the bus) if a moved clock doesn't run; main clock onto PLL8 and PLL12; a PHY test clock too slow for the link, which must set both FIFO flags (below), and the recovery; TX queue capped at 8 words with the PHY test clock at twice the packet clock (at equal rates 8 runs dry and 10 holds); sideband clock onto PLL8 /10; every clock meter after every move, and no PLL lock lost | +| `phytest-two-chip.c` | two chips, each one's UCIe1 wired to the other's UCIe0 (the two-chip ring, or two chips on a package) | an LFSR run each way; each RX hears only the TX wired to it; `rxManualCheck` scoring the partner's manual pattern against this chip's TX pattern SRAM, with one reference word deliberately wrong | + +**A slow PHY test clock starves this die's TX and overflows its RX.** When a run's next data word +isn't queued in time, `TxClkGater` sends an idle word instead. The receiving RX then gets an idle +word mid-run, or with the clock gated, the burst split in two. With the clock running, the RX still +takes a word every packet clock, more than a slow PHY test clock drains. On a looped-back link, +`UCIE_TX_TEST_FIFO_UNDERFLOW` and `UCIE_RX_TEST_FIFO_OVERFLOW` both set. Between two dies, the RX +overflow shows on the die with the slower PHY test clock, whichever die sends. + +Every wait in `phytest.h` is bounded in core cycles (`PT_TIMEOUT`). A bound counted in MMIO reads +is far too short on silicon next to a slow divided clock. ### How the two-chip program keeps in step -Each chip arms the RX it is about to be sent to, says so to its partner as a -sideband packet on that link, and only starts its own TX once the partner has -said the same of the RX that TX feeds. Both chips run the same binary and -need nothing else in common: not a host, not a shared clock, not matching -code timing. Run it on both chips at once in the lab. +Each chip arms the RX it is about to be sent to and tells its partner with a sideband packet on +that link. It starts its own TX only after the partner has said the same of the RX that TX feeds. +The chips need no host or shared clock, but they do need to start close together: +- Each message is sent once. One sent before the partner has set up that link (still in `ucieRst`, + or before `pt_sb_reset`) is lost, and nothing resends it. +- A chip waits `PT_TIMEOUT` (a few ms) for each message, then carries on alone. + +So start both chips within a few milliseconds of each other. On the bench, release both resets +together after both binaries are loaded. ### Running them in simulation @@ -333,24 +281,23 @@ make -C software phytest-loopback.riscv phytest-clocks.riscv phytest-two-chip.ri ./mill test.testOnly edu.berkeley.cs.iris.IrisSpec -- -z "should run phytest" ``` -VCS compiles its own C with the host `gcc`; GCC 14 rejects it -(`rmapats.c: implicit declaration of function`), so put a GCC 13 or older -first on `PATH` for the sim. - -The tests: +VCS compiles its own C with the host `gcc`. GCC 14 rejects it +(`rmapats.c: implicit declaration of function`), so put GCC 13 or older first on `PATH` for the +sim. -| Test | Config | Notes | -|---|---|---| -| `should run phytest loopback test` | `IrisConfig(sim = true)` | also checks that every observation bump of both links toggled, from `DebugBumpMonitor` in the harness, while the program had them on | -| `should run phytest loopback test on the tapeout config` | `IrisConfig(sim = false)`, serial TL at 100 MHz | the netlist's configuration | -| `should run phytest clocks test` | `IrisConfig(sim = true)` | | -| `should run phytest two-chip test` | two chips, `IrisConfig(sim = true)` | | +The tests run on `IrisConfig(sim = true)` unless noted: +- `should run phytest loopback test`. It also checks that every observation bump of both links + toggled while the program had them on. +- `should run phytest loopback test on the tapeout config`: `IrisConfig(sim = false)`, serial TL at + 100 MHz, the netlist's configuration. +- `should run phytest clocks test`. +- `should run phytest two-chip test`, on two chips. ### What simulation does not show -- The lanes are the behavioral models (`includeDefaultModels`): a shift - register per lane, so nothing about a code, a termination or a delay setting - makes a lane fail. The AMS models in `ucie/verilog` are the tier for that. -- The harness clocks are fixed: an 8 GHz main bypass clock, a 500 MHz PHY test - bypass clock, an 800 MHz sideband bypass clock and a 100 MHz PLL reference. +- The lanes are the behavioral models (`includeDefaultModels`): a shift register per lane. No + code, termination or delay setting makes a lane fail. The AMS models in `ucie/verilog` cover + that. +- The harness clocks are fixed (section 3): 8 GHz main bypass, 500 MHz PHY test bypass, 800 MHz + sideband bypass, 100 MHz PLL reference. - The observation bumps are only checked for toggling, not for what they carry. diff --git a/software/phytest-clocks.c b/software/phytest-clocks.c index ef6e69e..296c506 100644 --- a/software/phytest-clocks.c +++ b/software/phytest-clocks.c @@ -1,10 +1,10 @@ -// PhyTest across the clock configurations bring-up moves through, on UCIe0 -// with its bumps looped back: the TX divider, each PLL under the main clock, -// the PHY test and sideband clocks off a PLL, and a PHY test clock too slow -// for the link, which the crossing flags have to report. +// PhyTest on UCIe0 with its bumps looped back, through the clock setups of +// bring-up: the TX divider, the main clock on each PLL, the PHY test and +// sideband clocks on a PLL, and a PHY test clock too slow for the link, which +// the crossing flags must report. // -// Every move ends in `pt_setup`, which restarts the block on its new clocks, -// as bring-up does. +// As in bring-up, every change ends with `pt_setup`, which restarts the block +// on its new clocks. #include "phytest.h" @@ -29,6 +29,25 @@ static void move_main_clk(uintptr_t base, uint64_t sel, uint64_t div) { pt_setup(base); } +// After an apply that moved the PHY test or sideband clock: both must run +// before `pt_setup` touches their register windows, or the bus hangs. If +// either is stopped (a PLL that won't lock), end the apply, put both back on +// their bypass pins, and stop the program. +static void require_clocks(uintptr_t base, const char *what) { + int busy = !pt_wait_clk_cfg(base); + uint64_t pt = pt_meter_mhz(base, UCIE_CLK_METER_PHY_TEST, PT_CHIP_MHZ); + uint64_t sb = pt_meter_mhz(base, UCIE_CLK_METER_SB, PT_CHIP_MHZ); + if (!busy && pt != 0 && sb != 0) return; + PT_CHECK(0, "%s: apply busy %d, PHY test %lu MHz, sideband %lu MHz", what, + busy, pt, sb); + release_clk_gate(base); + pt_wr(base, UCIE_PHY_TEST_CLK_BYPASS_EN, 1); + pt_wr(base, UCIE_SB_CLK_BYPASS_EN, 1); + apply_clk_cfg(base); + release_clk_gate(base); + pt_finish("phytest-clocks"); +} + // The packet clocks, TX and looped-back RX, from the clock meters. static void check_packet_clocks(uintptr_t base, uint64_t mhz) { pt_check_meter(base, UCIE_CLK_METER_TX_DIV, mhz, "TX divided"); @@ -41,7 +60,7 @@ static void test_sideband_on_pll(uintptr_t base) { pt_wr(base, UCIE_SB_CLK_DIV, SB_DIV10); pt_wr(base, UCIE_SB_CLK_BYPASS_EN, 0); apply_clk_cfg(base); - pt_wait_clk_cfg(base); + require_clocks(base, "sideband onto PLL8 /10"); pt_setup(base); const uint64_t packet = 0x5a5a00000000c10cULL; pt_sb_send(base, packet); @@ -73,7 +92,7 @@ int main(void) { // holds the PHY test clock's gate shut until PLL8 has locked. pt_begin("ucie0", "PHY test clock onto PLL8 /8"); use_internal_clk(base, SRC_PLL8, PHY_TEST_DIV8); - pt_wait_clk_cfg(base); + require_clocks(base, "PHY test clock onto PLL8 /8"); pt_wait_eq(base, UCIE_PLL_LOCK_OBSERVED, 3, "both PLLs to lock"); pt_setup(base); pt_check_meter(base, UCIE_CLK_METER_PHY_TEST, 1000, "PHY test on PLL8 /8"); @@ -84,10 +103,10 @@ int main(void) { check_packet_clocks(base, 500); pt_lfsr_check(base, N_PACKETS, "main on PLL8 /1"); - // The TX queue capped tighter than its reset value of 16, for the lowest - // latency, with the PHY test clock at twice the packet clock. The closer - // the two clocks, the more room a cap needs: at equal rates 8 runs the - // queue dry and 10 is the least that holds. + // The TX queue capped below its reset value of 16, for the lowest latency, + // with the PHY test clock at twice the packet clock. The closer the two + // clocks, the larger the cap must be. At equal rates, 8 runs the queue dry + // and 10 is the smallest that works. pt_begin("ucie0", "TX queue capped at 8 words"); pt_wr(base, UCIE_TX_QUEUE_LIMIT, 8); pt_lfsr_check(base, N_PACKETS, "TX queue capped at 8 words"); @@ -98,13 +117,13 @@ int main(void) { check_packet_clocks(base, 750); pt_lfsr_check(base, N_PACKETS, "main on PLL12 /1"); - // The PHY test clock back onto its bypass pin, which the harness runs at - // 500 MHz, under 12 GHz lanes that move a word every 1.33 ns: the TX queue - // runs dry partway through the run, and its flag has to say so. The PHY end - // fills every word the queue does not have with an idle one, the forwarded - // clock running, so the looped-back RX still takes a word every packet - // clock, more than the PHY test clock can drain: its queue overflows too, - // and the two packet clocks meter the same. + // The PHY test clock back on its bypass pin, which the harness runs at + // 500 MHz. The 12 GHz lanes move a word every 1.33 ns, so the TX queue runs + // dry partway through the run and its underflow flag must be set. The PHY + // sends an idle word for each missing word and keeps the forwarded clock + // running. The looped-back RX still takes a word every packet clock, faster + // than the PHY test clock can drain, so the RX queue overflows too. The two + // packet clocks meter the same. pt_begin("ucie0", "PHY test clock too slow for the link"); pt_wr(base, UCIE_PHY_TEST_CLK_BYPASS_EN, 1); apply_clk_cfg(base); @@ -131,7 +150,7 @@ int main(void) { pt_begin("ucie0", "PHY test clock back onto PLL8 /8"); pt_wr(base, UCIE_PHY_TEST_CLK_BYPASS_EN, 0); apply_clk_cfg(base); - pt_wait_clk_cfg(base); + require_clocks(base, "PHY test clock back onto PLL8 /8"); move_main_clk(base, MAIN_PLL8, TX_DIV1); pt_lfsr_check(base, N_PACKETS, "after the slow PHY test clock"); diff --git a/software/phytest-loopback.c b/software/phytest-loopback.c index a13aad2..2e0501d 100644 --- a/software/phytest-loopback.c +++ b/software/phytest-loopback.c @@ -79,16 +79,16 @@ static void test_valid_on_track(uintptr_t base) { pt_wr(base, UCIE_RX_VALID_LANE_SEL, UCIE_DEFAULT_VALID_LANE_SEL); } -// Bursts with the forwarded clock gated between them, the way the UCIe -// controller parks it. The RX lanes only deserialize while clock edges -// arrive, so this is the real receiver stopping and restarting. -// UCIe's clock gating at the reset values: no preamble and a packet of -// postamble, parked high and low in turn, then always low. A packet is enough -// once the RX dividers have been realigned behind the parked clock and one 40 -// UI gap has moved the RX word boundary so that every burst ends 23 UI into -// an RX word (ucie/docs/phytest_bringup.md, section 8). With no preamble, the -// first edge after a park has to sample the burst's first data UI, so the -// forwarded clock is centred for this test and put back after it. +// Bursts with the forwarded clock gated between them, as the UCIe controller +// parks it. The RX lanes deserialize only on clock edges, so this stops and +// restarts the real receiver. +// Gating uses the UCIe reset values: no preamble, one packet of postamble. +// The clock parks high and low in turn, then always low. One packet is enough +// after the RX dividers are realigned behind the parked clock and one 40 UI +// gap moves the RX word boundary so every burst ends 23 UI into an RX word +// (ucie/docs/phytest_bringup.md, section 8). With no preamble, the first edge +// after a park must sample the burst's first data UI, so the test centres the +// forwarded clock and restores it afterwards. static void test_gated_bursts(uintptr_t base) { const uint64_t n = 24; const uint64_t phase = pt_rd(base, UCIE_CLK_PHASE_SEL); @@ -101,9 +101,9 @@ static void test_gated_bursts(uintptr_t base) { pt_wr(base, UCIE_RX_BURST_MODE, 1); for (int alternate = 1; alternate >= 0; alternate--) { pt_wr(base, UCIE_TX_CLK_PARK_ALTERNATE, alternate); - // Gated only after `pt_arm`: its RX datapath reset needs clock edges to - // release. Then the dividers realigned behind the parked clock, so the - // next burst's first edge samples its first data UI. + // Gate only after `pt_arm`, because its RX datapath reset needs clock + // edges to release. Then realign the dividers behind the parked clock, so + // the next burst's first edge samples its first data UI. pt_arm(base, UCIE_TX_TEST_MODE_LFSR, 1); pt_wr(base, UCIE_TX_CLK_GATE, 1); pt_wait_cycles(256); @@ -143,6 +143,8 @@ static void test_gated_bursts(uintptr_t base) { set_clk_en(base, 0); set_rx_clk_en(base, 0); pt_wr(base, UCIE_CLK_PHASE_SEL, phase); + apply_clk_cfg(base); + pt_wait_clk_cfg(base); reset_dividers(base); set_clk_en(base, 1); set_rx_clk_en(base, 1); @@ -185,9 +187,9 @@ static void test_manual_capture(uintptr_t base) { pt_wr(base, UCIE_TX_MANUAL_REPEAT_PERIOD, 0); } -// An error-triggered capture: two lanes carry the same stream, so one shows -// what the other should have received, and the SRAM has to hold exactly the -// one flipped bit. +// An error-triggered capture. Two lanes send the same stream, so one shows +// what the other should have received. The SRAM must hold exactly the one +// flipped bit. #define TWIN 0 #define VICTIM 1 static uint64_t twin_seed(int lane) { @@ -227,9 +229,10 @@ static void test_error_capture(uintptr_t base) { } pt_check_errors(base, PT_MAINBAND_MASK, one_on_victim, "error capture run"); pt_wr(base, UCIE_RX_PAUSE_COUNTERS, 0); + // Back to the reset values: half the SRAM after the trigger, every lane. pt_wr(base, UCIE_RX_CAPTURE_MODE, UCIE_CAPTURE_MODE_FIRST); - pt_wr(base, UCIE_RX_CAPTURE_POST_TRIGGER, 0); - pt_wr(base, UCIE_RX_TRIGGER_LANE_MASK, 0); + pt_wr(base, UCIE_RX_CAPTURE_POST_TRIGGER, UCIE_SRAM_PACKETS / 2); + pt_wr(base, UCIE_RX_TRIGGER_LANE_MASK, (1ULL << UCIE_NUM_TEST_LANES) - 1); pt_wr(base, UCIE_TX_INJECT_LANE, 0); reset_fsms(base); } @@ -278,7 +281,7 @@ static void test_track(uintptr_t base) { printf("[%s] track clock lands on %s UIs\n", pt_port, even == ones ? "even" : "odd"); pt_wr(base, UCIE_TX_TRACK_CLK, 0); - pt_wr(base, UCIE_TX_TRACK_WORD, 0); + pt_wr(base, UCIE_TX_TRACK_WORD, UCIE_DEFAULT_TRACK); } // ===== Loopback lane, debug lane, sideband ===== @@ -318,12 +321,12 @@ static void test_loopback_lane(uintptr_t base) { reset_fsms(base); } -// The observation bumps, which `setup_ucie` leaves off: on for this test -// alone, with something on each -- the TX data debug lane running, the clock -// mux on the TX divided clock, and traffic on the RX lane `rxData` watches. -// The simulation harness checks every bump moved; on the bench, this is when -// to look with a scope. The debug lane only drives a bump, so from here all -// that can be checked is that it runs to completion without starving. +// The observation bumps, which `setup_ucie` leaves off. Only this test turns +// them on and drives each: the TX data debug lane runs, the clock mux selects +// the TX divided clock, and the RX lane `rxData` watches gets traffic. The +// simulation harness checks every bump toggled; on the bench, probe them with +// a scope now. The debug lane only drives a bump, so software can check only +// that it runs to completion without starving. static void test_observation(uintptr_t base) { enable_debug_drivers(base, 1); pt_wr(base, UCIE_DEBUG_CLK_MUX_SEL, 1); @@ -375,9 +378,10 @@ static uint64_t err_positions(uintptr_t base, int lane) { return pt_rd(base, UCIE_RX_ERR_POS_MASK); } -// Victims and aggressors: one lane held at a static level, one inverted, -// clean when the RX expects the same; then the inverted lane read as its -// plain stream, which gets every bit wrong, half on each sampling edge. +// Victims and aggressors. First one lane is held at a static level and one is +// inverted, and the RX expects the same, so the run is clean. Then the RX +// reads the inverted lane as plain, so every bit is wrong, half on each +// sampling edge. static void test_lane_sources(uintptr_t base) { const uint64_t fixed = 1ULL << FIXED_LANE; const uint64_t inverted = (1ULL << INVERTED_LANE) | (1ULL << UCIE_TRACK_LANE); diff --git a/software/phytest-two-chip.c b/software/phytest-two-chip.c index d13f529..b10198d 100644 --- a/software/phytest-two-chip.c +++ b/software/phytest-two-chip.c @@ -1,11 +1,11 @@ -// PhyTest between two chips, each running this program, with UCIe1 of each -// wired to UCIe0 of the other: the two-chip ring in simulation, or two +// PhyTest between two chips, each running this program. UCIe1 of each chip +// is wired to UCIe0 of the other: the two-chip ring in simulation, or two // chips on a package. // -// Each direction is tested in its own phase. A chip only starts a TX once -// the partner has said, over the sideband of the same link, that the RX it -// feeds is armed, so the two programs need nothing else to keep in step: -// not a shared clock, not a host, not matching code timing. +// Each direction is tested in its own phase. A chip starts a TX only after +// the partner reports, over the sideband of the same link, that the RX it +// feeds is armed. The programs need nothing else to stay in step: no shared +// clock, no host, no matching code timing. // // my UCIe1 TX --> partner UCIe0 RX my UCIe0 sideband --> partner UCIe1 // my UCIe0 TX --> partner UCIe1 RX my UCIe1 sideband --> partner UCIe0 @@ -18,9 +18,9 @@ #define ARMED(phase) (0x5054000041524d00ULL | (phase)) -// Tells the partner, on the sideband of `rx`'s link, that `rx` is armed, and -// waits on the sideband of `tx`'s link for the partner to say the same of -// the RX that `tx` feeds. +// Tells the partner, on the sideband of `rx`'s link, that `rx` is armed. Then +// waits on the sideband of `tx`'s link for the partner to say the RX that +// `tx` feeds is armed. static int handshake(uintptr_t rx, uintptr_t tx, uint64_t phase) { pt_sb_send(rx, ARMED(phase)); uint64_t got; diff --git a/software/phytest.h b/software/phytest.h index 6a64837..aba6a3b 100644 --- a/software/phytest.h +++ b/software/phytest.h @@ -1,9 +1,9 @@ // PhyTest bring-up helpers, on top of the generated ucie.h. // -// Written for the lab as much as for simulation: every wait is bounded, and -// every check prints what it expected and what it read instead of stopping, -// so one run reports everything that is wrong. A program calls -// `pt_finish()` at the end, which exits nonzero if any check failed. +// For the lab and for simulation. Every wait is bounded. A failed check +// prints what it expected and what it read, then continues, so one run +// reports every problem. A program calls `pt_finish()` at the end; it exits +// nonzero if any check failed. #ifndef __PHYTEST_H__ #define __PHYTEST_H__ @@ -25,8 +25,8 @@ #define PT_MAINBAND_LANES (UCIE_TRACK_LANE + 1) #define PT_ALL_LANES_MASK ((1ULL << UCIE_NUM_TEST_LANES) - 1) -// Bounds on every wait, in core cycles. Generous: on silicon an MMIO read is -// quick next to a slow divided clock, so a bound counted in reads is not. +// Bound on every wait, in core cycles, not reads: on silicon an MMIO read is +// fast next to a slow divided clock. The bound is generous. #define PT_TIMEOUT 2000000ULL // The chip clock the UCIe clock register block runs on, in MHz: the rate the @@ -36,10 +36,10 @@ #endif // Global delay taps that centre the forwarded clock on the data of a -// looped-back link at 16 GT/s on the Iris harness, as the UCIe repo's tests -// and `setup_ucie_digital` use. Out of reset the line is at its longest, which -// is fine for a free-running clock but samples a gated burst's first data UI -// with no edge. On silicon, override it with the code mainband training finds. +// looped-back link at 16 GT/s on the Iris harness (as in the UCIe repo's tests +// and `setup_ucie_digital`). The reset value, the longest delay, works for a +// free-running clock but leaves a gated burst's first data UI with no edge. +// On silicon, override it with the code mainband training finds. #ifndef PT_CENTRED_DELAY_TAPS #define PT_CENTRED_DELAY_TAPS 29ULL #endif @@ -106,9 +106,9 @@ static inline int pt_wait_eq(uintptr_t base, uint64_t reg, uint64_t want, return 1; } -// Waits for the RX to hand over `n` more idle words than it had: the RX -// datapath is out of reset, and a forwarded clock is arriving. The counter is -// 32 bits and free running, so the difference is taken modulo that. +// Waits for `n` more RX idle words, which shows the RX datapath is out of +// reset and a forwarded clock is arriving. The counter is a free-running +// 32-bit count, so the difference is taken modulo 2^32. static inline int pt_wait_idle_words(uintptr_t base, uint32_t n) { uint32_t w0 = (uint32_t)pt_rd(base, UCIE_RX_IDLE_WORDS_OBSERVED); uint64_t start = rdcycle(); @@ -178,10 +178,9 @@ static inline void pt_check_fifo_flags(uintptr_t base, const char *what) { // ===== Clock meters ===== -// MHz of one of the clock meters (`UCIE_CLK_METER_*`), given the chip clock -// the meters count against. A meter in the clock register block answers -// whatever state the rest of the link is in, so this is safe before the -// PhyTest registers are. +// Reads a clock meter (`UCIE_CLK_METER_*`) in MHz, given the chip clock the +// meters count against. The meters respond in any link state, so this works +// before the PhyTest registers do. static inline uint64_t pt_meter_mhz(uintptr_t base, uint64_t reg, uint64_t chip_mhz) { pt_wait_cycles(4 * UCIE_CLK_METER_WINDOW_CYCLES); @@ -198,10 +197,9 @@ static inline void pt_check_meter(uintptr_t base, uint64_t reg, uint64_t mhz, // ===== Runs ===== -// Programs a finite mainband run of `n` packets each way and resets both -// FSMs, which reseeds the LFSRs. Starts nothing: options that need the RX -// datapath reset to have released first (`txClkGate`) go in between this -// and `pt_go`. +// Programs a finite mainband run of `n` packets each way, then resets both +// FSMs, which reseeds the LFSRs. It starts nothing. Set options that need the +// RX datapath out of reset (`txClkGate`) between this and `pt_go`. static inline void pt_arm(uintptr_t base, uint64_t mode, uint64_t n) { pt_wr(base, UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); pt_wr(base, UCIE_TX_TEST_MODE, mode); @@ -273,9 +271,9 @@ static inline uint32_t pt_captured(uintptr_t base, int lane, int entry) { return (uint32_t)pt_rd(base, UCIE_RX_DATA_CHUNK); } -// A manual pattern word: distinct per row and lane, with the framing -// waveform on valid. A mainband run reads the loopback lane as zero, so its -// slot is zero too, which a loopback-lane run overrides. +// A manual pattern word, distinct per row and lane, with the framing waveform +// on valid. The loopback lane's slot is zero because a mainband run reads +// that lane as zero. A loopback-lane run overrides it. static inline uint32_t pt_pattern_word(int row, int lane) { if (lane == UCIE_VALID_LANE) return (uint32_t)UCIE_DEFAULT_VALID; if (lane == UCIE_LOOPBACK_LANE) return 0; diff --git a/software/ucie.h b/software/ucie.h index 0502196..493bde3 100644 --- a/software/ucie.h +++ b/software/ucie.h @@ -90,7 +90,7 @@ #define UCIE_DEBUG_RX_LANE 0x3718ULL #define UCIE_DEBUG_RX_BIT 0x3720ULL #define UCIE_TX_VALID 0x3728ULL -#define UCIE_RX_LFSR_VALID 0x3730ULL +#define UCIE_RX_VALID 0x3730ULL #define UCIE_CONTROLLER_SEL 0x3738ULL #define UCIE_MAINBAND_MODE 0x3740ULL #define UCIE_SIDEBAND_MODE 0x3748ULL @@ -236,10 +236,10 @@ #define UCIE_VENDOR_DEBUG_UNLOCK 0x7010ULL #define UCIE_VENDOR_FORCE_LINK_ACTIVE 0x7014ULL #define UCIE_VENDOR_TS_OVERRIDE_EN 0x7018ULL -#define UCIE_UCIE_LINK_RESET 0x3c00ULL -#define UCIE_UCIE_PWR_GOOD 0x3c08ULL -#define UCIE_UCIE_RETRY_TRAINING_AMT 0x3c10ULL -#define UCIE_UCIE_CONTROLLER_RST 0x3c18ULL +#define UCIE_LINK_RESET 0x3c00ULL +#define UCIE_PWR_GOOD 0x3c08ULL +#define UCIE_RETRY_TRAINING_AMT 0x3c10ULL +#define UCIE_CONTROLLER_RST 0x3c18ULL #define UCIE_MAIN_CLK_SEL 0x10000ULL #define UCIE_PLL8_EN 0x10008ULL #define UCIE_PLL12_EN 0x10010ULL @@ -262,7 +262,7 @@ #define UCIE_CLK_CFG_UNGATE_DELAY 0x10098ULL #define UCIE_CLK_CFG_UNGATE_REQ 0x100a0ULL #define UCIE_PLL_LOCK_OBSERVED 0x100a8ULL -#define UCIE_UCIE_RST 0x100b0ULL +#define UCIE_RST 0x100b0ULL #define UCIE_PHY_TEST_CLK_SRC_SEL 0x100b8ULL #define UCIE_SB_CLK_SRC_SEL 0x100c0ULL #define UCIE_TX_DIVIDER_RST 0x100c8ULL @@ -280,6 +280,8 @@ #define UCIE_CLK_METER_TX_DIV 0x10128ULL #define UCIE_CLK_METER_RX_DIV 0x10130ULL #define UCIE_PLL_LOCK_LOST 0x10138ULL +#define UCIE_CLK_GATE_EDGE_SEL 0x10140ULL +#define UCIE_CLK_PHASE_AUTO_APPLY 0x10148ULL #define UCIE_RATE_CFG 0x10180ULL #define UCIE_RATE_CFG_WIDTH 0x8ULL @@ -352,8 +354,8 @@ static inline void reset_datapath(uintptr_t base) { reg_write64(base + UCIE_RX_DATAPATH_RST, 0x1ULL); } static inline void reset_fsms(uintptr_t base) { - reset_datapath(base); reg_write64(base + UCIE_TX_FSM_RST, 0x1ULL); + reset_datapath(base); reg_write64(base + UCIE_RX_FSM_RST, 0x1ULL); reg_write64(base + UCIE_DEBUG_TX_FSM_RST, 0x1ULL); assert(reg_read64(base + UCIE_TX_TEST_STATE) == (UCIE_TX_TEST_STATE_IDLE)); @@ -405,8 +407,8 @@ static inline void release_clk_gate(uintptr_t base) { reg_write64(base + UCIE_CLK_CFG_UNGATE_REQ, 0x1ULL); } static inline void reset_ucie(uintptr_t base) { - reg_write64(base + UCIE_UCIE_RST, 0x1ULL); - reg_write64(base + UCIE_UCIE_RST, 0x0ULL); + reg_write64(base + UCIE_RST, 0x1ULL); + reg_write64(base + UCIE_RST, 0x0ULL); } static inline void reset_dividers(uintptr_t base) { reg_write64(base + UCIE_TX_DIVIDER_RST, 0x1ULL); @@ -417,13 +419,11 @@ static inline void reset_dividers(uintptr_t base) { static inline void set_main_clk(uintptr_t base, uint64_t src, uint64_t div) { reg_write64(base + UCIE_MAIN_CLK_SEL, src); reg_write64(base + UCIE_TX_CLK_DIV, div); - reg_write64(base + UCIE_CLK_EN, 0x1ULL); apply_clk_cfg(base); } static inline void set_tx_phase(uintptr_t base, uint64_t half_cycles) { - reg_write64(base + UCIE_CLK_EN, 0x0ULL); reg_write64(base + UCIE_TX_CLK_PHASE, half_cycles); - reg_write64(base + UCIE_CLK_EN, 0x1ULL); + apply_clk_cfg(base); } static inline void use_internal_clk(uintptr_t base, uint64_t phytest_src, uint64_t phytest_div) { reg_write64(base + UCIE_PLL8_EN, 0x1ULL); @@ -439,12 +439,13 @@ static inline void set_rx_clk_en(uintptr_t base, uint64_t en) { } static inline void set_global_delay(uintptr_t base, uint64_t taps) { reg_write64(base + UCIE_CLK_PHASE_SEL, ((taps >= 64) ? ~0x0ULL : ((0x1ULL << taps) - 0x1ULL))); + apply_clk_cfg(base); } static inline void set_tx_delay(uintptr_t base, uint64_t lane, uint64_t taps) { { uint64_t tile; tile = reg_read64(base + UCIE_TXCTL + lane * UCIE_TXCTL_WIDTH + UCIE_TXCTL_TILE_OFS); - write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, ((tile & ~UCIE_TX_CTL_DELAY_MASK) | ((((0x1ULL << taps) - 0x1ULL) << UCIE_TX_CTL_DELAY_LSB) & UCIE_TX_CTL_DELAY_MASK))); + write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, ((tile & ~UCIE_TX_CTL_DELAY_MASK) | ((((taps >= 64) ? ~0x0ULL : ((0x1ULL << taps) - 0x1ULL)) << UCIE_TX_CTL_DELAY_LSB) & UCIE_TX_CTL_DELAY_MASK))); } } @@ -452,7 +453,7 @@ static inline void set_rx_vref(uintptr_t base, uint64_t lane, uint64_t code) { write_rxctl(base, lane, UCIE_RXCTL_VREF_SEL_OFS, code); } static inline void set_rx_delay(uintptr_t base, uint64_t lane, uint64_t taps) { - write_rxctl(base, lane, UCIE_RXCTL_DCTRL_OFS, ((0x1ULL << taps) - 0x1ULL)); + write_rxctl(base, lane, UCIE_RXCTL_DCTRL_OFS, ((taps >= 64) ? ~0x0ULL : ((0x1ULL << taps) - 0x1ULL))); } static inline void enable_debug_drivers(uintptr_t base, uint64_t en) { @@ -462,6 +463,8 @@ static inline void enable_debug_drivers(uintptr_t base, uint64_t en) { reg_write64(base + UCIE_DEBUG_TXCTL_TILE, (en ? UCIE_ENABLE_TX_CTL : UCIE_DISABLE_TX_CTL)); } static inline void setup_ucie(uintptr_t base) { + set_clk_en(base, 0x0ULL); + set_rx_clk_en(base, 0x0ULL); reset_ucie(base); for (int lane = 0; lane < 21; lane++) { write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, UCIE_ENABLE_TX_CTL); @@ -471,11 +474,8 @@ static inline void setup_ucie(uintptr_t base) { reg_write64(base + UCIE_TX_CLK_P, UCIE_DEFAULT_CLK_P); reg_write64(base + UCIE_TX_CLK_N, UCIE_DEFAULT_CLK_N); reg_write64(base + UCIE_TX_VALID, UCIE_DEFAULT_VALID); - reg_write64(base + UCIE_RX_LFSR_VALID, UCIE_DEFAULT_VALID); + reg_write64(base + UCIE_RX_VALID, UCIE_DEFAULT_VALID); enable_debug_drivers(base, 0x0ULL); - set_clk_en(base, 0x0ULL); - set_rx_clk_en(base, 0x0ULL); - reset_dividers(base); set_clk_en(base, 0x1ULL); set_rx_clk_en(base, 0x1ULL); reg_write64(base + UCIE_CONTROLLER_SEL, UCIE_CONTROLLER_SEL_PHYTEST); @@ -492,6 +492,12 @@ static inline void seed_lfsrs(uintptr_t base) { } static inline void run_lfsr(uintptr_t base, uint64_t packets) { + reg_write64(base + UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); + reg_write64(base + UCIE_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); + reg_write64(base + UCIE_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); + reg_write64(base + UCIE_RX_DATA_MODE, UCIE_DATA_MODE_FINITE); + reg_write64(base + UCIE_RX_PACKETS_TO_RECEIVE, packets); + reg_write64(base + UCIE_TX_PACKETS_TO_SEND, packets); reset_fsms(base); { uint64_t settle_w; @@ -506,12 +512,6 @@ static inline void run_lfsr(uintptr_t base, uint64_t packets) { printf("run_lfsr: the RX is handing over no words; no forwarded clock is arriving (see clkMeterRxDiv)\n"); } } - reg_write64(base + UCIE_TEST_TARGET, UCIE_TEST_TARGET_MAINBAND); - reg_write64(base + UCIE_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); - reg_write64(base + UCIE_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); - reg_write64(base + UCIE_RX_DATA_MODE, UCIE_DATA_MODE_FINITE); - reg_write64(base + UCIE_RX_PACKETS_TO_RECEIVE, packets); - reg_write64(base + UCIE_TX_PACKETS_TO_SEND, packets); reg_write64(base + UCIE_TX_EXECUTE, 0x1ULL); { uint64_t r; @@ -548,7 +548,7 @@ static inline void align_rx_words(uintptr_t base) { reg_write64(base + UCIE_TX_CLK_P, UCIE_DEFAULT_CLK_P); reg_write64(base + UCIE_TX_CLK_N, UCIE_DEFAULT_CLK_N); reg_write64(base + UCIE_TX_VALID, UCIE_DEFAULT_VALID); - reg_write64(base + UCIE_RX_LFSR_VALID, UCIE_DEFAULT_VALID); + reg_write64(base + UCIE_RX_VALID, UCIE_DEFAULT_VALID); for (int lane = 0; lane < 18; lane++) { reg_write64(base + UCIE_RX_UI_DELAY + lane * UCIE_RX_UI_DELAY_WIDTH, 0x0ULL); } @@ -571,7 +571,7 @@ static inline void align_rx_words(uintptr_t base) { } static inline void setup_ucie_digital(uintptr_t base) { - reg_write64(base + UCIE_UCIE_RST, 0x0ULL); + reg_write64(base + UCIE_RST, 0x0ULL); set_clk_en(base, 0x0ULL); set_rx_clk_en(base, 0x0ULL); set_global_delay(base, 0x1dULL); @@ -589,7 +589,7 @@ static inline void setup_ucie_digital(uintptr_t base) { reg_write64(base + UCIE_TX_CLK_POSTAMBLE, 0x20ULL); reg_write64(base + UCIE_CONTROLLER_SEL, UCIE_CONTROLLER_SEL_UCIE); reset_datapath(base); - reg_write64(base + UCIE_UCIE_CONTROLLER_RST, 0x0ULL); + reg_write64(base + UCIE_CONTROLLER_RST, 0x0ULL); { uint64_t linkControl; linkControl = reg_read64(base + UCIE_RAW_FORMAT_ENABLE); diff --git a/test/src/IrisSpec.scala b/test/src/IrisSpec.scala index 3e5cc8a..84846e5 100644 --- a/test/src/IrisSpec.scala +++ b/test/src/IrisSpec.scala @@ -62,9 +62,9 @@ class ClockSourceAtFreqMHz(val freqMHz: Double) ) } -/** Counts the transitions on a UCIe link's observation bumps and reports them - * when the simulation ends, so that a test can tell the bumps bring-up puts - * a scope on are driven at the chip's pins. +/** Counts transitions on a UCIe link's observation bumps and reports them at + * the end of simulation. A test uses this to check that the bumps bring-up + * probes with a scope are driven at the chip's pins. */ class DebugBumpMonitor(name: String) extends BlackBox(Map("NAME" -> StringParam(name))) @@ -516,12 +516,12 @@ class IrisSpec extends AnyFunSpec { ) } - // PhyTest from software on the core, through the SoC bus and the UCIe - // register map, over the behavioral lanes and clocking tile: the same - // programs bring-up runs on the chip. See docs/ucie_bringup.md. - // `setup_ucie` turns every observation driver on, and the program runs the - // TX debug lane and traffic on every RX lane, so every bump of both links - // has to have moved: the scope points bring-up relies on reach the pins. + // The PhyTest programs bring-up runs on the chip (docs/ucie_bringup.md), + // run by the core through the SoC bus and UCIe register map, over the + // behavioral lanes and clocking tile. + // The loopback program turns every observation driver on for one LFSR run + // and drives the TX debug lane and every RX lane. So every debug bump of + // both links must toggle, which shows the scope points reach the pins. def checkDebugBumps(simLog: String): Unit = for (link <- Seq("chip0.ucie0", "chip0.ucie1")) { val counts = Utils.debugBumpCounts(simLog, link) diff --git a/test/src/Utils.scala b/test/src/Utils.scala index b175103..39efc27 100644 --- a/test/src/Utils.scala +++ b/test/src/Utils.scala @@ -165,10 +165,9 @@ script -e -f -c "./simulation +permissive +vcs+thread+16 +dramsim +dramsim_ini_d simScript ).call(stdout = os.Inherit, stderr = os.Inherit, cwd = simDir) - // The simulator's exit status does not say whether the test passed: VCS - // ends with status 0 after a `$fatal`, whether from SimTop's timeout or - // from a failed assertion. SimTop prints its success line only when the - // chips report success, so the log decides it. + // The simulator's exit status does not show a pass: VCS exits 0 after a + // `$fatal`, from SimTop's timeout or a failed assertion. SimTop prints its + // success line only when the chips report success, so check the log. val simLog = os.read(simDir / "simulation.log") val failure = Seq("Assertion failed", "Fatal:", "Test timed out!").find(simLog.contains) diff --git a/ucie b/ucie index 62f031d..30f672c 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit 62f031dd8bca56ea4f1d3911b2031e1acd0c889d +Subproject commit 30f672ca9908b106fc7bce2a315e1fe6d27b92d2 From c4c38da15bbb70eb0e6d8204e2d10c62ad414994 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 25 Nov 2026 14:11:16 -0800 Subject: [PATCH 5/7] fix software --- docs/ucie_bringup.md | 17 +++++---- software/phytest-clocks.c | 7 ++-- software/phytest-two-chip.c | 62 ++++++++++++++++++++++++++------ software/ucie-digital-loopback.c | 8 +++++ software/ucie.h | 47 ++++++++++++++++++++---- ucie | 2 +- 6 files changed, 115 insertions(+), 28 deletions(-) diff --git a/docs/ucie_bringup.md b/docs/ucie_bringup.md index 2ff0c39..4affae3 100644 --- a/docs/ucie_bringup.md +++ b/docs/ucie_bringup.md @@ -264,13 +264,16 @@ is far too short on silicon next to a slow divided clock. Each chip arms the RX it is about to be sent to and tells its partner with a sideband packet on that link. It starts its own TX only after the partner has said the same of the RX that TX feeds. -The chips need no host or shared clock, but they do need to start close together: -- Each message is sent once. One sent before the partner has set up that link (still in `ucieRst`, - or before `pt_sb_reset`) is lost, and nothing resends it. -- A chip waits `PT_TIMEOUT` (a few ms) for each message, then carries on alone. - -So start both chips within a few milliseconds of each other. On the bench, release both resets -together after both binaries are loaded. +The chips need no host or shared clock, and needn't start together: +- A chip resends its message every `RESEND_CYCLES` until the partner acknowledges it on the same + link. A message sent before the partner has set up that link (still in `ucieRst`, or before + `pt_sb_reset`) is lost, and a resend replaces it. +- A packet that isn't one of the program's messages means the receiver came out of reset + mid-packet. The chip resets its receiver to realign, and the next resend gets through. +- A chip waits up to `HANDSHAKE_TIMEOUT` (1000 × `PT_TIMEOUT`, about 2 s at 1 GHz) for each + phase, then skips it. + +So start both chips within about a second of each other. ### Running them in simulation diff --git a/software/phytest-clocks.c b/software/phytest-clocks.c index 296c506..14f61ee 100644 --- a/software/phytest-clocks.c +++ b/software/phytest-clocks.c @@ -55,7 +55,8 @@ static void check_packet_clocks(uintptr_t base, uint64_t mhz) { } static void test_sideband_on_pll(uintptr_t base) { - // 800 MHz, /10 off PLL8. + // 800 MHz, /10 off PLL8, which this apply turns on if it isn't already. + pt_wr(base, UCIE_PLL8_EN, 1); pt_wr(base, UCIE_SB_CLK_SRC_SEL, SRC_PLL8); pt_wr(base, UCIE_SB_CLK_DIV, SB_DIV10); pt_wr(base, UCIE_SB_CLK_BYPASS_EN, 0); @@ -88,12 +89,12 @@ int main(void) { check_packet_clocks(base, 125); pt_lfsr_check(base, N_PACKETS, "bypass /4"); - // Both PLLs up, and the PHY test clock onto PLL8 /8, 1 GHz. The apply + // PLL8 up, and the PHY test clock onto it, /8 = 1 GHz. The apply // holds the PHY test clock's gate shut until PLL8 has locked. pt_begin("ucie0", "PHY test clock onto PLL8 /8"); use_internal_clk(base, SRC_PLL8, PHY_TEST_DIV8); require_clocks(base, "PHY test clock onto PLL8 /8"); - pt_wait_eq(base, UCIE_PLL_LOCK_OBSERVED, 3, "both PLLs to lock"); + pt_wait_eq(base, UCIE_PLL_LOCK_OBSERVED, 1, "PLL8 to lock"); pt_setup(base); pt_check_meter(base, UCIE_CLK_METER_PHY_TEST, 1000, "PHY test on PLL8 /8"); pt_lfsr_check(base, N_PACKETS, "PHY test clock on PLL8, main on bypass"); diff --git a/software/phytest-two-chip.c b/software/phytest-two-chip.c index b10198d..e623652 100644 --- a/software/phytest-two-chip.c +++ b/software/phytest-two-chip.c @@ -4,8 +4,9 @@ // // Each direction is tested in its own phase. A chip starts a TX only after // the partner reports, over the sideband of the same link, that the RX it -// feeds is armed. The programs need nothing else to stay in step: no shared -// clock, no host, no matching code timing. +// feeds is armed. Each report is resent until the partner acknowledges it, so +// the chips may start at different times. The programs need nothing else to +// stay in step: no shared clock, no host, no matching code timing. // // my UCIe1 TX --> partner UCIe0 RX my UCIe0 sideband --> partner UCIe1 // my UCIe0 TX --> partner UCIe1 RX my UCIe1 sideband --> partner UCIe0 @@ -17,16 +18,57 @@ #define N_MANUAL (8 * PERIOD) #define ARMED(phase) (0x5054000041524d00ULL | (phase)) +#define ACKED(phase) (0x5054000041434b00ULL | (phase)) +#define IS_MESSAGE(p) \ + (((p) & ~0xffULL) == ARMED(0) || ((p) & ~0xffULL) == ACKED(0)) -// Tells the partner, on the sideband of `rx`'s link, that `rx` is armed. Then -// waits on the sideband of `tx`'s link for the partner to say the RX that -// `tx` feeds is armed. +// Core cycles between resends of an unacknowledged message, and the longest +// a handshake waits for the partner. A message sent before the partner has +// set up its link is lost, so only a resend reaches a partner that started +// late. +#define RESEND_CYCLES 50000ULL +#define HANDSHAKE_TIMEOUT (1000 * PT_TIMEOUT) + +// Pops a sideband packet from `base` if one is waiting. A packet that isn't +// one of ours means the receiver came out of reset mid-packet and counts +// bits out of step, so realign it. The sender's next resend gets through. +static int sb_poll(uintptr_t base, uint64_t *packet) { + if (!pt_rd(base, UCIE_SB_RX_VALID)) return 0; + *packet = pt_rd(base, UCIE_SB_RX_PACKET); + pt_wr(base, UCIE_SB_RX_POP, 1); + if (IS_MESSAGE(*packet)) return 1; + pt_wr(base, UCIE_SB_RX_RST, 1); + return 0; +} + +// Tells the partner, on the sideband of `rx`'s link, that `rx` is armed, and +// resends until the partner acknowledges on that link. Meanwhile waits on the +// sideband of `tx`'s link for the partner to say the RX that `tx` feeds is +// armed, and acknowledges every copy. Done when both have happened. A packet +// for another phase is a late copy, or the partner running ahead. It is +// dropped; if it matters, a resend brings it back. static int handshake(uintptr_t rx, uintptr_t tx, uint64_t phase) { - pt_sb_send(rx, ARMED(phase)); - uint64_t got; - if (!pt_sb_recv(tx, &got)) return 0; - PT_CHECK_EQ("partner's armed message", got, ARMED(phase)); - return got == ARMED(phase); + int acked = 0, armed = 0, sent = 0; + uint64_t start = rdcycle(), last_send = 0, got; + while (!(acked && armed)) { + uint64_t now = rdcycle(); + if (now - start > HANDSHAKE_TIMEOUT) { + PT_CHECK(0, "partner never %s phase %lu", + armed ? "acknowledged" : "armed its RX for", phase); + return 0; + } + if (!acked && (!sent || now - last_send > RESEND_CYCLES)) { + if (!pt_sb_send(rx, ARMED(phase))) return 0; + last_send = now; + sent = 1; + } + if (sb_poll(rx, &got) && got == ACKED(phase)) acked = 1; + if (sb_poll(tx, &got) && got == ARMED(phase)) { + armed = 1; + if (!pt_sb_send(tx, ACKED(phase))) return 0; + } + } + return 1; } // One direction: an LFSR run from `tx` here to the partner, while `rx` here diff --git a/software/ucie-digital-loopback.c b/software/ucie-digital-loopback.c index e6b5c7e..f9b18be 100644 --- a/software/ucie-digital-loopback.c +++ b/software/ucie-digital-loopback.c @@ -8,6 +8,12 @@ #include "router.h" #include "ucie.h" +// The forwarded clock's global delay, centred on the data: the code training +// found on silicon, 29 taps on the simulation harness. +#ifndef CENTRED_DELAY_TAPS +#define CENTRED_DELAY_TAPS 29ULL +#endif + #define UCIE0_REG_BASE 0x200000UL #define UCIE1_REG_BASE 0x208000UL #define ROUTER_MMIO 0x4000 @@ -52,10 +58,12 @@ int main(void) { printf("Got chip ID: %d\n", chip_id); printf("Setting up UCIe0 (digital controller)\n"); + set_global_delay(UCIE0_REG_BASE, CENTRED_DELAY_TAPS); setup_ucie_digital(UCIE0_REG_BASE); printf("UCIe0 RX lanes held back %ld UI to align words\n", reg_read64(UCIE0_REG_BASE + UCIE_RX_UI_DELAY)); printf("Setting up UCIe1 (digital controller)\n"); + set_global_delay(UCIE1_REG_BASE, CENTRED_DELAY_TAPS); setup_ucie_digital(UCIE1_REG_BASE); printf("UCIe1 RX lanes held back %ld UI to align words\n", reg_read64(UCIE1_REG_BASE + UCIE_RX_UI_DELAY)); diff --git a/software/ucie.h b/software/ucie.h index 493bde3..c5c7dd1 100644 --- a/software/ucie.h +++ b/software/ucie.h @@ -161,6 +161,9 @@ #define UCIE_RX_UI_DELAY 0x39e0ULL #define UCIE_RX_UI_DELAY_WIDTH 0x8ULL #define UCIE_RX_VALID_START_THRESHOLD 0x3a70ULL +#define UCIE_DEBUG_TXCTL_SAMPLE_NEGEDGE 0x3a78ULL +#define UCIE_RX_AUTO_SEED 0x3a80ULL +#define UCIE_TL_RX_FIFO_OVERFLOW 0x3a88ULL #define UCIE_PCIE_EXT_CAP_ID 0x4000ULL #define UCIE_DVSEC_VENDOR_ID 0x4004ULL #define UCIE_DVSEC_ID 0x4008ULL @@ -282,7 +285,25 @@ #define UCIE_PLL_LOCK_LOST 0x10138ULL #define UCIE_CLK_GATE_EDGE_SEL 0x10140ULL #define UCIE_CLK_PHASE_AUTO_APPLY 0x10148ULL -#define UCIE_RATE_CFG 0x10180ULL +#define UCIE_PLL8_AUTO_EN 0x10150ULL +#define UCIE_PLL8_KP 0x10158ULL +#define UCIE_PLL8_KI 0x10160ULL +#define UCIE_PLL8_CODE_INIT 0x10168ULL +#define UCIE_PLL8_CODE_BYP 0x10170ULL +#define UCIE_PLL8_DBIAS 0x10178ULL +#define UCIE_PLL12_AUTO_EN 0x10180ULL +#define UCIE_PLL12_KP 0x10188ULL +#define UCIE_PLL12_KI 0x10190ULL +#define UCIE_PLL12_CODE_INIT 0x10198ULL +#define UCIE_PLL12_CODE_BYP 0x101a0ULL +#define UCIE_PLL12_DBIAS 0x101a8ULL +#define UCIE_PLL8_DCOARSE 0x101b0ULL +#define UCIE_PLL8_CODE_FULL 0x101b8ULL +#define UCIE_PLL8_CODE_INT 0x101c0ULL +#define UCIE_PLL12_CODE_FULL 0x101c8ULL +#define UCIE_PLL12_CODE_INT 0x101d0ULL +#define UCIE_CLK_CFG_GATE_DWELL 0x101d8ULL +#define UCIE_RATE_CFG 0x10200ULL #define UCIE_RATE_CFG_WIDTH 0x8ULL // === Constants === @@ -317,7 +338,7 @@ #define UCIE_TX_CTL_ENN_LSB 0x28ULL #define UCIE_TX_CTL_ENP_EQ_LSB 0x24ULL #define UCIE_TX_CTL_ENN_EQ_LSB 0x20ULL -#define UCIE_TRAIN_LFSR_SEED 0x123456789abcdefULL +#define UCIE_TRAIN_LFSR_SEED 0x8123456789abcdefULL #define UCIE_LFSR_SEED_LANE_STEP 0x1111ULL #define UCIE_TRAIN_DATA_LANES 0x10ULL #define UCIE_TRAIN_VALID_LANE 0x10ULL @@ -417,6 +438,12 @@ static inline void reset_dividers(uintptr_t base) { reg_write64(base + UCIE_RX_DIVIDER_RST, 0x0ULL); } static inline void set_main_clk(uintptr_t base, uint64_t src, uint64_t div) { + if (src == 0 || src == 2) { + reg_write64(base + UCIE_PLL8_EN, 0x1ULL); + } + if (src == 1) { + reg_write64(base + UCIE_PLL12_EN, 0x1ULL); + } reg_write64(base + UCIE_MAIN_CLK_SEL, src); reg_write64(base + UCIE_TX_CLK_DIV, div); apply_clk_cfg(base); @@ -426,9 +453,12 @@ static inline void set_tx_phase(uintptr_t base, uint64_t half_cycles) { apply_clk_cfg(base); } static inline void use_internal_clk(uintptr_t base, uint64_t phytest_src, uint64_t phytest_div) { - reg_write64(base + UCIE_PLL8_EN, 0x1ULL); - reg_write64(base + UCIE_PLL12_EN, 0x1ULL); - reg_write64(base + UCIE_X2_EN, 0x1ULL); + if (phytest_src == 0) { + reg_write64(base + UCIE_PLL8_EN, 0x1ULL); + } + if (phytest_src == 1) { + reg_write64(base + UCIE_PLL12_EN, 0x1ULL); + } reg_write64(base + UCIE_PHY_TEST_CLK_SRC_SEL, phytest_src); reg_write64(base + UCIE_PHY_TEST_CLK_DIV, phytest_div); reg_write64(base + UCIE_PHY_TEST_CLK_BYPASS_EN, 0x0ULL); @@ -574,12 +604,15 @@ static inline void setup_ucie_digital(uintptr_t base) { reg_write64(base + UCIE_RST, 0x0ULL); set_clk_en(base, 0x0ULL); set_rx_clk_en(base, 0x0ULL); - set_global_delay(base, 0x1dULL); reset_dividers(base); set_clk_en(base, 0x1ULL); set_rx_clk_en(base, 0x1ULL); for (int lane = 0; lane < 20; lane++) { - write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, UCIE_ENABLE_TX_CTL); + { + uint64_t tile; + tile = reg_read64(base + UCIE_TXCTL + lane * UCIE_TXCTL_WIDTH + UCIE_TXCTL_TILE_OFS); + write_txctl(base, lane, UCIE_TXCTL_TILE_OFS, ((tile & UCIE_TX_CTL_DELAY_MASK) | (UCIE_ENABLE_TX_CTL & ~UCIE_TX_CTL_DELAY_MASK))); + } } for (int lane = 0; lane < 18; lane++) { write_rxctl(base, lane, UCIE_RXCTL_ZEN_OFS, 0x1ULL); diff --git a/ucie b/ucie index 30f672c..21aae42 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit 30f672ca9908b106fc7bce2a315e1fe6d27b92d2 +Subproject commit 21aae42588ae43a296f9ff2dd943005de349514c From 877cada8c1db15571893ee129e442f312ff39528 Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 25 Nov 2026 14:54:21 -0800 Subject: [PATCH 6/7] fix software and merge main --- docs/ucie_bringup.md | 7 +- software/phytest-loopback.c | 11 +- software/phytest.h | 2 +- software/ucie-digital-loopback.c | 4 +- software/ucie.h | 171 ++++++++++++++++--------------- test/src/IrisSpec.scala | 38 +++---- ucie | 2 +- 7 files changed, 122 insertions(+), 113 deletions(-) diff --git a/docs/ucie_bringup.md b/docs/ucie_bringup.md index 4affae3..e5ffd83 100644 --- a/docs/ucie_bringup.md +++ b/docs/ucie_bringup.md @@ -149,8 +149,9 @@ Each `c2c_uciek` has two parts: - `phy`: `txData[16]`, `txValid`, `txTrack`, `txClkP`, `txClkN`, `rxData[16]`, `rxValid`, `rxTrack`, `rxClkP`, `rxClkN`, `sbTxClk`, `sbTxData`, `sbRxClk`, `sbRxData`, plus the four clock inputs of section 3. -- `debug`: the observation outputs `txClk`, `rxClk`, `rxData`, `clkMux` and `txData`. Each is off - until software enables its driver. +- `debug`: the observation outputs `mux0` and `mux1`, each watching any of ten clocks and data + taps through its own 16:1 mux (`UCIE_DEBUG_MUX_SEL`), and `txData`, the TX debug lane. Each is + off until software enables its driver. Chisel flattens the names with underscores, for example `c2c_ucie0_phy_bypassClk`. @@ -246,7 +247,7 @@ what it read instead of stopping. The program exits nonzero if any check failed. | Program | Topology | What it covers | |---|---|---| -| `phytest-loopback.c` | each link looped back onto itself (the single-chip harness, or a loopback board) | On both links: clock meters against the board clocks; LFSR run with distinct per-lane seeds; injected errors counted exactly once; `rxSelfSync` with every RX seed wrong; valid moved onto track at both ends; gated-clock bursts the UCIe way after the training in `phytest_bringup.md` §8.3, parking alternately and always low, with the forwarded clock centred (`PT_CENTRED_DELAY_TAPS` in `phytest.h`: 29 on the harness, the trained code on silicon); no RX words while parked; manual pattern into the capture SRAM; error-triggered capture; `rxStartMode` immediate; track counters; the loopback lane and its FIFO flags; per-lane fixed and inverted sources; one injected error found by lane, UI and class; the observation bumps (on for that test only) and the TX debug lane; the sideband tester | +| `phytest-loopback.c` | each link looped back onto itself (the single-chip harness, or a loopback board) | On both links: clock meters against the board clocks; LFSR run with distinct per-lane seeds; injected errors counted exactly once; `rxSelfSync` with every RX seed wrong; valid moved onto track at both ends; gated-clock bursts the UCIe way after the training in `phytest_bringup.md` §8.3, parking alternately and always low, with the forwarded clock centred (`PT_CENTRED_DELAY_TAPS` in `phytest.h`: 51 on the harness, the trained code on silicon); no RX words while parked; manual pattern into the capture SRAM; error-triggered capture; `rxStartMode` immediate; track counters; the loopback lane and its FIFO flags; per-lane fixed and inverted sources; one injected error found by lane, UI and class; the observation bumps (on for that test only) and the TX debug lane; the sideband tester | | `phytest-clocks.c` | UCIe0 looped back | TX divider at /1, /2, /4 off the bypass pin; PHY test clock onto PLL8 /8, stopping the program (instead of hanging the bus) if a moved clock doesn't run; main clock onto PLL8 and PLL12; a PHY test clock too slow for the link, which must set both FIFO flags (below), and the recovery; TX queue capped at 8 words with the PHY test clock at twice the packet clock (at equal rates 8 runs dry and 10 holds); sideband clock onto PLL8 /10; every clock meter after every move, and no PLL lock lost | | `phytest-two-chip.c` | two chips, each one's UCIe1 wired to the other's UCIe0 (the two-chip ring, or two chips on a package) | an LFSR run each way; each RX hears only the TX wired to it; `rxManualCheck` scoring the partner's manual pattern against this chip's TX pattern SRAM, with one reference word deliberately wrong | diff --git a/software/phytest-loopback.c b/software/phytest-loopback.c index 2e0501d..8f4e3b5 100644 --- a/software/phytest-loopback.c +++ b/software/phytest-loopback.c @@ -322,14 +322,16 @@ static void test_loopback_lane(uintptr_t base) { } // The observation bumps, which `setup_ucie` leaves off. Only this test turns -// them on and drives each: the TX data debug lane runs, the clock mux selects -// the TX divided clock, and the RX lane `rxData` watches gets traffic. The +// them on and drives each: the TX data debug lane runs, `mux0` watches the TX +// divided clock, and `mux1` watches RX data lane 0, which gets traffic. The // simulation harness checks every bump toggled; on the bench, probe them with // a scope now. The debug lane only drives a bump, so software can check only // that it runs to completion without starving. static void test_observation(uintptr_t base) { enable_debug_drivers(base, 1); - pt_wr(base, UCIE_DEBUG_CLK_MUX_SEL, 1); + pt_wr(base, UCIE_DEBUG_MUX_SEL, UCIE_DEBUG_MUX_TX_DIV_CLK); + pt_wr(base, UCIE_DEBUG_MUX_SEL + UCIE_DEBUG_MUX_SEL_WIDTH, + UCIE_DEBUG_MUX_RX_DATA_LSB); pt_wr(base, UCIE_DEBUG_TX_TEST_MODE, UCIE_TX_TEST_MODE_LFSR); pt_wr(base, UCIE_DEBUG_TX_DATA_MODE, UCIE_DATA_MODE_FINITE); pt_wr(base, UCIE_DEBUG_TX_PACKETS_TO_SEND, N_PACKETS); @@ -343,7 +345,8 @@ static void test_observation(uintptr_t base) { pt_rd(base, UCIE_TX_DEBUG_FIFO_UNDERFLOW), 0); pt_wr(base, UCIE_DEBUG_TX_FSM_RST, 1); pt_lfsr_check(base, N_PACKETS, "LFSR run with the observation drivers on"); - pt_wr(base, UCIE_DEBUG_CLK_MUX_SEL, 0); + pt_wr(base, UCIE_DEBUG_MUX_SEL, 0); + pt_wr(base, UCIE_DEBUG_MUX_SEL + UCIE_DEBUG_MUX_SEL_WIDTH, 0); enable_debug_drivers(base, 0); } diff --git a/software/phytest.h b/software/phytest.h index aba6a3b..cf7f891 100644 --- a/software/phytest.h +++ b/software/phytest.h @@ -41,7 +41,7 @@ // free-running clock but leaves a gated burst's first data UI with no edge. // On silicon, override it with the code mainband training finds. #ifndef PT_CENTRED_DELAY_TAPS -#define PT_CENTRED_DELAY_TAPS 29ULL +#define PT_CENTRED_DELAY_TAPS 51ULL #endif static int pt_failures = 0; diff --git a/software/ucie-digital-loopback.c b/software/ucie-digital-loopback.c index f9b18be..bf48318 100644 --- a/software/ucie-digital-loopback.c +++ b/software/ucie-digital-loopback.c @@ -9,9 +9,9 @@ #include "ucie.h" // The forwarded clock's global delay, centred on the data: the code training -// found on silicon, 29 taps on the simulation harness. +// found on silicon, 51 taps on the simulation harness. #ifndef CENTRED_DELAY_TAPS -#define CENTRED_DELAY_TAPS 29ULL +#define CENTRED_DELAY_TAPS 51ULL #endif #define UCIE0_REG_BASE 0x200000UL diff --git a/software/ucie.h b/software/ucie.h index c5c7dd1..7a82da4 100644 --- a/software/ucie.h +++ b/software/ucie.h @@ -81,89 +81,88 @@ #define UCIE_DEBUG_DATA_WIDTH 0x8ULL #define UCIE_DEBUG_DRIVERCTL 0x35d8ULL #define UCIE_DEBUG_DRIVERCTL_WIDTH 0x8ULL -#define UCIE_DEBUG_TXCTL_TILE 0x35f8ULL -#define UCIE_DEBUG_TXCTL_SHUFFLER 0x3600ULL +#define UCIE_DEBUG_TXCTL_TILE 0x35e8ULL +#define UCIE_DEBUG_TXCTL_SHUFFLER 0x35f0ULL #define UCIE_DEBUG_TXCTL_SHUFFLER_WIDTH 0x8ULL -#define UCIE_DEBUG_TX_TEST_STATE 0x3700ULL -#define UCIE_DEBUG_TX_PACKETS_SENT 0x3708ULL -#define UCIE_DEBUG_CLK_MUX_SEL 0x3710ULL -#define UCIE_DEBUG_RX_LANE 0x3718ULL -#define UCIE_DEBUG_RX_BIT 0x3720ULL -#define UCIE_TX_VALID 0x3728ULL -#define UCIE_RX_VALID 0x3730ULL -#define UCIE_CONTROLLER_SEL 0x3738ULL -#define UCIE_MAINBAND_MODE 0x3740ULL -#define UCIE_SIDEBAND_MODE 0x3748ULL -#define UCIE_CREDIT_FLOW_ENABLE 0x3750ULL -#define UCIE_TX_VALID_LANE_SEL 0x3758ULL -#define UCIE_RX_VALID_LANE_SEL 0x3760ULL -#define UCIE_LAST_SEEN_TL_REQ 0x3768ULL -#define UCIE_SB_TX_PACKET 0x3770ULL -#define UCIE_SB_TX_SEND 0x3778ULL -#define UCIE_SB_TX_BUSY 0x3780ULL -#define UCIE_SB_RX_PACKET 0x3788ULL -#define UCIE_SB_RX_VALID 0x3790ULL -#define UCIE_SB_RX_POP 0x3798ULL -#define UCIE_SB_RX_OVERFLOW 0x37a0ULL -#define UCIE_SB_RX_RST 0x37a8ULL -#define UCIE_SB_TL_RX_OVERFLOW 0x37b0ULL -#define UCIE_RX_START_MODE 0x37b8ULL -#define UCIE_RX_BURST_MODE 0x37c0ULL -#define UCIE_RX_SELF_SYNC 0x37c8ULL -#define UCIE_RX_MONITOR 0x37d0ULL -#define UCIE_RX_CAPTURE_MODE 0x37d8ULL -#define UCIE_RX_CAPTURE_POST_TRIGGER 0x37e0ULL -#define UCIE_RX_TRIGGER_LANE_MASK 0x37e8ULL -#define UCIE_RX_CAPTURE_TRIGGERED 0x37f0ULL -#define UCIE_RX_CAPTURE_TRIGGER_PACKET 0x37f8ULL -#define UCIE_TX_BURST_PACKETS 0x3800ULL -#define UCIE_TX_IDLE_PACKETS 0x3808ULL -#define UCIE_TX_CLK_GATE 0x3810ULL -#define UCIE_TX_CLK_PREAMBLE 0x3818ULL -#define UCIE_TX_CLK_POSTAMBLE 0x3820ULL -#define UCIE_TX_TRACK_CLK 0x3828ULL -#define UCIE_TX_INJECT_ERROR 0x3830ULL -#define UCIE_TX_INJECT_LANE 0x3838ULL -#define UCIE_TRACK_ONES 0x3840ULL -#define UCIE_TRACK_ZEROS 0x3848ULL -#define UCIE_TRACK_CNT_RST 0x3850ULL -#define UCIE_TRACK_CNT_HOLD 0x3858ULL -#define UCIE_TX_CLK_DIRECT 0x3860ULL -#define UCIE_TX_TEST_FIFO_UNDERFLOW 0x3868ULL -#define UCIE_RX_TEST_FIFO_OVERFLOW 0x3870ULL -#define UCIE_LOOPBACK_RX_FIFO_OVERFLOW 0x3878ULL -#define UCIE_TX_TRACK_WORD 0x3880ULL -#define UCIE_RX_CAPTURE_START 0x3888ULL -#define UCIE_LOOPBACK_TX_FIFO_UNDERFLOW 0x3890ULL -#define UCIE_TX_DEBUG_FIFO_UNDERFLOW 0x3898ULL -#define UCIE_TRACK_ONES_EVEN 0x38a0ULL -#define UCIE_RX_MANUAL_CHECK 0x38a8ULL -#define UCIE_TX_LANE_FIXED 0x38b0ULL -#define UCIE_TX_LANE_INVERT 0x38b8ULL -#define UCIE_TX_FIXED_WORD 0x38c0ULL -#define UCIE_RX_LANE_FIXED 0x38c8ULL -#define UCIE_RX_LANE_INVERT 0x38d0ULL -#define UCIE_RX_FIXED_WORD 0x38d8ULL -#define UCIE_RX_LANE_ERRORED 0x38e0ULL -#define UCIE_RX_ERR_POS_LANE 0x38e8ULL -#define UCIE_RX_ERR_POS_MASK 0x38f0ULL -#define UCIE_RX_ERR_CLASS_LANE 0x38f8ULL -#define UCIE_RX_ERR_RISE_ONE 0x3900ULL -#define UCIE_RX_ERR_RISE_ZERO 0x3908ULL -#define UCIE_RX_ERR_FALL_ONE 0x3910ULL -#define UCIE_RX_ERR_FALL_ZERO 0x3918ULL -#define UCIE_CONTROLLER_RX_FIFO_OVERFLOW 0x3920ULL -#define UCIE_TX_QUEUE_LIMIT 0x3928ULL -#define UCIE_TX_CLK_PARK_ALTERNATE 0x3930ULL -#define UCIE_RX_FRAME_OFFSET 0x3938ULL -#define UCIE_TX_UI_DELAY 0x3940ULL +#define UCIE_DEBUG_TX_TEST_STATE 0x36f0ULL +#define UCIE_DEBUG_TX_PACKETS_SENT 0x36f8ULL +#define UCIE_DEBUG_MUX_SEL 0x3700ULL +#define UCIE_DEBUG_MUX_SEL_WIDTH 0x8ULL +#define UCIE_TX_VALID 0x3710ULL +#define UCIE_RX_VALID 0x3718ULL +#define UCIE_CONTROLLER_SEL 0x3720ULL +#define UCIE_MAINBAND_MODE 0x3728ULL +#define UCIE_SIDEBAND_MODE 0x3730ULL +#define UCIE_CREDIT_FLOW_ENABLE 0x3738ULL +#define UCIE_TX_VALID_LANE_SEL 0x3740ULL +#define UCIE_RX_VALID_LANE_SEL 0x3748ULL +#define UCIE_LAST_SEEN_TL_REQ 0x3750ULL +#define UCIE_SB_TX_PACKET 0x3758ULL +#define UCIE_SB_TX_SEND 0x3760ULL +#define UCIE_SB_TX_BUSY 0x3768ULL +#define UCIE_SB_RX_PACKET 0x3770ULL +#define UCIE_SB_RX_VALID 0x3778ULL +#define UCIE_SB_RX_POP 0x3780ULL +#define UCIE_SB_RX_OVERFLOW 0x3788ULL +#define UCIE_SB_RX_RST 0x3790ULL +#define UCIE_SB_TL_RX_OVERFLOW 0x3798ULL +#define UCIE_RX_START_MODE 0x37a0ULL +#define UCIE_RX_BURST_MODE 0x37a8ULL +#define UCIE_RX_SELF_SYNC 0x37b0ULL +#define UCIE_RX_MONITOR 0x37b8ULL +#define UCIE_RX_CAPTURE_MODE 0x37c0ULL +#define UCIE_RX_CAPTURE_POST_TRIGGER 0x37c8ULL +#define UCIE_RX_TRIGGER_LANE_MASK 0x37d0ULL +#define UCIE_RX_CAPTURE_TRIGGERED 0x37d8ULL +#define UCIE_RX_CAPTURE_TRIGGER_PACKET 0x37e0ULL +#define UCIE_TX_BURST_PACKETS 0x37e8ULL +#define UCIE_TX_IDLE_PACKETS 0x37f0ULL +#define UCIE_TX_CLK_GATE 0x37f8ULL +#define UCIE_TX_CLK_PREAMBLE 0x3800ULL +#define UCIE_TX_CLK_POSTAMBLE 0x3808ULL +#define UCIE_TX_TRACK_CLK 0x3810ULL +#define UCIE_TX_INJECT_ERROR 0x3818ULL +#define UCIE_TX_INJECT_LANE 0x3820ULL +#define UCIE_TRACK_ONES 0x3828ULL +#define UCIE_TRACK_ZEROS 0x3830ULL +#define UCIE_TRACK_CNT_RST 0x3838ULL +#define UCIE_TRACK_CNT_HOLD 0x3840ULL +#define UCIE_TX_CLK_DIRECT 0x3848ULL +#define UCIE_TX_TEST_FIFO_UNDERFLOW 0x3850ULL +#define UCIE_RX_TEST_FIFO_OVERFLOW 0x3858ULL +#define UCIE_LOOPBACK_RX_FIFO_OVERFLOW 0x3860ULL +#define UCIE_TX_TRACK_WORD 0x3868ULL +#define UCIE_RX_CAPTURE_START 0x3870ULL +#define UCIE_LOOPBACK_TX_FIFO_UNDERFLOW 0x3878ULL +#define UCIE_TX_DEBUG_FIFO_UNDERFLOW 0x3880ULL +#define UCIE_TRACK_ONES_EVEN 0x3888ULL +#define UCIE_RX_MANUAL_CHECK 0x3890ULL +#define UCIE_TX_LANE_FIXED 0x3898ULL +#define UCIE_TX_LANE_INVERT 0x38a0ULL +#define UCIE_TX_FIXED_WORD 0x38a8ULL +#define UCIE_RX_LANE_FIXED 0x38b0ULL +#define UCIE_RX_LANE_INVERT 0x38b8ULL +#define UCIE_RX_FIXED_WORD 0x38c0ULL +#define UCIE_RX_LANE_ERRORED 0x38c8ULL +#define UCIE_RX_ERR_POS_LANE 0x38d0ULL +#define UCIE_RX_ERR_POS_MASK 0x38d8ULL +#define UCIE_RX_ERR_CLASS_LANE 0x38e0ULL +#define UCIE_RX_ERR_RISE_ONE 0x38e8ULL +#define UCIE_RX_ERR_RISE_ZERO 0x38f0ULL +#define UCIE_RX_ERR_FALL_ONE 0x38f8ULL +#define UCIE_RX_ERR_FALL_ZERO 0x3900ULL +#define UCIE_CONTROLLER_RX_FIFO_OVERFLOW 0x3908ULL +#define UCIE_TX_QUEUE_LIMIT 0x3910ULL +#define UCIE_TX_CLK_PARK_ALTERNATE 0x3918ULL +#define UCIE_RX_FRAME_OFFSET 0x3920ULL +#define UCIE_TX_UI_DELAY 0x3928ULL #define UCIE_TX_UI_DELAY_WIDTH 0x8ULL -#define UCIE_RX_UI_DELAY 0x39e0ULL +#define UCIE_RX_UI_DELAY 0x39c8ULL #define UCIE_RX_UI_DELAY_WIDTH 0x8ULL -#define UCIE_RX_VALID_START_THRESHOLD 0x3a70ULL -#define UCIE_DEBUG_TXCTL_SAMPLE_NEGEDGE 0x3a78ULL -#define UCIE_RX_AUTO_SEED 0x3a80ULL -#define UCIE_TL_RX_FIFO_OVERFLOW 0x3a88ULL +#define UCIE_RX_VALID_START_THRESHOLD 0x3a58ULL +#define UCIE_DEBUG_TXCTL_SAMPLE_NEGEDGE 0x3a60ULL +#define UCIE_RX_AUTO_SEED 0x3a68ULL +#define UCIE_TL_RX_FIFO_OVERFLOW 0x3a70ULL #define UCIE_PCIE_EXT_CAP_ID 0x4000ULL #define UCIE_DVSEC_VENDOR_ID 0x4004ULL #define UCIE_DVSEC_ID 0x4008ULL @@ -368,6 +367,16 @@ #define UCIE_CLK_UNGATE_SRC_PLL_LOCK 0x0ULL #define UCIE_CLK_UNGATE_SRC_MMIO 0x1ULL #define UCIE_CLK_UNGATE_SRC_DELAY 0x2ULL +#define UCIE_DEBUG_MUX_SB_TX_CLK 0x0ULL +#define UCIE_DEBUG_MUX_TX_DIV_CLK 0x1ULL +#define UCIE_DEBUG_MUX_RX_DIV_CLK 0x2ULL +#define UCIE_DEBUG_MUX_DIGITAL_BYPASS_CLK 0x3ULL +#define UCIE_DEBUG_MUX_SIDEBAND_BYPASS_CLK 0x4ULL +#define UCIE_DEBUG_MUX_REF_CLK 0x5ULL +#define UCIE_DEBUG_MUX_RX_DATA_LSB 0x6ULL +#define UCIE_DEBUG_MUX_TX_DATA_LSB 0x7ULL +#define UCIE_DEBUG_MUX_TEST_TX_PAD_CLK 0x8ULL +#define UCIE_DEBUG_MUX_TEST_RX_PAD_CLK 0x9ULL // === Helper functions === static inline void reset_datapath(uintptr_t base) { @@ -487,7 +496,7 @@ static inline void set_rx_delay(uintptr_t base, uint64_t lane, uint64_t taps) { } static inline void enable_debug_drivers(uintptr_t base, uint64_t en) { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < 2; i++) { reg_write64(base + UCIE_DEBUG_DRIVERCTL + 8 * i, (en ? UCIE_ENABLE_DRIVER_CTL : UCIE_DISABLE_DRIVER_CTL)); } reg_write64(base + UCIE_DEBUG_TXCTL_TILE, (en ? UCIE_ENABLE_TX_CTL : UCIE_DISABLE_TX_CTL)); diff --git a/test/src/IrisSpec.scala b/test/src/IrisSpec.scala index 84846e5..b428664 100644 --- a/test/src/IrisSpec.scala +++ b/test/src/IrisSpec.scala @@ -70,24 +70,20 @@ class DebugBumpMonitor(name: String) extends BlackBox(Map("NAME" -> StringParam(name))) with HasBlackBoxInline { val io = IO(new Bundle { - val txClk = Input(Bool()) - val rxClk = Input(Bool()) - val rxData = Input(Bool()) - val clkMux = Input(Bool()) + val mux0 = Input(Bool()) + val mux1 = Input(Bool()) val txData = Input(Bool()) }) setInline( "DebugBumpMonitor.sv", """module DebugBumpMonitor #(parameter NAME = "") ( - | input txClk, input rxClk, input rxData, input clkMux, input txData); - | longint unsigned n_txClk = 0, n_rxClk = 0, n_rxData = 0, n_clkMux = 0, n_txData = 0; - | always @(txClk) n_txClk++; - | always @(rxClk) n_rxClk++; - | always @(rxData) n_rxData++; - | always @(clkMux) n_clkMux++; + | input mux0, input mux1, input txData); + | longint unsigned n_mux0 = 0, n_mux1 = 0, n_txData = 0; + | always @(mux0) n_mux0++; + | always @(mux1) n_mux1++; | always @(txData) n_txData++; - | final $display("Debug bumps %s: txClk %0d rxClk %0d rxData %0d clkMux %0d txData %0d", - | NAME, n_txClk, n_rxClk, n_rxData, n_clkMux, n_txData); + | final $display("Debug bumps %s: mux0 %0d mux1 %0d txData %0d", + | NAME, n_mux0, n_mux1, n_txData); |endmodule |""".stripMargin ) @@ -279,11 +275,10 @@ class TestHarness( ucie.phy.sidebandBypassClk := ucieSidebandBypassClock ucie.phy.refClk := ucieRefClock val monitor = Module(new DebugBumpMonitor(s"chip$chipId.ucie$i")) - monitor.io.txClk := ucie.debug.txClk - monitor.io.rxClk := ucie.debug.rxClk - monitor.io.rxData := ucie.debug.rxData - monitor.io.clkMux := ucie.debug.clkMux - monitor.io.txData := ucie.debug.txData + monitor.io.mux0 := ucie.debug.mux0 + monitor.io.mux1 := ucie.debug.mux1 + // Absent on a link built without the TX data debug lane. + monitor.io.txData := ucie.debug.txData.getOrElse(false.B) } Seq(chiptop.c2c_ucie0, chiptop.c2c_ucie1) @@ -519,13 +514,14 @@ class IrisSpec extends AnyFunSpec { // The PhyTest programs bring-up runs on the chip (docs/ucie_bringup.md), // run by the core through the SoC bus and UCIe register map, over the // behavioral lanes and clocking tile. - // The loopback program turns every observation driver on for one LFSR run - // and drives the TX debug lane and every RX lane. So every debug bump of - // both links must toggle, which shows the scope points reach the pins. + // The loopback program turns every observation driver on for one LFSR run, + // with `mux0` on the TX divided clock and `mux1` on an RX data lane, and + // drives the TX debug lane. So every debug bump of both links must toggle, + // which shows the scope points reach the pins. def checkDebugBumps(simLog: String): Unit = for (link <- Seq("chip0.ucie0", "chip0.ucie1")) { val counts = Utils.debugBumpCounts(simLog, link) - assert(counts.keySet == Set("txClk", "rxClk", "rxData", "clkMux", "txData")) + assert(counts.keySet == Set("mux0", "mux1", "txData")) for ((bump, n) <- counts) { assert(n > 64, s"$link debug bump $bump only moved $n times") } diff --git a/ucie b/ucie index 21aae42..9d3cd20 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit 21aae42588ae43a296f9ff2dd943005de349514c +Subproject commit 9d3cd202ef3ea60bf5a950d473a8cd937f5a4e4b From 583eb88ae2152d5005677356fe31374215150f3a Mon Sep 17 00:00:00 2001 From: Rohan Kumar Date: Wed, 25 Nov 2026 15:09:17 -0800 Subject: [PATCH 7/7] bump ucie --- ucie | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ucie b/ucie index 9d3cd20..07a0c22 160000 --- a/ucie +++ b/ucie @@ -1 +1 @@ -Subproject commit 9d3cd202ef3ea60bf5a950d473a8cd937f5a4e4b +Subproject commit 07a0c22bd39e577e561e109b340a1b21bc0c775e