|
| 1 | +<!-- SPDX-License-Identifier: CC-BY-SA-4.0 --> |
| 2 | + |
| 3 | +# 2026-05-05 — LitePCIe ECP5 PHY contribution |
| 4 | + |
| 5 | +**Status:** Scoping (day-1 recon complete; **scope correction surfaced |
| 6 | +— blocked pending human + Agent R alignment**). |
| 7 | + |
| 8 | +## Upstream project |
| 9 | + |
| 10 | +`enjoy-digital/litepcie` — small-footprint configurable PCIe core |
| 11 | +powered by Migen / LiteX. License: BSD-2-Clause. |
| 12 | + |
| 13 | +## Bug / feature gap |
| 14 | + |
| 15 | +LitePCIe ships PHY modules for Cyclone V, Gowin GW5A, Lattice |
| 16 | +CertusPro-NX, Xilinx 7-Series, UltraScale, and UltraScale+. There is |
| 17 | +no `ecp5pciephy.py`. Zero open issues, zero closed issues, zero PRs in |
| 18 | +the upstream repo mention "lattice" or "ecp5". The upstream README |
| 19 | +explicitly lists "add Lattice support" under "Possible improvements", |
| 20 | +so the contribution is welcome in principle. |
| 21 | + |
| 22 | +## Project context |
| 23 | + |
| 24 | +- Surfaced by Agent 4's first ecosystem-health survey: |
| 25 | + `docs/upstream-contributions/0001-rev-a-known-upstream-issues.md` |
| 26 | + (popsolutions/Stays PR #3). |
| 27 | +- Cross-stream issue: popsolutions/MAST#13 — "[cross-stream] LitePCIe |
| 28 | + has no ECP5 PHY — rev-A host-link path is unsupported upstream". |
| 29 | +- Decision (2026-05-05, hybrid path): Agent 4 pursues Option 1 |
| 30 | + (author the PHY upstream) in parallel; Agent 2 switches the rev-A |
| 31 | + PCB host link to GbE via LiteEth and amends ADR-001 in |
| 32 | + `docs/adr/0001-fpga-target.md`. Agent 4 is no longer blocking on the |
| 33 | + rev-A schedule. |
| 34 | + |
| 35 | +## Local workaround |
| 36 | + |
| 37 | +Rev-A PCB switches host link to GbE via LiteEth (Agent 2's track). |
| 38 | +Once Agent 2's ADR-001 amendment lands, this contribution becomes a |
| 39 | +forward-looking upstream gift rather than a rev-A blocker — the |
| 40 | +cooperative still ships it because authoring the missing PHY is a |
| 41 | +mission-level deliverable per |
| 42 | +`project_mission_and_open_fpga_commitment.md`, not a tactical |
| 43 | +necessity. |
| 44 | + |
| 45 | +## Day-1 recon (2026-05-05) |
| 46 | + |
| 47 | +Performed the following before writing any code: |
| 48 | + |
| 49 | +1. **Forked the upstream repo:** |
| 50 | + `https://github.com/marcos-mendez/litepcie` (no clone yet — recon |
| 51 | + via `gh api` reads). |
| 52 | +2. **Read upstream README, full `phy/lfcpnxpciephy.py`** (309 lines), |
| 53 | + **and `phy/common.py`** (177 lines) to learn the PHY interface |
| 54 | + contract every module must implement. |
| 55 | +3. **Searched upstream issues + PRs** for any prior ECP5 work — none |
| 56 | + exists. |
| 57 | +4. **Searched GitHub broadly** for prior open-source ECP5 PCIe |
| 58 | + implementations — no clearly mature project found (LimeSDR |
| 59 | + variants use ECP5+PCIe via Lattice's proprietary Diamond IP; |
| 60 | + no open soft-stack precedent). |
| 61 | + |
| 62 | +## Critical scope correction (the part that needs human attention) |
| 63 | + |
| 64 | +When MAST#13 was filed, the cost estimate ("1-2 sprint-equivalents") |
| 65 | +assumed `ecp5pciephy.py` would follow the same wrapping pattern as |
| 66 | +`lfcpnxpciephy.py`. Day-1 recon shows that assumption is wrong. |
| 67 | + |
| 68 | +### What the CertusPro-NX PHY actually does |
| 69 | + |
| 70 | +`lfcpnxpciephy.py` is a Python wrapper that: |
| 71 | + |
| 72 | +1. Downloads a **vendor-generated Verilog IP blob** as a zip from a |
| 73 | + GitHub user-attachment URL (`do_finalize` calls `wget` + `unzip` |
| 74 | + at build time). |
| 75 | +2. Instantiates two Verilog modules from that blob (`lfcpnxpciephy` |
| 76 | + and `LMMI_app`) with hundreds of port mappings. |
| 77 | +3. Wires the Lattice Memory Mapped Interface (LMMI) for runtime |
| 78 | + configuration. |
| 79 | + |
| 80 | +The actual PCIe controller (LTSSM, TLP layer, Data Link Layer, MAC) is |
| 81 | +**inside the proprietary Verilog blob**. The Python file is a |
| 82 | +thin wrapper, hence its tractable size. |
| 83 | + |
| 84 | +### Why ECP5 is fundamentally different |
| 85 | + |
| 86 | +The ECP5 family has hard SerDes blocks (Dual Channel Units, "DCU") |
| 87 | +capable of 5 Gbps PCIe Gen2 line rate, but it does **not** have an |
| 88 | +integrated PCIe controller block. The DCU exposes the PCIe physical |
| 89 | +layer (8b/10b coding, scrambling, framing) only — the PIPE-to-TLP |
| 90 | +stack (LTSSM negotiation, link training, DLLP, TLP framing, |
| 91 | +flow-control credits) must be soft-implemented in fabric. |
| 92 | + |
| 93 | +ADR-001's phrase "Gen2 hard IP" was technically imprecise: ECP5 has a |
| 94 | +hard PCS, not a full hard PCIe IP. Lattice's closed-source Diamond |
| 95 | +toolchain ships a soft PCIe controller IP (in encrypted Verilog) that |
| 96 | +sits on top of the DCU; that is what closed-source ECP5+PCIe designs |
| 97 | +use. There is no open-source equivalent in production use today. |
| 98 | + |
| 99 | +### Three sub-options (none costed at 1-2 sprints) |
| 100 | + |
| 101 | +**Sub-option 1a — Wrap Lattice Diamond's closed PCIe IP** |
| 102 | + |
| 103 | +Mirror the CertusPro-NX pattern: download a Lattice-generated soft IP |
| 104 | +blob and wrap it in `ecp5pciephy.py`. Closed-source IP, requires |
| 105 | +Diamond licence to regenerate, contradicts ADR-001's open-toolchain |
| 106 | +commitment. **Rejected on mission grounds.** |
| 107 | + |
| 108 | +**Sub-option 1b — Write a soft PCIe stack atop the ECP5 DCU** |
| 109 | + |
| 110 | +Implement LTSSM, DLL, TLP, and the PHY adapter in Migen / LiteX, atop |
| 111 | +the ECP5 DCU primitives. Realistic scope: months to years for a |
| 112 | +production-grade implementation; PCIe specification is hundreds of |
| 113 | +pages and the LTSSM alone has dozens of states with non-trivial timing |
| 114 | +requirements. This is not 1-2 sprints; it is a major project on its |
| 115 | +own. |
| 116 | + |
| 117 | +**Sub-option 1c — Port an existing open-source soft PCIe stack** |
| 118 | + |
| 119 | +Find a permissively licensed open soft PCIe stack and adapt it to |
| 120 | +target the ECP5 DCU. Candidate projects exist in academic / research |
| 121 | +contexts (e.g., NoC-PCIe variants, Pulpino-PCIe sketches), but none |
| 122 | +are known production-mature. Realistic scope: weeks of evaluation + |
| 123 | +months of integration, depending on candidate quality. |
| 124 | + |
| 125 | +### What the cost estimate should have said |
| 126 | + |
| 127 | +The honest estimate for delivering a working ECP5 PCIe Gen2 PHY |
| 128 | +upstream — under any of 1b or 1c — is **multi-quarter, not multi-sprint**. |
| 129 | + |
| 130 | +This is exactly the kind of finding that should surface during day-1 |
| 131 | +recon, not month-2 implementation. |
| 132 | + |
| 133 | +## Recommendation (Agent 4) |
| 134 | + |
| 135 | +Pause coding work and **bring the scope correction back to the human + |
| 136 | +Agent R** before committing further effort. Three actionable paths: |
| 137 | + |
| 138 | +1. **Confirm the long-horizon path (1b or 1c) is still on-mission.** |
| 139 | + The cooperative's commitment to upstream contributions is real and |
| 140 | + load-bearing for differentiation, so a multi-quarter Agent 4 lane |
| 141 | + is defensible. But it should be an explicit choice, not the result |
| 142 | + of an under-informed estimate. |
| 143 | +2. **Open dialogue with the LitePCIe maintainers first.** Before |
| 144 | + sinking effort, file an upstream issue / discussion against |
| 145 | + `enjoy-digital/litepcie` summarising the gap and asking for |
| 146 | + guidance on the preferred architecture (sub-option 1c candidate, |
| 147 | + datapath width, integration strategy). This is the cheapest signal. |
| 148 | + The maintainers' email is in their README |
| 149 | + (`florent [AT] enjoy-digital.fr`); they also list paid-sponsorship |
| 150 | + labels on related issues, so a Lattice-support sponsorship dialogue |
| 151 | + is also possible if the cooperative chooses to fund the work. |
| 152 | +3. **Defer the ECP5 PHY work to post-rev-A.** Now that GbE is the rev-A |
| 153 | + host link, the ECP5 PHY contribution is no longer time-sensitive. |
| 154 | + Parking it until rev-B planning (where CertusPro-NX is the silicon |
| 155 | + target and the PHY landscape is different) is a defensible |
| 156 | + conservative choice. |
| 157 | + |
| 158 | +Agent 4 default if no further direction lands: option 2 — open the |
| 159 | +upstream dialogue, document the response, and wait for explicit |
| 160 | +prioritisation before any implementation. |
| 161 | + |
| 162 | +## Upstream link |
| 163 | + |
| 164 | +Not filed yet. Will be added once the path-forward decision lands. |
| 165 | + |
| 166 | +## Resolution status |
| 167 | + |
| 168 | +- **2026-05-05 (today):** Scoping complete. Scope correction |
| 169 | + documented. Awaiting human + Agent R direction on whether to |
| 170 | + continue (and on which sub-option), open upstream dialogue first, |
| 171 | + or defer. |
| 172 | + |
| 173 | +Authored by Agent 4 (Open FPGA Upstream Contributions). |
0 commit comments