Skip to content

wifi: apple: centauri: stop each function's DMA before freeing its buffers - #3207

Merged
RyanTheTide merged 2 commits into
mainfrom
fix/centauri-stop-dma-before-free
Nov 28, 2026
Merged

RyanTheTide merged 2 commits into
mainfrom
fix/centauri-stop-dma-before-free

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What: The N1 restart and removal paths freed every buffer the firmware can write right after clearing Bus Master, while the function's earlier writes could still be on their way. Now each function's command register is read back and its pending transactions waited for first, the same way the T6050 driver does it. If a function can't be stopped, all buffers are kept and the restart is retried later.

Tested: The changed objects build with W=1 on an arm64 16K-page config at d14a25a36d6c. No hardware row yet.

Risk: two-way · Macs whose N1 radio runs on the native driver: J813, J815, J873.

Not yet: A row on a J813, J815 or J873: a forced restart, Wi-Fi traffic, then a sleep. The J714s uses the T6050 driver, which never reaches this code.

Details
  • centauri_stop_dma() clears Bus Master, reads PCI_COMMAND back, checks that Bus Master really is clear, and calls pci_wait_for_pending_transaction(). The read returns only after the function's earlier posted writes.
  • centauri_stop_ipc() frees the IPC interrupts, unregisters Wi-Fi, disables MSI and clears Bus Master on all three functions, then stops each one.
  • centauri_free_boot() then disables the boot MSI and stops function 0's boot DMA. Only if both stops succeeded does it free anything: the IPC buffers (centauri_free_ipc()), the firmware image, the boot descriptor and the MSI page. Otherwise it returns false and keeps all of them.
  • centauri_recover() doesn't run the port cycle and warm reset while buffers are still held. It returns -EBUSY, and the worker's existing retry (10 s, at most three restarts in 30 minutes) tries again. A later call starts by stopping the DMA again.
  • If removal can't stop the DMA, the buffers stay allocated rather than being freed under a live device.
  • The T6050 driver already does this, in centauri_t6050_stop_dma() and centauri_t6050_ipc_fenced().
  • How to force a restart for the row: echo 5 > /sys/kernel/debug/apple_centauri/<pci>/rom_boot (the debugfs stall injection already in the driver).
Evidence
  • ./linux-build/build kernel linux-pciewifi-fixes -- -j3 W=1 drivers/net/wireless/apple/centauri/centauri_pci.o drivers/net/wireless/apple/centauri/centauri_ipc.o with CONFIG_ARM64_16K_PAGES=y, CONFIG_APPLE_CENTAURI=m: no warnings.
  • scripts/checkpatch.pl --strict: clean.
  • Base: 40e5e29cc915.

…ffers

A restart, and removal, clear Bus Master on the N1's functions and free
every buffer the firmware can write right after. Clearing Bus Master
only stops new requests: writes a function issued before it can still
be on their way.

Before any buffer is freed, read each function's command register back
after clearing Bus Master, which returns after the function's earlier
posted writes, and wait for its pending transactions; the same for the
boot DMA. If a function cannot be stopped, keep all the buffers. A
restart is then not attempted, and the worker tries again in 10 s
within its usual limit; removal leaves them allocated.

The T6050 driver already does this in centauri_t6050_stop_dma().

Fixes: efa93c2 ("wifi: apple: add hardware-qualified N1 driver and J813 workbench")
Fixes: 47706b5 ("wifi: apple: centauri: restart a stopped N1 firmware without a reboot")
Signed-off-by: Dj <[email protected]>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners November 26, 2026 07:51
… both stopped

The previous change freed the IPC buffers as soon as the IPC functions
had stopped, before the boot DMA's stop was checked. Split stopping the
IPC from freeing it, so a failed stop of either keeps every buffer.

