Skip to content

wifi: brcmfmac: pcie: don't drop ring completions in the hard IRQ handler - #3770

Merged
DjDeveloperr merged 2 commits into
mainfrom
satchlj/brcmfmac-hardirq-ring-completions
Dec 1, 2026
Merged

DjDeveloperr merged 2 commits into
mainfrom
satchlj/brcmfmac-hardirq-ring-completions

Conversation

@satchlj

@satchlj satchlj commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What: brcmfmac's hard IRQ handler clears irq_ready whenever it sees mailboxint set, so the threaded handler skips ring servicing for that interrupt and D2H completions (ioctl responses, the D3 ACK on firmware that sends mailbox data over the control ring) stay in the rings until a later interrupt. The first commit carries Naeem Malik's fix: the hard handler masks the dongle without touching irq_ready, and the thread unmasks without setting it. The second commit makes irq_ready and the mask explicit across the two sleeps that keep the function in D0 (WoWLAN and Apple s2idle): with the first commit alone, irq_ready stayed set through those sleeps, and a J473 reset after every s2idle resume.
Tested: J473 (T8112, BCM4388) at 6b8d44f (first commit only): reset 3/3 about 2 s after an s2idle resume; without it 3/3 survived. No Mac yet at 9dab09e. arm64 LLVM=1 W=1 build of brcmfmac/ is clean; brcmf-suspend-tests pass with all 13 mutations caught (3 new).
Risk: two-way door · Macs with Broadcom PCIe Wi-Fi (brcmfmac): M1, M2, M3 and later
Not yet: any hardware run at 9dab09e: s2idle cycles unassociated and associated (the J473 case above), WoWLAN s2idle wake, deep sleep, and a throughput check. Draft until one passes.

Details

Commit 1 is carried from draft #1989 (13 fixes, conflicts with main). It applies cleanly to main. Author, author date, message and diff are unchanged (patch-id identical to 60de23202956), except that an AI-attribution trailer is removed, as the commit policy requires.

Commit 2:

  • intr_disable() clears irq_ready before masking. intr_enable() sets it before unmasking, so an interrupt raised as the mask opens can't leave the dongle masked.
  • Both D0 sleeps call intr_quiesce(): ring servicing off, wait for a running handler, then mask again. WoWLAN then unmasks the dongle for its wake interrupt with irq_ready still clear (after wowl_sleeping is set), so the thread reports the wakeup and does nothing else.
  • pm_leave_D3() keeps the IRQ disabled around pci_restore_state() in both D0 sleeps. That restore rewrites config space, ASPM/L1SS and MSI state on a link that stayed up.
  • wowl_wake() sets irq_ready and the mask explicitly before the bus comes up. It then runs the thread once for completions posted while the dongle was masked, since in MSI mode they may have no interrupt of their own.

Credit: Naeem Malik wrote the first commit in omacom/linux-aurora (3a936ed). RyanTheTide carried it into #1989, then found the reset on J473 and pointed at the irq_ready ownership. Thank you both.

Evidence
  • Base: main d5e9949314fd; the branch still merges cleanly with main 4e4603f31864.
  • Commit 1: git diff 60de2320^ 60de2320 | git patch-id = git diff d5e99493 6b8d44fe | git patch-id = 7e7ad490652f.
  • Commit 2 host tests: brcmf-suspend-tests.py passes (50 controls). Every mutation fails, including d0-quiesce (no quiesce at the s2idle sleep), d0-restore-irq (restore with the IRQ enabled) and d0-kick (no thread run at resume). The other brcmf*/brcmfmac-* host tests pass, except brcmf-ps-nap-tests: its ASan harness fails to compile in this environment on plain main too.

…dler

