Skip to content

jaguar3: SetWideTxIgiFloor, the wide-TX IGI floor at run time - #609

Open
gilankpam wants to merge 1 commit into
OpenIPC:masterfrom
gilankpam:pr/igi-floor-setter
Open

gilankpam wants to merge 1 commit into
OpenIPC:masterfrom
gilankpam:pr/igi-floor-setter

Conversation

@gilankpam

Copy link
Copy Markdown
Contributor

The gap

DeviceConfig::Tuning::wide_tx_igi_floor is fixed at construction. Its comment already says the edge is per unit, and that 0x35 costs idle-channel RX sensitivity that was estimated but not measured. One more 8812EU, measured below, shows the edge also moves with the channel, and that the cost is large. So no single construction-time value fits. A caller that wants the lowest safe floor has to start low and raise it while the radio runs, and today it cannot.

The change

  • IRtlRadio::SetWideTxIgiFloor(uint8_t floor) (Jaguar3). It records the floor and re-applies it under _reg_mu, under the same rule as the construction-time value: after the session's first ≥ 40 MHz frame, while tuned that wide; every retune re-applies it. Values above 0x7f return false. Other generations return false (default virtual).
    • Callable from any thread, including while a sender is blocked in bulk-OUT, because the sender holds no lock.
    • Throws on a failed USB transfer. The floor is recorded before any register access, so after a throw the DIG tick still enforces it.
  • PhydmRuntimeJaguar3::set_igi_floor clamps IGI at once whenever the floor is lowered, not only when it drops to 0. IGI goes to max(new floor, top of the channel's DIG window) instead of keeping the old floor's gain until DIG walks it down. The rule is a pure jaguar3::igi_on_floor_change (IgiFloor.h) with an igi_floor selftest. The old dropped-to-0 behaviour is unchanged.
  • build_tx_block arms on the first wide frame even when the floor is 0, so a floor set later still applies. With 0 the apply writes no register; it is still one _reg_mu take per session, and the hot path stays lock-free.

Measured

One 8812EU (USB high speed), MCS2/40/LDPC, 1400-byte frames, sent with no gap (ceiling ~2790 frames/s). IGI pinned with DIG off; share of the ceiling per value:

IGI 144(-) 157(+) 100(+)
0x24, 0x22 100 % 100 % 100 %
0x20 98-99 % 100 % 100 %
0x1f 41-47 % 94 % 97 %
0x1e 40-45 % 95 % 97 %
0x1c 44-56 % 35 % 54 %

This unit's edge is 0x1f on 144 and 0x1c on 157 and 100. 20 MHz frames run at full rate at every IGI from 0x08 to 0x24.

What the floor costs the receiver. A second card sent MCS0/20 frames at three levels while the 8812EU transmitted at 40 MHz and counted them per floor. Reception falls from ~99 % to 0 in one floor step, about 19-23 IGI above the frames' RSSI (chip units):

RSSI last floor that hears first floor that is deaf
62 0x51 0x52
47 0x45 0x46
44 0x43 0x44

Extended down, 0x35 is deaf below an RSSI of about 28-30 and 0x22-0x24 below about 9-11. The weakest frames either card decoded at IGI 0x1e-0x20 were at RSSI 16 (13-15 dB SNR). So on this unit 0x35 costs at least ~12 dB of sensitivity to weak frames, against 0-4 dB for a floor just above its edge.

A caller using the setter. It starts at a low floor and raises it when its TX stalls (longest send ≥ 30 ms, or PUB queue backlog ≥ 60 %). It reverts if the stall does not clear and keeps the value after 3 clean 1 s windows. Windows with CLM busy ≥ 20 % are not judged. A 60 fps video downlink at 40 MHz, 170 s runs (330 s with the jammer); "spread" is p99 − p50 frame arrival per 30 s slice:

channel, start floor floor moves video
161, 0x22 (MCS2) none 60 fps; spread 17-21 ms for the first 60 s, then 6 ms
161, 0x1e (MCS2; below this unit's edge) 0x20 at 2 s, 0x24 at 6 s, kept at 9 s 60 fps; spread 13-19 ms to ~100 s, then 5 ms
161, 0x22 (adaptive MCS) none 60 fps; spread ≤ 6.6 ms
161, 0x1e (adaptive MCS) 0x20 at 2 s, 0x24 at 4 s, kept at 7 s 60 fps; clean after the first slice
144, a second card jamming at ~56 % airtime (MCS2) none in 5½ min 32-35 fps, the same as with the controller off

161 is rough for its first minute at MCS2 whatever the floor (the 0x22 row never moves).

Build: full, no-Jaguar3 and Jaguar3-only configure + build; ctest 92/92 (83/83 Jaguar3-only). The igi_floor selftest was revert-checked: with the old dropped-to-0-only clamp, the three "lowered" checks fail.

Not covered

  • One 8812EU. No 8812CU with a floor change at run time.
  • The receiver-cost rows go down to RSSI 44 only; the lower thresholds are extrapolated along the measured line.
  • 80 MHz.
  • No caller in this tree. The controller above lives in an application; this PR adds only the setter.

🤖 Generated with Claude Code

DeviceConfig::Tuning::wide_tx_igi_floor is fixed at construction. The edge
below which a Jaguar3 transmitter loses 40 MHz capacity differs per unit and
per channel, and the 0x35 default costs uplink sensitivity, so a caller that
wants the lowest safe floor has to move it while the radio runs.

IRtlRadio::SetWideTxIgiFloor(floor) records the new floor and re-applies it
under _reg_mu, under the same rule as the construction-time value (after the
session's first >= 40 MHz frame, while tuned that wide; every retune
re-applies it). It is callable while another thread is blocked in bulk-OUT,
and it can throw on a failed USB transfer; the floor is recorded first, so
the DIG tick enforces it either way. Default: false (unsupported).

PhydmRuntimeJaguar3::set_igi_floor now clamps IGI at once whenever the floor
is lowered, not only when it is dropped to 0: a lowered non-zero floor pulls
IGI down to max(floor, top of the channel's DIG window). The rule is a pure
function (jaguar3/IgiFloor.h) with an igi_floor selftest.

The TX arm in build_tx_block now runs on the first wide frame even when the
floor is 0, so a floor set later still applies; with a floor of 0 the apply
writes no register, and it takes _reg_mu once per session as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Allow Jaguar3 wide-TX IGI floor changes at runtime

✨ Enhancement 🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Add a Jaguar3 radio setter so callers can adjust the wide-TX IGI floor without restarting.
• Apply floor changes immediately and retain wide-frame eligibility when the initial floor is zero.
• Test IGI behavior when floors rise, fall, or are disabled.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The setter, first-wide-frame arming, retune application, and PHYDM IGI transition helper all control the same end-to-end behavior: selecting and enforcing the IGI floor for a Jaguar3 session.
  • The propagation path stays within this bounded tuning integration; no separate consumer or independent user outcome was identified.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: the floor was sourced only from immutable session configuration, was armed by the first wide transmission, and floor removal primarily relied on the next DIG window.
  • After: a live value can change during a session, including while wide transmission and periodic PHYDM activity are in progress, and lowering to another nonzero value or zero immediately clamps the current IGI.
  • New correctness condition: the stored live floor, _wide_tx_seen state, tuned width, current IGI, normal DIG window, first-wide-frame publication, retune application, and register writes must agree across setter, sender, retune, and tick interleavings.
  • The setter and first-frame path serialize register access with _reg_mu, while atomic publication coordinates the first-frame state.
  • The helper adds explicit state-dependent transition cases for raising, lowering, dropping, and no-op updates.
  • These are newly interacting runtime states, not complexity inherited merely from using existing PHYDM or mutex infrastructure.
Potential damage 🟡 Medium 🩹 Recoverable

  • If this capability regresses, the radio may retain an unnecessarily high IGI after a floor is lowered or removed, or may apply an unsuitable floor while wide-band traffic is active.
  • The supported consequence is degraded receiver sensitivity or wide-band link performance, rather than persistent data corruption or an independent downstream failure.
  • Restoring the prior code/configuration can stop future incorrect enforcement; an already-written IGI is corrected by a subsequent valid floor application, retune, or periodic PHYDM tick.
  • No persistent storage or external side effect requires compensation.
  • A failed USB transfer can leave the new policy recorded, but the source establishes that periodic ticking remains the enforcement path; exact timing of correction after repeated transfer failures is not otherwise bounded.
  • Reversible through a valid runtime update, retune/tick, or session reinitialization.
  • Code rollback alone does not necessarily immediately restore the prior chip register value in an already-running session; the register must be rewritten by the normal control path.
Assessed commit 8b0ca9c
Diagram

graph TD
  Caller["Radio caller"] --> Setter["Runtime setter"] --> Gate{"Wide TX active"} --> Runtime["DIG runtime"] --> Registers["IGI registers"]
  Frame["First wide frame"] --> Gate
  Retune["Channel retune"] --> Gate
Loading
High-Level Assessment

Keep the live floor in Jaguar3 and reuse its existing width and wide-frame gating. Relying on construction-time configuration would require a restart, while waiting for a DIG tick would delay the sensitivity benefit after lowering the floor.

Files changed (9) +118 / -24

Enhancement (3) +41 / -11
IRtlRadio.hExpose an optional runtime IGI floor setter +12/-0

Expose an optional runtime IGI floor setter

• Adds SetWideTxIgiFloor with a default unsupported result. Documents eligibility, validation, threading, and USB failure behavior.

src/IRtlRadio.h

RtlJaguar3Device.cppApply the live floor and arm on every first wide frame +24/-11

Apply the live floor and arm on every first wide frame

• Implements the validated, register-serialized setter and reads the live floor when applying the width-dependent policy. A first wide frame now arms eligibility even when the current floor is zero.

src/jaguar3/RtlJaguar3Device.cpp

RtlJaguar3Device.hStore Jaguar3's live wide-TX floor +5/-0

Store Jaguar3's live wide-TX floor

• Declares the setter override and adds an atomic floor initialized from device configuration.

src/jaguar3/RtlJaguar3Device.h

Bug fix (2) +32 / -10
IgiFloor.hDefine the immediate IGI adjustment rule +23/-0

Define the immediate IGI adjustment rule

• Adds a pure function that selects an IGI write when a floor rises, falls, or is disabled, using the channel's DIG window as a lower-floor bound.

src/jaguar3/IgiFloor.h

PhydmRuntimeJaguar3.cppClamp IGI immediately after lowering a floor +9/-10

Clamp IGI immediately after lowering a floor

• Uses the new adjustment rule so nonzero floor reductions need not wait for a DIG tick. Preserves the no-register-access path when both old and new floors are zero.

src/jaguar3/PhydmRuntimeJaguar3.cpp

Tests (2) +40 / -0
CMakeLists.txtRegister the IGI floor selftest +8/-0

Register the IGI floor selftest

• Builds the standalone IGI floor selftest and adds it to CTest.

CMakeLists.txt

igi_floor_selftest.cppCover raised, lowered, dropped, and unchanged floors +32/-0

Cover raised, lowered, dropped, and unchanged floors

• Checks the pure IGI adjustment rule against normal and DFS window bounds, including lowered nonzero floors.

tests/igi_floor_selftest.cpp

Documentation (2) +5 / -3
DeviceConfig.hPoint configuration users to the runtime setter +1/-0

Point configuration users to the runtime setter

• Documents the new API alongside the construction-time wide-TX IGI floor setting.

src/DeviceConfig.h

PhydmRuntimeJaguar3.hDocument immediate behavior for lowered floors +4/-3

Document immediate behavior for lowered floors

• Clarifies that lowering a floor to a nonzero value also clamps IGI immediately.

src/jaguar3/PhydmRuntimeJaguar3.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Failed floor writes look successful 🐞 Bug ≡ Correctness
Description
SetWideTxIgiFloor() returns true after set_igi() even when an IGI register write fails, because
the register-write path discards the transport's failure result. On a failed USB control write, the
requested floor may not reach the chip, and disabling DIG leaves no periodic correction.
Code

src/jaguar3/RtlJaguar3Device.cpp[R2376-2377]

+  apply_igi_floor_locked(_channel.Channel, _channel.ChannelWidth);
+  return true;
Evidence
The new setter reports success after applying the floor. Its apply path reaches set_igi(), whose
two BB writes use a void adapter method that ignores the boolean result of rtw_write32; USB
synchronous writes return false on failure. DIG is optional, so it cannot be relied on to correct a
failed write.

src/jaguar3/RtlJaguar3Device.cpp[2370-2377]
src/jaguar3/PhydmRuntimeJaguar3.cpp[27-46]
src/RtlAdapter.cpp[257-274]
src/UsbTransport.h[329-341]
src/jaguar3/PhydmRuntimeJaguar3.cpp[228-235]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new setter reports success when an IGI register write fails, contrary to its documented failure behavior.

## Fix Focus Areas
- src/jaguar3/RtlJaguar3Device.cpp[2370-2377]
- src/jaguar3/PhydmRuntimeJaguar3.cpp[27-46]
- src/RtlAdapter.cpp[257-274]

## Recommended Fix
Make the IGI write path check the transport's write result and propagate failure to the setter. Preserve the floor-recording-before-I/O behavior, and test a failed write.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Retrying a lowered floor leaves gain high 🐞 Bug ☼ Reliability
Description
set_igi_floor() records the new floor before reading IGI, but igi_on_floor_change() lowers IGI
only when that floor is below the previously recorded value. If the read throws during a lowering
request, retrying the same value sees equal floors and skips the clamp; the gain remains high until
a DIG tick, or indefinitely when DIG is disabled.
Code

src/jaguar3/IgiFloor.h[R15-18]

+  if (floor < prev_floor) {
+    const uint8_t hi = window_hi > floor ? window_hi : floor;
+    if (cur_igi > hi)
+      return hi;
Evidence
The setter records a requested floor and calls the apply path. That path assigns _igi_floor before
get_igi(), whose USB read can throw; the new helper's downward branch then depends solely on
floor < prev_floor. A retry of the same value cannot enter it, while skip_dig can prevent later
correction.

src/jaguar3/RtlJaguar3Device.cpp[2370-2377]
src/jaguar3/PhydmRuntimeJaguar3.cpp[27-46]
src/jaguar3/IgiFloor.h[11-20]
src/UsbTransport.h[308-325]
src/jaguar3/PhydmRuntimeJaguar3.cpp[228-235]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A failed read after a lowered floor is recorded makes a retry of that value skip the immediate downward clamp.

## Fix Focus Areas
- src/jaguar3/IgiFloor.h[11-20]
- src/jaguar3/PhydmRuntimeJaguar3.cpp[36-46]
- src/jaguar3/RtlJaguar3Device.cpp[2370-2377]

## Recommended Fix
Track whether the downward clamp completed, or defer committing the applied floor until the read and required write succeed while retaining the requested floor for later DIG ticks. Make a retry reattempt an incomplete clamp, and test a failed read followed by a retry of the same value.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: Auto: ⚖️ Balanced: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 13/18, lines 142/200; both must reach the floor). Router rationale: Runtime API, concurrency, USB, and PHY logic span independent paths.

Grey Divider

Tip of the day
💡 Did you know, you can copy the agent prompt from any finding and feed it to your IDE agent

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@josephnef josephnef left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setter behaves as described. I checked it on a second 8812EU (bare BL-M8812EU2, 0bda:a81a), channel 157(+) at 40 MHz, MCS2/40/LDPC, 1400-byte frames, with this PR merged together with #610 (clean merge, full build, ctest 96/96 with the two MT7612U generator checks skipped). IGI was read out of band (chipstate --no-claim --peek 0x1d70:4) while the probe held the interface.

Reproduced

Step IGI observed
Set 0x30 before any wide frame unchanged (DIG window)
First wide frame, floor 0x35 0x35
0x35 → 0x24 0x24 at once
0x24 → 0x1e 0x22 at once, then DIG walks it to 0x1e
Raise to 0x22, 0x2c, 0x35 at once
0x80 refused
  • No-gap flood: 2745–2780 frames/s at IGI 0x22 and above. At 0x1e it fell to 2381 with 15 send timeouts, then 1590 with 60, and was back at 2746 in the step that raised the floor to 0x22.
  • A device constructed with wide_tx_igi_floor = 0 stalls at 0x1e (2026 frames/s, 21 timeouts) and takes a run-time 0x35 (2743 frames/s), so the build_tx_block arming change works.

Requested before merge

  1. Land the measurements in the tree, not only in this description (inline on DeviceConfig.h).
  2. An in-tree caller. Nothing in the repo calls the setter, so neither table can be reproduced from the tree. tests/cca_gates_probe.cpp was added for the same reason for the gate split; one small probe could cover this and GetTxQueuePages together.

Also

  • Fork CI has not run on this PR; it needs a green run.
  • Three non-blocking notes inline.

Limits of my check: one unit, one channel, one run per arm, TX power at −20 dB (this module's bench supply sags at full power under a no-gap flood, on master too), and host-side submitted rates rather than frames counted by a witness receiver. I did not reproduce the receiver-cost table.

Comment thread src/DeviceConfig.h
* 0x1e..0x22 non-DFS window. Lower it to a unit's own measured edge to
* buy that back. 80 MHz carries the same floor, only partially
* validated. docs/experiments/8822c-ht40-tx-stall.md. */
/* Run-time changes: IRtlRadio::SetWideTxIgiFloor. */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment just above this line still says the edge is "PER UNIT" and that the receiver cost is "estimated from the ~1 dB IGI step and NOT measured". This PR's description measures both: the edge moves with the channel on one unit (0x1f on 144, 0x1c on 157 and 100), and 0x35 costs at least ~12 dB of weak-frame sensitivity on that unit. With only this one line added, the tree contradicts the PR that motivated it.

Please update this comment and docs/experiments/8822c-ht40-tx-stall.md with the per-channel edge table and the receiver-cost table, including their scope (one 8812EU, cost rows down to RSSI 44 with the rest extrapolated). That is also what tells a caller why a run-time setter exists.

Comment thread src/jaguar3/IgiFloor.h
uint8_t cur_igi, uint8_t window_hi) {
if (floor != 0 && cur_igi < floor)
return floor;
if (floor < prev_floor) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking, and narrower than the automated review makes it sound. set_igi_floor stores _igi_floor before get_igi(). If that read throws while the floor is being lowered, a retry of the same value arrives with prev_floor == floor, so this branch is skipped and IGI is not pulled down.

With DIG running it heals itself: the next dig() tick clamps to hi = max(window top, floor) within ~2 s. It only sticks when tuning.skip_dig is set. Either store the floor after the read, or document that a retry after a throw relies on the DIG tick.

Comment thread src/IRtlRadio.h
* thread is blocked in a bulk-OUT send. Returns false where unsupported or
* for a value the chip cannot take (Jaguar3: above 0x7f).
*
* THROWS on a failed USB transfer (the IGI read-modify-write is a register

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking wording. Only the read half of the read-modify-write throws. phy_set_bb_reg goes through PHY_SetBBReg8812, which drops the write's result, as every BB write in the tree does. So a failed write returns true here with the floor recorded but IGI unchanged until the next DIG tick. "THROWS on a failed register read" would be accurate.

Two behaviours I observed that the comment could state:

  • A non-zero floor below the DIG minimum returns true and changes nothing: with 0x1c set, IGI stayed at 0x1e.
  • The live value outlives the session. Stop / Init / InitWrite clear _wide_tx_seen but not _wide_tx_igi_floor, so a re-init keeps the last value set here rather than returning to DeviceConfig::Tuning::wide_tx_igi_floor. Fine if intended, but it should say so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants