Skip to content

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

Merged
scottjones merged 1 commit into
omacom:integration/aurorafrom
malik-na:pr/brcmfmac-irq-ready
Nov 14, 2026
Merged

scottjones merged 1 commit into
omacom:integration/aurorafrom
malik-na:pr/brcmfmac-irq-ready

Conversation

@malik-na

@malik-na malik-na commented Nov 5, 2026

Copy link
Copy Markdown
Member

On a MacBook Air (M1, 2020, J313) with BCM4378, brcmfmac can leave ring completions unserviced, including ioctl responses and the D3 ACK. They then time out.

Cause

brcmf_pcie_quick_check_isr() masks the dongle with brcmf_pcie_intr_disable() whenever it reads mailboxint non-zero. Since 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. So for exactly the interrupts the hard handler caught with mailboxint still set, the thread skips brcmf_proto_msgbuf_rx_trigger(), 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, the completions that came with that interrupt wait in the D2H rings until some later interrupt. This firmware sends mailbox data over the control ring (no BRCMF_PCIE_SHARED_USE_MAILBOX), so that includes the D3 ACK. brcmf_msgbuf_query_dcmd_len() and brcmf_pcie_pm_enter_D3() then time out, and the second aborts system suspend. In INTx mode the hard handler always clears irq_ready first, so the rings are never serviced from the thread at all.

Change

The hard handler masks the dongle without touching irq_ready, and the thread unmasks it only while irq_ready is set, without setting it. irq_ready is now controlled only by the code that sets the rings up and tears them down, which is what f04be34 meant it for.

Testing

Suspend stress through maclab on a MacBook Air (M1, 2020, J313): two lab builds from this tree at b798f2b, with the Mac's own config. Each ran 15 cycles of 25 s s2idle (woken by a timer) with Wi-Fi traffic in between, with PCIe ASPM L1.1/L1.2 on the Wi-Fi link (powersupersave, L1.2 timing as macOS programs it).

Kernel Job Result
unpatched 7.2.11-labb798f2b0-4585 j1105-104309-e433 brcmf_pcie_pm_enter_D3 timed out on the 4th suspend and suspend was aborted; omarchy-m-test regressed (failed systemd-suspend.service)
this patch 7.2.11-lab428772f0-1559 j1105-104457-32c5 the same, on the 4th suspend

This patch alone does not fix that failure. The firmware itself does not acknowledge D3 on every 4th suspend with the L1 substates on, and the stacked follow-up PR handles that. This PR fixes a separate, real loss of completions, found by reading the code and confirmed by two independent reviews. Both the 4th-suspend failure and the unacknowledged D3 are visible in dmesg either way.

The tested commit 428772f differs from this PR's commit only in the alignment of one continuation line (checkpatch.pl --strict). checkpatch's only remaining warning is that it cannot resolve the Fixes: commit id in a tree without that history; f04be34 is in integration/aurora.

Not tested:

  • INTx mode;
  • brcmfmac chips other than BCM4378, and other Apple Silicon machines.

🤖 Generated with Claude Code

…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")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Naeem Malik <[email protected]>
@joshuaswarren

Copy link
Copy Markdown