Signed-off-by: Dj <[email protected]>
@github-actions github-actions Bot added ci-failing A check failed at the PR head (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 Nov 26, 2026
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Merge readiness at d14a25a3: not ready yet

Check Detail
CI at head no failing: pr-text / pr-text
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head ok comment at d14a25a3
Conflicts ok none
PR text ok Risk: two-way · Macs whose N1 radio runs on the native driver: J813, J815, J873.

Areas: none matched in CODEOWNERS

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

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Verdict at d14a25a36d6c: ready (code); the J813, J815 or J873 restart row listed under "Not yet" is still owed before merge

Blockers: none

Checked

  • centauri_stop_dma() (centauri_ipc.c:571) clears Bus Master, reads PCI_COMMAND back, and refuses if Bus Master still reads set (all-ones included). Then it waits on pci_wait_for_pending_transaction(). The config-read completion can't pass the function's earlier posted writes, so once it returns those writes have landed. This matches centauri_t6050_stop_dma().
  • Nothing is freed until both stops succeed: centauri_stop_ipc() for all three functions, then the boot DMA on function 0 in centauri_free_boot(). Otherwise the IPC buffers, firmware image, descriptor and MSI page are all kept, and centauri_free_ipc() only runs after both.
  • A retry is safe to repeat. free_vectors() counts vectors[] down to 0, centauri_wifi_unregister() was already called twice on the remove path, MSI disable and clearing Bus Master are idempotent, and c->ipc stays set, so the worker's restart_failed retry runs again under the existing three-in-30-minutes limit. centauri_recover() returns -EBUSY before the port cycle and warm reset, so nothing is reset under live buffers.
  • Removal and the probe failure path keep the buffers allocated when the stop fails, instead of freeing them under a live device.
  • No runtime switches, no new constants, and no SoC or board gates.

Not a blocker: if the link has really dropped, the config read returns all-ones, so the stop counts as failed and the restart never runs. Without a link, the function can't write either. Today that leaves Wi-Fi down until a reboot, where before the port cycle might have brought it back. If that shows up in the row, the root port's link state (no Data Link Layer Link Active) could count as stopped.

Evidence
  • make W=1 drivers/net/wireless/apple/centauri/centauri_pci.o drivers/net/wireless/apple/centauri/centauri_ipc.o (asahi profile, 16K pages, LLVM=1, arm64) at d14a25a36d6c: builds, no warnings.
  • checkpatch.pl --strict on both commits: clean.
  • CI host tests at this head: pass.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label Nov 26, 2026
@sithglan

Copy link
Copy Markdown
Contributor

J813 (Apple MacBook Air 13-inch, M5 / T8142) row at exact head d14a25a36d6c: PASS.

  • Boot: guarded one-shot aura-try (7.3.0-aurora-j813-pr3207+, default J813 cmdline, btcentauri preloaded before rom_boot=3 to avoid the pre-wifi: apple: centauri: enable function memory space before polling Beta BAR0 #3373 fn2 BAR0 panic); Wi-Fi associated cleanly and hci0 came up.
  • Forced N1 recovery (echo 5 > /sys/kernel/debug/apple_centauri/0000:01:00.0/rom_boot): recovery: stage 0x2, releasing the firmware's buffers -> stage 0x0 after the warm reset -> post-reset execution stage=0x1 -> recovery: IPC start 0 -> restarted; Bluetooth function attach: 1; Wi-Fi re-associated and hci0 returned UP RUNNING.
  • Throughput (iperf3, 220 MB each direction over local Wi-Fi AP, vs main deb2df2a9e2b + wifi: apple: centauri: enable function memory space before polling Beta BAR0 #3373 baseline on the same Mac & AP):
    • d14a25a36d6c: TX 73.3 MB/s (0 retransmits), RX 16.9 MB/s
    • Baseline (main): TX 55.0 MB/s (0 retransmits), RX 4.78 MB/s
  • Deep sleep (mem, 8 s PMU alarm wake): rc=0, suspend_stats/success 0->1, fail=0, elapsed 8.64 s (back from sleep, boot object resumes 0 -> 1, NUB.SPMI0.SW3, Alpha ACIPC host wake: ret=0, apple_sep back from sleep); post-wake gateway ping 3/3 0% loss (5.1 ms avg) and hci0 UP RUNNING.
  • Counts & restore: 0 DART faults, 0 "retaining DMA buffers" lines, 0 new kernel errors vs baseline, 0 failed units. boot-pr3207 removed from ESP and J813 rebooted back to default 7.3.0-aurora-j813-main+ (0 failed units).

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

Non-author review at d14a25a36d6c: READY on the code, 0 blockers.

  • centauri_stop_dma(): it clears Bus Master, reads PCI_COMMAND back and requires Bus Master clear, then waits for pending transactions. A dead link reads back all ones, so the stop reports failure and the buffers are kept. That's the right default.
  • Ordering:
    • centauri_stop_ipc() takes over the vector, Wi-Fi, MSI and Bus Master teardown, then stops each function.
    • centauri_free_boot() frees the IPC buffers, the firmware image, the descriptor and the MSI page only after both the IPC stop and function 0's boot-DMA stop succeed. Otherwise it keeps them and returns false.
    • Every buffer free now goes through that path. centauri_start_ipc()'s failure path still leaves its DMA pinned.
  • Retries:
    • centauri_recover() returns -EBUSY while buffers are held, and the existing worker retry runs the stop again.
    • A second centauri_stop_ipc() on the same ipc is safe: free_vectors() counts vectors[i] down to 0, and centauri_wifi_unregister() returns early once Wi-Fi is gone.
    • All paths are sleepable (worker, remove, debugfs), which pci_wait_for_pending_transaction() needs.
  • Overlap with wifi: apple: centauri: enable function memory space before polling Beta BAR0 #3373: both touch centauri_ipc.c. They merge cleanly in either order, and wifi: apple: centauri: enable function memory space before polling Beta BAR0 #3373's pci_disable_device() in centauri_free_ipc() then runs only after the DMA has stopped.
  • Checks: checkpatch.pl --strict is 0/0/0 on both commits. Both are signed off, with no attribution, and the branch merges cleanly onto current main.
  • CI at this head: 2/3 checks pass, 0 pending, failing: readiness / readiness.
    • drivers/net/wireless/apple isn't in the Apple build workflow's path filter, so no CI build covers this driver. The exact-head J813 kernel (7.3.0-aurora-j813-pr3207+) is the build evidence.
    • The failing check is the readiness bot from 11-26, not a code check.
  • Hardware: the J813 row at this head (#issuecomment-7215554519) covers the forced restart, Wi-Fi traffic and deep sleep, with 0 retained-buffer lines. The PR body's "No hardware row yet" is now out of date.
  • Owed before merge: a J873 (T8152) row as the second-generation check, since centauri_ipc.c is shared. J714s isn't needed: the T6050 driver never reaches this code.

@sithglan

Copy link
Copy Markdown
Contributor

J873g (Apple Mac mini, M6 / T8152) peer row at exact head d14a25a36d6c: PASS.

  • Baseline: 7.3.0-aurora-j873-main+ (065904c137fa) on the same J873g and local 5 GHz AP (iperf3 220 MBytes each direction bound to wlp1s0f0, verified 230 MiB TX / 230 MiB RX on interface counters): TX 27.5 MB/s (5 retr), RX 20.0 MB/s (71 retr).
  • Trial boot: guarded one-shot aura-try (7.3.0-aurora-j873-pr3207+, default J873g cmdline); Wi-Fi associated cleanly (wlp1s0f0 UP).
  • Throughput (iperf3, 220 MBytes each direction over wlp1s0f0, verified 230 MiB TX / 230 MiB RX on interface counters): TX 27.5 MB/s (3 retr), RX 16.9 MB/s (595 retr).
  • DMA-fence & buffer-free exercise: t8152-j873-n1.dtsi does not yet carry apple,warm-reset-writes, so c->warm_reset is false on J873g (rom_boot=4 returns -EOPNOTSUPP and rom_boot=5 returns early without restarting; forced warm-reset restart + deep sleep is covered on J813 above). Exercised the #3207 centauri_free_boot() -> centauri_stop_ipc() -> centauri_stop_dma() -> centauri_free_ipc() path live via modprobe -r apple_centauri under active Wi-Fi association: Bus Master cleared on all three N1 functions (0000:01:00.0 0006 -> 0002, 0000:01:00.1 0406 -> 0002, 0000:01:00.2 0002 -> 0002). Sleep/wake is N/A on J873g (/sys/power/state empty).
  • Counts & restore: 0 DART faults, 0 "retaining DMA buffers" lines, 0 new kernel errors/warnings, 0 failed units. Trial kernel and aura-try removed from ESP; J873g verified back on default 7.3.0-aurora-j873-main+ (12 CPUs, Wi-Fi + hci0 up, 0 failed units).

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at d14a25a3 (once cancelled CI checks are rerun green)

Blockers: none (code and two-generation exact-head hardware rows are ready; rerun the 3 cancelled CI checks before merge).

Checked:

  • drivers/net/wireless/apple/centauri/centauri_ipc.c:28-66: verified centauri_stop_dma() clears Bus Master, reads PCI_COMMAND back and fails if read fails or PCI_COMMAND_MASTER remains set (covering dead links reading 0xffff), and calls pci_wait_for_pending_transaction(pdev).
  • drivers/net/wireless/apple/centauri/centauri_pci.c:99-140: verified centauri_free_boot() calls both centauri_stop_ipc(c) and centauri_stop_dma(c->pdev) (with centauri_stop_dma(c->pdev) first in || so it is never short-circuited), retains all IPC and boot DMA buffers on any stop failure, and centauri_recover() returns -EBUSY without resetting when !centauri_free_boot(c).
  • Verified exact-head (d14a25a36d6c) hardware rows on both J813 (M5/T8142, including forced N1 recovery) and J873g (M6/T8152, iperf3 TX/RX PASS).
Evidence
  • Diff reviewed at d14a25a3 (all 3 files, 143 lines).
  • CI at review time: 2 passed, 0 failed, 3 cancelled.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merge-train status at d14a25a3 (App approval noted; rows: 3 cancelled; J813 + J873g exact-head PASS). @DjDeveloperr code-owner ping (6-point rule, point 6): merge earliest 17:15 AEDT once full CI is green (I re-ran cancelled jobs) and the second-family row point holds. Revert: git revert -m 1 <merge>.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Merging under the 6-point rule (Ryan 09:29, permanent), at d14a25a3. (1) The review App approved at this head. (2) Full CI is green. (3/4) Rows: J813+J873g. (5) There's no blocking review. (6) Dj was pinged here 61 min ago with no objection. Revert: git revert -m 1 <merge>.

@RyanTheTide
RyanTheTide merged commit f5d7392 into main Nov 28, 2026
3 of 7 checks passed
@RyanTheTide
RyanTheTide deleted the fix/centauri-stop-dma-before-free branch November 28, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants