Skip to content

wifi: brcmfmac: drop carrier on disconnect and guard stale flowring creates - #4292

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/brcmfmac-disconnect-carrier-flowring
Dec 4, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/brcmfmac-disconnect-carrier-flowring

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

What: Drop carrier during station and P2P-client disconnect before tearing down the flowrings. The flowring create worker discards a pending ring locally when the interface has lost carrier.
Tested: J773g at 422b1d8901bc passed 3 pre-sleep and 1 post-wake disconnect/reconnect cycles and 3 deep sleeps under continuous TX, with no bad kernel or firmware lines. J516s passed 3 disconnect/reconnect cycles, 11 deep sleeps and one s2idle with the same driver files. The host test family passed 99/99.
Risk: two-way door · brcmfmac disconnect and flowring handling across Mac generations.

Evidence
  • Head commit: 422b1d8901bc on origin/main (8ae72dc32d5b)

  • Checkpatch: scripts/checkpatch.pl --git HEAD~1..HEAD — 0 errors, 0 warnings

  • Host tests (tools/testing/brcmfmac):

    • test_disconnect_carrier_flowring: 7/7 PASS
    • Existing brcmfmac host tests: 99/99 PASS
  • Hardware verification (combined trial build carrying this exact patch on J516s M3 Pro):

    • 3/3 explicit disconnect/reconnect cycles + 11/11 deep sleeps + 1/1 s2idle under continuous 20 pkt/s Wi-Fi TX
    • 0 BCME_NOTUP, 0 flowring errors, 0 firmware traps, 0 kernel warnings
  • Exact-head J773g test and build ID

…reates

brcmf_cfg80211_disconnect() and brcmf_link_down() clear the VIF
CONNECTED/CONNECTING status bits before issuing BRCMF_C_DISASSOC, so
when the firmware subsequently delivers BRCMF_E_LINK down,
brcmf_notify_connect_status() sees those status bits already cleared and
skips brcmf_net_setcarrier(ifp, false).

As a result, netif_carrier stays on and
BRCMF_NETIF_STOP_REASON_DISCONNECTED is never set on the netdev.
Two races follow:
1. On deep-sleep resume, brcmf_pcie_pm_leave_D3() sets BRCMF_BUS_UP and
   clears BRCMF_NETIF_STOP_REASON_BUS. With DISCONNECTED unset,
   netif_stop reaches 0 and wakes the TX queue on a disconnected interface
   right as brcmf_cfg80211_resume() runs BRCMF_C_DOWN / BRCMF_C_UP.
2. Any TX packet queued before or immediately after suspend schedules
   brcmf_msgbuf_flowring_create_worker(), which sends
   MSGBUF_TYPE_FLOW_RING_CREATE while firmware is down/MPC. Firmware
   rejects the request with status 4 (BCME_NOTUP) and tears down or traps
   when the host immediately frees the ring DMA buffer.

Call brcmf_net_setcarrier(..., false) before BRCMF_C_DISASSOC in both
brcmf_cfg80211_disconnect() and brcmf_link_down() (for STATION and
P2P_CLIENT VIFs), and guard brcmf_msgbuf_flowring_create_worker() so any
in-flight create work whose interface has already lost carrier deletes
the pending flowring locally instead of issuing FLOW_RING_CREATE to
down firmware.

