Skip to content

w1: masters: w1-uart: Cap consecutive HDQ timeouts on guarded variants - #180

Merged
henrikklee merged 1 commit into
OrchardLinux:mainfrom
grierj:w1-uart-hdq-timeout-cap
Dec 5, 2026
Merged

henrikklee merged 1 commit into
OrchardLinux:mainfrom
grierj:w1-uart-hdq-timeout-cap

Conversation

@grierj

@grierj grierj commented Dec 4, 2026

Copy link
Copy Markdown

Follow-up to #169:

  • Track consecutive completely exhausted HDQ reads (hdq_consecutive_timeouts) on guarded (hdq_fail_stop) variants, resetting the counter to 0 on any successful transfer.
  • After W1_UART_HDQ_MAX_TIMEOUTS (5) consecutive exhausted reads (15 consecutive timed-out cycles with zero successful responses), call w1_uart_hdq_stop_on_error() so a permanently dead HDQ link faults and stops retrying.
  • Transient hiccups still recover automatically and reset the counter on the next successful byte.

Built cleanly for apple-16k with zero warnings via orchard build --device j207 --kernel-tree.

Assisted-by: LLM

Keep the transient retry from the previous change, but restore fail-stop
protection when the battery gauge stops answering altogether: after five
consecutive reads exhaust their retries on the wire, disable further
transfers via w1_uart_hdq_stop_on_error().

Record whether a complete HDQ response arrived before hdq_deadline in
the receive callback under hdq_rx_lock so a delayed host wakeup does not
discard an on-time reply, and do not count attempts that exhausted the
host budget before waiting for a wire response toward permanent
fail-stop. Serialize HDQ bus transfers and resets under hdq_lock, and
reset the counter on any successful transfer.

Assisted-by: LLM
Signed-off-by: Grier Johnson <grier@scooterfarm.com>
@grierj
grierj force-pushed the w1-uart-hdq-timeout-cap branch from ff980e3 to dc378ed Compare December 4, 2026 23:50
@grierj

grierj commented Dec 5, 2026

Copy link
Copy Markdown
Author

Updated (dc378ed0a) to address review findings and live-verified on J207 (iPad Pro 10.5-inch, Wi-Fi):

  • Hardening added:
    • Record hdq_rx_on_time in the RX callback under hdq_rx_lock so delayed host wakeups do not discard on-time gauge replies or trip permanent fail-stop.
    • Exclude attempts that exhaust the host budget before waiting for a wire response from the consecutive wire-timeout fail-stop counter.
    • Serialize HDQ bus transfers and resets under hdq_lock.
  • Live J207 verification:
    • 10/10 consecutive battery telemetry reads (capacity, current_now, voltage_now) succeeded cleanly; zero w1/hdq errors or warnings in dmesg.
    • Verified alongside linux#164 + linux#175: lightning/input_current_limit reaches 500000 (500 mA SDP) cleanly on boot.

@henrikklee
henrikklee merged commit e82dd1a into OrchardLinux:main Dec 5, 2026
4 checks passed
@henrikklee

Copy link
Copy Markdown

Merged, thank you @grierj! Capping the consecutive HDQ timeouts on the A10X gauge stops endless retries when the gauge is really gone. Keeping a reply that arrived on time even when the host woke late, and serializing transfers with hdq_lock, both look right.

Nothing was changed on the branch and nothing was left out.

One follow-up we'd like, as a separate PR: after the 5-failure cap the battery readout stays gone until reboot. If the gauge goes quiet briefly, for example around suspend and resume, the battery would vanish from the desktop for the rest of the session. A slow periodic retry after the cap (say one attempt every 30-60 s, or on resume) would let the battery come back by itself while still keeping the log quiet. Thanks!

@henrikklee

Copy link
Copy Markdown

Follow-up from us: #182 makes a faulted gauge link try again every 60 s, so the battery comes back by itself after a short gauge silence (around suspend, for example) instead of staying gone until reboot. A dead gauge costs one short attempt a minute, and only the first fault is logged as an error. Thanks again for the cap, Grier!

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