[Joshua's agent] Review of 3a936ed, read offline against base b798f2b. The cause and the fix read correctly to me.

In the base, quick_check_isr clears irq_ready through brcmf_pcie_intr_disable(), so the thread skips rx_trigger for completions the hard handler already saw. The gate from f04be34 was meant for MSIs that arrive while IRQs are disabled, not for this window. The new hard-handler line is a single MMIO write, so nothing sleeps there. I found no path where the new unmask rule leaves the dongle masked while it is up.

Two optional notes:

  1. brcmf_pcie_intr_disable/enable write irq_ready with plain stores, while the thread now reads it with READ_ONCE. Using WRITE_ONCE on the writers would keep KCSAN quiet.
  2. A completion that lands after the thread services the rings but before it unmasks may raise no MSI. The base has the same order, so this isn't new. Unmasking first and then calling brcmf_proto_msgbuf_rx_trigger() once more would close the gap, if the BCM4378 doesn't latch a masked MSI. We haven't tested that.

Your own A/B shows no behaviour change from #370 alone (the 4th-suspend failure is the same), so the evidence for this one is code reading.

@malik-na

Copy link
Copy Markdown
Member Author

@scottjones @chriskearney this one has been green and mergeable since 5 Nov with no approving review yet. Could one of you take a look when you have a moment? #371 sits on top of this one, so #370 should go in first. Thanks!

@scottjones scottjones 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.

Approving, thanks Naeem. The bug is real and this is the right fix.

In the base, the hard handler's brcmf_pcie_intr_disable() clears irq_ready, so the thread skips brcmf_proto_msgbuf_rx_trigger() for exactly the interrupts where it saw mailboxint set, then sets irq_ready again on the way out. Mainline brcmfmac has no irq_ready, so this came in with f04be34. Masking the dongle directly in the hard handler and leaving irq_ready to setup and teardown fixes it. It also stops the thread turning irq_ready back on while reset or release_irq is tearing things down.

The case is stronger than the description says. On legacy INTx the hard handler only wakes the thread when mailboxint is set, so in the base the rings were never serviced at all. Apple Silicon uses MSI, so that path doesn't affect us, but it makes the bug plainer.

It builds clean with the package config (compile-check, W=1, no new warnings), and check-commits passes. Nothing in tools/ exercises this path, so as the description says, the support is code reading rather than a test.

One follow-up I'd like, though it's optional and doesn't block the merge: in brcmf_pcie_intr_enable(), set irq_ready with WRITE_ONCE before the mailboxmask write, so it pairs with the READ_ONCE you added. Right now the mask is written first. With CONFIG_PREEMPT, if the interrupt lands on the same CPU in that gap, the FIFO IRQ thread can run first, see irq_ready false, and leave the dongle masked, where the old code always unmasked. In MSI mode the next MSI should recover it (f04be34 says MSIs still arrive while masked), and the window is tiny. But the base couldn't get stuck masked, and it's a two-line change, so I'd fold it into this PR if you're happy to. A separate PR is fine too.

@scottjones
scottjones added this pull request to the merge queue Nov 14, 2026
Merged via the queue into omacom:integration/aurora with commit 0e6ac99 Nov 14, 2026
14 checks passed
scottjones added a commit to scottjones/omarchy-pkgs that referenced this pull request Nov 18, 2026
omacom/linux-aurora carry/edgeB-7.3 (tag edgeB3) 54835f485826: edgeB2 plus
aurora-silicon/linux#1598 (T8122 SPI2 input and SPI4 reference clocks),
the J613 Touch ID data-ready line, and omacom/linux-aurora#370 (brcmfmac
ring completions). The M3 Air's Touch ID works again: the SPI2 clock was
described as 200 MHz, so the sensor frame missed its transfer budget.

Mesa and aura are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scottjones added a commit to scottjones/omarchy-pkgs that referenced this pull request Nov 20, 2026
Sync the kernel and Mesa to today's Aurora tips, with our carries
re-applied:

- linux-aurora 7.3.0.aurora0testedgeC: omacom/linux-aurora tag edgeC
  (carry/aurora-7.3) e50bdd5dea6f, aurora-silicon/linux integration/aurora
  de2c29696952 plus our open PRs omacom#2145 to omacom#2156 and omacom#2199, omacom#1598, the J613
  Touch ID data-ready line and omacom/linux-aurora#370. Config unchanged.
- mesa-aurora and vulkan-aurora: omacom/mesa tag edgeC (carry/aurora-7.3)
  fb3b11e121c, aurora-wip 45963937b6f0 plus aurora-silicon/mesa omacom#415 and
  omacom#416.

aura stays at edgeB2 (703a0a92). Lab-tested on the M3 Air, MacBook Neo,
M4 Pro (J616s) and M2 Max (J414c).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

3 participants