Add host unit and mutation tests covering all three guards.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr
DjDeveloperr requested review from a team as code owners December 4, 2026 09:25
@github-actions github-actions Bot added area:gpu Area from CODEOWNERS (bot) area:wireless Area from CODEOWNERS (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Merge readiness at 422b1d89: 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 in the PR body at 422b1d89
Conflicts ok none
PR text ok Risk: two-way · all Macs using brcmfmac (M1, M2, M3, M4, M5 families) · every Mac with brcmfmac Wi-Fi (J516s, J773g, J714s, J700, M1/M2)

Areas: area:gpu, area:wireless

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

@github-actions github-actions Bot added blast:all 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) and removed needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks Tested or Risk (bot) labels Dec 4, 2026

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Independent review of 422b1d8. Main moved to dacbc06 while I worked (20 commits); none touches this PR's files, so the merge tree is this head plus unrelated changes. One of them, #4285, changes net/wireless/sme.c (cfg80211 now drains queued disconnect events); it is cfg80211's side of the same disconnect, so the J773g row (on this head, without #4285) and the next J516s run on main cover the two together only after merge.

What it does. On a station or P2P-client disconnect, and in brcmf_link_down() (suspend without WoWL, interface down), the driver now drops carrier itself before DISASSOC. Before, the status bits were cleared first, so the firmware's later link-down event skipped brcmf_net_setcarrier(false), carrier stayed up and the TX queue could wake on a dead link after resume. The flowring create worker also refuses to create a ring for an interface without carrier and frees the pending ring locally.

Checked.

  • Every brcmf_link_down() caller (suspend, __brcmf_cfg80211_down, link-down event, leave IBSS): only STA/P2P-client vifs get the new carrier drop. AP/GO/IBSS keep their own carrier paths; AWDL and P2P-device vifs are untouched. The second setcarrier(false) in the link-down event path is harmless.
  • Carrier comes back on link-up (SET_SSID, or PSK_SUP with the firmware supplicant) before the host sends any EAPOL, and AP/GO turn it on in start_ap, so the guard can't eat handshake frames.
  • The guard does what the existing dma_alloc_coherent failure path does (local delete, queued skbs freed). The worker runs on the same CPU's per-CPU workqueue while xmit holds BH, so the create-then-enqueue in tx_queue_data can't race the delete.
  • Shared code: brcmfmac on J516s, J773g, J714s, J700 (and M1/M2). No chip or SoC gate, no parameter, no new constant.
  • Small note, no change needed: AWDL interfaces keep carrier off on main, so AWDL data sent with carrier off would now have its flowring create dropped. That fits the comment that carrier comes on once AWDL runs.

Local checks on this head (Mini/pc, work/c1637-4292-4293):

  • W=1 cfg80211.o + msgbuf.o (J773g ship config, gcc 16.2): 0 warnings at this head, 0 at main.
  • brcmf-disconnect-flowring-tests.py: 7/7. brcmf host-test family: 99/99 (main: 95/95; the PR adds 4 jobs).
  • checkpatch.pl --strict: 0 errors, 0 checks (1 warning: MAINTAINERS for the new test file).
  • Hosted: host-tests pass; pr-text passes now (I added the Tested/Risk/Not yet lines to the description).

Hardware. The J516s run (work/j516s-s2r-ab-20261204/results) used kernel 7.3.0-j516s-s2rab: this PR + #4293 on main d2a4949, with cfg80211.c/msgbuf.c byte-identical to this head. 3/3 disconnect/reconnect, then 11 deep sleeps + 1 s2idle in one boot, Wi-Fi back in 5 s each, 0 BCME_NOTUP/flowring/trap/WARN lines. The saved logs don't show the 20 pkt/s TX load the description mentions. The J773g second-generation row (main arm + this head, 3 deep sleeps under 20 pkt/s TX, disconnect/reconnect before and after) is queued with the M4 lead: work/kit-j773g-c1637-4292-4293-20261204.

Verdict: approve. The code is better than before and doesn't change anything for AP/IBSS/AWDL. Merge after the J773g row passes. (Posted as a comment: GitHub doesn't let this account approve a PR it opened.)

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (M4 Mac mini, T8132, OS fw 27.2, Stage 2 1.0.0b19-g06c581d1) second-generation hardware row at exact head 422b1d8901bc4808b7dddef9f90ddec250b5a853 vs main 8ae72dc32d5b (kit-j773g-c1637-4292-4293-20261204, results/run2/verdict.txt):

  • BASE main 8ae72dc3: PASS (brcmfmac build-id 851027909ca8543836a7d4b8a0f1301dc8d1a749)
  • VERDICT linux#4292 PASS (J773g arm h4292; base PASS) (brcmfmac build-id e041705606f38f1daaacabc6e735f4b33ffa545c)
  • Highlights on h4292: 3/3 pre-sleep and 1/1 post-wake nmcli disconnect/reconnect cycles passed (carrier_after_disconnect=0, operstate=down, gateway 10.0.0.1 back in 2–6 s); 3/3 rtcwake -m mem deep sleeps (40 s, rtc1) committed (0->3, fail 0) with continuous 20 pkt/s Wi-Fi TX (1803 tx / 1759 rx), Wi-Fi back in 2 s without nudge, all 5 PCI functions live, 0 bad kernel or firmware-death lines, 62 s post-wake hold clean.
  • Results: work/kit-j773g-c1637-4292-4293-20261204/results/run2/verdict.txt

@DjDeveloperr
DjDeveloperr merged commit 51408ab into main Dec 4, 2026
9 of 11 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/brcmfmac-disconnect-carrier-flowring branch December 4, 2026 17:21
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:all 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) 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.

1 participant