brcmf_pcie_quick_check_isr() masks the dongle with
brcmf_pcie_intr_disable() whenever mailboxint reads non-zero.  Since
commit f04be34 ("wifi: brcmfmac: Do not service msgbuf IRQs until
ready in MSI mode") that helper also clears irq_ready, and the threaded
handler services the rings only while irq_ready is set.  The thread
therefore skips brcmf_proto_msgbuf_rx_trigger() for exactly the
interrupts the hard handler caught with mailboxint still set, and then
sets irq_ready again on its way out.

In MSI mode the firmware clears mailboxint itself, so whether the hard
handler sees it set is a race.  When it does, completions that arrived
with that interrupt stay in the D2H rings until a later interrupt.  On
firmware that sends mailbox data over the control ring (no
BRCMF_PCIE_SHARED_USE_MAILBOX) that includes the D3 ACK, and ioctl
responses: brcmf_msgbuf_query_dcmd_len() and brcmf_pcie_pm_enter_D3()
then time out, the latter aborting system suspend.  On a MacBook Air (M1)
with BCM4378 this became frequent with PCIe ASPM L1.2 enabled.  In INTx
mode the hard handler always clears irq_ready first, so the rings are
never serviced at all.

Let the hard handler mask the dongle without touching irq_ready, and let
the thread unmask without setting it, so irq_ready is controlled only by
the code that sets the rings up and tears them down.

Fixes: f04be34 ("wifi: brcmfmac: Do not service msgbuf IRQs until ready in MSI mode")
Signed-off-by: Naeem Malik <malik2015naeem@gmail.com>
Link: omacom/linux-aurora@3a936ed
@satchlj
satchlj requested review from a team as code owners December 1, 2026 10:08
@satchlj
satchlj requested review from LiamRay11 and malik-na December 1, 2026 10:08
@github-actions github-actions Bot added area:wireless Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Merge readiness at 9dab09e9: not ready yet

Check Detail
CI at head no failing: host-tests
Review ok approved by RyanTheTide
Requested changes ok none
Hardware row at head ok in the PR body at 9dab09e9
Conflicts ok not computed yet
PR text ok Risk: two-way · Macs with Broadcom PCIe Wi-Fi (brcmfmac): M1, M2, M3 and later

Areas: area:gpu, area:wireless

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: HOLD at 6b8d44fe

Blocker (shown on hardware): with this change, the J473 (T8112, BCM4388, 27.2) reset 3/3 times within seconds of an s2idle resume. The same module built without the change survived 3/3.

  • Setup: the J473's production kernel source (18058ea2; the diff applies cleanly), with brcmfmac built from it once with and once without this diff, same config and same out-of-tree build. Modules were swapped live. Each cycle: load, wait 5 s, then rtcwake -d rtc1 -m mem -s 8 with mem_sleep=s2idle. Wi-Fi was powered but not associated; Ethernet carried management.
  • With this change: the suspend logs brcmf_configure_lpas: LPAS setup failed (-107), using disconnect fallback, then PM: suspend exit, and about 2 s later the Mac resets while awake (rtcwake never returns). There is no panic text in the journal. This happened 3/3 times.
  • Without it (stock module reloaded, and our own build without the diff): it slept the full 10 s and was still alive 30 s later, 3/3.
  • Caveat: one control boot reset later, while I unloaded the control module after its cycle (the journal isn't flushed past the suspend entry, so I don't know why). The reset right after resume happened only with this change.
  • Not tested yet: associated Wi-Fi cycles, and the PR head on main.

Checked (code): the bug is real on main. brcmf_pcie_quick_check_isr() → brcmf_pcie_intr_disable() clears irq_ready, so brcmf_pcie_isr_thread() skips brcmf_proto_msgbuf_rx_trigger() for that interrupt. Masking only mailboxmask in the hard handler, and unmasking only while irq_ready is still set, reads correctly and no longer re-arms irq_ready behind a teardown. One thing worth checking for the reset: the resume path now depends on irq_ready alone to unmask. If irq_ready is false or stale across the D3 leave in the s2idle_d0 path, the dongle stays masked. Conversely, if an interrupt lands before the rings are reinitialized, the thread can now unmask and service them while irq_ready is true from before the suspend.

@satchlj
satchlj marked this pull request as draft December 1, 2026 11:58
With irq_ready no longer cleared by the hard handler, nothing cleared it
for the two sleeps that keep the function in D0 (WoWLAN and the Apple
s2idle path): it stayed set from before the suspend. Every interrupt in
that window then had its thread service the rings and unmask the dongle,
also while brcmf_pcie_pm_leave_D3() runs pci_restore_state() on the live
link, which rewrites its config space, ASPM/L1SS and MSI state. A J473
(BCM4388) reset seconds after every s2idle resume with the previous
commit alone, and survived without it.

Make the ownership explicit:

- intr_disable() clears irq_ready before masking and intr_enable() sets
  it before unmasking, so an interrupt raised as the mask opens cannot
  leave the dongle masked.
- Both D0 sleeps stop ring servicing with intr_quiesce(), which also
  waits for a running handler and masks again. WoWLAN unmasks the dongle
  for its wake interrupt with irq_ready still clear, after wowl_sleeping
  is set.
- leave_D3() keeps the IRQ disabled around pci_restore_state() in both
  D0 sleeps.
- brcmf_pcie_wowl_wake() sets irq_ready and the mask explicitly before
  the bus comes up, and runs the thread once for completions posted
  while the dongle was masked.

brcmf-suspend-tests checks both sleeps keep ring servicing off, that the
restore runs with the IRQ disabled and that the resume kicks the thread,
with a mutation for each.

Signed-off-by: Satya Benson <satya@benson.earth>
@satchlj
satchlj force-pushed the satchlj/brcmfmac-hardirq-ring-completions branch from 75e9ab1 to 9dab09e Compare December 1, 2026 12:04
@satchlj

satchlj commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@RyanTheTide thanks for the run and the pointer. The reset is real, and you were right about irq_ready.

Why commit 1 alone resets in s2idle: on main, nothing clears irq_ready for the two sleeps that keep the function in D0 (brcmf_pcie_s2idle_sleep(), brcmf_pcie_wowl_sleep()). Before commit 1 that was hidden: any interrupt whose hard handler saw mailboxint set cleared irq_ready, and every thread run ended in intr_enable(). With commit 1, irq_ready stays true from before the suspend. So every interrupt during the sleep and the resume has its thread run brcmf_proto_msgbuf_rx_trigger() and unmask the dongle, while the bus is down and msgbuf suspended. That includes the stretch where brcmf_pcie_pm_leave_D3() calls pci_restore_state() on the live link: that call rewrites LNKCTL, the L1SS control registers (pci_restore_aspm_l1ss_state() turns ASPM off, rewrites L1.2, then restores it) and MSI state, while the thread does BAR0 MMIO. That fits a reset a couple of seconds after PM: suspend exit. I couldn't reproduce it here, so this is the most likely mechanism, not a proven root cause. Your second point is also real: in intr_enable() the unmask came before irq_ready = true, so an interrupt in that gap left the dongle masked for good.

Commit 2 (9dab09e9) makes the ownership explicit. irq_ready is cleared before masking and set before unmasking. Both D0 sleeps quiesce (servicing off, synchronize_irq(), mask again). WoWLAN re-unmasks only for its wake interrupt, with irq_ready clear. pm_leave_D3() disables the IRQ around pci_restore_state(). wowl_wake() sets the mask and irq_ready explicitly before the bus comes up, then runs the thread once for completions posted while masked. Commit 1 is unchanged. Host tests gained a check and a mutation for each of these.

Untested: everything on hardware at 9dab09e9. I can't run it on a J613 right now. Back in draft until a run passes.

Could you repeat your J473 cycle at 9dab09e9 (same module swap, unassociated, rtcwake -m mem -s 8 in s2idle), and if it survives, a few associated cycles?

@github-actions github-actions Bot removed needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 1, 2026

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Verdict: MERGE at 9dab09e9

J473 (T8112, BCM4388) at 9dab09e9 (pcie.c applied to the J473's production source 18058ea2, module swapped live): s2idle pass 8/8 cycles with no reset after resume (2 fresh loads with one cycle each, then 6 consecutive cycles in one load). Wi-Fi was powered but not associated.

Correcting my earlier HOLD numbers: unloading brcmfmac after an s2idle in the same boot resets this Mac whether or not your change is in. It happened once during a v2 reload, and once with my unpatched control module. Two of the three v1 resets I reported came after such an unload, so they don't count. The clean v1 evidence is a single case (fresh load, first s2idle, reset about 2 s after resume), which matches your irq_ready analysis. v2 shows no reset in the clean procedure.

Checked: commit 2 sets irq_ready before unmasking and clears it before masking, and both D0 sleeps quiesce (servicing off, synchronize_irq(), mask). That closes both the post-resume window and the gap in intr_enable().

Not covered (follow-up, not blocking): associated-Wi-Fi s2idle cycles on the J473 (needs the lab AP), and the unload-after-s2idle reset, which happens without this change too and probably deserves its own issue.

@satchlj
satchlj marked this pull request as ready for review December 1, 2026 12:31
@satchlj
satchlj requested a review from DjDeveloperr as a code owner December 1, 2026 12:31
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) labels Dec 1, 2026
@satchlj

satchlj commented Dec 1, 2026 •

Copy link
Copy Markdown
Member Author

host-tests at 9dab09e9: the failing tests are the same four that fail on main (ave-recovery-old, brcmf-ps-nap-tests, g17-output-fence-tests, g17-render-owed-stamp-tests, with their mutations), e.g. main's Host tests run 46633083577 at 4e4603f3. brcmf-ps-nap-tests is the only brcmfmac one, and it fails on main without this PR too.

@DjDeveloperr
DjDeveloperr merged commit ac3f4d9 into main Dec 1, 2026
3 of 9 checks passed
@DjDeveloperr
DjDeveloperr deleted the satchlj/brcmfmac-hardirq-ring-completions branch December 1, 2026 13:39
maralcbr added a commit to omacom/linux-aurora that referenced this pull request Dec 2, 2026
Follow aurora-silicon/linux main (integration/aurora no longer exists)
at 4a42f31, which brings in #3133 (T8112 DCP on firmware 27.2).

Retire, each merged upstream and in this intake:
  aurora-silicon/linux#2145 as 6f84f56
  aurora-silicon/linux#2150 as 15b1e2e
  aurora-silicon/linux#2152 as 8bd4942
  aurora-silicon/linux#2153 as a2801d4
  aurora-silicon/linux#2154 as 90d3f11
  aurora-silicon/linux#2156 as dff34de
  aurora-silicon/linux#2199 as d51160c
  aurora-silicon/linux#2147, closed in favour of #3114 (merged as
  e8d93e4, in this intake)
  j613-touchid-data-ready, superseded by aurora-silicon/linux#2678
  (merged as 3777510), which describes the same line for the J613
  and J615 in t8122-j613-j615.dtsi

Update remaining carries:
- #2146, #2148, #2149 and #2151 re-pinned to their main-merged PR heads
  (carried via merge = true).
- #2155 pinned to ad63582 (last reviewed commit before #2155
  rebased onto the post-4a42f3105002 IIO API change in #3473; adds the
  describe-by-role follow-up).
- #3490 (merged on integration/aurora-7.3 in #529) re-pinned cleanly to
  upstream 717a6ff..e6e8509, dropping the 00cbc67 rebase
  commit d98f2a8.
- #370 replaced by merged upstream
  aurora-silicon/linux#3770 (6b8d44f + 9dab09e, adding the D0
  sleep quiesce/resume fix for BCM4388 s2idle).
- #3607 now carries all three commits including KUnit tests in
  drivers/bluetooth/hci_bcm4377_test.c (present in 4a42f31).
- xart-pin-7.3 note updated (#486 open, #506 closed).

Based-on-work-by: Satya Benson <satya@benson.earth>
Signed-off-by: Marcelo Alcantara <maralc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:gpu Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) blast:m1 Macs affected, from Merge risk (bot) blast:m2 Macs affected, from Merge risk (bot) blast:m3 Macs affected, from Merge risk (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants