Repository navigation
mt76x0u: receive-only MT7610U / MT7630U / MT7650U backend (DEVOURER_MT76X0U) - #611
MichealShoemaker wants to merge 4 commits into
Conversation
A port of the kernel's mt76x0u (reference/mt76 @ be5ce79) as a self- contained subtree, src/mt76x0u, behind IRadio as Mt76x0uRadio and the opt-in DEVOURER_MT76X0U (default OFF). Built for monitor capture: send_packet is refused, no TX power/TSSI, no beacons. - transport, EP 0x84 RX ring, in-band MCU, firmware (mt7610e.bin then mt7610u.bin, found at runtime), EFUSE, power-on and init, 20/40 MHz channel set with calibration, RXWI parse and RSSI correction; - warm start keeps running firmware (a forced re-upload is refused), and drains EP 0x84 and pulses the DMA|PBF reset; no USB reset at open for the chip's exclusive ids (it desyncs the running firmware's command ring); - the RX loop returns on NO_DEVICE or a dry ring so the caller can reclaim; - after the firmware start command, a read with no answer is followed by a MT_FCE_PSE_CTRL write before the next read: over USB/IP (usbipd) the dropped first read otherwise wedges EP0; - 7392:b711 is listed by both mt76x0u and mt76x2u, so the factory routes it by MT_ASIC_VERSION (MediatekProbe.h); - counts as chip support in the no-chip-selected check, like MT7612U. mt76x0/ sources are GPL-2.0-only and the shared mt76x02 code BSD-3-Clause-Clear; each file carries the licence of what it derives from. Selftests: USB ids vs the kernel's table, channel math over a real 43-entry hop list, EEPROM, firmware parse/framing and the firmware-start wait, RX ring, RXWI mapping, and mt76x0u_wire (the library against a scripted MT7610U). Tools: the initvals extractor (--check), a recovery CLI, and a transfer-level comparison against wifit3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/mt76x0u.md: bring-up (cold/warm, native and WSL2 + usbipd), RX against the kernel mt76x0u on the same adapter, channel-set cost, a 24 h soak and loss handling, each with its counterpart, and the open list (VHT RX not yet demonstrated, DFS RX untested, MT7630U/MT7650U untested). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Turn the option on beside DEVOURER_MT7612U in the platform, mingw and sanitizer jobs, and add an mt76x0u-only build-configs cell (every Realtek chip off) so the subtree cannot quietly depend on a Realtek chip's sources. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mt76x0u_wire runs the wire model against this binary, but the aggregate only collects *Selftest targets, so a selftests-only build (the mingw job) left the registered test without its harness and it failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR Summary by QodoAdd opt-in, receive-only MT76x0U monitor backend
AI Description
Merge Risk
|
Code Review by Qodo
1. CCA mode requests are silently discarded
|
josephnef
left a comment
There was a problem hiding this comment.
Thanks for this — it is a careful port, and the offline test coverage (wire model, generated-table --check, id table vs the kernel) is exactly the right shape.
What I checked
- All-on build (
DEVOURER_MT7612U=ON,DEVOURER_MT76X0U=ON), GCC 16: clean, no warnings in the new files;ctest107/107.extract_mt76x0u_tables.py --check(770 entries, 15 tables) andmt76x0u_usb_ids_vs_mt76.py(25 ids) reproduce againstreference/mt76@be5ce79. - Realtek dispatch is unaffected: the PR's
rxdemoon an RTL8733BU still routes and receives. - Read against the kernel function by function: RF channel programming, HT40 centre/ext-CCA, RSSI/LNA correction, EFUSE decode and size check, the calibration tick and table coverage all match.
- Not checked: the backend on hardware. I have no MT7610U on the bench, so every on-air figure here is yours.
Requesting changes for (details inline):
- RX parser clamps and delivers frames the kernel drops; no FCS on this part to catch it.
MT_TX_PIN_CFG(LNA / T-R switch pins) is never written.mt0_pollwaits ~1 ms where the kernel does ~101 reads; the WPDMA wait is a hard failure.7392:b711regresses for the MT7612U backend when the ASIC read fails, and still takes the USB reset.tune_twicedefaults on without support from the kernel source or your own measurement.force_fw_uploadis a dead knob; a warm start still demands a firmware file.SetCcaModesilently no-ops.- Three lifecycle races (abandoned sync transfer after close,
start_rx_loopfailure path, stop from the RX callback).
Also, not tied to a line
- Please add
src/mt76x0u/CLAUDE.md(the subtree convention;src/mt7612u/has one) and the backend's entry in the rootCLAUDE.md. The dated bench narratives in code comments belong indocs/mt76x0u.md; comments should describe the code as it is. mt76x0u_get_statsreadsd->io_errfrom the RX-loop thread while the calibration tick writes it; make it atomic.- Smaller decode differences from
mt76x02_mac_process_rate: CCK indices 4–7 and OFDM ≥ 8 are masked rather than rejected, and SGI/LDPC/STBC are reported for legacy rates. - Licensing: GPL-2.0-only files inside a GPLv2 repository are compatible, and marking each file is the right call. No change needed.
Given the size, I am happy to take the fixes as additional commits rather than a rewrite.
| /* MPDU_LEN excludes the L2 pad: the buffer holds hdr + pad + body. */ | ||
| const int pad = (rxinfo & MT_RXINFO_L2PAD) ? 2 : 0; | ||
| int len = (int)info->mpdu_len; | ||
| if (len > n - MT_DMA_HDR_LEN - MT_RXWI_LEN - pad) |
There was a problem hiding this comment.
The parser delivers what the kernel drops. The DMA header length word is never read, and an oversize MPDU_LEN is clamped here instead of rejected. The kernel drops in both places: mt76u_get_rx_entry_len (usb.c: data_len < min_len, !dma_len, dma_len + MT_DMA_HDR_LEN > data_len, dma_len & 3) and mt76x02_mac_process_rx (len > skb->len). The clamp bound also still includes the 4-byte FCE trailer, so a clamped frame carries trailer bytes as payload. This part delivers no FCS, so nothing downstream can tell a truncated or garbage completion from a real frame. Please validate the DMA length against actual_length and return MT_RX_PARSE_INVALID rather than clamp, with a selftest case for each drop condition.
| /* mt76x02_edcca_init with ed_monitor off (mac80211's default outside ETSI | ||
| * DFS operation), minus mt76x02_edcca_tx_enable. */ | ||
| static void edcca_init(struct mt76x0u_dev *d) | ||
| { |
There was a problem hiding this comment.
MT_TX_PIN_CFG is never written anywhere in the subtree. mt76x02_edcca_tx_enable(dev, true) runs on every kernel channel set and ORs TXANT | RXANT | RFTR_EN | TRSW_EN into it ("enable pa-lna"). Dropping ENABLE_TX and AUTO_RSP_EN is right for a receive-only backend, but RXANT and TRSW_EN are receive-path pins, so this is not a TX-only omission. On a board with an external LNA or T/R switch it could cost sensitivity. Please either port the pin write, or show the register's value after bring-up and an RSSI A/B with the four bits set, and record the result in docs/mt76x0u.md.
| * access can itself cost up to VEND_RETRIES * CTRL_TIMEOUT_MS, so counting | ||
| * iterations would let a caller asking for 200 ms block for seconds. | ||
| */ | ||
| int mt0_poll(struct mt76x0u_dev *d, uint32_t addr, uint32_t mask, |
There was a problem hiding this comment.
This poll is far shorter than the kernel's for the same argument. __mt76_poll(…, timeout) does timeout/10 + 1 reads regardless of how long each read takes; mt0_poll treats the argument as a wall-clock deadline in µs. For 1000 that is 101 reads in the kernel and one or two here. The call sites were ported with the kernel's numbers, so each one now waits about 1 ms.
| /* mt76x0_init_hardware */ | ||
| static int init_hardware(struct mt76x0u_dev *d) | ||
| { | ||
| if (!mt0_poll(d, MT_WPDMA_GLO_CFG, |
There was a problem hiding this comment.
This is the call site where the shorter poll matters: mt76x02_wait_for_wpdma(…, 1000) is 101 reads, this is ~1 ms, and a miss is a hard bring-up failure. Please give it the kernel's read budget.
| if (!route_mt76x0u && mt76x0u::is_usb_id(vid, pid)) { | ||
| const std::optional<uint32_t> rev = | ||
| devourer::mediatek::read_asic_version(dev_handle); | ||
| if (!rev) { |
There was a problem hiding this comment.
Regression for an id the MT7612U backend already serves. Before this PR 7392:b711 went straight to Mt7612uRadio, which has its own identify step and retries. Now a failed MT_ASIC_VERSION read refuses the adapter, including in builds with DEVOURER_MT76X0U=OFF where MT7612U is the only backend that could take it. Please fall through to the MT7612U gate when the read fails (and skip the probe entirely when MT76x0U is not compiled in).
Also, the comment in MediatekProbe.h says the synchronous libusb_control_transfer is safe because no backend has an event thread on the context yet. That holds for a single-adapter process only: a caller with a second radio already running on the same libusb_context hits exactly the race the comment describes.
| * | ||
| * The complete mt76x0_device_table, transcribed from the pinned reference tree | ||
| * reference/mt76 @ be5ce79, mt76x0/usb.c:14-44, and held to it by | ||
| * tests/mt76x0u_usb_ids_vs_mt76.py. No entry is hardware-verified yet; the |
There was a problem hiding this comment.
Stale for 0e8d:7610, which the measured record covers. Please state which ids are verified and which are routed only.
| * here (it would invalidate the caller's handle) and no kernel-driver detach | ||
| * (the caller dealt with it). | ||
| * | ||
| * Deliberately NOT here yet: the kernel's probe-time sequence |
There was a problem hiding this comment.
This paragraph and the other "(phase 3)" references describe a development plan, not the code as it stands (the warm path is in init.cpp/fw.cpp). Please reword to current state.
| @@ -0,0 +1,739 @@ | |||
| /* SPDX-License-Identifier: BSD-3-Clause-Clear */ | |||
| /* | |||
| * libusb transport for the MT76x0U. Copied from src/mt7612u/usb.cpp (the | |||
There was a problem hiding this comment.
usb.cpp and async.cpp are near-copies of the MT7612U transport, so every fix now has to land twice (the abandoned-transfer and status-bit comments in this review are both examples). I would rather see a shared MediaTek transport before this merges than as an open-ended follow-up. If you would prefer to keep this PR scoped, say so and we can agree a tracked issue for it instead.
| * (exits if the device re-enumerated) | ||
| * sleep MS | ||
| * | ||
| * Build (no CMake target; standalone against the backend sources): |
There was a problem hiding this comment.
With no CMake target, CI never compiles this against internal.h, so it will rot. Please add a target under DEVOURER_MT76X0U (UNIX-gated if needed, like mt7612uprobe). It should also take a bus/port selector rather than opening the first matching id: with two adapters attached the reset and chip-power steps hit whichever libusb returns first.
| dev = _dev; | ||
| _dev = nullptr; | ||
| if (dev) | ||
| mt76x0u_stop(dev); |
There was a problem hiding this comment.
The kernel powers the chip off on teardown (mt76x0u_cleanup → mt76x0_chip_onoff(dev, false, false)); here the chip stays powered and the firmware running after Stop(). If that is deliberate (it is what makes the next start warm), please say so here and in the doc, since the other backends power down on Stop().
MT7610U / MT7630U / MT7650U: receive-only MediaTek backend (
DEVOURER_MT76X0U, default OFF)A port of the kernel's
mt76x0u(reference/mt76@be5ce79) as a self-contained subtree,src/mt76x0u/, behindIRadioasMt76x0uRadio. It is built for monitor capture and is receive-only by design:send_packetis refused, and there is no TX power/TSSI and no beacons. Same shape as the MT7612U backend (#412): opt-in, own transport, firmware found at runtime (mt7610e.bin, thenmt7610u.bin). LikeDEVOURER_MT7612U, the option counts as chip support, so an MT76x0U-only build configures.Commits
mt76x0u:the backend, factory/USB hooks, CMake, selftests and toolsdocs:docs/mt76x0u.md(measured record) and the README Supported hardware rowci:DEVOURER_MT76X0U=ONin the platform, mingw and sanitizer jobs, plus anmt76x0u-onlybuild-configs cellcmake:theselftestsaggregate also buildsmt76x0u_wire_harness, so the mingw selftests-only build can runmt76x0u_wireMeasured on hardware
MT7610U
0e8d:7610, two units, on a native Linux host and on WSL2 + usbipd. The reference is the kernelmt76x0uon the same adapter, run sequentially. Full record, with each result's counterpart, indocs/mt76x0u.md:kill -9FastRetune, no 80 MHzBuild and test
mt76x0u-only. Both macOS cells were cancelled three times with "job was not acquired by Runner … capacity constraints". macOS GCC passed in an earlier run of the same code (f3d9004; only the CMake fix differs). macOS Clang has not run yet, so I'm relying on this PR's CI for it.mt76x0u-only89/89. Windows MSVC 19.51 (vcpkg libusb/OpenSSL): 106/106 includingmt76x0u_wire, with 0 warnings in the new code.Please look at
mt76x0/(chan,eeprom,init,initvals,mac,phy) are GPL-2.0-only; the ones derived frommt76x02are BSD-3-Clause-Clear. Each file is marked. The repo licence is GPLv2, but the rest ofsrc/is BSD-3-Clause-Clear, so I'm flagging it explicitly.7392:b711is listed by both mt76x0u and mt76x2u. The factory now readsMT_ASIC_VERSIONto route it (src/MediatekProbe.h), which touches an id the MT7612U backend already claims.usb.cppandasync.cppare adapted fromsrc/mt7612u(prefixmt0_, RX-only ring). I'm happy to factor out a shared MediaTek transport in a follow-up if you prefer.mt0_fw_wait_runningwritesMT_FCE_PSE_CTRLafter an unanswered read. Details in the doc.🤖 Generated with Claude Code